#include "objectSensorsEnumirator.h" objectSensorsEnumirator* objectSensorsEnumirator::_instance = 0; /** * Returns the single instance of the object. */ objectSensorsEnumirator* objectSensorsEnumirator::getInstance() { // check if the instance has been created yet if (0 == _instance) { // if not, then create it _instance = new objectSensorsEnumirator; } // return the single instance return _instance; }; // Constructor implementation objectSensorsEnumirator::objectSensorsEnumirator(){ m_pLog = basicLogCollection::getInstance(); m_pSettings = basicSettingsProvider::getInstance()->getSubNode(NULL, "SENSORS_MANAGER"); loadDefinedSensors(); }; // Destructor implementation objectSensorsEnumirator::~objectSensorsEnumirator(){ }; objectLGS *objectSensorsEnumirator::getSensor( int index ){ objectLGS *RetVal = NULL; if( index < m_vSensors.size() ){ RetVal = m_vSensors.at( index ); }; return RetVal; }; bool objectSensorsEnumirator::loadDefinedSensors(void){ int index, count, tType, tSType; config_setting_t *tRec; config_setting_t *ttRec; count = config_setting_length(m_pSettings); if (count){ for (index = 0; index < count; index++){ ttRec = config_setting_get_elem(m_pSettings, index); if (ttRec != NULL){ //ttRec = config_setting_get_elem(tRec, 0); //config_setting_get_member(tRec, "SENSOR" ); if (!config_setting_lookup_int(ttRec, BSI_TAG_SENSOR_TYPE, &tType)) continue; if (!config_setting_lookup_int(ttRec, BSI_TAG_CONNECTION_TYPE, &tSType)) continue; switch (tType){ default:{ objectLGS *tSensor; tSensor = new objectLGS(ttRec); if( tSensor != NULL ){ // Init will be done at Control binding //if( tSensor->create() ){ m_vSensors.push_back( tSensor ); //} else { // delete( tSensor ); //}; }; break; }; }; }; }; }; return true; }; objectLGS *objectSensorsEnumirator::addSensor(SENSOR_INFO *SRC){ objectLGS *RetVal = NULL; if( SRC != NULL ){ char Buffer[64]; config_setting_t *tSettingsNode; objectLGS *ttSensor = NULL; sprintf(Buffer, "LRF_SENSOR_%d", m_vSensors.size()); tSettingsNode = basicSettingsProvider::getInstance()->getSubNode(m_pSettings, Buffer); if( tSettingsNode != NULL ){ config_setting_t *pSetting; pSetting = config_setting_add(tSettingsNode, BSI_TAG_SENSOR_TYPE, CONFIG_TYPE_INT); config_setting_set_int(pSetting, SRC->deviceType ); pSetting = config_setting_add(tSettingsNode, BSI_TAG_CONNECTION_TYPE, CONFIG_TYPE_INT); config_setting_set_int(pSetting, SRC->deviceType ); switch ( SRC->deviceType ){ default:{ objectLGS *tSensor; tSensor = new objectLGS( tSettingsNode ); if(tSensor!=NULL){ // Init will be done at Control binding //if( tSensor->create() ){ ttSensor = tSensor; //} else { // delete( tSensor ); //}; }; break; }; }; }; if (ttSensor != NULL){ m_vSensors.push_back(ttSensor); RetVal = ttSensor; //ToDo: Make Metod to abadon added config node in case camera failure basicSettingsProvider::getInstance()->compromise(); }; }; basicSettingsProvider::getInstance()->validate(); return RetVal; }; size_t objectSensorsEnumirator::getCount( void ){ return m_vSensors.size(); };