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