Loading Makefile +7 −2 Original line number Diff line number Diff line Loading @@ -6,15 +6,20 @@ DEBUG_LEV := -v4 INC_DIR := /usr/local/omniORB-4.1.7/include \ /usr/local/zeromq-3.2.3/include/zmq \ /usr/local/tango-8.1.2/include/tango \ /usr/local/soci-3.2.1/include \ /usr/local/soci-3.2.1/include/soci \ /usr/include/mysql \ ./src LIB_DIR := /usr/local/omniORB-4.1.7/lib \ /usr/local/zeromq-3.2.3/lib \ /usr/local/tango-8.1.2/lib /usr/local/tango-8.1.2/lib \ /usr/local/soci-3.2.1/lib64 #================================================================================ CC :=g++ DEBUG :=-g CXXFLAGS :=-c -Wall -std=c++11 -std=gnu++11 LDFLAGS :=-Wall -lomniORB4 -lomniDynamic4 -lCOS4 -lomnithread -ltango -llog4tango LDFLAGS :=-Wall -lomniORB4 -lomniDynamic4 -lCOS4 -lomnithread \ -ltango -llog4tango -lsoci_core -lsoci_mysql INC_PARM := $(foreach d, $(INC_DIR), -I$d) LIB_PARM := $(foreach d, $(LIB_DIR), -L$d) #================================================================================ Loading sql/data_model_dump.sql +5 −4 Original line number Diff line number Diff line Loading @@ -59,6 +59,7 @@ CREATE TABLE `instrument` ( `name` varchar(255) NOT NULL, `fits_key` varchar(255) NOT NULL, `fits_value` varchar(255) NOT NULL, `fits_date` varchar(255) NOT NULL, `dest_id` mediumint(9) NOT NULL, `comment` text, `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, Loading @@ -75,7 +76,7 @@ CREATE TABLE `instrument` ( LOCK TABLES `instrument` WRITE; /*!40000 ALTER TABLE `instrument` DISABLE KEYS */; INSERT INTO `instrument` VALUES (1,'Lucifer','INSTRUME','Lucifer',1,NULL,'2013-05-13 08:18:16'),(2,'FGS','INSTRUME','FGS',2,NULL,'2013-05-02 13:31:24'),(3,'Default','Default','Default',3,NULL,'2013-05-23 10:56:06'); INSERT INTO `instrument` VALUES (1,'Lucifer','INSTRUME','Lucifer','DATE',1,NULL,'2013-08-07 15:57:48'),(2,'FGS','INSTRUME','FGS','DATE',2,NULL,'2013-08-07 15:57:48'),(3,'Default','Default','Default','DATE',3,NULL,'2013-08-07 15:57:48'); /*!40000 ALTER TABLE `instrument` ENABLE KEYS */; UNLOCK TABLES; Loading @@ -88,12 +89,12 @@ DROP TABLE IF EXISTS `mapping`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `mapping` ( `id` mediumint(9) NOT NULL AUTO_INCREMENT, `dest_id` mediumint(9) NOT NULL, `column_name` varchar(255) NOT NULL, `column_type` varchar(255) NOT NULL, `fits_key_pri` varchar(255) NOT NULL, `fits_key_sec` varchar(255) DEFAULT NULL, `mandatory` tinyint(1) NOT NULL DEFAULT '0', `dest_id` mediumint(9) NOT NULL, `comment` text, `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), Loading @@ -108,7 +109,7 @@ CREATE TABLE `mapping` ( LOCK TABLES `mapping` WRITE; /*!40000 ALTER TABLE `mapping` DISABLE KEYS */; INSERT INTO `mapping` VALUES (1,2,'root_name','string','ROOTNAME','ROOTNAME',0,NULL,'2013-05-08 12:29:59'),(2,2,'prime','string','PRIMESI','PRIMESI',0,NULL,'2013-05-08 12:31:54'),(3,1,'date_obs','string','DATE-OBS','DATE-OBS',0,NULL,'2013-05-14 13:34:16'),(4,1,'ra_obs','string','RA','RA',0,NULL,'2013-05-14 13:34:46'),(5,1,'dec_obs','string','DEC','DEC',0,NULL,'2013-05-14 13:35:00'); INSERT INTO `mapping` VALUES (1,'root_name','string','ROOTNAME','ROOTNAME',0,2,NULL,'2013-05-08 12:29:59'),(2,'prime','string','PRIMESI','PRIMESI',0,2,NULL,'2013-05-08 12:31:54'),(3,'date_obs','string','DATE-OBS','DATE-OBS',0,1,NULL,'2013-05-14 13:34:16'),(4,'ra_obs','string','RA','RA',0,1,NULL,'2013-05-14 13:34:46'),(5,'dec_obs','string','DEC','DEC',0,1,NULL,'2013-05-14 13:35:00'); /*!40000 ALTER TABLE `mapping` ENABLE KEYS */; UNLOCK TABLES; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; Loading @@ -121,4 +122,4 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; -- Dump completed on 2013-08-07 10:08:40 -- Dump completed on 2013-08-07 18:10:55 src/Configuration.h +12 −53 Original line number Diff line number Diff line #ifndef CONFIGURATION_H #define CONFIGURATION_H /******************************************************************************* * ALMA - Atacama Large Millimiter Array * Copyright (c) UNSPECIFIED - FILL IN, 2013 * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * "@(#) $Id$" * * who when what * -------- -------- ---------------------------------------------- * almadev 2013-03-28 created */ /************************************************************************ * *---------------------------------------------------------------------- */ #ifndef __cplusplus #error This is a C++ include file and cannot be used from plain C #endif #include <iostream> #include <unistd.h> #include <stdint.h> #include <vector> #include <boost/shared_ptr.hpp> class Configuration Loading @@ -53,10 +19,9 @@ private: //------------------------------------------------------------------------------ // Private constructor destructor and deleter //------------------------------------------------------------------------------ Configuration(std::string name, std::string watchPath, int workerNumber, int sleepTime, int waitTime, int connectionNumber, uint32_t iNotifyMask): m_name(name), m_watchPath(watchPath), m_workerNumber(workerNumber), m_sleepTime(sleepTime), m_waitTime(waitTime), Configuration(std::string watchPath, int workerNumber, int waitTime, int connectionNumber, uint32_t iNotifyMask): m_watchPath(watchPath), m_workerNumber(workerNumber), m_waitTime(waitTime), m_connectionNumber(connectionNumber), m_iNotifyMask(iNotifyMask) {} virtual ~Configuration() {} Loading @@ -72,37 +37,31 @@ public: //------------------------------------------------------------------------------ // Public methods //------------------------------------------------------------------------------ static Configuration::SP create(std::string name, std::string watchPath, int workerNumber, int sleepTime, int waitTime, int connectionNumber, uint32_t iNotifyMask) static Configuration::SP create(std::string watchPath, int workerNumber, int waitTime, int connectionNumber, uint32_t iNotifyMask) { Configuration::SP c_sp(new Configuration(name, watchPath, workerNumber, sleepTime, waitTime, connectionNumber, iNotifyMask), Configuration::deleter()); Configuration::SP c_sp(new Configuration(watchPath, workerNumber, waitTime, connectionNumber, iNotifyMask), Configuration::deleter()); return c_sp; } std::string getName() const { return m_name; } std::string getWatchPath() const { return m_watchPath; } int getWorkerNumber() const { return m_workerNumber; } int getSleepTime() const { return m_sleepTime; } int getWaitTime() const { return m_waitTime; } int getConnectionNumber() const { return m_connectionNumber; } uint32_t getINotifyMask() const { return m_iNotifyMask; } private: //Component name const std::string m_name; //------------------------------------------------------------------------------ // Private class member variables //------------------------------------------------------------------------------ //INotify watch path const std::string m_watchPath; //Worker thread number const int m_workerNumber; //Worker thread sleep time const int m_sleepTime; //Worker thread wait time const int m_waitTime; Loading src/DataModelManager.cpp 0 → 100644 +165 −0 Original line number Diff line number Diff line #include <DataModelManager.h> #include <soci.h> #include <soci/rowset.h> #include <soci/use.h> #include <soci/mysql/soci-mysql.h> #include <soci/boost-optional.h> #include <soci/boost-tuple.h> //============================================================================== // DataModelManager::DataModelManager() //============================================================================== DataModelManager::DataModelManager(Tango::DeviceImpl* device_impl_p, std::string host, unsigned short port, std::string user, std::string password, std::string schema, std::string instrumentTable, std::string destinationTable, std::string mappingTable) : Tango::LogAdapter(device_impl_p), m_host(host), m_port(port), m_user(user), m_password(password), m_schema(schema), m_instrumentTable(instrumentTable), m_destinationTable(destinationTable), m_mappingTable(mappingTable) { DEBUG_STREAM << "DataModelManager::DataModelManager()" << endl; m_session_sp.reset(new soci::session); } //============================================================================== // DataModelManager::~DataModelManager() //============================================================================== DataModelManager::~DataModelManager() { DEBUG_STREAM << "DataModelManager::~DataModelManager()" << endl; m_session_sp->close(); } //============================================================================== // DataModelManager::connect() //============================================================================== void DataModelManager::connect() throw(soci::soci_error) { DEBUG_STREAM << "DataModelManager::connect()" << endl; std::stringstream connection; connection << " host=" << m_host; connection << " port=" << m_port; connection << " user=" << m_user; connection << " password=" << m_password; connection << " dbname=" << m_schema; m_session_sp->open(soci::mysql, connection.str()); } //============================================================================== // DataModelManager::isConnected() //============================================================================== bool DataModelManager::isConnected() { DEBUG_STREAM << "DataModelManager::isConnect()" << endl; if(m_session_sp->get_backend() == NULL) return false; else return true; } //============================================================================== // DataModelManager::disconnect() //============================================================================== void DataModelManager::disconnect() { DEBUG_STREAM << "DataModelManager::disconnect()" << endl; m_session_sp->close(); } //============================================================================== // DataModelManager::retrieveInstrumentList() //============================================================================== Instrument::SPVector DataModelManager::retrieveInstrumentList(std::vector<std::string>& instrumentList) throw(std::invalid_argument, soci::soci_error) { DEBUG_STREAM << "DataModelManager::retrieveInstrumentList()" << endl; //TODO: if empty what? if(instrumentList.empty()) throw(std::invalid_argument("")); } //============================================================================== // DataModelManager::retrieveInstrument() //============================================================================== Instrument::SP DataModelManager::retrieveInstrument(std::string instrument) throw(std::invalid_argument, soci::soci_error) { DEBUG_STREAM << "DataModelManager::retrieveInstrument()" << endl; } //============================================================================== // DataModelManager::retrieveInstrumentTuple() //============================================================================== Destination::SP DataModelManager::retrieveDestinations(int destinationId) throw(soci::soci_error) { DEBUG_STREAM << "DataModelManager::retrieveDestinations()" << endl; } //============================================================================== // DataModelManager::retrieveInstrumentTuple() //============================================================================== Mapping::SPVector DataModelManager::retrieveMappings(int destinationId) throw(soci::soci_error) { DEBUG_STREAM << "DataModelManager::retrieveMappings()" << endl; } //============================================================================== // DataModelManager::retrieveInstrumentTuple() //============================================================================== void DataModelManager::retrieveInstrumentTuple(std::vector<std::string>& instrumentList, InstrumentTupleVector& instrumentTuple_vector) throw(soci::soci_error) { DEBUG_STREAM << "DataModelManager::retrieveInstrumentTuple()" << endl; /* soci::rowset< InstrumentTuple > rows = (m_session_sp->prepare << "SELECT i.id, i.name, i.fits_key, i.fits_value, i.fits_date, i.dest_id, " "i.default_inst FROM " << m_instrumentTable << " WHERE " "c.name=:name", soci::use(componentName,"name")); std::copy(rows.begin(), rows.end(), std::back_inserter(instrumentTuple_vector)); */ } //============================================================================== // DataModelManager::retrieveDestinationTuple() //============================================================================== void DataModelManager::retrieveDestinationTuple(int destinationId, DestinationTupleVector& destinationTuple_vector) throw(soci::soci_error) { DEBUG_STREAM << "DataModelManager::retrieveDestinationTuple()" << endl; soci::rowset< DestinationTuple > rows = (m_session_sp->prepare << "SELECT id, host, port, user, password, schema_name, table_name, " "storage_path, id FROM " << m_destinationTable << " WHERE id=:id", soci::use(destinationId,"id")); std::copy(rows.begin(), rows.end(), std::back_inserter(destinationTuple_vector)); } //============================================================================== // DataModelManager::retrieveMappingTuple() //============================================================================== void DataModelManager::retrieveMappingTuple(int destinationId, MappingTupleVector& mappingTuple_vector) throw(soci::soci_error) { DEBUG_STREAM << "DataModelManager::retrieveMappingTuple()" << endl; soci::rowset< MappingTuple > rows = (m_session_sp->prepare << "SELECT id, column_name, column_type, fits_key_pri, fits_key_sec, mandatory " "FROM " << m_mappingTable << " WHERE dest_id=:id", soci::use(destinationId,"id")); std::copy(rows.begin(), rows.end(), std::back_inserter(mappingTuple_vector)); } src/DataModelManager.h 0 → 100644 +117 −0 Original line number Diff line number Diff line #ifndef DATAMODELMANAGER_H #define DATAMODELMANAGER_H #include <Instrument.h> #include <tango.h> #include <stdexcept> #include <boost/shared_ptr.hpp> #include <boost/optional/optional.hpp> #include <boost/tuple/tuple.hpp> #include <boost/scoped_ptr.hpp> #include <soci/error.h> #include <soci/session.h> class DataModelManager : public Tango::LogAdapter { public: //------------------------------------------------------------------------------ // Shared pointer typedef //------------------------------------------------------------------------------ typedef boost::shared_ptr<DataModelManager> SP; //------------------------------------------------------------------------------ // Constructor and destructor //------------------------------------------------------------------------------ DataModelManager(Tango::DeviceImpl*, std::string, unsigned short, std::string, std::string, std::string, std::string, std::string, std::string); virtual ~DataModelManager(); //------------------------------------------------------------------------------ // Public methods //------------------------------------------------------------------------------ virtual void connect() throw(soci::soci_error); virtual bool isConnected(); virtual void disconnect(); virtual Instrument::SPVector retrieveInstrumentList(std::vector<std::string>&) throw(std::invalid_argument, soci::soci_error); virtual Instrument::SP retrieveInstrument(std::string) throw(std::invalid_argument, soci::soci_error); protected: //------------------------------------------------------------------------------ // Protected methods //------------------------------------------------------------------------------ virtual Destination::SP retrieveDestinations(int) throw(soci::soci_error); virtual Mapping::SPVector retrieveMappings(int) throw(soci::soci_error); typedef boost::tuple< boost::optional<int>, boost::optional<std::string>, boost::optional<std::string>, boost::optional<std::string>, boost::optional<std::string>, boost::optional<int> > InstrumentTuple; typedef std::vector< InstrumentTuple > InstrumentTupleVector; virtual void retrieveInstrumentTuple(std::vector<std::string>&, InstrumentTupleVector&) throw(soci::soci_error); typedef boost::tuple< boost::optional<int>, boost::optional<std::string>, boost::optional<int>, boost::optional<std::string>, boost::optional<std::string>, boost::optional<std::string>, boost::optional<std::string>, boost::optional<std::string> > DestinationTuple; typedef std::vector< DestinationTuple > DestinationTupleVector; virtual void retrieveDestinationTuple(int, DestinationTupleVector&) throw(soci::soci_error); typedef boost::tuple< boost::optional<int>, boost::optional<std::string>, boost::optional<std::string>, boost::optional<std::string>, boost::optional<std::string>, boost::optional<int>, boost::optional<int> > MappingTuple; typedef std::vector< MappingTuple > MappingTupleVector; virtual void retrieveMappingTuple(int, MappingTupleVector&) throw(soci::soci_error); //------------------------------------------------------------------------------ // Protected variables //------------------------------------------------------------------------------ //Data model database host std::string m_host; //Data model database port unsigned short m_port; //Data model database login user std::string m_user; //Data model database login password std::string m_password; //Data model schema name std::string m_schema; //Data model instrument table name std::string m_instrumentTable; //Data model destination table name std::string m_destinationTable; //Data model mapping table name std::string m_mappingTable; //Database connection scoped pointer boost::scoped_ptr<soci::session> m_session_sp; }; #endif /* DATAMODELMANAGER_H */ Loading
Makefile +7 −2 Original line number Diff line number Diff line Loading @@ -6,15 +6,20 @@ DEBUG_LEV := -v4 INC_DIR := /usr/local/omniORB-4.1.7/include \ /usr/local/zeromq-3.2.3/include/zmq \ /usr/local/tango-8.1.2/include/tango \ /usr/local/soci-3.2.1/include \ /usr/local/soci-3.2.1/include/soci \ /usr/include/mysql \ ./src LIB_DIR := /usr/local/omniORB-4.1.7/lib \ /usr/local/zeromq-3.2.3/lib \ /usr/local/tango-8.1.2/lib /usr/local/tango-8.1.2/lib \ /usr/local/soci-3.2.1/lib64 #================================================================================ CC :=g++ DEBUG :=-g CXXFLAGS :=-c -Wall -std=c++11 -std=gnu++11 LDFLAGS :=-Wall -lomniORB4 -lomniDynamic4 -lCOS4 -lomnithread -ltango -llog4tango LDFLAGS :=-Wall -lomniORB4 -lomniDynamic4 -lCOS4 -lomnithread \ -ltango -llog4tango -lsoci_core -lsoci_mysql INC_PARM := $(foreach d, $(INC_DIR), -I$d) LIB_PARM := $(foreach d, $(LIB_DIR), -L$d) #================================================================================ Loading
sql/data_model_dump.sql +5 −4 Original line number Diff line number Diff line Loading @@ -59,6 +59,7 @@ CREATE TABLE `instrument` ( `name` varchar(255) NOT NULL, `fits_key` varchar(255) NOT NULL, `fits_value` varchar(255) NOT NULL, `fits_date` varchar(255) NOT NULL, `dest_id` mediumint(9) NOT NULL, `comment` text, `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, Loading @@ -75,7 +76,7 @@ CREATE TABLE `instrument` ( LOCK TABLES `instrument` WRITE; /*!40000 ALTER TABLE `instrument` DISABLE KEYS */; INSERT INTO `instrument` VALUES (1,'Lucifer','INSTRUME','Lucifer',1,NULL,'2013-05-13 08:18:16'),(2,'FGS','INSTRUME','FGS',2,NULL,'2013-05-02 13:31:24'),(3,'Default','Default','Default',3,NULL,'2013-05-23 10:56:06'); INSERT INTO `instrument` VALUES (1,'Lucifer','INSTRUME','Lucifer','DATE',1,NULL,'2013-08-07 15:57:48'),(2,'FGS','INSTRUME','FGS','DATE',2,NULL,'2013-08-07 15:57:48'),(3,'Default','Default','Default','DATE',3,NULL,'2013-08-07 15:57:48'); /*!40000 ALTER TABLE `instrument` ENABLE KEYS */; UNLOCK TABLES; Loading @@ -88,12 +89,12 @@ DROP TABLE IF EXISTS `mapping`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `mapping` ( `id` mediumint(9) NOT NULL AUTO_INCREMENT, `dest_id` mediumint(9) NOT NULL, `column_name` varchar(255) NOT NULL, `column_type` varchar(255) NOT NULL, `fits_key_pri` varchar(255) NOT NULL, `fits_key_sec` varchar(255) DEFAULT NULL, `mandatory` tinyint(1) NOT NULL DEFAULT '0', `dest_id` mediumint(9) NOT NULL, `comment` text, `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), Loading @@ -108,7 +109,7 @@ CREATE TABLE `mapping` ( LOCK TABLES `mapping` WRITE; /*!40000 ALTER TABLE `mapping` DISABLE KEYS */; INSERT INTO `mapping` VALUES (1,2,'root_name','string','ROOTNAME','ROOTNAME',0,NULL,'2013-05-08 12:29:59'),(2,2,'prime','string','PRIMESI','PRIMESI',0,NULL,'2013-05-08 12:31:54'),(3,1,'date_obs','string','DATE-OBS','DATE-OBS',0,NULL,'2013-05-14 13:34:16'),(4,1,'ra_obs','string','RA','RA',0,NULL,'2013-05-14 13:34:46'),(5,1,'dec_obs','string','DEC','DEC',0,NULL,'2013-05-14 13:35:00'); INSERT INTO `mapping` VALUES (1,'root_name','string','ROOTNAME','ROOTNAME',0,2,NULL,'2013-05-08 12:29:59'),(2,'prime','string','PRIMESI','PRIMESI',0,2,NULL,'2013-05-08 12:31:54'),(3,'date_obs','string','DATE-OBS','DATE-OBS',0,1,NULL,'2013-05-14 13:34:16'),(4,'ra_obs','string','RA','RA',0,1,NULL,'2013-05-14 13:34:46'),(5,'dec_obs','string','DEC','DEC',0,1,NULL,'2013-05-14 13:35:00'); /*!40000 ALTER TABLE `mapping` ENABLE KEYS */; UNLOCK TABLES; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; Loading @@ -121,4 +122,4 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; -- Dump completed on 2013-08-07 10:08:40 -- Dump completed on 2013-08-07 18:10:55
src/Configuration.h +12 −53 Original line number Diff line number Diff line #ifndef CONFIGURATION_H #define CONFIGURATION_H /******************************************************************************* * ALMA - Atacama Large Millimiter Array * Copyright (c) UNSPECIFIED - FILL IN, 2013 * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * "@(#) $Id$" * * who when what * -------- -------- ---------------------------------------------- * almadev 2013-03-28 created */ /************************************************************************ * *---------------------------------------------------------------------- */ #ifndef __cplusplus #error This is a C++ include file and cannot be used from plain C #endif #include <iostream> #include <unistd.h> #include <stdint.h> #include <vector> #include <boost/shared_ptr.hpp> class Configuration Loading @@ -53,10 +19,9 @@ private: //------------------------------------------------------------------------------ // Private constructor destructor and deleter //------------------------------------------------------------------------------ Configuration(std::string name, std::string watchPath, int workerNumber, int sleepTime, int waitTime, int connectionNumber, uint32_t iNotifyMask): m_name(name), m_watchPath(watchPath), m_workerNumber(workerNumber), m_sleepTime(sleepTime), m_waitTime(waitTime), Configuration(std::string watchPath, int workerNumber, int waitTime, int connectionNumber, uint32_t iNotifyMask): m_watchPath(watchPath), m_workerNumber(workerNumber), m_waitTime(waitTime), m_connectionNumber(connectionNumber), m_iNotifyMask(iNotifyMask) {} virtual ~Configuration() {} Loading @@ -72,37 +37,31 @@ public: //------------------------------------------------------------------------------ // Public methods //------------------------------------------------------------------------------ static Configuration::SP create(std::string name, std::string watchPath, int workerNumber, int sleepTime, int waitTime, int connectionNumber, uint32_t iNotifyMask) static Configuration::SP create(std::string watchPath, int workerNumber, int waitTime, int connectionNumber, uint32_t iNotifyMask) { Configuration::SP c_sp(new Configuration(name, watchPath, workerNumber, sleepTime, waitTime, connectionNumber, iNotifyMask), Configuration::deleter()); Configuration::SP c_sp(new Configuration(watchPath, workerNumber, waitTime, connectionNumber, iNotifyMask), Configuration::deleter()); return c_sp; } std::string getName() const { return m_name; } std::string getWatchPath() const { return m_watchPath; } int getWorkerNumber() const { return m_workerNumber; } int getSleepTime() const { return m_sleepTime; } int getWaitTime() const { return m_waitTime; } int getConnectionNumber() const { return m_connectionNumber; } uint32_t getINotifyMask() const { return m_iNotifyMask; } private: //Component name const std::string m_name; //------------------------------------------------------------------------------ // Private class member variables //------------------------------------------------------------------------------ //INotify watch path const std::string m_watchPath; //Worker thread number const int m_workerNumber; //Worker thread sleep time const int m_sleepTime; //Worker thread wait time const int m_waitTime; Loading
src/DataModelManager.cpp 0 → 100644 +165 −0 Original line number Diff line number Diff line #include <DataModelManager.h> #include <soci.h> #include <soci/rowset.h> #include <soci/use.h> #include <soci/mysql/soci-mysql.h> #include <soci/boost-optional.h> #include <soci/boost-tuple.h> //============================================================================== // DataModelManager::DataModelManager() //============================================================================== DataModelManager::DataModelManager(Tango::DeviceImpl* device_impl_p, std::string host, unsigned short port, std::string user, std::string password, std::string schema, std::string instrumentTable, std::string destinationTable, std::string mappingTable) : Tango::LogAdapter(device_impl_p), m_host(host), m_port(port), m_user(user), m_password(password), m_schema(schema), m_instrumentTable(instrumentTable), m_destinationTable(destinationTable), m_mappingTable(mappingTable) { DEBUG_STREAM << "DataModelManager::DataModelManager()" << endl; m_session_sp.reset(new soci::session); } //============================================================================== // DataModelManager::~DataModelManager() //============================================================================== DataModelManager::~DataModelManager() { DEBUG_STREAM << "DataModelManager::~DataModelManager()" << endl; m_session_sp->close(); } //============================================================================== // DataModelManager::connect() //============================================================================== void DataModelManager::connect() throw(soci::soci_error) { DEBUG_STREAM << "DataModelManager::connect()" << endl; std::stringstream connection; connection << " host=" << m_host; connection << " port=" << m_port; connection << " user=" << m_user; connection << " password=" << m_password; connection << " dbname=" << m_schema; m_session_sp->open(soci::mysql, connection.str()); } //============================================================================== // DataModelManager::isConnected() //============================================================================== bool DataModelManager::isConnected() { DEBUG_STREAM << "DataModelManager::isConnect()" << endl; if(m_session_sp->get_backend() == NULL) return false; else return true; } //============================================================================== // DataModelManager::disconnect() //============================================================================== void DataModelManager::disconnect() { DEBUG_STREAM << "DataModelManager::disconnect()" << endl; m_session_sp->close(); } //============================================================================== // DataModelManager::retrieveInstrumentList() //============================================================================== Instrument::SPVector DataModelManager::retrieveInstrumentList(std::vector<std::string>& instrumentList) throw(std::invalid_argument, soci::soci_error) { DEBUG_STREAM << "DataModelManager::retrieveInstrumentList()" << endl; //TODO: if empty what? if(instrumentList.empty()) throw(std::invalid_argument("")); } //============================================================================== // DataModelManager::retrieveInstrument() //============================================================================== Instrument::SP DataModelManager::retrieveInstrument(std::string instrument) throw(std::invalid_argument, soci::soci_error) { DEBUG_STREAM << "DataModelManager::retrieveInstrument()" << endl; } //============================================================================== // DataModelManager::retrieveInstrumentTuple() //============================================================================== Destination::SP DataModelManager::retrieveDestinations(int destinationId) throw(soci::soci_error) { DEBUG_STREAM << "DataModelManager::retrieveDestinations()" << endl; } //============================================================================== // DataModelManager::retrieveInstrumentTuple() //============================================================================== Mapping::SPVector DataModelManager::retrieveMappings(int destinationId) throw(soci::soci_error) { DEBUG_STREAM << "DataModelManager::retrieveMappings()" << endl; } //============================================================================== // DataModelManager::retrieveInstrumentTuple() //============================================================================== void DataModelManager::retrieveInstrumentTuple(std::vector<std::string>& instrumentList, InstrumentTupleVector& instrumentTuple_vector) throw(soci::soci_error) { DEBUG_STREAM << "DataModelManager::retrieveInstrumentTuple()" << endl; /* soci::rowset< InstrumentTuple > rows = (m_session_sp->prepare << "SELECT i.id, i.name, i.fits_key, i.fits_value, i.fits_date, i.dest_id, " "i.default_inst FROM " << m_instrumentTable << " WHERE " "c.name=:name", soci::use(componentName,"name")); std::copy(rows.begin(), rows.end(), std::back_inserter(instrumentTuple_vector)); */ } //============================================================================== // DataModelManager::retrieveDestinationTuple() //============================================================================== void DataModelManager::retrieveDestinationTuple(int destinationId, DestinationTupleVector& destinationTuple_vector) throw(soci::soci_error) { DEBUG_STREAM << "DataModelManager::retrieveDestinationTuple()" << endl; soci::rowset< DestinationTuple > rows = (m_session_sp->prepare << "SELECT id, host, port, user, password, schema_name, table_name, " "storage_path, id FROM " << m_destinationTable << " WHERE id=:id", soci::use(destinationId,"id")); std::copy(rows.begin(), rows.end(), std::back_inserter(destinationTuple_vector)); } //============================================================================== // DataModelManager::retrieveMappingTuple() //============================================================================== void DataModelManager::retrieveMappingTuple(int destinationId, MappingTupleVector& mappingTuple_vector) throw(soci::soci_error) { DEBUG_STREAM << "DataModelManager::retrieveMappingTuple()" << endl; soci::rowset< MappingTuple > rows = (m_session_sp->prepare << "SELECT id, column_name, column_type, fits_key_pri, fits_key_sec, mandatory " "FROM " << m_mappingTable << " WHERE dest_id=:id", soci::use(destinationId,"id")); std::copy(rows.begin(), rows.end(), std::back_inserter(mappingTuple_vector)); }
src/DataModelManager.h 0 → 100644 +117 −0 Original line number Diff line number Diff line #ifndef DATAMODELMANAGER_H #define DATAMODELMANAGER_H #include <Instrument.h> #include <tango.h> #include <stdexcept> #include <boost/shared_ptr.hpp> #include <boost/optional/optional.hpp> #include <boost/tuple/tuple.hpp> #include <boost/scoped_ptr.hpp> #include <soci/error.h> #include <soci/session.h> class DataModelManager : public Tango::LogAdapter { public: //------------------------------------------------------------------------------ // Shared pointer typedef //------------------------------------------------------------------------------ typedef boost::shared_ptr<DataModelManager> SP; //------------------------------------------------------------------------------ // Constructor and destructor //------------------------------------------------------------------------------ DataModelManager(Tango::DeviceImpl*, std::string, unsigned short, std::string, std::string, std::string, std::string, std::string, std::string); virtual ~DataModelManager(); //------------------------------------------------------------------------------ // Public methods //------------------------------------------------------------------------------ virtual void connect() throw(soci::soci_error); virtual bool isConnected(); virtual void disconnect(); virtual Instrument::SPVector retrieveInstrumentList(std::vector<std::string>&) throw(std::invalid_argument, soci::soci_error); virtual Instrument::SP retrieveInstrument(std::string) throw(std::invalid_argument, soci::soci_error); protected: //------------------------------------------------------------------------------ // Protected methods //------------------------------------------------------------------------------ virtual Destination::SP retrieveDestinations(int) throw(soci::soci_error); virtual Mapping::SPVector retrieveMappings(int) throw(soci::soci_error); typedef boost::tuple< boost::optional<int>, boost::optional<std::string>, boost::optional<std::string>, boost::optional<std::string>, boost::optional<std::string>, boost::optional<int> > InstrumentTuple; typedef std::vector< InstrumentTuple > InstrumentTupleVector; virtual void retrieveInstrumentTuple(std::vector<std::string>&, InstrumentTupleVector&) throw(soci::soci_error); typedef boost::tuple< boost::optional<int>, boost::optional<std::string>, boost::optional<int>, boost::optional<std::string>, boost::optional<std::string>, boost::optional<std::string>, boost::optional<std::string>, boost::optional<std::string> > DestinationTuple; typedef std::vector< DestinationTuple > DestinationTupleVector; virtual void retrieveDestinationTuple(int, DestinationTupleVector&) throw(soci::soci_error); typedef boost::tuple< boost::optional<int>, boost::optional<std::string>, boost::optional<std::string>, boost::optional<std::string>, boost::optional<std::string>, boost::optional<int>, boost::optional<int> > MappingTuple; typedef std::vector< MappingTuple > MappingTupleVector; virtual void retrieveMappingTuple(int, MappingTupleVector&) throw(soci::soci_error); //------------------------------------------------------------------------------ // Protected variables //------------------------------------------------------------------------------ //Data model database host std::string m_host; //Data model database port unsigned short m_port; //Data model database login user std::string m_user; //Data model database login password std::string m_password; //Data model schema name std::string m_schema; //Data model instrument table name std::string m_instrumentTable; //Data model destination table name std::string m_destinationTable; //Data model mapping table name std::string m_mappingTable; //Database connection scoped pointer boost::scoped_ptr<soci::session> m_session_sp; }; #endif /* DATAMODELMANAGER_H */