]> git.sesse.net Git - vlc/blob - src/misc/beos_specific.cpp
36d287f3129efd87d8d6d2c33c096147f2fe077c
[vlc] / src / misc / beos_specific.cpp
1 /*****************************************************************************
2  * beos_init.cpp: Initialization for BeOS specific features 
3  *****************************************************************************
4  * Copyright (C) 1999-2001 VideoLAN
5  * $Id: beos_specific.cpp,v 1.18 2002/04/26 05:43:37 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 <Application.h>
24 #include <Roster.h>
25 #include <Path.h>
26 #include <Alert.h>
27 #include <stdio.h>
28 #include <string.h> /* strdup() */
29 #include <malloc.h>   /* free() */
30
31 extern "C"
32 {
33 #include <videolan/vlc.h>
34 }
35
36 /*****************************************************************************
37  * The VlcApplication class
38  *****************************************************************************/
39 class VlcApplication : public BApplication
40 {
41 public:
42     VlcApplication(char* );
43     ~VlcApplication();
44
45     virtual void ReadyToRun();
46     virtual void AboutRequested();
47 };
48
49 /*****************************************************************************
50  * Static vars
51  *****************************************************************************/
52 static vlc_thread_t app_thread;
53 static vlc_mutex_t  app_lock;
54 static vlc_cond_t   app_wait;
55 static char        *psz_program_path;
56
57 extern "C"
58 {
59
60 /*****************************************************************************
61  * Local prototypes.
62  *****************************************************************************/
63 static void system_AppThread( void * args );
64
65 /*****************************************************************************
66  * system_Init: create a BApplication object and fill in program path.
67  *****************************************************************************/
68 void system_Init( int *pi_argc, char *ppsz_argv[], char *ppsz_env[] )
69 {
70     /* Prepare the lock/wait before launching the BApplication thread */
71     vlc_mutex_init( &app_lock );
72     vlc_cond_init( &app_wait );
73     vlc_mutex_lock( &app_lock );
74
75     /* Create the BApplication thread */
76     vlc_thread_create( &app_thread, "app thread",
77                        (vlc_thread_func_t)system_AppThread, 0 );
78
79     /* Wait for the application to be initialized */
80     vlc_cond_wait( &app_wait, &app_lock );
81     vlc_mutex_unlock( &app_lock );
82
83     /* Destroy the locks */
84     vlc_mutex_destroy( &app_lock );
85     vlc_cond_destroy( &app_wait );
86 }
87
88 /*****************************************************************************
89  * system_Configure: check for system specific configuration options.
90  *****************************************************************************/
91 void system_Configure( void )
92 {
93
94 }
95
96 /*****************************************************************************
97  * system_End: destroy the BApplication object.
98  *****************************************************************************/
99 void system_End( void )
100 {
101     free( psz_program_path );
102
103     /* Tell the BApplication to die */
104     be_app->PostMessage( B_QUIT_REQUESTED );
105     vlc_thread_join( app_thread );
106 }
107
108 /*****************************************************************************
109  * system_GetProgramPath: get the full path to the program.
110  *****************************************************************************/
111 char * system_GetProgramPath( void )
112 {
113     return( psz_program_path );
114 }
115
116 /* following functions are local */
117
118 /*****************************************************************************
119  * system_AppThread: the BApplication thread.
120  *****************************************************************************/
121 static void system_AppThread( void * args )
122 {
123     VlcApplication *BeApp = new VlcApplication("application/x-vnd.Ink-vlc");
124     BeApp->Run();
125     delete BeApp;
126 }
127
128 } /* extern "C" */
129
130 /*****************************************************************************
131  * VlcApplication: application constructor
132  *****************************************************************************/
133 VlcApplication::VlcApplication( char * psz_mimetype )
134                :BApplication( psz_mimetype )
135 {
136     /* Nothing to do, we use the default constructor */
137 }
138
139 /*****************************************************************************
140  * ~VlcApplication: application destructor
141  *****************************************************************************/
142 VlcApplication::~VlcApplication( )
143 {
144     /* Nothing to do, we use the default destructor */
145 }
146
147 /*****************************************************************************
148  * AboutRequested: called by the system on B_ABOUT_REQUESTED
149  *****************************************************************************/
150 void VlcApplication::AboutRequested( )
151 {
152     BAlert *alert;
153     alert = new BAlert( VOUT_TITLE,
154                         "BeOS " VOUT_TITLE "\n\n<www.videolan.org>",
155                         "Ok" );
156     alert->Go( NULL );
157 }
158
159 /*****************************************************************************
160  * ReadyToRun: called when the BApplication is initialized
161  *****************************************************************************/
162 void VlcApplication::ReadyToRun( )
163 {
164     BPath path;
165     app_info info; 
166
167     /* Get the program path */
168     be_app->GetAppInfo( &info ); 
169     BEntry entry( &info.ref ); 
170     entry.GetPath( &path ); 
171     path.GetParent( &path );
172     psz_program_path = strdup( path.Path() );
173
174     /* Tell the main thread we are finished initializing the BApplication */
175     vlc_mutex_lock( &app_lock );
176     vlc_cond_signal( &app_wait );
177     vlc_mutex_unlock( &app_lock );
178 }
179