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 $
7 * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
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.
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.
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 *****************************************************************************/
25 #include <Application.h>
29 #include <string.h> /* strdup() */
30 #include <malloc.h> /* free() */
38 #include "beos_specific.h"
40 /*****************************************************************************
41 * The VlcApplication class
42 *****************************************************************************/
43 class VlcApplication : public BApplication
46 VlcApplication(char* );
52 /*****************************************************************************
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;
63 /*****************************************************************************
65 *****************************************************************************/
66 static void system_AppThread( void * args );
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[] )
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 );
78 /* Create the BApplication thread */
79 vlc_thread_create( &app_thread, "app thread",
80 (vlc_thread_func_t)system_AppThread, 0 );
82 /* Wait for the application to be initialized */
83 vlc_cond_wait( &app_wait, &app_lock );
84 vlc_mutex_unlock( &app_lock );
86 /* Destroy the locks */
87 vlc_mutex_destroy( &app_lock );
88 vlc_cond_destroy( &app_wait );
91 /*****************************************************************************
92 * system_Destroy: destroy the BApplication object.
93 *****************************************************************************/
94 void system_Destroy( void )
96 free( psz_program_path );
98 /* Tell the BApplication to die */
99 be_app->PostMessage( B_QUIT_REQUESTED );
100 vlc_thread_join( app_thread );
103 /*****************************************************************************
104 * system_GetProgramPath: get the full path to the program.
105 *****************************************************************************/
106 char * system_GetProgramPath( void )
108 return( psz_program_path );
111 /* following functions are local */
113 /*****************************************************************************
114 * system_AppThread: the BApplication thread.
115 *****************************************************************************/
116 static void system_AppThread( void * args )
118 VlcApplication *BeApp = new VlcApplication("application/x-vnd.Ink-vlc");
125 /*****************************************************************************
126 * VlcApplication: application constructor
127 *****************************************************************************/
128 VlcApplication::VlcApplication( char * psz_mimetype )
129 :BApplication( psz_mimetype )
131 /* Nothing to do, we use the default constructor */
134 /*****************************************************************************
135 * ~VlcApplication: application destructor
136 *****************************************************************************/
137 VlcApplication::~VlcApplication( )
139 /* Nothing to do, we use the default destructor */
142 /*****************************************************************************
143 * ~ReadyToRun: called when the BApplication is initialized
144 *****************************************************************************/
145 void VlcApplication::ReadyToRun( )
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() );
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 );