Ginga  0.13.6
 All Classes Namespaces Functions Variables
LocalScreenManager.h
1 /******************************************************************************
2 Este arquivo eh parte da implementacao do ambiente declarativo do middleware
3 Ginga (Ginga-NCL).
4 
5 Direitos Autorais Reservados (c) 1989-2007 PUC-Rio/Laboratorio TeleMidia
6 
7 Este programa eh software livre; voce pode redistribui-lo e/ou modificah-lo sob
8 os termos da Licenca Publica Geral GNU versao 2 conforme publicada pela Free
9 Software Foundation.
10 
11 Este programa eh distribuido na expectativa de que seja util, porem, SEM
12 NENHUMA GARANTIA; nem mesmo a garantia implicita de COMERCIABILIDADE OU
13 ADEQUACAO A UMA FINALIDADE ESPECIFICA. Consulte a Licenca Publica Geral do
14 GNU versao 2 para mais detalhes.
15 
16 Voce deve ter recebido uma copia da Licenca Publica Geral do GNU versao 2 junto
17 com este programa; se nao, escreva para a Free Software Foundation, Inc., no
18 endereco 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
19 
20 Para maiores informacoes:
21 ncl @ telemidia.puc-rio.br
22 http://www.ncl.org.br
23 http://www.ginga.org.br
24 http://www.telemidia.puc-rio.br
25 ******************************************************************************
26 This file is part of the declarative environment of middleware Ginga (Ginga-NCL)
27 
28 Copyright: 1989-2007 PUC-RIO/LABORATORIO TELEMIDIA, All Rights Reserved.
29 
30 This program is free software; you can redistribute it and/or modify it under
31 the terms of the GNU General Public License version 2 as published by
32 the Free Software Foundation.
33 
34 This program is distributed in the hope that it will be useful, but WITHOUT ANY
35 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
36 PARTICULAR PURPOSE. See the GNU General Public License version 2 for more
37 details.
38 
39 You should have received a copy of the GNU General Public License version 2
40 along with this program; if not, write to the Free Software
41 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
42 
43 For further information contact:
44 ncl @ telemidia.puc-rio.br
45 http://www.ncl.org.br
46 http://www.ginga.org.br
47 http://www.telemidia.puc-rio.br
48 *******************************************************************************/
49 
50 #ifndef LocalScreenManager_H_
51 #define LocalScreenManager_H_
52 
53 #include "interface/IDeviceScreen.h"
54 #include "ILocalScreenManager.h"
55 #include "IInputManager.h"
56 
57 #include <pthread.h>
58 
59 #include "system/thread/Thread.h"
60 using namespace br::pucrio::telemidia::ginga::core::system::thread;
61 
62 #include <string>
63 #include <iostream>
64 #include <map>
65 using namespace std;
66 
67 namespace br {
68 namespace pucrio {
69 namespace telemidia {
70 namespace ginga {
71 namespace core {
72 namespace mb {
74  public:
75  /* Ginga defining its Multimedia Backend System Types (GMBST) */
76  /* System Description String */
77  static const short GMBST_DFLT; /* Default system: dflt */
78  static const short GMBST_DFB; /* DirectFB: dfb */
79  static const short GMBST_DX; /* DirectX: dx */
80  static const short GMBST_SDL; /* SDL: sdl */
81  static const short GMBST_TERM; /* Teminal: term */
82 
83  /* Ginga defining its Multimedia Backend SubSystem Types (GMBSST)*/
84  /* System Description String */
85  static const short GMBSST_DFLT; /* Default subsystem: dflt */
86  static const short GMBSST_FBDEV; /* Frame buffer: fbdev */
87  static const short GMBSST_X11; /* X11: x11 */
88  static const short GMBSST_HWND; /* MS-W Window Handle: hwnd */
89  static const short GMBSST_SDL; /* SDL: sdl */
90  static const short GMBSST_COCOA; /* COCOA: cocoa */
91 
92  private:
93  map<GingaScreenID, IDeviceScreen*> screens;
94  pthread_mutex_t mapMutex;
95  pthread_mutex_t genMutex;
96 
97  static set<IInputEventListener*> iListeners;
98  static pthread_mutex_t ilMutex;
99 
100  static set<IMotionEventListener*> mListeners;
101  static pthread_mutex_t mlMutex;
102 
103  static bool initMutex;
104 
105  vector<short> sortSys;
106  map<string, short> sysNames;
107  pthread_mutex_t sysMutex;
108 
109  bool running;
110 
111  bool isWaiting;
112  pthread_cond_t wsSignal;
113  pthread_mutex_t wsMutex;
114  GingaScreenID waitingRefreshScreen;
115 
116  static LocalScreenManager* _instance;
117 
119  virtual ~LocalScreenManager();
120 
121  static void checkInitMutex();
122 
123  public:
124  void releaseHandler();
125 
126  static void addIEListenerInstance(
127  IInputEventListener* listener);
128 
129  static void removeIEListenerInstance(
130  IInputEventListener* listener);
131 
132  static bool hasIEListenerInstance(
133  IInputEventListener* listener, bool removeInstance=false);
134 
135  static void addMEListenerInstance(
136  IMotionEventListener* listener);
137 
138  static void removeMEListenerInstance(
139  IMotionEventListener* listener);
140 
141  static bool hasMEListenerInstance(
142  IMotionEventListener* listener, bool removeInstance=false);
143 
144  void setBackgroundImage(GingaScreenID screenId, string uri);
145 
146  static LocalScreenManager* getInstance();
147 
148  int getDeviceWidth(GingaScreenID screenId);
149 
150  int getDeviceHeight(GingaScreenID screenId);
151 
152  void* getGfxRoot(GingaScreenID screenId);
153 
154  void releaseScreen(GingaScreenID screenId);
155  void releaseMB(GingaScreenID screenId);
156  void clearWidgetPools(GingaScreenID screenId);
157 
158  GingaScreenID createScreen(int argc, char** args);
159 
160  private:
161  GingaScreenID createScreen(
162  string vSystem,
163  string vSubSystem,
164  string vMode,
165  string vParent,
166  string vEmbed,
167  string aSystem,
168  bool externalRenderer,
169  bool useStdin);
170 
171  public:
172  string getScreenName(GingaScreenID screenId);
173  GingaWindowID getScreenUnderlyingWindow(GingaScreenID screenId);
174 
175  private:
176  void getMBSystemType(string mbSystemName, short* mbSystemType);
177 
178  bool isAvailable(short mbSysType);
179  void lockSysNames();
180  void unlockSysNames();
181 
182  public:
183  IWindow* getIWindowFromId(
184  GingaScreenID screenId, GingaWindowID winId);
185 
186  bool mergeIds(
187  GingaScreenID screenId,
188  GingaWindowID destId,
189  vector<GingaWindowID>* srcIds);
190 
191  void blitScreen(GingaScreenID screenId, ISurface* destination);
192  void blitScreen(GingaScreenID screenId, string fileUri);
193  void refreshScreen(GingaScreenID screenId);
194 
195 
196  /* Interfacing output */
197  IWindow* createWindow(
198  GingaScreenID screenId,
199  int x, int y,
200  int w, int h,
201  float z);
202 
203  GingaWindowID createUnderlyingSubWindow(
204  GingaScreenID screenId,
205  int x, int y,
206  int w, int h,
207  float z);
208 
209  IWindow* createWindowFrom(
210  GingaScreenID screenId, GingaWindowID underlyingWindow);
211 
212  bool hasWindow(GingaScreenID screenId, IWindow* window);
213  void releaseWindow(GingaScreenID screenId, IWindow* window);
214 
215  ISurface* createSurface(GingaScreenID screenId);
216 
217  ISurface* createSurface(GingaScreenID screenId, int w, int h);
218 
219  ISurface* createSurfaceFrom(
220  GingaScreenID screenId, void* underlyingSurface);
221 
222  bool hasSurface(GingaScreenID screenId, ISurface* surface);
223  bool releaseSurface(GingaScreenID screenId, ISurface* surface);
224 
225 
226  /* Interfacing content */
227  IContinuousMediaProvider* createContinuousMediaProvider(
228  GingaScreenID screenId,
229  const char* mrl,
230  bool* hasVisual,
231  bool isRemote);
232 
233  void releaseContinuousMediaProvider(
234  GingaScreenID screenId,
235  IContinuousMediaProvider* provider);
236 
237  IFontProvider* createFontProvider(
238  GingaScreenID screenId,
239  const char* mrl,
240  int fontSize);
241 
242  void releaseFontProvider(
243  GingaScreenID screenId, IFontProvider* provider);
244 
245  IImageProvider* createImageProvider(
246  GingaScreenID screenId, const char* mrl);
247 
248  void releaseImageProvider(
249  GingaScreenID screenId, IImageProvider* provider);
250 
251  ISurface* createRenderedSurfaceFromImageFile(
252  GingaScreenID screenId, const char* mrl);
253 
254 
255  /* interfacing input */
256  IInputManager* getInputManager(GingaScreenID screenId);
257  IEventBuffer* createEventBuffer(GingaScreenID screenId);
258  IInputEvent* createInputEvent(
259  GingaScreenID screenId, void* event, const int symbol);
260 
261  IInputEvent* createApplicationEvent(
262  GingaScreenID screenId, int type, void* data);
263 
264  int fromMBToGinga(GingaScreenID screenId, int keyCode);
265  int fromGingaToMB(GingaScreenID screenId, int keyCode);
266 
267  /* and finally some private stuff */
268  private:
269  void addScreen(
270  GingaScreenID screenId, IDeviceScreen* screen);
271 
272  short getNumOfScreens();
273 
274  bool getScreen(
275  GingaScreenID screenId, IDeviceScreen** screen);
276 
277  bool removeScreen(GingaScreenID screenId);
278 
279  void lockScreenMap();
280  void unlockScreenMap();
281 
282  void lock();
283  void unlock();
284  };
285 }
286 }
287 }
288 }
289 }
290 }
291 
292 #endif /*LocalScreenManager_H_*/