diff --git a/src/Client.cpp b/src/Client.cpp index 7942dd298e3c2f8e4af1d029063575b8444bf519..f07a457e1352ffa58f39f0456e99360cde2d4892 100644 --- a/src/Client.cpp +++ b/src/Client.cpp @@ -54,18 +54,33 @@ void Client::start() { DEBUG_STREAM << "Client::start()" << endl; - m_dBManager_sp->connectAll(); + try + { + m_dBManager_sp->connectAll(); - m_protocolManager_sp = ProtocolManager::create(m_dataImporter_p, - m_configuration_sp, m_dBManager_sp); + m_protocolManager_sp = ProtocolManager::create(m_dataImporter_p, + m_configuration_sp, m_dBManager_sp); - m_ioService.reset(); + m_ioService.reset(); - m_work_sp.reset(new boost::asio::io_service::work(m_ioService)); + m_work_sp.reset(new boost::asio::io_service::work(m_ioService)); - m_thread_sp.reset(new boost::thread(boost::bind(&Client::run, this))); + m_thread_sp.reset(new boost::thread(boost::bind(&Client::run, this))); - Client::startUpdateLists(); + Client::startUpdateLists(); + } + catch(std::exception& ex) + { + writeState(Tango::ALARM); + std::stringstream error_stream; + error_stream << "Client::start() " << ex.what() << std::endl; + writeStatus(error_stream.str()); + } + catch(...) + { + writeState(Tango::ALARM); + writeStatus("Client::start() unknown error"); + } } //============================================================================== @@ -363,7 +378,7 @@ void Client::handleReadResponseBody(const boost::system::error_code& errorCode) onTransferFailed(); } - catch(std::runtime_error& ec) + catch(std::exception& ec) { ERROR_STREAM << "Client::handleReadResponseBody() " << ec.what() << endl; diff --git a/src/DBManager.h b/src/DBManager.h index e1f5980f4fed2548b084fec7a2c2bc7744432968..14f389fe445dd93258d6f8e6fe77eda3522316be 100644 --- a/src/DBManager.h +++ b/src/DBManager.h @@ -83,8 +83,8 @@ public: throw(soci::soci_error); virtual void persistLastTimestamp(boost::posix_time::ptime) - throw(soci::soci_error); - + throw(soci::soci_error); + //------------------------------------------------------------------------------ // [Public] File row set definition //------------------------------------------------------------------------------ @@ -94,8 +94,8 @@ public: typedef soci::rowset< FileRow > FileRowset; - typedef boost::shared_ptr< FileRowset > FileRowsetSP; - + typedef boost::shared_ptr< FileRowset > FileRowsetSP; + //------------------------------------------------------------------------------ // [Public] New file method //------------------------------------------------------------------------------ diff --git a/src/DataImporter.cpp b/src/DataImporter.cpp index 1d4180a3c5aea0ec918bda2f2832455763b56823..a9d264812c2953338ab87c1c5772ce8f7787163f 100644 --- a/src/DataImporter.cpp +++ b/src/DataImporter.cpp @@ -716,23 +716,8 @@ void DataImporter::on() DEBUG_STREAM << "DataImporter::On() - " << device_name << endl; /*----- PROTECTED REGION ID(DataImporter::on) ENABLED START -----*/ - try - { - if(m_client_sp) - m_client_sp->start(); - } - catch(std::exception& ex) - { - set_state(Tango::ALARM); - std::stringstream error_stream; - error_stream << "DataImporter::On() " << ex.what() << std::endl; - set_status(error_stream.str()); - } - catch(...) - { - set_state(Tango::ALARM); - set_status("DataImporter::On() unknown error"); - } + if(m_client_sp) + m_client_sp->start(); /*----- PROTECTED REGION END -----*/ // DataImporter::on } @@ -748,23 +733,8 @@ void DataImporter::off() DEBUG_STREAM << "DataImporter::Off() - " << device_name << endl; /*----- PROTECTED REGION ID(DataImporter::off) ENABLED START -----*/ - try - { - if(m_client_sp) - m_client_sp->stop(); - } - catch(std::exception& ex) - { - set_state(Tango::ALARM); - std::stringstream error_stream; - error_stream << "DataImporter::Off() " << ex.what() << std::endl; - set_status(error_stream.str()); - } - catch(...) - { - set_state(Tango::ALARM); - set_status("DataImporter::Off() unknown error"); - } + if(m_client_sp) + m_client_sp->stop(); /*----- PROTECTED REGION END -----*/ // DataImporter::off } diff --git a/src/DataImporter.h b/src/DataImporter.h index 2e3cca7e5669f992b3a0667d5c60ceb8cf5de861..dbdb4f59d670ccefc47a74f3d5da687283a721a9 100644 --- a/src/DataImporter.h +++ b/src/DataImporter.h @@ -269,7 +269,6 @@ public: //------------------------------------------------------------------------------ // [Public] Counters methods //------------------------------------------------------------------------------ - virtual void incrementRegularCounter(); virtual void incrementFailedCounter(); diff --git a/src/PlainClient.cpp b/src/PlainClient.cpp index 8e9be2083bfa24694494d83bc6ae4916eb6e3cff..34409e511fec44c48fcbd5c2c9dc3acadf4133a2 100644 --- a/src/PlainClient.cpp +++ b/src/PlainClient.cpp @@ -145,7 +145,7 @@ void PlainClient::startWriteRequest() boost::bind(&PlainClient::handleWriteRequest, this, boost::asio::placeholders::error)); } - catch(std::runtime_error& ec) + catch(std::exception& ec) { ERROR_STREAM << "PlainClient::startWriteRequest() " << ec.what() << endl; diff --git a/src/ProtocolManager.cpp b/src/ProtocolManager.cpp index fc91f6cd6b719f078a1ed927c555e685a65ef229..7dd11789fe6b4dc0a7f0bbed6ac6f56d00158052 100644 --- a/src/ProtocolManager.cpp +++ b/src/ProtocolManager.cpp @@ -53,7 +53,7 @@ void ProtocolManager::setRemoteEndpoint(std::string remoteEndpoint) void ProtocolManager::retrieveFiles() throw(std::runtime_error) { DEBUG_STREAM << "ProtocolManager::retrieveFiles()" << endl; - + boost::posix_time::ptime m_lastTimestamp = m_dBManager_sp->retrieveLastTimestamp(); @@ -61,12 +61,12 @@ void ProtocolManager::retrieveFiles() throw(std::runtime_error) << boost::posix_time::to_simple_string(m_lastTimestamp) << endl; m_newFileRowset_sp = m_dBManager_sp->retrieveNewFiles(m_lastTimestamp); - + m_newFileRowsetIt = m_newFileRowset_sp->begin(); m_failedFileRowset_sp = m_dBManager_sp->retrieveFailedFiles(); - - m_failedFileRowsetIt = m_failedFileRowset_sp->begin(); + + m_failedFileRowsetIt = m_failedFileRowset_sp->begin(); } //============================================================================== @@ -75,24 +75,24 @@ void ProtocolManager::retrieveFiles() throw(std::runtime_error) bool ProtocolManager::hasFilesToTransfer() { DEBUG_STREAM << "ProtocolManager::hasFilesToTransfer()" << endl; - + if(m_newFileRowset_sp && m_newFileRowsetIt != m_newFileRowset_sp->end()) - { + { INFO_STREAM << "ProtocolManager::hasFilesToTransfer() in new list" << endl; - return true; - } + return true; + } else if(m_failedFileRowset_sp && m_failedFileRowsetIt != m_failedFileRowset_sp->end()) - { + { if(isRecoveryTimeElapsed()) - { + { INFO_STREAM << "ProtocolManager::hasFilesToTransfer() in failed list" << endl; - return true; - } - } - - return false; + return true; + } + } + + return false; } //============================================================================== @@ -115,7 +115,7 @@ bool ProtocolManager::hasNextFile() else { return false; - } + } } //============================================================================== @@ -124,7 +124,7 @@ bool ProtocolManager::hasNextFile() RequestSP ProtocolManager::createtRequest() throw(std::runtime_error) { DEBUG_STREAM << "ProtocolManager::createtRequest()" << endl; - + if(m_newFileRowset_sp && m_newFileRowsetIt != m_newFileRowset_sp->end()) { @@ -138,7 +138,7 @@ RequestSP ProtocolManager::createtRequest() throw(std::runtime_error) else { throw std::runtime_error("Lists not initialized"); - } + } } //============================================================================== @@ -196,7 +196,7 @@ void ProtocolManager::setCurrentFileDownloaded(FileWrapper::SP fileWrapper_sp) std::string storagePath = fileWrapper_sp->getStoragePath(); std::string filePath = fileWrapper_sp->getFilePath(); - + if(m_newFileRowset_sp && m_newFileRowsetIt != m_newFileRowset_sp->end()) { @@ -240,7 +240,9 @@ void ProtocolManager::setCurrentFileDownloaded(FileWrapper::SP fileWrapper_sp) m_dBManager_sp->updateNewFilePath(storagePath, filePath, fileVersion, fileName); auxTransaction_sp->commit(); - mainTransaction_sp->commit(); + mainTransaction_sp->commit(); + + m_dataImporter_p->incrementRegularCounter(); } else if(m_failedFileRowset_sp && m_failedFileRowsetIt != m_failedFileRowset_sp->end()) @@ -263,12 +265,15 @@ void ProtocolManager::setCurrentFileDownloaded(FileWrapper::SP fileWrapper_sp) m_dBManager_sp->updateNewFilePath(storagePath, filePath, fileVersion, fileName); auxTransaction_sp->commit(); - mainTransaction_sp->commit(); + mainTransaction_sp->commit(); + + m_dataImporter_p->decrementFailedCounter(); + m_dataImporter_p->incrementRegularCounter(); } else { throw std::runtime_error("Lists not initialized"); - } + } } //============================================================================== @@ -321,17 +326,19 @@ void ProtocolManager::setCurrentFileFailed() throw(std::runtime_error) m_dBManager_sp->addFailedFile(fileVersion, fileName); auxTransaction_sp->commit(); - mainTransaction_sp->commit(); + mainTransaction_sp->commit(); + + m_dataImporter_p->incrementFailedCounter(); } else if(m_failedFileRowset_sp && m_failedFileRowsetIt != m_failedFileRowset_sp->end()) { - ++m_failedFileRowsetIt; + ++m_failedFileRowsetIt; } else { throw std::runtime_error("Lists not initialized"); - } + } } //============================================================================== @@ -369,7 +376,7 @@ RequestSP ProtocolManager::fillRequest(DBManager::FileRowset::const_iterator it) throw(std::runtime_error) { DEBUG_STREAM << "ProtocolManager::fillRequest()" << endl; - + RequestSP request_sp(new Request); request_sp->set_username(m_configuration_sp->getDatabaseUsername()); @@ -395,7 +402,7 @@ RequestSP ProtocolManager::fillRequest(DBManager::FileRowset::const_iterator it) if(!request_sp->IsInitialized()) throw std::runtime_error("Request not initialized"); - return request_sp; + return request_sp; } } //namespace diff --git a/src/SSLClient.cpp b/src/SSLClient.cpp index e3a8b090a44329f3cb00e105089a2a57d774f688..40b46df31e6017584614f4785ed81d8c4d8f4a01 100644 --- a/src/SSLClient.cpp +++ b/src/SSLClient.cpp @@ -198,7 +198,7 @@ void SSLClient::startWriteRequest() boost::bind(&SSLClient::handleWriteRequest, this, boost::asio::placeholders::error)); } - catch(std::runtime_error& ec) + catch(std::exception& ec) { ERROR_STREAM << "SSLClient::startWriteRequest() " << ec.what() << endl;