cmil::DeviceRegistry Class Reference

#include <InputDevice.h>

Inheritance diagram for cmil::DeviceRegistry:

Inheritance graph
[legend]
Collaboration diagram for cmil::DeviceRegistry:

Collaboration graph
[legend]
List of all members.

Public Types

typedef std::vector< InputDeviceDeviceMultiple
 This type defines the structure of the registry.
typedef std::map< const std::string,
DeviceMultiple
DeviceIndex
 This type defines the structure of the registry.

Public Member Functions

 DeviceRegistry ()
void cleanup ()
 This unallocates memory.
void clear ()
virtual ~DeviceRegistry ()
virtual std::string getName () const
void registerDevice (InputDevice &dev)
 This function should "copy" the device into the registry.
void mergeRegistry (DeviceRegistry &reg)
 This registers each device from the passed registry to this one.
void SetInputIDs (InputDevice &dev)
int getSize () const
std::string getDefaultDevice () const
InputData *const getData (unsigned int id) const
InputData *const getData (const Ev &event) const
int getID (const Ev &event) const
void integrityCheck () const

Private Member Functions

void copyDevice (InputDevice &dev)

Private Attributes

DeviceIndex m_index
std::string m_default_device
std::vector< InputData * > m_inputs
 This is used for fast access of the InputData associated with an ID.

Detailed Description

This is the base DeviceRegistry which provides functions for storage of devices and their inputs.

Definition at line 197 of file InputDevice.h.


Member Typedef Documentation

typedef std::map<const std::string, DeviceMultiple> cmil::DeviceRegistry::DeviceIndex

This type defines the structure of the registry.

Definition at line 202 of file InputDevice.h.

typedef std::vector<InputDevice > cmil::DeviceRegistry::DeviceMultiple

This type defines the structure of the registry.

Definition at line 200 of file InputDevice.h.


Constructor & Destructor Documentation

cmil::DeviceRegistry::DeviceRegistry (  )  [inline]

Definition at line 204 of file InputDevice.h.

00204 {}

virtual cmil::DeviceRegistry::~DeviceRegistry (  )  [inline, virtual]

Definition at line 209 of file InputDevice.h.

00209 {}; 


Member Function Documentation

void cmil::DeviceRegistry::cleanup (  ) 

This unallocates memory.

Definition at line 464 of file InputDevice.cpp.

References getSize(), Logger::log_debug(), and m_index.

Referenced by cmil::InputArbitrator::~InputArbitrator().

00464                                {
00465     log_debug("cleanup()");
00466     std::cout << "registry size: " << getSize() << std::endl;
00467     DeviceIndex::iterator di_iter;
00468     DeviceMultiple::iterator dm_iter;
00469     for(di_iter = m_index.begin() ; di_iter != m_index.end() ; ++di_iter) 
00470       for(dm_iter = di_iter->second.begin() ; dm_iter != di_iter->second.end() ; ++dm_iter) { 
00471         log_debug("calling dm_iter->cleanup()");
00472         dm_iter->cleanup();
00473       }
00474   };

Here is the call graph for this function:

Here is the caller graph for this function:

void cmil::DeviceRegistry::clear (  ) 

This clears the device registry. Care with this must be taken because the memory (InputData) left by the devices will remains allocated.

Definition at line 453 of file InputDevice.cpp.

References getSize(), Logger::log_debug(), and m_index.

Referenced by cmil::SDL::SDLControllers::getDevices(), cmil::SDL::SDLMice::getDevices(), and cmil::SDL::SDLKeyboards::getDevices().

00453                              {
00454     log_debug("cleanup()");
00455     std::cout << "registry size: " << getSize() << std::endl;
00456     DeviceIndex::iterator di_iter;
00457     DeviceMultiple::iterator dm_iter;
00458     for(di_iter = m_index.begin() ; di_iter != m_index.end() ; ++di_iter) 
00459       di_iter->second.clear();
00460     m_index.clear();
00461   }

Here is the call graph for this function:

Here is the caller graph for this function:

void cmil::DeviceRegistry::copyDevice ( InputDevice dev  )  [private]

Definition at line 577 of file InputDevice.cpp.

References cmil::DeviceInputs::getCustomInputs(), cmil::InputDevice::getInputs(), cmil::InputDevice::getName(), Logger::log_debug(), m_index, m_inputs, cmil::InputDevice::resetIDs(), and cmil::InputDevice::resetWhichDevice().

Referenced by registerDevice().

00577                                                    {
00578      DeviceInputs::Inputs::const_iterator i;
00579      int which_device;
00580 
00582      log_debug("copyDevice(): copying device");
00583      m_index[dev.getName()].push_back(dev);
00584 
00585      which_device = m_index[dev.getName()].size();
00586 
00587      //TODO Reverse lookup features should probably be decoupled from the InputData type instead, but this makes things fast. 
00588 
00589      dev.resetIDs(m_inputs.size());
00590      dev.resetWhichDevice(which_device);
00591 
00592      for(i = dev.getInputs().getCustomInputs().begin(); i != dev.getInputs().getCustomInputs().end(); ++i) 
00594        m_inputs.push_back(i->second); 
00595 
00596    }

Here is the call graph for this function:

Here is the caller graph for this function:

InputData *const cmil::DeviceRegistry::getData ( const Ev event  )  const

Definition at line 488 of file InputDevice.cpp.

References getDefaultDevice(), cmil::Ev::getDeviceMultiple(), cmil::Ev::getDeviceName(), cmil::Ev::getName(), Logger::log_debug(), Logger::log_error(), m_index, and cmil::DeviceInputs::use_custom.

00488                                                                  {
00489     std::string name; 
00490 
00491     if((name = event.getDeviceName()) == "") {
00492       name = getDefaultDevice(); 
00493       log_debug(std::string("getData() setting name to default: ").append(name));
00494     }
00495     if(name == "")
00496       log_error("getData() returning null since no default device is available.");
00497     else {
00498       log_debug(std::string("getData() for device name: ").append(name));
00499 
00500 
00502       DeviceIndex::const_iterator i = m_index.find(name); 
00503 
00504       std::ostringstream size_ss;
00505 
00506       if(i != m_index.end()) 
00507         if(i->second.size() >= event.getDeviceMultiple()) {
00508           size_ss << "getData() number of devices with name: " << i->second.size();
00509           log_debug(size_ss.str());
00510 
00512           return i->second[event.getDeviceMultiple()].getData(DeviceInputs::use_custom, event.getName());
00513         }
00514     }
00515 
00516     log_error("getData() returning null");
00517     return NULL;
00518   };

Here is the call graph for this function:

InputData *const cmil::DeviceRegistry::getData ( unsigned int  id  )  const

Definition at line 480 of file InputDevice.cpp.

References Logger::log_error(), and m_inputs.

Referenced by cmil::InputArbitrator::getData(), and getID().

00480                                                                 {
00481     if(id <= m_inputs.size())
00482       return m_inputs[id];
00483 
00484     log_error("getData(id) bounds error, returnning NULL");
00485     return NULL;
00486   };

Here is the call graph for this function:

Here is the caller graph for this function:

std::string cmil::DeviceRegistry::getDefaultDevice (  )  const

Definition at line 476 of file InputDevice.cpp.

References m_default_device.

Referenced by getData(), and cmil::InputArbitrator::getDefaultDevice().

00476                                                    {
00477     return m_default_device;
00478   };

Here is the caller graph for this function:

int cmil::DeviceRegistry::getID ( const Ev event  )  const

In addition to returning and ID, this is used to validate an events structure via deference to getData (return 0 on error)

Definition at line 520 of file InputDevice.cpp.

References getData(), cmil::InputData::getID(), Logger::log_debug(), and Logger::log_error().

Referenced by cmil::InputArbitrator::getID().

00520                                                  {
00521     if(getData(event)) {
00522       log_debug("getID() found data matching event, returning id");
00523       return getData(event)->getID();
00524     }
00525     else {
00526       log_error("getID() no id found in registry which matched id");
00527       return 0;
00528     }
00529   };

Here is the call graph for this function:

Here is the caller graph for this function:

virtual std::string cmil::DeviceRegistry::getName (  )  const [inline, virtual]

Implements Logger.

Definition at line 211 of file InputDevice.h.

00211                                         {
00212         return "DeviceRegistry";
00213       }; 

int cmil::DeviceRegistry::getSize (  )  const

Definition at line 531 of file InputDevice.cpp.

References m_inputs.

Referenced by cleanup(), clear(), cmil::SDL::SDLControllers::getDevices(), cmil::SDL::SDLMice::getDevices(), cmil::SDL::SDLKeyboards::getDevices(), and cmil::InputArbitrator::getSize().

00531                                     {
00532      return m_inputs.size();
00533   };

Here is the caller graph for this function:

void cmil::DeviceRegistry::integrityCheck (  )  const

void cmil::DeviceRegistry::mergeRegistry ( DeviceRegistry reg  ) 

This registers each device from the passed registry to this one.

Definition at line 536 of file InputDevice.cpp.

References Logger::log_debug(), m_index, and registerDevice().

Referenced by cmil::SDL::SDLTranslator::addTranslated(), and cmil::InputArbitrator::registerDevices().

00536                                                         {
00537     log_debug("mergeRegistery() ");
00538     for(DeviceIndex::iterator di_iter = reg.m_index.begin() ; di_iter != reg.m_index.end() ; ++di_iter) 
00539       for(DeviceMultiple::iterator dm_iter = di_iter->second.begin() ; dm_iter != di_iter->second.end() ; ++dm_iter) {
00540         registerDevice(*dm_iter);
00541         log_debug(std::string("mergeRegistery() calling registerDevice() with name: ").append((*dm_iter).getName()));
00542       }
00543   };

Here is the call graph for this function:

Here is the caller graph for this function:

void cmil::DeviceRegistry::registerDevice ( InputDevice dev  ) 

This function should "copy" the device into the registry.

First match the device by name.

None found, add this as a new device, even if their members match some other device, derive/change if you would like different behavior.

Set the first added device as the default device name.

Matched, now ensure a match using the InputDevice::operator==

Definition at line 546 of file InputDevice.cpp.

References copyDevice(), cmil::InputDevice::getName(), Logger::log_debug(), Logger::log_error(), m_default_device, and m_index.

Referenced by cmil::SDL::SDLControllers::getDevices(), cmil::SDL::SDLMice::getDevices(), cmil::SDL::SDLKeyboards::getDevices(), mergeRegistry(), and cmil::InputArbitrator::registerDevice().

00546                                                        {
00547      DeviceIndex::iterator i;
00548 
00550      if( (i=m_index.find(dev.getName())) == m_index.end())  {
00553 
00554        log_debug(std::string("registerDevice() adding device named: ").append(dev.getName()));
00555 
00557        if(m_index.empty()) {
00558          log_debug(std::string("registerDevice() setting default device to: ").append(dev.getName()));
00559          m_default_device = dev.getName();
00560        }
00561        copyDevice(dev); 
00562      }
00563      else {
00565        if ( *(i->second.begin()) == dev) {
00566          log_debug(std::string("registerDevices() registering another device of the same type and name: ").append(dev.getName()));
00567         
00568          copyDevice(dev); 
00569        }
00570        else {
00571          log_error(std::string("registerDevices() not adding device of the same name and type: ").append(dev.getName()).
00572            append("due to member unequality."));
00573        }
00574      }
00575   }

Here is the call graph for this function:

Here is the caller graph for this function:

void cmil::DeviceRegistry::SetInputIDs ( InputDevice dev  ) 


Member Data Documentation

std::string cmil::DeviceRegistry::m_default_device [private]

Definition at line 237 of file InputDevice.h.

Referenced by getDefaultDevice(), and registerDevice().

DeviceIndex cmil::DeviceRegistry::m_index [private]

Definition at line 235 of file InputDevice.h.

Referenced by cleanup(), clear(), copyDevice(), getData(), mergeRegistry(), and registerDevice().

std::vector<InputData* > cmil::DeviceRegistry::m_inputs [private]

This is used for fast access of the InputData associated with an ID.

Definition at line 240 of file InputDevice.h.

Referenced by copyDevice(), getData(), and getSize().


The documentation for this class was generated from the following files:
(c) 2006-2007 John P. Feltz
Generated on Wed Jul 25 16:08:03 2007 for Common Media Input Layer by doxygen 1.4.7

SourceForge.net Logo