Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

beos_specific.cpp

00001 /*****************************************************************************
00002  * beos_init.cpp: Initialization for BeOS specific features
00003  *****************************************************************************
00004  * Copyright (C) 1999-2004 the VideoLAN team
00005  * $Id: beos_specific.cpp 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Jean-Marc Dressler <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 #include <Application.h>
00024 #include <Roster.h>
00025 #include <Path.h>
00026 #include <Alert.h>
00027 #include <Message.h>
00028 #include <Window.h>
00029 
00030 #include <stdio.h>
00031 #include <string.h> /* strdup() */
00032 #include <malloc.h> /* free() */
00033 
00034 extern "C"
00035 {
00036 #include <vlc/vlc.h>
00037 }
00038 
00039 /*****************************************************************************
00040  * The VlcApplication class
00041  *****************************************************************************/
00042 class VlcApplication : public BApplication
00043 {
00044 public:
00045     vlc_object_t *p_this;
00046 
00047     VlcApplication(char* );
00048     ~VlcApplication();
00049 
00050     virtual void ReadyToRun();
00051     virtual void AboutRequested();
00052     virtual void RefsReceived(BMessage* message);
00053     virtual void MessageReceived(BMessage* message);
00054     virtual bool QuitRequested();
00055 
00056 private:
00057     BWindow*     fInterfaceWindow;
00058     BMessage*    fRefsMessage;
00059     bool         fReadyToQuit;
00060 };
00061 
00062 /*****************************************************************************
00063  * Static vars
00064  *****************************************************************************/
00065 
00066 #include "../../modules/gui/beos/MsgVals.h"
00067 #define REALLY_QUIT 'requ'
00068 
00069 extern "C"
00070 {
00071 
00072 /*****************************************************************************
00073  * Local prototypes.
00074  *****************************************************************************/
00075 static void AppThread( vlc_object_t *p_appthread );
00076 
00077 /*****************************************************************************
00078  * system_Init: create a BApplication object and fill in program path.
00079  *****************************************************************************/
00080 void system_Init( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
00081 {
00082     p_this->p_libvlc->p_appthread =
00083             (vlc_object_t *)vlc_object_create( p_this, sizeof(vlc_object_t) );
00084 
00085     /* Create the BApplication thread and wait for initialization */
00086     vlc_thread_create( p_this->p_libvlc->p_appthread, "app thread", AppThread,
00087                        VLC_THREAD_PRIORITY_LOW, VLC_TRUE );
00088 }
00089 
00090 /*****************************************************************************
00091  * system_Configure: check for system specific configuration options.
00092  *****************************************************************************/
00093 void system_Configure( vlc_t *, int *pi_argc, char *ppsz_argv[] )
00094 {
00095 }
00096 
00097 /*****************************************************************************
00098  * system_End: destroy the BApplication object.
00099  *****************************************************************************/
00100 void system_End( vlc_t *p_this )
00101 {
00102     /* Tell the BApplication to die */
00103     be_app->PostMessage( REALLY_QUIT );
00104 
00105     vlc_thread_join( p_this->p_libvlc->p_appthread );
00106     vlc_object_destroy( p_this->p_libvlc->p_appthread );
00107 
00108     free( p_this->p_libvlc->psz_vlcpath );
00109 }
00110 
00111 /* following functions are local */
00112 
00113 /*****************************************************************************
00114  * AppThread: the BApplication thread.
00115  *****************************************************************************/
00116 static void AppThread( vlc_object_t * p_this )
00117 {
00118     VlcApplication * BeApp =
00119         new VlcApplication("application/x-vnd.videolan-vlc");
00120     vlc_object_attach( p_this, p_this->p_vlc );
00121     BeApp->p_this = p_this;
00122     BeApp->Run();
00123     vlc_object_detach( p_this );
00124     delete BeApp;
00125 }
00126 
00127 } /* extern "C" */
00128 
00129 /*****************************************************************************
00130  * VlcApplication: application constructor
00131  *****************************************************************************/
00132 VlcApplication::VlcApplication( char * psz_mimetype )
00133                :BApplication( psz_mimetype ),
00134                 fInterfaceWindow( NULL ),
00135                 fRefsMessage( NULL ),
00136                 fReadyToQuit( false )
00137 {
00138     /* Nothing to do, we use the default constructor */
00139 }
00140 
00141 /*****************************************************************************
00142  * ~VlcApplication: application destructor
00143  *****************************************************************************/
00144 VlcApplication::~VlcApplication( )
00145 {
00146     /* Nothing to do, we use the default destructor */
00147     delete fRefsMessage;
00148 }
00149 
00150 /*****************************************************************************
00151  * AboutRequested: called by the system on B_ABOUT_REQUESTED
00152  *****************************************************************************/
00153 void VlcApplication::AboutRequested( )
00154 {
00155     BAlert *alert;
00156     alert = new BAlert( "VLC " PACKAGE_VERSION,
00157                         "VLC " PACKAGE_VERSION " for BeOS\n\n"
00158                                         "<www.videolan.org>", "OK");
00159     alert->Go( NULL );
00160 }
00161 
00162 /*****************************************************************************
00163  * ReadyToRun: called when the BApplication is initialized
00164  *****************************************************************************/
00165 void VlcApplication::ReadyToRun( )
00166 {
00167     BPath path;
00168     app_info info;
00169 
00170     /* Get the program path */
00171     be_app->GetAppInfo( &info );
00172     BEntry entry( &info.ref );
00173     entry.GetPath( &path );
00174     path.GetParent( &path );
00175     p_this->p_libvlc->psz_vlcpath = strdup( path.Path() );
00176 
00177     /* Tell the main thread we are finished initializing the BApplication */
00178     vlc_thread_ready( p_this );
00179 }
00180 
00181 /*****************************************************************************
00182  * RefsReceived: called when files are sent to our application
00183  *               (for example when the user drops fils onto our icon)
00184  *****************************************************************************/
00185 void VlcApplication::RefsReceived(BMessage* message)
00186 {
00187     if (fInterfaceWindow)
00188         fInterfaceWindow->PostMessage(message);
00189     else {
00190         delete fRefsMessage;
00191         fRefsMessage = new BMessage(*message);
00192     }
00193 }
00194 
00195 /*****************************************************************************
00196  * MessageReceived: a BeOS applications main message loop
00197  *                  Since VlcApplication and interface are separated
00198  *                  in the vlc binary and the interface plugin,
00199  *                  we use this method to "stick" them together.
00200  *                  The interface will post a message to the global
00201  *                  "be_app" pointer when the interface is created
00202  *                  containing a pointer to the interface window.
00203  *                  In this way, we can keep a B_REFS_RECEIVED message
00204  *                  in store for the interface window to handle later.
00205  *****************************************************************************/
00206 void VlcApplication::MessageReceived(BMessage* message)
00207 {
00208     switch (message->what) {
00209         case INTERFACE_CREATED: {
00210             BWindow* interfaceWindow;
00211             if (message->FindPointer("window", (void**)&interfaceWindow) == B_OK) {
00212                 fInterfaceWindow = interfaceWindow;
00213                 if (fRefsMessage) {
00214                     fInterfaceWindow->PostMessage(fRefsMessage);
00215                     delete fRefsMessage;
00216                     fRefsMessage = NULL;
00217                 }
00218             }
00219             break;
00220         }
00221 
00222         case REALLY_QUIT:
00223             fReadyToQuit = true;
00224             PostMessage( B_QUIT_REQUESTED );
00225             break;
00226 
00227         default:
00228             BApplication::MessageReceived(message);
00229     }
00230 }
00231 
00232 bool VlcApplication::QuitRequested()
00233 {
00234     if( !fReadyToQuit )
00235     {
00236         p_this->p_vlc->b_die = 1;
00237         return false;
00238     }
00239 
00240     BApplication::QuitRequested();
00241     return true;
00242 }

Generated on Tue Dec 20 10:15:00 2005 for vlc-0.8.4a by  doxygen 1.4.2