]> git.sesse.net Git - vlc/blobdiff - src/misc/beos_specific.cpp
* Added a "make package-beos" rule.
[vlc] / src / misc / beos_specific.cpp
index 9fcebb6d0836ad08600022d7b09d7d7aff3c1db9..1ccb25cc3e1dffeb7aafdb1811f3ae4d13fbaa31 100644 (file)
@@ -2,6 +2,7 @@
  * beos_init.cpp: Initialization for BeOS specific features 
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
+ * $Id: beos_specific.cpp,v 1.11 2001/05/06 04:32:02 sam Exp $
  *
  * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
  *
 #include <Application.h>
 #include <Roster.h>
 #include <Path.h>
+#include <Alert.h>
 #include <stdio.h>
-#include <malloc.h>
+#include <string.h> /* strdup() */
+#include <malloc.h>   /* free() */
 
 extern "C"
 {
+#include "config.h"
 #include "common.h"
 #include "threads.h"
 #include "mtime.h"
 }
 #include "beos_specific.h"
 
+/*****************************************************************************
+ * The VlcApplication class
+ *****************************************************************************/
+class VlcApplication : public BApplication
+{
+public:
+    VlcApplication(char* );
+    ~VlcApplication();
 
+    virtual void ReadyToRun();
+    virtual void AboutRequested();
+};
 
 /*****************************************************************************
  * Static vars
  *****************************************************************************/
-static vlc_thread_t beos_app_thread;
-static char * psz_beos_program_path;
-
+static vlc_thread_t app_thread;
+static vlc_mutex_t  app_lock;
+static vlc_cond_t   app_wait;
+static char        *psz_program_path;
 
 extern "C"
 {
 
-void beos_AppThread( void * args )
+/*****************************************************************************
+ * Local prototypes.
+ *****************************************************************************/
+static void system_AppThread( void * args );
+
+/*****************************************************************************
+ * system_Init: create a BApplication object and fill in program path.
+ *****************************************************************************/
+void system_Init( int *pi_argc, char *ppsz_argv[], char *ppsz_env[] )
+{
+    /* Prepare the lock/wait before launching the BApplication thread */
+    vlc_mutex_init( &app_lock );
+    vlc_cond_init( &app_wait );
+    vlc_mutex_lock( &app_lock );
+
+    /* Create the BApplication thread */
+    vlc_thread_create( &app_thread, "app thread",
+                       (vlc_thread_func_t)system_AppThread, 0 );
+
+    /* Wait for the application to be initialized */
+    vlc_cond_wait( &app_wait, &app_lock );
+    vlc_mutex_unlock( &app_lock );
+
+    /* Destroy the locks */
+    vlc_mutex_destroy( &app_lock );
+    vlc_cond_destroy( &app_wait );
+}
+
+/*****************************************************************************
+ * system_End: destroy the BApplication object.
+ *****************************************************************************/
+void system_End( void )
+{
+    free( psz_program_path );
+
+    /* Tell the BApplication to die */
+    be_app->PostMessage( B_QUIT_REQUESTED );
+    vlc_thread_join( app_thread );
+}
+
+/*****************************************************************************
+ * system_GetProgramPath: get the full path to the program.
+ *****************************************************************************/
+char * system_GetProgramPath( void )
 {
-    BApplication * BeApp = new BApplication("application/x-VLC");
+    return( psz_program_path );
+}
+
+/* following functions are local */
+
+/*****************************************************************************
+ * system_AppThread: the BApplication thread.
+ *****************************************************************************/
+static void system_AppThread( void * args )
+{
+    VlcApplication *BeApp = new VlcApplication("application/x-vnd.Ink-vlc");
     BeApp->Run();
     delete BeApp;
 }
 
-void beos_Create( void )
+} /* extern "C" */
+
+/*****************************************************************************
+ * VlcApplication: application constructor
+ *****************************************************************************/
+VlcApplication::VlcApplication( char * psz_mimetype )
+               :BApplication( psz_mimetype )
 {
-    int i_lenght;
-    BPath path;
-    app_info info; 
-    
-    vlc_thread_create( &beos_app_thread, "app thread", (vlc_thread_func_t)beos_AppThread, 0 );
-    msleep( 100000 );
-    // FIXME: we need to verify that be_app is initialized and the msleep is not enough
-    //        but the following code does not work as it should and I have no good
-    //        solution at the moment.
-    //while( be_app == NULL )
-    //    msleep( 5000 );
-    
-    be_app->GetAppInfo(&info); 
-    BEntry entry(&info.ref); 
-    entry.GetPath(&path); 
-    path.GetParent(&path);
-    i_lenght = strlen( path.Path() );
-    psz_beos_program_path = (char*) malloc( i_lenght+1 ); /* XXX */
-    strcpy( psz_beos_program_path, path.Path() );
+    /* Nothing to do, we use the default constructor */
 }
 
-void beos_Destroy( void )
+/*****************************************************************************
+ * ~VlcApplication: application destructor
+ *****************************************************************************/
+VlcApplication::~VlcApplication( )
 {
-    free( psz_beos_program_path ); /* XXX */
-    be_app->PostMessage( B_QUIT_REQUESTED );
-    vlc_thread_join( beos_app_thread );
+    /* Nothing to do, we use the default destructor */
 }
 
-char * beos_GetProgramPath( void )
+/*****************************************************************************
+ * AboutRequested: called by the system on B_ABOUT_REQUESTED
+ *****************************************************************************/
+void VlcApplication::AboutRequested( )
 {
-    return( psz_beos_program_path );
+       BAlert *alert;
+       alert = new BAlert( VOUT_TITLE, "BeOS " VOUT_TITLE "\n\n<www.videolan.org>", "Ok" );
+       alert->Go( NULL );
+}
+
+/*****************************************************************************
+ * ReadyToRun: called when the BApplication is initialized
+ *****************************************************************************/
+void VlcApplication::ReadyToRun( )
+{
+    BPath path;
+    app_info info; 
+
+    /* Get the program path */
+    be_app->GetAppInfo( &info ); 
+    BEntry entry( &info.ref ); 
+    entry.GetPath( &path ); 
+    path.GetParent( &path );
+    psz_program_path = strdup( path.Path() );
+
+    /* Tell the main thread we are finished initializing the BApplication */
+    vlc_mutex_lock( &app_lock );
+    vlc_cond_signal( &app_wait );
+    vlc_mutex_unlock( &app_lock );
 }
 
-} /* extern "C" */