]> git.sesse.net Git - vlc/blob - src/misc/beos_specific.cpp
* ./src/misc/objects.c: two big changes in the object API: now objects can
[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.24 2002/08/12 09:34:15 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 <stdio.h>
28 #include <string.h> /* strdup() */
29 #include <malloc.h>   /* free() */
30
31 extern "C"
32 {
33 #include <vlc/vlc.h>
34 }
35
36 /*****************************************************************************
37  * The VlcApplication class
38  *****************************************************************************/
39 class VlcApplication : public BApplication
40 {
41 public:
42     vlc_object_t *p_this;
43
44     VlcApplication(char* );
45     ~VlcApplication();
46
47     virtual void ReadyToRun();
48     virtual void AboutRequested();
49 };
50
51 /*****************************************************************************
52  * Static vars
53  *****************************************************************************/
54 static char *         psz_program_path;
55
56 extern "C"
57 {
58
59 /*****************************************************************************
60  * Local prototypes.
61  *****************************************************************************/
62 static void AppThread( vlc_object_t *p_appthread );
63
64 /*****************************************************************************
65  * system_Init: create a BApplication object and fill in program path.
66  *****************************************************************************/
67 void system_Init( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
68 {
69     p_this->p_vlc->p_appthread =
70             (vlc_object_t *)vlc_object_create( p_this, sizeof(vlc_object_t) );
71
72     /* Create the BApplication thread and wait for initialization */
73     vlc_thread_create( p_this->p_vlc->p_appthread, "app thread", AppThread, 1 );
74 }
75
76 /*****************************************************************************
77  * system_Configure: check for system specific configuration options.
78  *****************************************************************************/
79 void system_Configure( vlc_t * )
80 {
81
82 }
83
84 /*****************************************************************************
85  * system_End: destroy the BApplication object.
86  *****************************************************************************/
87 void system_End( vlc_t *p_this )
88 {
89     /* Tell the BApplication to die */
90     be_app->PostMessage( B_QUIT_REQUESTED );
91
92     vlc_thread_join( p_this->p_vlc->p_appthread );
93     vlc_object_destroy( p_this->p_vlc->p_appthread );
94
95     free( psz_program_path );
96 }
97
98 /*****************************************************************************
99  * system_GetProgramPath: get the full path to the program.
100  *****************************************************************************/
101 char * system_GetProgramPath( void )
102 {
103     return( psz_program_path );
104 }
105
106 /* following functions are local */
107
108 /*****************************************************************************
109  * AppThread: the BApplication thread.
110  *****************************************************************************/
111 static void AppThread( vlc_object_t * p_this )
112 {
113     VlcApplication *BeApp = new VlcApplication("application/x-vnd.Ink-vlc");
114     vlc_object_attach( p_this, p_this->p_vlc );
115     BeApp->p_this = p_this;
116     BeApp->Run();
117     vlc_object_detach( p_this );
118     delete BeApp;
119 }
120
121 } /* extern "C" */
122
123 /*****************************************************************************
124  * VlcApplication: application constructor
125  *****************************************************************************/
126 VlcApplication::VlcApplication( char * psz_mimetype )
127                :BApplication( psz_mimetype )
128 {
129     /* Nothing to do, we use the default constructor */
130 }
131
132 /*****************************************************************************
133  * ~VlcApplication: application destructor
134  *****************************************************************************/
135 VlcApplication::~VlcApplication( )
136 {
137     /* Nothing to do, we use the default destructor */
138 }
139
140 /*****************************************************************************
141  * AboutRequested: called by the system on B_ABOUT_REQUESTED
142  *****************************************************************************/
143 void VlcApplication::AboutRequested( )
144 {
145     BAlert *alert;
146     alert = new BAlert( VOUT_TITLE,
147                         "BeOS " VOUT_TITLE "\n\n<www.videolan.org>",
148                         "Ok" );
149     alert->Go( NULL );
150 }
151
152 /*****************************************************************************
153  * ReadyToRun: called when the BApplication is initialized
154  *****************************************************************************/
155 void VlcApplication::ReadyToRun( )
156 {
157     BPath path;
158     app_info info; 
159
160     /* Get the program path */
161     be_app->GetAppInfo( &info ); 
162     BEntry entry( &info.ref ); 
163     entry.GetPath( &path ); 
164     path.GetParent( &path );
165     psz_program_path = strdup( path.Path() );
166
167     /* Tell the main thread we are finished initializing the BApplication */
168     vlc_thread_ready( p_this );
169 }