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 $
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>
30 #include <string.h> /* strdup() */
31 #include <malloc.h> /* free() */
41 #include "beos_specific.h"
43 /*****************************************************************************
44 * The VlcApplication class
45 *****************************************************************************/
46 class VlcApplication : public BApplication
49 VlcApplication(char* );
52 virtual void ReadyToRun();
53 virtual void AboutRequested();
56 /*****************************************************************************
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;
67 /*****************************************************************************
69 *****************************************************************************/
70 static void system_AppThread( void * args );
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[] )
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 );
82 /* Create the BApplication thread */
83 vlc_thread_create( &app_thread, "app thread",
84 (vlc_thread_func_t)system_AppThread, 0 );
86 /* Wait for the application to be initialized */
87 vlc_cond_wait( &app_wait, &app_lock );
88 vlc_mutex_unlock( &app_lock );
90 /* Destroy the locks */
91 vlc_mutex_destroy( &app_lock );
92 vlc_cond_destroy( &app_wait );
95 /*****************************************************************************
96 * system_End: destroy the BApplication object.
97 *****************************************************************************/
98 void system_End( void )
100 free( psz_program_path );
102 /* Tell the BApplication to die */
103 be_app->PostMessage( B_QUIT_REQUESTED );
104 vlc_thread_join( app_thread );
107 /*****************************************************************************
108 * system_GetProgramPath: get the full path to the program.
109 *****************************************************************************/
110 char * system_GetProgramPath( void )
112 return( psz_program_path );
115 /* following functions are local */
117 /*****************************************************************************
118 * system_AppThread: the BApplication thread.
119 *****************************************************************************/
120 static void system_AppThread( void * args )
122 VlcApplication *BeApp = new VlcApplication("application/x-vnd.Ink-vlc");
129 /*****************************************************************************
130 * VlcApplication: application constructor
131 *****************************************************************************/
132 VlcApplication::VlcApplication( char * psz_mimetype )
133 :BApplication( psz_mimetype )
135 /* Nothing to do, we use the default constructor */
138 /*****************************************************************************
139 * ~VlcApplication: application destructor
140 *****************************************************************************/
141 VlcApplication::~VlcApplication( )
143 /* Nothing to do, we use the default destructor */
146 /*****************************************************************************
147 * AboutRequested: called by the system on B_ABOUT_REQUESTED
148 *****************************************************************************/
149 void VlcApplication::AboutRequested( )
152 alert = new BAlert( VOUT_TITLE, "BeOS " VOUT_TITLE "\n\n<www.videolan.org>", "Ok" );
156 /*****************************************************************************
157 * ReadyToRun: called when the BApplication is initialized
158 *****************************************************************************/
159 void VlcApplication::ReadyToRun( )
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() );
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 );