]> git.sesse.net Git - vlc/blob - src/misc/beos_specific.cpp
* ./plugins/beos/vout_beos.cpp: ported the BeOS RGB video output to
[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.17 2002/02/08 15:57:29 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_End: destroy the BApplication object.
90  *****************************************************************************/
91 void system_End( void )
92 {
93     free( psz_program_path );
94
95     /* Tell the BApplication to die */
96     be_app->PostMessage( B_QUIT_REQUESTED );
97     vlc_thread_join( app_thread );
98 }
99
100 /*****************************************************************************
101  * system_GetProgramPath: get the full path to the program.
102  *****************************************************************************/
103 char * system_GetProgramPath( void )
104 {
105     return( psz_program_path );
106 }
107
108 /* following functions are local */
109
110 /*****************************************************************************
111  * system_AppThread: the BApplication thread.
112  *****************************************************************************/
113 static void system_AppThread( void * args )
114 {
115     VlcApplication *BeApp = new VlcApplication("application/x-vnd.Ink-vlc");
116     BeApp->Run();
117     delete BeApp;
118 }
119
120 } /* extern "C" */
121
122 /*****************************************************************************
123  * VlcApplication: application constructor
124  *****************************************************************************/
125 VlcApplication::VlcApplication( char * psz_mimetype )
126                :BApplication( psz_mimetype )
127 {
128     /* Nothing to do, we use the default constructor */
129 }
130
131 /*****************************************************************************
132  * ~VlcApplication: application destructor
133  *****************************************************************************/
134 VlcApplication::~VlcApplication( )
135 {
136     /* Nothing to do, we use the default destructor */
137 }
138
139 /*****************************************************************************
140  * AboutRequested: called by the system on B_ABOUT_REQUESTED
141  *****************************************************************************/
142 void VlcApplication::AboutRequested( )
143 {
144     BAlert *alert;
145     alert = new BAlert( VOUT_TITLE,
146                         "BeOS " VOUT_TITLE "\n\n<www.videolan.org>",
147                         "Ok" );
148     alert->Go( NULL );
149 }
150
151 /*****************************************************************************
152  * ReadyToRun: called when the BApplication is initialized
153  *****************************************************************************/
154 void VlcApplication::ReadyToRun( )
155 {
156     BPath path;
157     app_info info; 
158
159     /* Get the program path */
160     be_app->GetAppInfo( &info ); 
161     BEntry entry( &info.ref ); 
162     entry.GetPath( &path ); 
163     path.GetParent( &path );
164     psz_program_path = strdup( path.Path() );
165
166     /* Tell the main thread we are finished initializing the BApplication */
167     vlc_mutex_lock( &app_lock );
168     vlc_cond_signal( &app_wait );
169     vlc_mutex_unlock( &app_lock );
170 }
171