diff --git a/src/Client.cpp b/src/Client.cpp index 45f3e48d86385136a7a971946d234306af3875c8..0294aaf8816631390eaf3cba53ad53dfe19e8d0e 100644 --- a/src/Client.cpp +++ b/src/Client.cpp @@ -208,26 +208,41 @@ void Client::startUpdateLists() writeStatus("Unknown error"); } - handleUpdateLists(); + if(readState() != Tango::ALARM && m_protocolManager_sp->hasNextFile()) + { + startResolve(); + } + else + { + m_listsUpdateTimer.expires_from_now( + boost::posix_time::seconds(m_configuration_sp->getRefreshTime())); + + m_listsUpdateTimer.async_wait(boost::bind(&Client::handleUpdateLists, + this, boost::asio::placeholders::error)); + } } //============================================================================== // Client::handleUpdateLists() //============================================================================== -void Client::handleUpdateLists() +void Client::handleUpdateLists(const boost::system::error_code& errorCode) { DEBUG_STREAM << "Client::handleUpdateLists()" << endl; - if(readState() != Tango::ALARM && m_protocolManager_sp->hasNextFile()) + if(!errorCode) { - startResolve(); + startUpdateLists(); + } + else if(errorCode == boost::asio::error::operation_aborted) + { + DEBUG_STREAM << "Client::handleUpdateLists() STOP" << endl; } else { - m_listsUpdateTimer.expires_from_now( - boost::posix_time::seconds(m_configuration_sp->getRefreshTime())); + ERROR_STREAM << "Client::handleResolve() " << errorCode.message() << endl; - m_listsUpdateTimer.async_wait(boost::bind(&Client::handleUpdateLists, this)); + writeState(Tango::ALARM); + writeStatus(errorCode.message()); } } @@ -420,8 +435,6 @@ void Client::onTransferCompleted(FileWrapper::SP fileWrapper_sp) { m_protocolManager_sp->setFileTransfered(fileWrapper_sp); - m_protocolManager_sp->nextFile(); - if(m_protocolManager_sp->hasNextFile()) { startWriteRequest(); @@ -460,8 +473,6 @@ void Client::onTransferFailed() { m_protocolManager_sp->setFileFailed(); - m_protocolManager_sp->nextFile(); - if(m_protocolManager_sp->hasNextFile()) { startWriteRequest(); diff --git a/src/Client.h b/src/Client.h index bfb901e55fee4d7d360da5b6ff216e7a60b1bd7e..b5dfdf77c61b5cd97ec2c66b733b97fc74f5b3f5 100644 --- a/src/Client.h +++ b/src/Client.h @@ -69,7 +69,7 @@ protected: //------------------------------------------------------------------------------ virtual void startUpdateLists(); - virtual void handleUpdateLists(); + virtual void handleUpdateLists(const boost::system::error_code&); //------------------------------------------------------------------------------ // [Protected] Endpoint resolution methods diff --git a/src/DBManager.cpp b/src/DBManager.cpp index 8d09bee3d008a352768f07f16b8e3d323f66aaf8..98c8ba0c58869af9cda6cfa12755151909a0074a 100644 --- a/src/DBManager.cpp +++ b/src/DBManager.cpp @@ -26,7 +26,7 @@ DBManager::DBManager(Tango::DeviceImpl* deviceImpl_p, } //============================================================================== -// DBManager::DBManager() +// DBManager::~DBManager() //============================================================================== DBManager::~DBManager() { @@ -38,7 +38,7 @@ DBManager::~DBManager() } //============================================================================== -// DBManager::DBManager() +// DBManager::create() //============================================================================== DBManager::SP DBManager::create(Tango::DeviceImpl* deviceImpl_p, Configuration::SP configuration_sp) @@ -66,7 +66,7 @@ void DBManager::connectAll() throw(soci::soci_error) connection << " password=" << m_configuration_sp->getDatabasePassword(); #ifdef VERBOSE_DEBUG - INFO_STREAM << "MAIN CONNECTION: " << connection.str() << endl; + INFO_STREAM << "MAIN CONNECTION: " << connection.str() << endl; #endif m_mainSession_sp->open(soci::mysql, connection.str()); @@ -79,7 +79,7 @@ void DBManager::connectAll() throw(soci::soci_error) connection << " password=" << m_configuration_sp->getAuxDatabasePassword(); #ifdef VERBOSE_DEBUG - INFO_STREAM << "AUX CONNECTION: " << connection.str() << endl; + INFO_STREAM << "AUX CONNECTION: " << connection.str() << endl; #endif m_auxSession_sp->open(soci::mysql, connection.str()); diff --git a/src/DataImporter.cpp b/src/DataImporter.cpp index 23aa8702a5896a1c0613ddcc18bf623407584436..bc540d7fc5d6b3754f30b5ad50567b33e931f45a 100644 --- a/src/DataImporter.cpp +++ b/src/DataImporter.cpp @@ -610,7 +610,7 @@ void DataImporter::get_device_property() //-------------------------------------------------------- void DataImporter::always_executed_hook() { - INFO_STREAM << "DataImporter::always_executed_hook() " << device_name << endl; + DEBUG_STREAM << "DataImporter::always_executed_hook() " << device_name << endl; /*----- PROTECTED REGION ID(DataImporter::always_executed_hook) ENABLED START -----*/ if(get_state() != Tango::FAULT) diff --git a/src/PlainClient.cpp b/src/PlainClient.cpp index a2446595542cbd42198cf54eab5ca5b013bb5482..e6b570814b4afc10819fa8777d4c0492003fcfdd 100644 --- a/src/PlainClient.cpp +++ b/src/PlainClient.cpp @@ -242,6 +242,7 @@ void PlainClient::closeConnection() INFO_STREAM << "PlainClient::closeConnection() " << infoStream.str() << endl; + m_listsUpdateTimer.expires_at(boost::posix_time::pos_infin); m_resetConnectionTimer.expires_at(boost::posix_time::pos_infin); boost::system::error_code errorCode; diff --git a/src/ProtocolManager.cpp b/src/ProtocolManager.cpp index b2d4b87b8eb516cc6072944cd835b5869bb50b6c..66154e9e4c13f0a3f0cef714f8608e4b345c6504 100644 --- a/src/ProtocolManager.cpp +++ b/src/ProtocolManager.cpp @@ -1,6 +1,5 @@ #include <ProtocolManager.h> #include <boost/filesystem.hpp> -#include <stdexcept> namespace DataImporter_ns { @@ -98,35 +97,6 @@ bool ProtocolManager::hasNextFile() } } -//============================================================================== -// ProtocolManager::nextFile() -//============================================================================== -void ProtocolManager::nextFile() -{ - DEBUG_STREAM << "ProtocolManager::nextFile()" << endl; - - if(!m_recoveryMode) - { - if(m_newFileRowset_sp && - m_newFileRowsetIt != m_newFileRowset_sp->end()) - { - DEBUG_STREAM << "ProtocolManager::nextFile() new list" << endl; - - ++m_newFileRowsetIt; - } - } - else - { - if(m_failedFileRowset_sp && - m_failedFileRowsetIt != m_failedFileRowset_sp->end()) - { - DEBUG_STREAM << "ProtocolManager::nextFile() from failed list" << endl; - - ++m_failedFileRowsetIt; - } - } -} - //============================================================================== // ProtocolManager::createRequest() //============================================================================== @@ -261,21 +231,33 @@ void ProtocolManager::setFileTransfered(FileWrapper::SP fileWrapper_sp) if(!m_newFileRowsetIt->get<2>()) throw std::invalid_argument("Empty update time found on new list"); - std::tm update_time = m_newFileRowsetIt->get<2>().get(); + std::tm currentTm = m_newFileRowsetIt->get<2>().get(); INFO_STREAM << "ProtocolManager::setFileTransfered() file " << fileName << " version " << fileVersion << " transfered" << endl; - boost::posix_time::ptime newPtime = boost::posix_time::ptime_from_tm(update_time); + boost::posix_time::ptime currentPtime = + boost::posix_time::ptime_from_tm(currentTm); + + boost::posix_time::ptime nextPtime(boost::posix_time::pos_infin); - if(m_currentPtime.is_not_a_date_time()) - m_currentPtime = newPtime; + //FIXME: not incremented in case of exception!!! + ++m_newFileRowsetIt; + + if(m_newFileRowsetIt != m_newFileRowset_sp->end()) + { + if(!m_newFileRowsetIt->get<2>()) + throw std::invalid_argument("Empty next update time found on new list"); + std::tm nextTm = m_newFileRowsetIt->get<2>().get(); + + nextPtime =boost::posix_time::ptime_from_tm(nextTm); + } DBManager::TransactionSP auxTransaction_sp = m_dBManager_sp->getAuxTransaction(); DBManager::TransactionSP mainTransaction_sp = m_dBManager_sp->getMainTransaction(); - if(newPtime > m_currentPtime) - m_dBManager_sp->persistLastTimestamp(newPtime); + if(nextPtime > currentPtime) + m_dBManager_sp->persistLastTimestamp(currentPtime); m_dBManager_sp->updateNewFilePath(storagePath, filePath, fileVersion, fileName); @@ -296,6 +278,8 @@ void ProtocolManager::setFileTransfered(FileWrapper::SP fileWrapper_sp) throw std::invalid_argument("Empty file name found on failed list"); string fileName = m_failedFileRowsetIt->get<1>().get(); + ++m_failedFileRowsetIt; + DBManager::TransactionSP auxTransaction_sp = m_dBManager_sp->getAuxTransaction(); DBManager::TransactionSP mainTransaction_sp = m_dBManager_sp->getMainTransaction(); @@ -329,11 +313,13 @@ void ProtocolManager::setFileFailed() throw(std::logic_error, std::runtime_error throw std::invalid_argument("Empty file name found on new list"); string fileName = m_newFileRowsetIt->get<1>().get(); + ++m_newFileRowsetIt; + m_dBManager_sp->addFailedFile(fileVersion, fileName); } else { - //TODO: file failed again -> what to do? + ++m_failedFileRowsetIt; } } diff --git a/src/ProtocolManager.h b/src/ProtocolManager.h index cd8e6791e139a414cc17d53da6a1d83404c0e826..9cfc9913fc73305d03bc5eaeaa4ecce91be499df 100644 --- a/src/ProtocolManager.h +++ b/src/ProtocolManager.h @@ -63,8 +63,6 @@ public: virtual bool hasNextFile(); - virtual void nextFile(); - //------------------------------------------------------------------------------ // [Public] Request response methods //------------------------------------------------------------------------------ @@ -102,9 +100,6 @@ protected: //Processing file from recovery list bool m_recoveryMode; - //New file list current timestamp index - boost::posix_time::ptime m_currentPtime; - //New file list shared pointer DBManager::NewFileRowsetSP m_newFileRowset_sp; diff --git a/src/SSLClient.cpp b/src/SSLClient.cpp index 35201d5a342c57c67f154523d1213de1eab6a244..62ae06125c095bdda61615468ac93ab9babe8260 100644 --- a/src/SSLClient.cpp +++ b/src/SSLClient.cpp @@ -295,6 +295,7 @@ void SSLClient::closeConnection() INFO_STREAM << "SSLClient::closeConnection() " << infoStream.str() << endl; + m_listsUpdateTimer.expires_at(boost::posix_time::pos_infin); m_resetConnectionTimer.expires_at(boost::posix_time::pos_infin); boost::system::error_code errorCode;