]> git.sesse.net Git - vlc/blob - plugins/beos/intf_beos.cpp
de4852e7fefbbada26b22e120cab8f5bb84e5118
[vlc] / plugins / beos / intf_beos.cpp
1 /*****************************************************************************
2  * intf_beos.cpp: beos interface
3  *****************************************************************************
4  * Copyright (C) 1999, 2000, 2001 VideoLAN
5  * $Id: intf_beos.cpp,v 1.8 2001/02/18 03:32:02 polux Exp $
6  *
7  * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8  *          Samuel Hocevar <sam@zoy.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  * 
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include "defs.h"
29
30 #include <stdio.h>
31 #include <stdlib.h>                                      /* malloc(), free() */
32 #include <kernel/OS.h>
33 #include <View.h>
34 #include <Application.h>
35 #include <Message.h>
36 #include <Locker.h>
37 #include <DirectWindow.h>
38 #include <malloc.h>
39 #include <string.h>
40
41 extern "C"
42 {
43 #include "config.h"
44 #include "common.h"
45 #include "threads.h"
46 #include "mtime.h"
47 #include "tests.h"
48 #include "modules.h"
49
50 #include "intf_msg.h"
51 #include "interface.h"
52
53 #include "main.h"
54 }
55
56 #include "beos_window.h"
57
58 /*****************************************************************************
59  * intf_sys_t: description and status of FB interface
60  *****************************************************************************/
61 typedef struct intf_sys_s
62 {
63     InterfaceWindow * p_window;
64     char              i_key;
65 } intf_sys_t;
66
67 /*****************************************************************************
68  * InterfaceWindow
69  *****************************************************************************/
70  
71 InterfaceWindow::InterfaceWindow( BRect frame, const char *name , intf_thread_t  *p_intf )
72     : BWindow(frame, name, B_TITLED_WINDOW, B_NOT_RESIZABLE|B_NOT_ZOOMABLE)
73 {
74     p_interface = p_intf;
75     SetName( "interface" );
76     
77     BView * p_view;
78     
79     p_view = new BView( Bounds(), "", B_FOLLOW_ALL, B_WILL_DRAW );
80     AddChild( p_view );
81     
82     Show();
83 }
84
85 InterfaceWindow::~InterfaceWindow()
86 {
87 }
88
89 /*****************************************************************************
90  * InterfaceWindow::MessageReceived
91  *****************************************************************************/
92
93 void InterfaceWindow::MessageReceived( BMessage * p_message )
94 {
95     char * psz_key;
96     
97     switch( p_message->what )
98     {
99     case B_KEY_DOWN:
100         p_message->FindString( "bytes", (const char **)&psz_key );
101         p_interface->p_sys->i_key = psz_key[0];
102         break;
103         
104     default:
105         BWindow::MessageReceived( p_message );
106         break;
107     }
108 }
109
110 /*****************************************************************************
111  * InterfaceWindow::QuitRequested
112  *****************************************************************************/
113
114 bool InterfaceWindow::QuitRequested()
115 {
116     return( false );
117 }
118
119
120 extern "C"
121 {
122
123 /*****************************************************************************
124  * Local prototypes.
125  *****************************************************************************/
126 static int  intf_Probe     ( probedata_t *p_data );
127 static int  intf_Open      ( intf_thread_t *p_intf );
128 static void intf_Close     ( intf_thread_t *p_intf );
129 static void intf_Run       ( intf_thread_t *p_intf );
130
131 /*****************************************************************************
132  * Functions exported as capabilities. They are declared as static so that
133  * we don't pollute the namespace too much.
134  *****************************************************************************/
135 void intf_getfunctions( function_list_t * p_function_list )
136 {
137     p_function_list->pf_probe = intf_Probe;
138     p_function_list->functions.intf.pf_open  = intf_Open;
139     p_function_list->functions.intf.pf_close = intf_Close;
140     p_function_list->functions.intf.pf_run   = intf_Run;
141 }
142
143 /*****************************************************************************
144  * intf_Probe: probe the interface and return a score
145  *****************************************************************************
146  * This function tries to initialize Gnome and returns a score to the
147  * plugin manager so that it can select the best plugin.
148  *****************************************************************************/
149 static int intf_Probe( probedata_t *p_data )
150 {
151     if( TestMethod( INTF_METHOD_VAR, "beos" ) )
152     {
153         return( 999 );
154     }
155
156     return( 100 );
157 }
158
159 /*****************************************************************************
160  * intf_Open: initialize dummy interface
161  *****************************************************************************/
162 static int intf_Open( intf_thread_t *p_intf )
163 {
164     /* Allocate instance and initialize some members */
165     p_intf->p_sys = (intf_sys_t*) malloc( sizeof( intf_sys_t ) );
166     if( p_intf->p_sys == NULL )
167     {
168         intf_ErrMsg("error: %s", strerror(ENOMEM));
169         return( 1 );
170     }
171     p_intf->p_sys->i_key = -1;
172     
173     /* Create the interface window */
174     p_intf->p_sys->p_window =
175         new InterfaceWindow( BRect( 50, 50, 400, 100 ),
176                              VOUT_TITLE " (BeOS interface)", p_intf );
177     if( p_intf->p_sys->p_window == 0 )
178     {
179         free( p_intf->p_sys );
180         intf_ErrMsg( "error: cannot allocate memory for InterfaceWindow" );
181         return( 1 );
182     }
183     
184     /* Bind normal keys. */
185     intf_AssignNormalKeys( p_intf );
186
187     return( 0 );
188 }
189
190 /*****************************************************************************
191  * intf_Close: destroy dummy interface
192  *****************************************************************************/
193 static void intf_Close( intf_thread_t *p_intf )
194 {
195     /* Destroy the interface window */
196     p_intf->p_sys->p_window->Lock();
197     p_intf->p_sys->p_window->Quit();    
198
199     /* Destroy structure */
200     free( p_intf->p_sys );
201 }
202
203
204 /*****************************************************************************
205  * intf_Run: event loop
206  *****************************************************************************/
207 static void intf_Run( intf_thread_t *p_intf )
208 {
209     while( !p_intf->b_die )
210     {
211         /* Manage core vlc functions through the callback */
212         p_intf->pf_manage( p_intf );
213
214         /* Manage keys */
215         if( p_intf->p_sys->i_key != -1 )
216         {
217             intf_ProcessKey( p_intf, p_intf->p_sys->i_key );
218             p_intf->p_sys->i_key = -1;
219         }
220
221         /* Wait a bit */
222         msleep( INTF_IDLE_SLEEP );
223     }
224 }
225
226 } /* extern "C" */