]> git.sesse.net Git - vlc/blob - src/misc/beos_specific.cpp
72ef7c7226ee3b9f1b03a2edfe7a8785706d3570
[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.25 2002/08/29 23:53:22 massiot 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,
74                        VLC_THREAD_PRIORITY_LOW, VLC_TRUE );
75 }
76
77 /*****************************************************************************
78  * system_Configure: check for system specific configuration options.
79  *****************************************************************************/
80 void system_Configure( vlc_t * )
81 {
82
83 }
84
85 /*****************************************************************************
86  * system_End: destroy the BApplication object.
87  *****************************************************************************/
88 void system_End( vlc_t *p_this )
89 {
90     /* Tell the BApplication to die */
91     be_app->PostMessage( B_QUIT_REQUESTED );
92
93     vlc_thread_join( p_this->p_vlc->p_appthread );
94     vlc_object_destroy( p_this->p_vlc->p_appthread );
95
96     free( psz_program_path );
97 }
98
99 /*****************************************************************************
100  * system_GetProgramPath: get the full path to the program.
101  *****************************************************************************/
102 char * system_GetProgramPath( void )
103 {
104     return( psz_program_path );
105 }
106
107 /* following functions are local */
108
109 /*****************************************************************************
110  * AppThread: the BApplication thread.
111  *****************************************************************************/
112 static void AppThread( vlc_object_t * p_this )
113 {
114     VlcApplication *BeApp = new VlcApplication("application/x-vnd.Ink-vlc");
115     vlc_object_attach( p_this, p_this->p_vlc );
116     BeApp->p_this = p_this;
117     BeApp->Run();
118     vlc_object_detach( p_this );
119     delete BeApp;
120 }
121
122 } /* extern "C" */
123
124 /*****************************************************************************
125  * VlcApplication: application constructor
126  *****************************************************************************/
127 VlcApplication::VlcApplication( char * psz_mimetype )
128                :BApplication( psz_mimetype )
129 {
130     /* Nothing to do, we use the default constructor */
131 }
132
133 /*****************************************************************************
134  * ~VlcApplication: application destructor
135  *****************************************************************************/
136 VlcApplication::~VlcApplication( )
137 {
138     /* Nothing to do, we use the default destructor */
139 }
140
141 /*****************************************************************************
142  * AboutRequested: called by the system on B_ABOUT_REQUESTED
143  *****************************************************************************/
144 void VlcApplication::AboutRequested( )
145 {
146     BAlert *alert;
147     alert = new BAlert( VOUT_TITLE,
148                         "BeOS " VOUT_TITLE "\n\n<www.videolan.org>",
149                         "Ok" );
150     alert->Go( NULL );
151 }
152
153 /*****************************************************************************
154  * ReadyToRun: called when the BApplication is initialized
155  *****************************************************************************/
156 void VlcApplication::ReadyToRun( )
157 {
158     BPath path;
159     app_info info; 
160
161     /* Get the program path */
162     be_app->GetAppInfo( &info ); 
163     BEntry entry( &info.ref ); 
164     entry.GetPath( &path ); 
165     path.GetParent( &path );
166     psz_program_path = strdup( path.Path() );
167
168     /* Tell the main thread we are finished initializing the BApplication */
169     vlc_thread_ready( p_this );
170 }