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