NLMISC::CInputDeviceServer Class Reference

#include <input_device_server.h>


Detailed Description

Base class for an input device server. Unlike an event server, it manages several devices, and can sort their events (by date for example). It keeps a list of active devices. It can poll datas from every active device. It can sort devices messages to submit them in correct order to a CEventServer.

Definition at line 47 of file input_device_server.h.

Public Member Functions

IInputDevicegetDevice (uint index)
uint getNumDevices () const
bool isDevice (IInputDevice *device) const
 Test wether the given device is handled by this server.

void poll (CEventServer *server)
 Retrieve datas from the devices, and submit them to the given CEventServer.

void registerDevice (IInputDevice *device)
 register a device into this device server.

void removeDevice (IInputDevice *device)
 remove a device from this server (but does not delete it).

void submitEvent (IInputDeviceEvent *deviceEvent)
 Allow an input device to register an event. The event will then be deleted by this server.

virtual ~CInputDeviceServer ()

Private Types

typedef std::vector< IInputDevice * > TDeviceCont
typedef std::vector< IInputDeviceEvent * > TEventCont

Private Attributes

TDeviceCont _Devices
TEventCont _Events


Member Typedef Documentation

typedef std::vector<IInputDevice *> NLMISC::CInputDeviceServer::TDeviceCont [private]
 

Definition at line 67 of file input_device_server.h.

typedef std::vector<IInputDeviceEvent *> NLMISC::CInputDeviceServer::TEventCont [private]
 

Definition at line 68 of file input_device_server.h.


Constructor & Destructor Documentation

virtual NLMISC::CInputDeviceServer::~CInputDeviceServer  )  [inline, virtual]
 

Definition at line 65 of file input_device_server.h.

00065 {}


Member Function Documentation

IInputDevice* NLMISC::CInputDeviceServer::getDevice uint  index  )  [inline]
 

Definition at line 57 of file input_device_server.h.

References _Devices, index, and uint.

00057 { return _Devices[index]; }

uint NLMISC::CInputDeviceServer::getNumDevices  )  const [inline]
 

Definition at line 55 of file input_device_server.h.

References _Devices, and uint.

00055 { return _Devices.size(); }

bool NLMISC::CInputDeviceServer::isDevice IInputDevice device  )  const
 

Test wether the given device is handled by this server.

Definition at line 50 of file input_device_server.cpp.

References _Devices.

Referenced by registerDevice().

00051 {
00052         TDeviceCont::const_iterator it = std::find(_Devices.begin(), _Devices.end(), device);
00053         return it != _Devices.end();
00054 }

void NLMISC::CInputDeviceServer::poll CEventServer server  ) 
 

Retrieve datas from the devices, and submit them to the given CEventServer.

Definition at line 67 of file input_device_server.cpp.

References _Devices, nlassert, and NLMISC::IInputDevice::transitionOccured().

00068 {
00069         nlassert(_Events.empty());
00070         TDeviceCont::iterator deviceIt;
00071         for (deviceIt = _Devices.begin(); deviceIt != _Devices.end(); ++deviceIt)
00072         {
00073                 (*deviceIt)->begin(server);
00074                 (*deviceIt)->poll(this);
00075         }                       
00076         // Sort the messages to get the right dates.
00077         std::sort(_Events.begin(), _Events.end(), CInputDeviceEventLess());
00078         // submit the result to the server
00079         IInputDevice *lastVisitedDevice = NULL;
00080         TEventCont::iterator eventIt;
00081         for (eventIt = _Events.begin(); eventIt != _Events.end(); ++eventIt)
00082         {
00083                 // see if this message is from a previous device then the last we visited.
00084                 if (lastVisitedDevice && (*eventIt)->Emitter != lastVisitedDevice)
00085                 {
00086                         // yes, tells that a transition occured
00087                         lastVisitedDevice->transitionOccured(server, *eventIt);
00088                         lastVisitedDevice = (*eventIt)->Emitter;
00089                 }
00090                 nlassert((*eventIt)->Emitter != NULL);
00091                 (*eventIt)->Emitter->submit(*eventIt, server);
00092         }
00093         //
00094         for (deviceIt = _Devices.begin(); deviceIt != _Devices.end(); ++deviceIt)
00095         {
00096                 (*deviceIt)->transitionOccured(server, NULL);
00097         }
00098         // delete the messages
00099         for (eventIt = _Events.begin(); eventIt != _Events.end(); ++eventIt)
00100         {
00101                 delete *eventIt;                
00102         }
00103         //
00104         _Events.clear();
00105 }

void NLMISC::CInputDeviceServer::registerDevice IInputDevice device  ) 
 

register a device into this device server.

Definition at line 35 of file input_device_server.cpp.

References _Devices, isDevice(), and nlassert.

00036 {
00037         nlassert(!isDevice(device));
00038         _Devices.push_back(device);
00039 }

void NLMISC::CInputDeviceServer::removeDevice IInputDevice device  ) 
 

remove a device from this server (but does not delete it).

Definition at line 42 of file input_device_server.cpp.

References _Devices, and nlassert.

00043 {
00044         TDeviceCont::iterator it = std::find(_Devices.begin(), _Devices.end(), device);
00045         nlassert(it != _Devices.end());
00046         _Devices.erase(it);
00047 }

void NLMISC::CInputDeviceServer::submitEvent IInputDeviceEvent deviceEvent  ) 
 

Allow an input device to register an event. The event will then be deleted by this server.

Definition at line 108 of file input_device_server.cpp.

00109 {
00110         _Events.push_back(deviceEvent);
00111 }


Field Documentation

TDeviceCont NLMISC::CInputDeviceServer::_Devices [private]
 

Definition at line 70 of file input_device_server.h.

Referenced by getDevice(), getNumDevices(), isDevice(), poll(), registerDevice(), and removeDevice().

TEventCont NLMISC::CInputDeviceServer::_Events [private]
 

Definition at line 71 of file input_device_server.h.


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 13:19:48 2004 for NeL by doxygen 1.3.6