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 $
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 *****************************************************************************/
23 #include <Application.h>
28 #include <string.h> /* strdup() */
29 #include <malloc.h> /* free() */
33 #include <videolan/vlc.h>
40 /*****************************************************************************
41 * The VlcApplication class
42 *****************************************************************************/
43 class VlcApplication : public BApplication
46 VlcApplication(char* );
49 virtual void ReadyToRun();
50 virtual void AboutRequested();
53 /*****************************************************************************
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;
64 /*****************************************************************************
66 *****************************************************************************/
67 static void system_AppThread( void * args );
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[] )
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 );
79 /* Create the BApplication thread */
80 vlc_thread_create( &app_thread, "app thread",
81 (vlc_thread_func_t)system_AppThread, 0 );
83 /* Wait for the application to be initialized */
84 vlc_cond_wait( &app_wait, &app_lock );
85 vlc_mutex_unlock( &app_lock );
87 /* Destroy the locks */
88 vlc_mutex_destroy( &app_lock );
89 vlc_cond_destroy( &app_wait );
92 /*****************************************************************************
93 * system_End: destroy the BApplication object.
94 *****************************************************************************/
95 void system_End( void )
97 free( psz_program_path );
99 /* Tell the BApplication to die */
100 be_app->PostMessage( B_QUIT_REQUESTED );
101 vlc_thread_join( app_thread );
104 /*****************************************************************************
105 * system_GetProgramPath: get the full path to the program.
106 *****************************************************************************/
107 char * system_GetProgramPath( void )
109 return( psz_program_path );
112 /* following functions are local */
114 /*****************************************************************************
115 * system_AppThread: the BApplication thread.
116 *****************************************************************************/
117 static void system_AppThread( void * args )
119 VlcApplication *BeApp = new VlcApplication("application/x-vnd.Ink-vlc");
126 /*****************************************************************************
127 * VlcApplication: application constructor
128 *****************************************************************************/
129 VlcApplication::VlcApplication( char * psz_mimetype )
130 :BApplication( psz_mimetype )
132 /* Nothing to do, we use the default constructor */
135 /*****************************************************************************
136 * ~VlcApplication: application destructor
137 *****************************************************************************/
138 VlcApplication::~VlcApplication( )
140 /* Nothing to do, we use the default destructor */
143 /*****************************************************************************
144 * AboutRequested: called by the system on B_ABOUT_REQUESTED
145 *****************************************************************************/
146 void VlcApplication::AboutRequested( )
149 alert = new BAlert( VOUT_TITLE, "BeOS " VOUT_TITLE "\n\n<www.videolan.org>", "Ok" );
153 /*****************************************************************************
154 * ReadyToRun: called when the BApplication is initialized
155 *****************************************************************************/
156 void VlcApplication::ReadyToRun( )
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() );
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 );