]> git.sesse.net Git - vlc/blob - src/misc/beos_specific.cpp
* ./src/misc/beos_specific.cpp, ./src/misc/darwin_specific.m: removed
[vlc] / src / misc / beos_specific.cpp
1 /*****************************************************************************
2  * beos_init.cpp: Initialization for BeOS specific features 
3  *****************************************************************************
4  * Copyright (C) 1999-2001 VideoLAN
5  * $Id: beos_specific.cpp,v 1.29 2003/01/19 03:16:24 sam Exp $
6  *
7  * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8  *
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.
13  * 
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.
18  *
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>
24 #include <Roster.h>
25 #include <Path.h>
26 #include <Alert.h>
27 #include <Message.h>
28 #include <Window.h>
29
30 #include <stdio.h>
31 #include <string.h> /* strdup() */
32 #include <malloc.h>   /* free() */
33
34 extern "C"
35 {
36 #include <vlc/vlc.h>
37 }
38
39 /*****************************************************************************
40  * The VlcApplication class
41  *****************************************************************************/
42 class VlcApplication : public BApplication
43 {
44 public:
45     vlc_object_t *p_this;
46
47     VlcApplication(char* );
48     ~VlcApplication();
49
50     virtual void ReadyToRun();
51     virtual void AboutRequested();
52     virtual void RefsReceived(BMessage* message);
53     virtual void MessageReceived(BMessage* message);
54     
55 private:
56     BWindow*     fInterfaceWindow;
57     BMessage*    fRefsMessage;
58 };
59
60 /*****************************************************************************
61  * Static vars
62  *****************************************************************************/
63
64 //const uint32 INTERFACE_CREATED = 'ifcr';  /* message sent from interface */
65 #include "../../modules/gui/beos/MsgVals.h"
66
67 extern "C"
68 {
69
70 /*****************************************************************************
71  * Local prototypes.
72  *****************************************************************************/
73 static void AppThread( vlc_object_t *p_appthread );
74
75 /*****************************************************************************
76  * system_Init: create a BApplication object and fill in program path.
77  *****************************************************************************/
78 void system_Init( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
79 {
80     p_this->p_libvlc->p_appthread =
81             (vlc_object_t *)vlc_object_create( p_this, sizeof(vlc_object_t) );
82
83     /* Create the BApplication thread and wait for initialization */
84     vlc_thread_create( p_this->p_libvlc->p_appthread, "app thread", AppThread,
85                        VLC_THREAD_PRIORITY_LOW, VLC_TRUE );
86 }
87
88 /*****************************************************************************
89  * system_Configure: check for system specific configuration options.
90  *****************************************************************************/
91 void system_Configure( vlc_t * )
92 {
93
94 }
95
96 /*****************************************************************************
97  * system_End: destroy the BApplication object.
98  *****************************************************************************/
99 void system_End( vlc_t *p_this )
100 {
101     /* Tell the BApplication to die */
102     be_app->PostMessage( B_QUIT_REQUESTED );
103
104     vlc_thread_join( p_this->p_libvlc->p_appthread );
105     vlc_object_destroy( p_this->p_libvlc->p_appthread );
106
107     free( p_this->p_libvlc->psz_vlcpath );
108 }
109
110 /* following functions are local */
111
112 /*****************************************************************************
113  * AppThread: the BApplication thread.
114  *****************************************************************************/
115 static void AppThread( vlc_object_t * p_this )
116 {
117     VlcApplication *BeApp = new VlcApplication("application/x-vnd.videolan-vlc");
118     vlc_object_attach( p_this, p_this->p_vlc );
119     BeApp->p_this = p_this;
120     BeApp->Run();
121     vlc_object_detach( p_this );
122     delete BeApp;
123 }
124
125 } /* extern "C" */
126
127 /*****************************************************************************
128  * VlcApplication: application constructor
129  *****************************************************************************/
130 VlcApplication::VlcApplication( char * psz_mimetype )
131                :BApplication( psz_mimetype ),
132                 fInterfaceWindow( NULL ),
133                 fRefsMessage( NULL )
134 {
135     /* Nothing to do, we use the default constructor */
136 }
137
138 /*****************************************************************************
139  * ~VlcApplication: application destructor
140  *****************************************************************************/
141 VlcApplication::~VlcApplication( )
142 {
143     /* Nothing to do, we use the default destructor */
144     delete fRefsMessage;
145 }
146
147 /*****************************************************************************
148  * AboutRequested: called by the system on B_ABOUT_REQUESTED
149  *****************************************************************************/
150 void VlcApplication::AboutRequested( )
151 {
152     BAlert *alert;
153     alert = new BAlert( VOUT_TITLE,
154                         "BeOS " VOUT_TITLE "\n\n<www.videolan.org>",
155                         "Ok" );
156     alert->Go( NULL );
157 }
158
159 /*****************************************************************************
160  * ReadyToRun: called when the BApplication is initialized
161  *****************************************************************************/
162 void VlcApplication::ReadyToRun( )
163 {
164     BPath path;
165     app_info info; 
166
167     /* Get the program path */
168     be_app->GetAppInfo( &info ); 
169     BEntry entry( &info.ref ); 
170     entry.GetPath( &path ); 
171     path.GetParent( &path );
172     p_this->p_libvlc->psz_vlcpath = strdup( path.Path() );
173
174     /* Tell the main thread we are finished initializing the BApplication */
175     vlc_thread_ready( p_this );
176 }
177
178 /*****************************************************************************
179  * RefsReceived: called when files are sent to our application
180  *               (for example when the user drops fils onto our icon)
181  *****************************************************************************/
182 void VlcApplication::RefsReceived(BMessage* message)
183 {
184         if (fInterfaceWindow)
185                 fInterfaceWindow->PostMessage(message);
186         else {
187                 delete fRefsMessage;
188                 fRefsMessage = new BMessage(*message);
189         }
190 }
191
192 /*****************************************************************************
193  * MessageReceived: a BeOS applications main message loop
194  *                  Since VlcApplication and interface are separated
195  *                  in the vlc binary and the interface plugin,
196  *                  we use this method to "stick" them together.
197  *                  The interface will post a message to the global
198  *                  "be_app" pointer when the interface is created
199  *                  containing a pointer to the interface window.
200  *                  In this way, we can keep a B_REFS_RECEIVED message
201  *                  in store for the interface window to handle later.
202  *****************************************************************************/
203 void VlcApplication::MessageReceived(BMessage* message)
204 {
205         switch (message->what) {
206                 case INTERFACE_CREATED: {
207                         BWindow* interfaceWindow;
208                         if (message->FindPointer("window", (void**)&interfaceWindow) == B_OK) {
209                                 fInterfaceWindow = interfaceWindow;
210                                 if (fRefsMessage) {
211                                         fInterfaceWindow->PostMessage(fRefsMessage);
212                                         delete fRefsMessage;
213                                         fRefsMessage = NULL;
214                                 }
215                         }
216                         break;
217                 }
218                 default:
219                         BApplication::MessageReceived(message);
220         }
221 }