]> git.sesse.net Git - vlc/blob - src/misc/beos_specific.cpp
dfcdb1c3b9fd634cad88b64af7b15c602a9f8608
[vlc] / src / misc / beos_specific.cpp
1 /*****************************************************************************
2  * beos_init.cpp: Initialization for BeOS specific features 
3  *****************************************************************************
4  * Copyright (C) 1999, 2000 VideoLAN
5  * $Id: beos_specific.cpp,v 1.10 2001/04/29 17:03:20 sam Exp $
6  *
7  * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  * 
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23 #include "defs.h"
24
25 #include <Application.h>
26 #include <Roster.h>
27 #include <Path.h>
28 #include <Alert.h>
29 #include <stdio.h>
30 #include <string.h> /* strdup() */
31 #include <malloc.h>   /* free() */
32
33 extern "C"
34 {
35 #include "config.h"
36 #include "common.h"
37 #include "threads.h"
38 #include "mtime.h"
39 }
40 #include "beos_specific.h"
41
42 /*****************************************************************************
43  * The VlcApplication class
44  *****************************************************************************/
45 class VlcApplication : public BApplication
46 {
47 public:
48     VlcApplication(char* );
49     ~VlcApplication();
50
51     virtual void ReadyToRun();
52     virtual void AboutRequested();
53 };
54
55 /*****************************************************************************
56  * Static vars
57  *****************************************************************************/
58 static vlc_thread_t app_thread;
59 static vlc_mutex_t  app_lock;
60 static vlc_cond_t   app_wait;
61 static char        *psz_program_path;
62
63 extern "C"
64 {
65
66 /*****************************************************************************
67  * Local prototypes.
68  *****************************************************************************/
69 static void system_AppThread( void * args );
70
71 /*****************************************************************************
72  * system_Create: create a BApplication object and fill in program path.
73  *****************************************************************************/
74 void system_Create( int *pi_argc, char *ppsz_argv[], char *ppsz_env[] )
75 {
76     /* Prepare the lock/wait before launching the BApplication thread */
77     vlc_mutex_init( &app_lock );
78     vlc_cond_init( &app_wait );
79     vlc_mutex_lock( &app_lock );
80
81     /* Create the BApplication thread */
82     vlc_thread_create( &app_thread, "app thread",
83                        (vlc_thread_func_t)system_AppThread, 0 );
84
85     /* Wait for the application to be initialized */
86     vlc_cond_wait( &app_wait, &app_lock );
87     vlc_mutex_unlock( &app_lock );
88
89     /* Destroy the locks */
90     vlc_mutex_destroy( &app_lock );
91     vlc_cond_destroy( &app_wait );
92 }
93
94 /*****************************************************************************
95  * system_Destroy: destroy the BApplication object.
96  *****************************************************************************/
97 void system_Destroy( void )
98 {
99     free( psz_program_path );
100
101     /* Tell the BApplication to die */
102     be_app->PostMessage( B_QUIT_REQUESTED );
103     vlc_thread_join( app_thread );
104 }
105
106 /*****************************************************************************
107  * system_GetProgramPath: get the full path to the program.
108  *****************************************************************************/
109 char * system_GetProgramPath( void )
110 {
111     return( psz_program_path );
112 }
113
114 /* following functions are local */
115
116 /*****************************************************************************
117  * system_AppThread: the BApplication thread.
118  *****************************************************************************/
119 static void system_AppThread( void * args )
120 {
121     VlcApplication *BeApp = new VlcApplication("application/x-vnd.Ink-vlc");
122     BeApp->Run();
123     delete BeApp;
124 }
125
126 } /* extern "C" */
127
128 /*****************************************************************************
129  * VlcApplication: application constructor
130  *****************************************************************************/
131 VlcApplication::VlcApplication( char * psz_mimetype )
132                :BApplication( psz_mimetype )
133 {
134     /* Nothing to do, we use the default constructor */
135 }
136
137 /*****************************************************************************
138  * ~VlcApplication: application destructor
139  *****************************************************************************/
140 VlcApplication::~VlcApplication( )
141 {
142     /* Nothing to do, we use the default destructor */
143 }
144
145 /*****************************************************************************
146  * AboutRequested: called by the system on B_ABOUT_REQUESTED
147  *****************************************************************************/
148 void VlcApplication::AboutRequested( )
149 {
150         BAlert *alert;
151         alert = new BAlert( VOUT_TITLE, "BeOS " VOUT_TITLE "\n\n<www.videolan.org>", "Ok" );
152         alert->Go( NULL );
153 }
154
155 /*****************************************************************************
156  * ReadyToRun: called when the BApplication is initialized
157  *****************************************************************************/
158 void VlcApplication::ReadyToRun( )
159 {
160     BPath path;
161     app_info info; 
162
163     /* Get the program path */
164     be_app->GetAppInfo( &info ); 
165     BEntry entry( &info.ref ); 
166     entry.GetPath( &path ); 
167     path.GetParent( &path );
168     psz_program_path = strdup( path.Path() );
169
170     /* Tell the main thread we are finished initializing the BApplication */
171     vlc_mutex_lock( &app_lock );
172     vlc_cond_signal( &app_wait );
173     vlc_mutex_unlock( &app_lock );
174 }
175