]> git.sesse.net Git - vlc/blob - plugins/beos/intf_beos.cpp
* Added error checking in pthread wrapper ; as a result, intf_msg.h must
[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.33 2001/11/28 15:08:05 massiot Exp $
6  *
7  * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8  *          Samuel Hocevar <sam@zoy.org>
9  *          Tony Castley <tony@castley.net>
10  *          Richard Shepherd <richard@rshepherd.demon.co.uk>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
25  *****************************************************************************/
26
27 #define MODULE_NAME beos
28 #include "modules_inner.h"
29
30 /*****************************************************************************
31  * Preamble
32  *****************************************************************************/
33 #include "defs.h"
34
35 #include <stdio.h>
36 #include <stdlib.h>                                      /* malloc(), free() */
37 #include <InterfaceKit.h>
38 #include <string.h>
39
40 extern "C"
41 {
42 #include "config.h"
43 #include "common.h"
44 #include "intf_msg.h"
45 #include "threads.h"
46 #include "mtime.h"
47 #include "tests.h"
48 #include "stream_control.h"
49 #include "interface.h"
50 #include "input_ext-intf.h"
51 #include "main.h"
52 #include "modules.h"
53 #include "modules_export.h"
54 }
55
56 #include "InterfaceWindow.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 extern "C"
69 {
70
71 /*****************************************************************************
72  * Local prototypes.
73  *****************************************************************************/
74 static int  intf_Probe     ( probedata_t *p_data );
75 static int  intf_Open      ( intf_thread_t *p_intf );
76 static void intf_Close     ( intf_thread_t *p_intf );
77 static void intf_Run       ( intf_thread_t *p_intf );
78
79 /*****************************************************************************
80  * Functions exported as capabilities. They are declared as static so that
81  * we don't pollute the namespace too much.
82  *****************************************************************************/
83 void _M( intf_getfunctions )( function_list_t * p_function_list )
84 {
85     p_function_list->pf_probe = intf_Probe;
86     p_function_list->functions.intf.pf_open  = intf_Open;
87     p_function_list->functions.intf.pf_close = intf_Close;
88     p_function_list->functions.intf.pf_run   = intf_Run;
89 }
90
91 /*****************************************************************************
92  * intf_Probe: probe the interface and return a score
93  *****************************************************************************
94  * This function tries to initialize Gnome and returns a score to the
95  * plugin manager so that it can select the best plugin.
96  *****************************************************************************/
97 static int intf_Probe( probedata_t *p_data )
98 {
99     if( TestMethod( INTF_METHOD_VAR, "beos" ) )
100     {
101         return( 999 );
102     }
103
104     return( 100 );
105 }
106
107 /*****************************************************************************
108  * intf_Open: initialize interface
109  *****************************************************************************/
110 static int intf_Open( intf_thread_t *p_intf )
111 {
112     BScreen *screen;
113     screen = new BScreen();
114     BRect rect = screen->Frame();
115     rect.top = rect.bottom-100;
116     rect.bottom -= 50;
117     rect.left += 50;
118     rect.right = rect.left + 350;
119     delete screen;
120
121     /* Allocate instance and initialize some members */
122     p_intf->p_sys = (intf_sys_t*) malloc( sizeof( intf_sys_t ) );
123     if( p_intf->p_sys == NULL )
124     {
125         intf_ErrMsg("error: %s", strerror(ENOMEM));
126         return( 1 );
127     }
128     p_intf->p_sys->i_key = -1;
129
130     /* Create the interface window */
131     p_intf->p_sys->p_window =
132         new InterfaceWindow( rect,
133                              VOUT_TITLE " (BeOS interface)", p_intf );
134     if( p_intf->p_sys->p_window == 0 )
135     {
136         free( p_intf->p_sys );
137         intf_ErrMsg( "error: cannot allocate memory for InterfaceWindow" );
138         return( 1 );
139     }
140
141     return( 0 );
142 }
143
144 /*****************************************************************************
145  * intf_Close: destroy dummy interface
146  *****************************************************************************/
147 static void intf_Close( intf_thread_t *p_intf )
148 {
149     /* Destroy the interface window */
150     p_intf->p_sys->p_window->Lock();
151     p_intf->p_sys->p_window->Quit();
152
153     /* Destroy structure */
154     free( p_intf->p_sys );
155 }
156
157
158 /*****************************************************************************
159  * intf_Run: event loop
160  *****************************************************************************/
161 static void intf_Run( intf_thread_t *p_intf )
162 {
163
164     while( !p_intf->b_die )
165     {
166         /* Manage core vlc functions through the callback */
167         p_intf->pf_manage( p_intf );
168
169         /* Manage the slider */
170         if( p_intf->p_input != NULL && p_intf->p_sys->p_window != NULL)
171         {
172         p_intf->p_sys->p_window->updateInterface();
173         }
174
175         /* Wait a bit */
176         msleep( INTF_IDLE_SLEEP );
177     }
178 }
179
180 } /* extern "C" */
181