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