]> git.sesse.net Git - vlc/blob - plugins/beos/intf_beos.cpp
A lot of bug fixs for the BeOS side of VideoLAN:
[vlc] / plugins / beos / intf_beos.cpp
1 /*****************************************************************************
2  * intf_beos.cpp: beos interface
3  *****************************************************************************
4  * Copyright (C) 1999, 2000 VideoLAN
5  *
6  * Authors:
7  * Jean-Marc Dressler
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
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include "defs.h"
28
29 #include <stdio.h>
30 #include <stdlib.h>                                      /* malloc(), free() */
31 #include <sys/types.h>                        /* on BSD, uio.h needs types.h */
32 #include <sys/uio.h>                                            /* "input.h" */
33 #include <kernel/OS.h>
34 #include <View.h>
35 #include <Application.h>
36 #include <Message.h>
37 #include <Locker.h>
38 #include <DirectWindow.h>
39 #include <malloc.h>
40 #include <string.h>
41
42 extern "C"
43 {
44 #include "config.h"
45 #include "common.h"
46 #include "threads.h"
47 #include "mtime.h"
48 #include "plugins.h"
49
50 #include "input.h"
51 #include "video.h"
52 #include "video_output.h"
53
54 #include "intf_msg.h"
55 #include "interface.h"
56
57 #include "main.h"
58 }
59
60 #include "beos_window.h"
61
62 /*****************************************************************************
63  * intf_sys_t: description and status of FB interface
64  *****************************************************************************/
65 typedef struct intf_sys_s
66 {
67     InterfaceWindow * p_window;
68     char              i_key;
69 } intf_sys_t;
70
71 /*****************************************************************************
72  * InterfaceWindow
73  *****************************************************************************/
74  
75 InterfaceWindow::InterfaceWindow( BRect frame, const char *name , intf_thread_t  *p_intf )
76     : BWindow(frame, name, B_TITLED_WINDOW, B_NOT_RESIZABLE|B_NOT_ZOOMABLE)
77 {
78     p_interface = p_intf;
79     SetName( "interface" );
80     
81     BView * p_view;
82     
83     p_view = new BView( Bounds(), "", B_FOLLOW_ALL, B_WILL_DRAW );
84     AddChild( p_view );
85     
86     Show();
87 }
88
89 InterfaceWindow::~InterfaceWindow()
90 {
91 }
92
93 /*****************************************************************************
94  * InterfaceWindow::MessageReceived
95  *****************************************************************************/
96
97 void InterfaceWindow::MessageReceived( BMessage * p_message )
98 {
99     char * psz_key;
100     
101     switch( p_message->what )
102     {
103     case B_KEY_DOWN:
104         p_message->FindString( "bytes", (const char **)&psz_key );
105         p_interface->p_sys->i_key = psz_key[0];
106         break;
107         
108     default:
109         BWindow::MessageReceived( p_message );
110         break;
111     }
112 }
113
114 /*****************************************************************************
115  * InterfaceWindow::QuitRequested
116  *****************************************************************************/
117
118 bool InterfaceWindow::QuitRequested()
119 {
120     return( false );
121 }
122
123
124 extern "C"
125 {
126
127 /*****************************************************************************
128  * intf_BeCreate: initialize dummy interface
129  *****************************************************************************/
130 int intf_BeCreate( intf_thread_t *p_intf )
131 {
132     /* Allocate instance and initialize some members */
133     p_intf->p_sys = (intf_sys_t*) malloc( sizeof( intf_sys_t ) );
134     if( p_intf->p_sys == NULL )
135     {
136         intf_ErrMsg("error: %s\n", strerror(ENOMEM));
137         return( 1 );
138     }
139     p_intf->p_sys->i_key = -1;
140     
141     /* Create the interface window */
142     p_intf->p_sys->p_window =
143         new InterfaceWindow( BRect( 100, 100, 200, 200 ), "Interface :)", p_intf );
144     if( p_intf->p_sys->p_window == 0 )
145     {
146         free( p_intf->p_sys );
147         intf_ErrMsg( "error: cannot allocate memory for InterfaceWindow\n" );
148         return( 1 );
149     }
150     
151     /* Spawn video output thread */
152     if( p_main->b_video )
153     {
154         p_intf->p_vout = vout_CreateThread( NULL, 0, 0, 0, NULL, 0, NULL );
155         if( p_intf->p_vout == NULL )                                /* error */
156         {
157             intf_ErrMsg("intf error: can't create output thread\n" );
158             return( 1 );
159         }
160     }
161
162     /* Bind normal keys. */
163     intf_AssignNormalKeys( p_intf );
164
165     return( 0 );
166 }
167
168 /*****************************************************************************
169  * intf_BeDestroy: destroy dummy interface
170  *****************************************************************************/
171 void intf_BeDestroy( intf_thread_t *p_intf )
172 {
173     /* Close input thread, if any (blocking) */
174     if( p_intf->p_input )
175     {
176         input_DestroyThread( p_intf->p_input, NULL );
177     }
178
179     /* Close video output thread, if any (blocking) */
180     if( p_intf->p_vout )
181     {
182         vout_DestroyThread( p_intf->p_vout, NULL );
183     }
184
185     /* Destroy the interface window */
186     p_intf->p_sys->p_window->Lock();
187     p_intf->p_sys->p_window->Quit();    
188
189     /* Destroy structure */
190     free( p_intf->p_sys );
191 }
192
193
194 /*****************************************************************************
195  * intf_BeManage: event loop
196  *****************************************************************************/
197 void intf_BeManage( intf_thread_t *p_intf )
198 {
199     if( p_intf->p_sys->i_key != -1 )
200     {
201         intf_ProcessKey( p_intf, p_intf->p_sys->i_key );
202         p_intf->p_sys->i_key = -1;
203     }
204 }
205
206 } /* extern "C" */