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 $
7 * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8 * Samuel Hocevar <sam@zoy.org>
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.
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.
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 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
31 #include <stdlib.h> /* malloc(), free() */
32 #include <kernel/OS.h>
34 #include <Application.h>
37 #include <DirectWindow.h>
51 #include "interface.h"
56 #include "beos_window.h"
58 /*****************************************************************************
59 * intf_sys_t: description and status of FB interface
60 *****************************************************************************/
61 typedef struct intf_sys_s
63 InterfaceWindow * p_window;
67 /*****************************************************************************
69 *****************************************************************************/
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)
75 SetName( "interface" );
79 p_view = new BView( Bounds(), "", B_FOLLOW_ALL, B_WILL_DRAW );
85 InterfaceWindow::~InterfaceWindow()
89 /*****************************************************************************
90 * InterfaceWindow::MessageReceived
91 *****************************************************************************/
93 void InterfaceWindow::MessageReceived( BMessage * p_message )
97 switch( p_message->what )
100 p_message->FindString( "bytes", (const char **)&psz_key );
101 p_interface->p_sys->i_key = psz_key[0];
105 BWindow::MessageReceived( p_message );
110 /*****************************************************************************
111 * InterfaceWindow::QuitRequested
112 *****************************************************************************/
114 bool InterfaceWindow::QuitRequested()
123 /*****************************************************************************
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 );
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 )
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;
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 )
151 if( TestMethod( INTF_METHOD_VAR, "beos" ) )
159 /*****************************************************************************
160 * intf_Open: initialize dummy interface
161 *****************************************************************************/
162 static int intf_Open( intf_thread_t *p_intf )
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 )
168 intf_ErrMsg("error: %s", strerror(ENOMEM));
171 p_intf->p_sys->i_key = -1;
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 )
179 free( p_intf->p_sys );
180 intf_ErrMsg( "error: cannot allocate memory for InterfaceWindow" );
184 /* Bind normal keys. */
185 intf_AssignNormalKeys( p_intf );
190 /*****************************************************************************
191 * intf_Close: destroy dummy interface
192 *****************************************************************************/
193 static void intf_Close( intf_thread_t *p_intf )
195 /* Destroy the interface window */
196 p_intf->p_sys->p_window->Lock();
197 p_intf->p_sys->p_window->Quit();
199 /* Destroy structure */
200 free( p_intf->p_sys );
204 /*****************************************************************************
205 * intf_Run: event loop
206 *****************************************************************************/
207 static void intf_Run( intf_thread_t *p_intf )
209 while( !p_intf->b_die )
211 /* Manage core vlc functions through the callback */
212 p_intf->pf_manage( p_intf );
215 if( p_intf->p_sys->i_key != -1 )
217 intf_ProcessKey( p_intf, p_intf->p_sys->i_key );
218 p_intf->p_sys->i_key = -1;
222 msleep( INTF_IDLE_SLEEP );