1 /*****************************************************************************
2 * beos_init.cpp: Initialization for BeOS specific features
3 *****************************************************************************
4 * Copyright (C) 1999, 2000 VideoLAN
5 * $Id: beos_specific.cpp,v 1.11 2001/05/06 04:32:02 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>
30 #include <string.h> /* strdup() */
31 #include <malloc.h> /* free() */
40 #include "beos_specific.h"
42 /*****************************************************************************
43 * The VlcApplication class
44 *****************************************************************************/
45 class VlcApplication : public BApplication
48 VlcApplication(char* );
51 virtual void ReadyToRun();
52 virtual void AboutRequested();
55 /*****************************************************************************
57 *****************************************************************************/
58 static vlc_thread_t app_thread;
59 static vlc_mutex_t app_lock;
60 static vlc_cond_t app_wait;
61 static char *psz_program_path;
66 /*****************************************************************************
68 *****************************************************************************/
69 static void system_AppThread( void * args );
71 /*****************************************************************************
72 * system_Init: create a BApplication object and fill in program path.
73 *****************************************************************************/
74 void system_Init( int *pi_argc, char *ppsz_argv[], char *ppsz_env[] )
76 /* Prepare the lock/wait before launching the BApplication thread */
77 vlc_mutex_init( &app_lock );
78 vlc_cond_init( &app_wait );
79 vlc_mutex_lock( &app_lock );
81 /* Create the BApplication thread */
82 vlc_thread_create( &app_thread, "app thread",
83 (vlc_thread_func_t)system_AppThread, 0 );
85 /* Wait for the application to be initialized */
86 vlc_cond_wait( &app_wait, &app_lock );
87 vlc_mutex_unlock( &app_lock );
89 /* Destroy the locks */
90 vlc_mutex_destroy( &app_lock );
91 vlc_cond_destroy( &app_wait );
94 /*****************************************************************************
95 * system_End: destroy the BApplication object.
96 *****************************************************************************/
97 void system_End( void )
99 free( psz_program_path );
101 /* Tell the BApplication to die */
102 be_app->PostMessage( B_QUIT_REQUESTED );
103 vlc_thread_join( app_thread );
106 /*****************************************************************************
107 * system_GetProgramPath: get the full path to the program.
108 *****************************************************************************/
109 char * system_GetProgramPath( void )
111 return( psz_program_path );
114 /* following functions are local */
116 /*****************************************************************************
117 * system_AppThread: the BApplication thread.
118 *****************************************************************************/
119 static void system_AppThread( void * args )
121 VlcApplication *BeApp = new VlcApplication("application/x-vnd.Ink-vlc");
128 /*****************************************************************************
129 * VlcApplication: application constructor
130 *****************************************************************************/
131 VlcApplication::VlcApplication( char * psz_mimetype )
132 :BApplication( psz_mimetype )
134 /* Nothing to do, we use the default constructor */
137 /*****************************************************************************
138 * ~VlcApplication: application destructor
139 *****************************************************************************/
140 VlcApplication::~VlcApplication( )
142 /* Nothing to do, we use the default destructor */
145 /*****************************************************************************
146 * AboutRequested: called by the system on B_ABOUT_REQUESTED
147 *****************************************************************************/
148 void VlcApplication::AboutRequested( )
151 alert = new BAlert( VOUT_TITLE, "BeOS " VOUT_TITLE "\n\n<www.videolan.org>", "Ok" );
155 /*****************************************************************************
156 * ReadyToRun: called when the BApplication is initialized
157 *****************************************************************************/
158 void VlcApplication::ReadyToRun( )
163 /* Get the program path */
164 be_app->GetAppInfo( &info );
165 BEntry entry( &info.ref );
166 entry.GetPath( &path );
167 path.GetParent( &path );
168 psz_program_path = strdup( path.Path() );
170 /* Tell the main thread we are finished initializing the BApplication */
171 vlc_mutex_lock( &app_lock );
172 vlc_cond_signal( &app_wait );
173 vlc_mutex_unlock( &app_lock );