libmoldeo (Moldeo 1.0 Core)  1.0
libmoldeo is the group of objects and functions that executes the basic operations of Moldeo 1.0 Platform.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
moIODeviceManager.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2 
3  moIODeviceManager.cpp
4 
5  ****************************************************************************
6  * *
7  * This source is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This code is distributed in the hope that it will be useful, but *
13  * WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
15  * General Public License for more details. *
16  * *
17  * A copy of the GNU General Public License is available on the World *
18  * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
19  * obtain it by writing to the Free Software Foundation, *
20  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  * *
22  ****************************************************************************
23 
24  Copyright(C) 2006 Fabricio Costa
25 
26  Authors:
27  Fabricio Costa
28 
29 
30 *******************************************************************************/
31 
32 #include "moIODeviceManager.h"
33 
34 #include "moArray.h"
35 moDefineDynamicArray(moIODevicesArray)
36 
38  SetType(MO_OBJECT_IODEVICE);
39 }
40 
42 
43 }
44 
46  MODebug2->Message( " moIODevice::SetValue [NI] > cd: " + IntToStr(cd)
47  + " vl: " + IntToStr(vl) );
48 }
49 
51  MODebug2->Message( " moIODevice::SetValue [NI] > cd: " + IntToStr(cd)
52  + " vl: " + FloatToStr(vl) );
53 }
54 
56  MODebug2->Message( " moIODevice::SetValue [NI] > cd: " + IntToStr(cd)
57  + " data: " + data.ToText() );
58 }
59 
61  MODebug2->Message( " moIODevice::SetValue [NI] > cd: " + IntToStr(cd)
62  + " s: " + IntToStr(s)
63  + " pointer: " + IntToStr((long)pt) );
64 }
65 
66 moData
68  MODebug2->Message( " moIODevice::GetValue [NI] > cd: " + IntToStr(cd)
69  + " p_type: " + IntToStr((int)p_type) );
70  return moData();
71 
72 }
73 
75  MODebug2->Message( " moIODevice::GetValue [NI] > devcode: " + IntToStr(devcode)
76  + " i: " + IntToStr((int)i) );
77  return 0;
78 }
79 
81  MODebug2->Message( " moIODevice::GetNValues [NI] > devcode: " + IntToStr(devcode));
82  return 0;
83 }
84 
86  MODebug2->Message( " moIODevice::GetPointer [NI] > devcode: " + IntToStr(devcode));
87  return NULL;
88 }
89 
90 //===================================
91 //
92 // CONSOLA E/S ARRAY
93 //
94 //===================================
95 
97  Events = NULL;
98  m_IODevices.Init(0,NULL);
99 }
100 
102  Finish();
103 }
104 
105 
106 MOboolean
108  Events = new moEventList();
109  m_Plugins.Init(0,NULL);
110  return true;
111 }
112 
113 
114 moIODevice*
115 moIODeviceManager::NewIODevice( const moText& p_devname, const moText& p_configname, const moText& p_labelname, const moText& p_keyname, moMoldeoObjectType type, int paramindex, int valueindex, bool p_activate ) {
116 
117  moIODevice* pdevice = NULL;
118 
119  switch (type) {
120  case MO_OBJECT_IODEVICE:
121  pdevice = moNewIODevice( p_devname, m_Plugins );
122  if (pdevice) m_IODevices.Add( pdevice );
123  break;
124  default:
125  break;
126  }
127 
128  if (pdevice) {
129  moMobDefinition MDef = pdevice->GetMobDefinition();
130 
131  MDef.SetConsoleParamIndex(paramindex);
132  MDef.SetConsoleValueIndex(valueindex);
133  MDef.SetConfigName( p_configname );
134  MDef.SetLabelName( p_labelname );
135  MDef.SetKeyName( p_keyname );
136  MDef.SetActivate(p_activate);
137 
138  pdevice->SetMobDefinition(MDef);
139  }
140 
141  return pdevice;
142 }
143 
144 moIODevicesArray&
146 
147  return m_IODevices;
148 }
149 
150 MOboolean
152 
153 
154  moIODevice* pdevice = NULL;
155 
156  pdevice = m_IODevices.GetRef(p_ID);
157  if (pdevice) {
158  moDeleteIODevice( pdevice, m_Plugins );
159  m_IODevices.Remove(p_ID);
160  return true;
161  }
162 
163  return false;
164 }
165 
166 
167 void
169 
172 
173  PollEvents();
174 
175  for(MOuint i = 0; i < m_IODevices.Count(); i++) {
176  moIODevice* piodevice = m_IODevices.GetRef(i);
177  if(piodevice!=NULL) {
178  if (piodevice->Activated())
179  piodevice->Update(Events);
180  }
181  }
182 
183 
184 }
185 
187 void
188 moIODeviceManager::PollEvents() {
189 
190 /*
191  SDL_Event event;
192 
193  //SDL_KEYDOWN, // Keys pressed
194  //SDL_KEYUP, // Keys released
195  //SDL_MOUSEMOTION, // Mouse moved
196  //SDL_MOUSEBUTTONDOWN, // Mouse button pressed
197  //SDL_MOUSEBUTTONUP, // Mouse button released
198 
199  while(SDL_PollEvent(&event)) {
200  switch(event.type) {
201  case SDL_MOUSEMOTION:
202  Events->Add(MO_IODEVICE_MOUSE,SDL_MOUSEMOTION, event.motion.xrel, event.motion.yrel, event.motion.x, event.motion.y);
203  break;
204  case SDL_MOUSEBUTTONDOWN:
205  Events->Add(MO_IODEVICE_MOUSE,SDL_MOUSEBUTTONDOWN, event.button.button, event.button.x, event.button.y);
206  break;
207  case SDL_MOUSEBUTTONUP:
208  Events->Add(MO_IODEVICE_MOUSE,SDL_MOUSEBUTTONUP, event.button.button, event.button.x, event.button.y);
209  break;
210  case SDL_KEYDOWN:
211  // Ignore ALT-TAB for windows
212  if((event.key.keysym.sym == SDLK_LALT) ||
213  (event.key.keysym.sym == SDLK_RALT) ||
214  (event.key.keysym.sym == SDLK_TAB)) {
215  break;
216  }
217  Events->Add(MO_IODEVICE_KEYBOARD,SDL_KEYDOWN, event.key.keysym.sym, event.key.keysym.mod,0,0);
218  break;
219 
220  case SDL_KEYUP:
221  if((event.key.keysym.sym == SDLK_LALT) ||
222  (event.key.keysym.sym == SDLK_RALT) ||
223  (event.key.keysym.sym == SDLK_TAB)) {
224  break;
225  }
226  Events->Add(MO_IODEVICE_KEYBOARD,SDL_KEYUP, event.key.keysym.sym, event.key.keysym.mod,0,0);
227  break;
228  default:
229  break;
230  }
231  }
232 */
233 }
234 
241 void
243 
244  moEvent *actual=NULL,*tmp;
246 
247  if (Events) actual = Events->First;
248 
250  while(actual!=NULL) {
251  tmp = actual->next;
253  if (actual->reservedvalue3 != MO_MESSAGE
254  && actual->reservedvalue3 != MO_DATAMESSAGE) {
255  Events->Delete(actual);
256 
257  }
258  actual = tmp;
259  }
260 }
261 
264  return Events;
265 }
266 
267 MOdevcode
269  MODebug2->Message( "moIODeviceManager::GetCode > n: " + moText(n) );
270  return 0;
271 }
272 
273 MOswitch
275  MODebug2->Message( "moIODeviceManager::GetStatus > MOdevcode a: " + IntToStr(a) );
276  return 0;
277 }
278 
279 MOswitch
281  MODebug2->Message( "moIODeviceManager::GetStatus > MOdevcode a: " + IntToStr(a)
282  +" MOswitch b: " + IntToStr(b) );
283  return 0;
284 }
285 
286 
287 MOboolean
289  if(Events!=NULL) delete Events;
290  Events = NULL;
291  return true;
292 }
293 
moMoldeoObjectType
Tipos de objetos en Moldeo.
Definition: moTypes.h:525
moEvent * next
Definition: moEventList.h:60
moIODevice * NewIODevice(const moText &p_devname, const moText &p_configname, const moText &p_labelname, const moText &p_keyname, moMoldeoObjectType p_type, int paramindex=-1, int valueindex=-1, bool p_activate=true)
moEvent * First
Definition: moEventList.h:145
Clase Evento.
Definition: moEventList.h:56
moDataType
Definition: moValue.h:98
MOboolean RemoveIODevice(MOint p_ID)
virtual bool Activated() const
MOboolean Delete(moEvent *ev)
virtual MOint GetValue(MOdevcode)=0
virtual ~moIODevice()
LIBMOLDEO_API moText0 FloatToStr(double a)
Definition: moText.cpp:1134
virtual void Update(moEventList *)=0
moText ToText() const
Definition: moValue.cpp:707
#define MOboolean
Definition: moTypes.h:385
Objeto dibujable, efecto-maestro ( puede controlar otros efectos )
Definition: moTypes.h:531
virtual MOboolean Init()
void SetLabelName(const moText &p_labelname)
Fija la etiqueta de este objeto.
virtual MOpointer GetPointer(MOdevcode)
#define MOswitch
Definition: moTypes.h:386
#define MO_MESSAGE
Definition: moEventList.h:84
#define MOfloat
Definition: moTypes.h:403
Lista de eventos.
Definition: moEventList.h:139
clase de para manejar textos
Definition: moText.h:75
void SetConsoleValueIndex(MOint p_valueindex)
#define MOlong
Definition: moTypes.h:391
Clase Base Descriptiva de un Objeto Moldeo.
#define MOdevcode
Definition: moTypes.h:412
virtual MOint GetNValues(MOdevcode)
void SetConfigName(const moText &p_configname)
Fijar el nombre del archivo de configuración
moText0 moText
Definition: moText.h:291
const moMobDefinition & GetMobDefinition() const
LIBMOLDEO_API bool moDeleteIODevice(moIODevice *IODevice, moIODevicePluginsArray &plugins)
#define MOint
Definition: moTypes.h:388
MOswitch SetStatus(MOdevcode, MOswitch)
MOint reservedvalue3
Definition: moEventList.h:67
#define MO_DATAMESSAGE
Definition: moEventList.h:85
void SetKeyName(const moText &p_keyname)
Fija la etiqueta del padre de este objeto.
static moDebug * MODebug2
Clase de impresión de errores para depuración
Definition: moAbstract.h:225
void SetConsoleParamIndex(MOint p_paramindex)
MOdevcode GetCode(char *)
virtual MOboolean Finish()
#define MOuint
Definition: moTypes.h:387
LIBMOLDEO_API moIODevice * moNewIODevice(moText effect_name, moIODevicePluginsArray &plugins)
MOswitch GetStatus(MOdevcode)
LIBMOLDEO_API moText0 IntToStr(int a)
Definition: moText.cpp:1070
void SetMobDefinition(const moMobDefinition &p_MobDef)
moIODevicesArray & IODevices()
moEventList * GetEvents()
void SetActivate(bool p_activate)
Fija el modo de activación al inicio del proyecto.
void Message(moText p_text)
Anuncia un mensaje al usuario además de guardarlo en el log de texto.
Definition: moAbstract.cpp:114
#define MOpointer
Definition: moTypes.h:409
moDefineDynamicArray(moIODevicesArray) moIODevice
virtual void SetValue(MOdevcode, MOint)