Loading src/FileManager.cpp→src/FileWrapper.cpp +25 −21 Original line number Original line Diff line number Diff line #include <FileManager.h> #include <FileWrapper.h> #include <stdexcept> namespace DataExporter_ns namespace DataExporter_ns { { //============================================================================== //============================================================================== // FileManager::FileManager() // FileWrapper::FileWrapper() //============================================================================== //============================================================================== FileManager::FileManager(Tango::DeviceImpl* deviceImpl_p, FileWrapper::FileWrapper(Tango::DeviceImpl* deviceImpl_p, boost::filesystem::path& path) : Tango::LogAdapter(deviceImpl_p) boost::filesystem::path& path) : Tango::LogAdapter(deviceImpl_p) { { DEBUG_STREAM << "FileManager::FileManager()" << endl; DEBUG_STREAM << "FileWrapper::FileWrapper()" << endl; m_inputFileStream.open(path.string(), std::ios::binary | std::ios::ate); m_inputFileStream.open(path.string(), std::ios::binary | std::ios::ate); Loading @@ -20,51 +19,56 @@ FileManager::FileManager(Tango::DeviceImpl* deviceImpl_p, } } //============================================================================== //============================================================================== // FileManager::~FileManager() // FileWrapper::~FileWrapper() //============================================================================== //============================================================================== FileManager::~FileManager() FileWrapper::~FileWrapper() { { DEBUG_STREAM << "FileManager::~FileManager()" << endl; DEBUG_STREAM << "FileWrapper::~FileWrapper()" << endl; m_inputFileStream.close(); m_inputFileStream.close(); } } //============================================================================== //============================================================================== // FileManager::create() // FileWrapper::create() //============================================================================== //============================================================================== FileManager::SP FileManager::create(Tango::DeviceImpl* deviceImpl_p, FileWrapper::SP FileWrapper::create(Tango::DeviceImpl* deviceImpl_p, boost::filesystem::path& path) boost::filesystem::path& path) { { FileManager::SP d_sp(new FileManager(deviceImpl_p, path), FileWrapper::SP d_sp(new FileWrapper(deviceImpl_p, path), FileManager::Deleter()); FileWrapper::Deleter()); return d_sp; return d_sp; } } //============================================================================== //============================================================================== // FileManager::isOpen() // FileWrapper::isOpen() //============================================================================== //============================================================================== bool FileManager::isOpen() bool FileWrapper::isOpen() { { return m_inputFileStream.is_open(); return m_inputFileStream.is_open(); } } //============================================================================== //============================================================================== // FileManager::isCompleted() // FileWrapper::isBad() //============================================================================== //============================================================================== bool FileManager::isCompleted() bool FileWrapper::isBad() { { return m_inputFileStream.tellg() >= m_inputFileSize; return m_inputFileStream.bad(); } } //============================================================================== //============================================================================== // FileManager::read() // FileWrapper::isCompleted() //============================================================================== //============================================================================== void FileManager::read(std::vector<char>& writeBuff) throw(std::runtime_error) bool FileWrapper::isCompleted() { { if(m_inputFileStream.tellg() >= m_inputFileSize) return m_inputFileStream.tellg() >= m_inputFileSize; throw std::runtime_error("Already completed"); } //============================================================================== // FileWrapper::read() //============================================================================== void FileWrapper::read(std::vector<char>& writeBuff) throw(std::runtime_error) { int leftToRead = m_inputFileSize - m_inputFileStream.tellg(); int leftToRead = m_inputFileSize - m_inputFileStream.tellg(); int bufferSize = 0; int bufferSize = 0; Loading src/FileManager.h→src/FileWrapper.h +11 −9 Original line number Original line Diff line number Diff line #ifndef FILEMANAGER_H #ifndef FILEWRAPPER_H #define FILEMANAGER_H #define FILEWRAPPER_H #include <Configuration.h> #include <Configuration.h> Loading @@ -10,41 +10,43 @@ namespace DataExporter_ns namespace DataExporter_ns { { class FileManager : public Tango::LogAdapter class FileWrapper : public Tango::LogAdapter { { public: public: //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ // [Public] Shared pointer typedef // [Public] Shared pointer typedef //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ typedef boost::shared_ptr<FileManager> SP; typedef boost::shared_ptr<FileWrapper> SP; protected: protected: //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ // [Protected] Constructor destructor deleter // [Protected] Constructor destructor deleter //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ FileManager(Tango::DeviceImpl*, boost::filesystem::path&); FileWrapper(Tango::DeviceImpl*, boost::filesystem::path&); virtual ~FileManager(); virtual ~FileWrapper(); class Deleter; class Deleter; friend Deleter; friend Deleter; class Deleter class Deleter { { public: public: void operator()(FileManager* d) { delete d; } void operator()(FileWrapper* d) { delete d; } }; }; public: public: //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ // [Public] Class creation method // [Public] Class creation method //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ static FileManager::SP create(Tango::DeviceImpl*, boost::filesystem::path&); static FileWrapper::SP create(Tango::DeviceImpl*, boost::filesystem::path&); //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ // [Public] Input stream methods // [Public] Input stream methods //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ virtual bool isOpen(); virtual bool isOpen(); virtual bool isBad(); virtual bool isCompleted(); virtual bool isCompleted(); virtual void read(std::vector<char>&) throw(std::runtime_error); virtual void read(std::vector<char>&) throw(std::runtime_error); Loading @@ -65,4 +67,4 @@ protected: } //End of namespace } //End of namespace #endif /* FILEMANAGER_H */ #endif /* FILEWRAPPER_H */ src/PlainSession.cpp +8 −20 Original line number Original line Diff line number Diff line Loading @@ -154,52 +154,40 @@ void PlainSession::startWriteResponse() { { ERROR_STREAM << "SSLSession::startWriteResponse() unknown error from " ERROR_STREAM << "SSLSession::startWriteResponse() unknown error from " << m_remoteEndpoint << endl; << m_remoteEndpoint << endl; } } } } //============================================================================== //============================================================================== // PlainSession::startWriteData() // PlainSession::startWriteData() //============================================================================== //============================================================================== void PlainSession::startWriteData() void PlainSession::startWriteData(FileWrapper::SP fileWrapper_sp) { { try try { { if(!m_inputStream.bad()) if(!fileWrapper_sp->isBad()) { { if(m_inputStream.tellg()<m_inputStreamSize) if(!fileWrapper_sp->isCompleted()) { { int leftToRead = m_inputStreamSize - m_inputStream.tellg(); int bufferSize = 0; if(leftToRead < BUFFER_SIZE) bufferSize = leftToRead; else bufferSize = BUFFER_SIZE; std::vector<char> writeBuff; std::vector<char> writeBuff; writeBuff.resize(bufferSize); m_inputStream.read(&writeBuff[0], bufferSize); fileWrapper_sp->read(writeBuff); boost::asio::async_write(m_plainSocket, boost::asio::buffer(writeBuff), boost::asio::async_write(m_plainSocket, boost::asio::buffer(writeBuff), m_strand.wrap(boost::bind(&PlainSession::handleWriteData, m_strand.wrap(boost::bind(&PlainSession::handleWriteData, shared_from_this(), boost::asio::placeholders::error))); shared_from_this(), fileWrapper_sp, boost::asio::placeholders::error))); } } else else { { INFO_STREAM << "SSLSession::startWriteData() " INFO_STREAM << "PlainSession::startWriteData() " << " transfer completed " << endl; << " transfer completed " << endl; m_inputStream.close(); startReadRequestHeader(); startReadRequestHeader(); } } } } else else { { ERROR_STREAM << "SSLSession::startWriteData() error on file I/O " ERROR_STREAM << "PlainSession::startWriteData() error on file I/O " << "from " << m_remoteEndpoint << endl; << "from " << m_remoteEndpoint << endl; } } } } Loading src/PlainSession.h +1 −1 Original line number Original line Diff line number Diff line Loading @@ -54,7 +54,7 @@ protected: virtual void startWriteResponse(); virtual void startWriteResponse(); virtual void startWriteData(); virtual void startWriteData(FileWrapper::SP); //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ // [Protected] Class variables // [Protected] Class variables Loading src/ProtocolManager.cpp +37 −6 Original line number Original line Diff line number Diff line Loading @@ -11,8 +11,8 @@ namespace DataExporter_ns //============================================================================== //============================================================================== ProtocolManager::ProtocolManager(Tango::DeviceImpl* deviceImpl_p, ProtocolManager::ProtocolManager(Tango::DeviceImpl* deviceImpl_p, Configuration::SP configuration_sp, DBManager::SP dBManager_sp) : Configuration::SP configuration_sp, DBManager::SP dBManager_sp) : Tango::LogAdapter(deviceImpl_p), m_configuration_sp(configuration_sp), Tango::LogAdapter(deviceImpl_p), m_deviceImpl_p(deviceImpl_p), m_dBManager_sp(dBManager_sp) m_configuration_sp(configuration_sp), m_dBManager_sp(dBManager_sp) { { DEBUG_STREAM << "ProtocolManager::ProtocolManager()" << endl; DEBUG_STREAM << "ProtocolManager::ProtocolManager()" << endl; } } Loading Loading @@ -55,14 +55,17 @@ ResponseSP ProtocolManager::prepareResponse(RequestSP request_sp) { { DEBUG_STREAM << "ProtocolManager::prepareResponse()" << endl; DEBUG_STREAM << "ProtocolManager::prepareResponse()" << endl; m_fileFound = false; m_fileWrapper_sp.reset(); if(!request_sp->IsInitialized()) if(!request_sp->IsInitialized()) throw std::runtime_error("Not initialized request!"); throw std::runtime_error("Not initialized request!"); ResponseSP response_sp(new Response()); std::string username = request_sp->username(); std::string username = request_sp->username(); std::string password = request_sp->password(); std::string password = request_sp->password(); ResponseSP response_sp(new Response()); if(m_configuration_sp->isUserAuthorized(username, password)) if(m_configuration_sp->isUserAuthorized(username, password)) { { std::string schema = request_sp->schema(); std::string schema = request_sp->schema(); Loading Loading @@ -91,8 +94,13 @@ ResponseSP ProtocolManager::prepareResponse(RequestSP request_sp) boost::uint64_t fileSize = boost::uint64_t fileSize = boost::filesystem::file_size(absolutePath); boost::filesystem::file_size(absolutePath); DEBUG_STREAM << "ProtocolManager::prepareResponse() " INFO_STREAM << "ProtocolManager::prepareResponse() " << "file size " << fileSize << endl; << " transfer file " << fileName << " version " << fileVersion << " size " << fileSize << endl; m_fileFound = true; m_fileWrapper_sp = FileWrapper::create(m_deviceImpl_p, absolutePath); response_sp->set_state(Response::REQUEST_ACCEPTED); response_sp->set_state(Response::REQUEST_ACCEPTED); response_sp->set_status("Request accepted"); response_sp->set_status("Request accepted"); Loading Loading @@ -153,6 +161,29 @@ ResponseSP ProtocolManager::prepareResponse(RequestSP request_sp) return response_sp; return response_sp; } } //============================================================================== // ProtocolManager::isFileFound() //============================================================================== bool ProtocolManager::isFileFound() { DEBUG_STREAM << "ProtocolManager::isFileFound()" << endl; return m_fileFound; } //============================================================================== // ProtocolManager::getFileWrapper() //============================================================================== FileWrapper::SP ProtocolManager::getFileWrapper() throw(std::runtime_error) { DEBUG_STREAM << "ProtocolManager::getFileWrapper()" << endl; if(!m_fileWrapper_sp) throw std::runtime_error("File wrapper not created"); return m_fileWrapper_sp; } //============================================================================== //============================================================================== // ProtocolManager::composePath() // ProtocolManager::composePath() //============================================================================== //============================================================================== Loading Loading
src/FileManager.cpp→src/FileWrapper.cpp +25 −21 Original line number Original line Diff line number Diff line #include <FileManager.h> #include <FileWrapper.h> #include <stdexcept> namespace DataExporter_ns namespace DataExporter_ns { { //============================================================================== //============================================================================== // FileManager::FileManager() // FileWrapper::FileWrapper() //============================================================================== //============================================================================== FileManager::FileManager(Tango::DeviceImpl* deviceImpl_p, FileWrapper::FileWrapper(Tango::DeviceImpl* deviceImpl_p, boost::filesystem::path& path) : Tango::LogAdapter(deviceImpl_p) boost::filesystem::path& path) : Tango::LogAdapter(deviceImpl_p) { { DEBUG_STREAM << "FileManager::FileManager()" << endl; DEBUG_STREAM << "FileWrapper::FileWrapper()" << endl; m_inputFileStream.open(path.string(), std::ios::binary | std::ios::ate); m_inputFileStream.open(path.string(), std::ios::binary | std::ios::ate); Loading @@ -20,51 +19,56 @@ FileManager::FileManager(Tango::DeviceImpl* deviceImpl_p, } } //============================================================================== //============================================================================== // FileManager::~FileManager() // FileWrapper::~FileWrapper() //============================================================================== //============================================================================== FileManager::~FileManager() FileWrapper::~FileWrapper() { { DEBUG_STREAM << "FileManager::~FileManager()" << endl; DEBUG_STREAM << "FileWrapper::~FileWrapper()" << endl; m_inputFileStream.close(); m_inputFileStream.close(); } } //============================================================================== //============================================================================== // FileManager::create() // FileWrapper::create() //============================================================================== //============================================================================== FileManager::SP FileManager::create(Tango::DeviceImpl* deviceImpl_p, FileWrapper::SP FileWrapper::create(Tango::DeviceImpl* deviceImpl_p, boost::filesystem::path& path) boost::filesystem::path& path) { { FileManager::SP d_sp(new FileManager(deviceImpl_p, path), FileWrapper::SP d_sp(new FileWrapper(deviceImpl_p, path), FileManager::Deleter()); FileWrapper::Deleter()); return d_sp; return d_sp; } } //============================================================================== //============================================================================== // FileManager::isOpen() // FileWrapper::isOpen() //============================================================================== //============================================================================== bool FileManager::isOpen() bool FileWrapper::isOpen() { { return m_inputFileStream.is_open(); return m_inputFileStream.is_open(); } } //============================================================================== //============================================================================== // FileManager::isCompleted() // FileWrapper::isBad() //============================================================================== //============================================================================== bool FileManager::isCompleted() bool FileWrapper::isBad() { { return m_inputFileStream.tellg() >= m_inputFileSize; return m_inputFileStream.bad(); } } //============================================================================== //============================================================================== // FileManager::read() // FileWrapper::isCompleted() //============================================================================== //============================================================================== void FileManager::read(std::vector<char>& writeBuff) throw(std::runtime_error) bool FileWrapper::isCompleted() { { if(m_inputFileStream.tellg() >= m_inputFileSize) return m_inputFileStream.tellg() >= m_inputFileSize; throw std::runtime_error("Already completed"); } //============================================================================== // FileWrapper::read() //============================================================================== void FileWrapper::read(std::vector<char>& writeBuff) throw(std::runtime_error) { int leftToRead = m_inputFileSize - m_inputFileStream.tellg(); int leftToRead = m_inputFileSize - m_inputFileStream.tellg(); int bufferSize = 0; int bufferSize = 0; Loading
src/FileManager.h→src/FileWrapper.h +11 −9 Original line number Original line Diff line number Diff line #ifndef FILEMANAGER_H #ifndef FILEWRAPPER_H #define FILEMANAGER_H #define FILEWRAPPER_H #include <Configuration.h> #include <Configuration.h> Loading @@ -10,41 +10,43 @@ namespace DataExporter_ns namespace DataExporter_ns { { class FileManager : public Tango::LogAdapter class FileWrapper : public Tango::LogAdapter { { public: public: //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ // [Public] Shared pointer typedef // [Public] Shared pointer typedef //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ typedef boost::shared_ptr<FileManager> SP; typedef boost::shared_ptr<FileWrapper> SP; protected: protected: //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ // [Protected] Constructor destructor deleter // [Protected] Constructor destructor deleter //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ FileManager(Tango::DeviceImpl*, boost::filesystem::path&); FileWrapper(Tango::DeviceImpl*, boost::filesystem::path&); virtual ~FileManager(); virtual ~FileWrapper(); class Deleter; class Deleter; friend Deleter; friend Deleter; class Deleter class Deleter { { public: public: void operator()(FileManager* d) { delete d; } void operator()(FileWrapper* d) { delete d; } }; }; public: public: //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ // [Public] Class creation method // [Public] Class creation method //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ static FileManager::SP create(Tango::DeviceImpl*, boost::filesystem::path&); static FileWrapper::SP create(Tango::DeviceImpl*, boost::filesystem::path&); //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ // [Public] Input stream methods // [Public] Input stream methods //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ virtual bool isOpen(); virtual bool isOpen(); virtual bool isBad(); virtual bool isCompleted(); virtual bool isCompleted(); virtual void read(std::vector<char>&) throw(std::runtime_error); virtual void read(std::vector<char>&) throw(std::runtime_error); Loading @@ -65,4 +67,4 @@ protected: } //End of namespace } //End of namespace #endif /* FILEMANAGER_H */ #endif /* FILEWRAPPER_H */
src/PlainSession.cpp +8 −20 Original line number Original line Diff line number Diff line Loading @@ -154,52 +154,40 @@ void PlainSession::startWriteResponse() { { ERROR_STREAM << "SSLSession::startWriteResponse() unknown error from " ERROR_STREAM << "SSLSession::startWriteResponse() unknown error from " << m_remoteEndpoint << endl; << m_remoteEndpoint << endl; } } } } //============================================================================== //============================================================================== // PlainSession::startWriteData() // PlainSession::startWriteData() //============================================================================== //============================================================================== void PlainSession::startWriteData() void PlainSession::startWriteData(FileWrapper::SP fileWrapper_sp) { { try try { { if(!m_inputStream.bad()) if(!fileWrapper_sp->isBad()) { { if(m_inputStream.tellg()<m_inputStreamSize) if(!fileWrapper_sp->isCompleted()) { { int leftToRead = m_inputStreamSize - m_inputStream.tellg(); int bufferSize = 0; if(leftToRead < BUFFER_SIZE) bufferSize = leftToRead; else bufferSize = BUFFER_SIZE; std::vector<char> writeBuff; std::vector<char> writeBuff; writeBuff.resize(bufferSize); m_inputStream.read(&writeBuff[0], bufferSize); fileWrapper_sp->read(writeBuff); boost::asio::async_write(m_plainSocket, boost::asio::buffer(writeBuff), boost::asio::async_write(m_plainSocket, boost::asio::buffer(writeBuff), m_strand.wrap(boost::bind(&PlainSession::handleWriteData, m_strand.wrap(boost::bind(&PlainSession::handleWriteData, shared_from_this(), boost::asio::placeholders::error))); shared_from_this(), fileWrapper_sp, boost::asio::placeholders::error))); } } else else { { INFO_STREAM << "SSLSession::startWriteData() " INFO_STREAM << "PlainSession::startWriteData() " << " transfer completed " << endl; << " transfer completed " << endl; m_inputStream.close(); startReadRequestHeader(); startReadRequestHeader(); } } } } else else { { ERROR_STREAM << "SSLSession::startWriteData() error on file I/O " ERROR_STREAM << "PlainSession::startWriteData() error on file I/O " << "from " << m_remoteEndpoint << endl; << "from " << m_remoteEndpoint << endl; } } } } Loading
src/PlainSession.h +1 −1 Original line number Original line Diff line number Diff line Loading @@ -54,7 +54,7 @@ protected: virtual void startWriteResponse(); virtual void startWriteResponse(); virtual void startWriteData(); virtual void startWriteData(FileWrapper::SP); //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ // [Protected] Class variables // [Protected] Class variables Loading
src/ProtocolManager.cpp +37 −6 Original line number Original line Diff line number Diff line Loading @@ -11,8 +11,8 @@ namespace DataExporter_ns //============================================================================== //============================================================================== ProtocolManager::ProtocolManager(Tango::DeviceImpl* deviceImpl_p, ProtocolManager::ProtocolManager(Tango::DeviceImpl* deviceImpl_p, Configuration::SP configuration_sp, DBManager::SP dBManager_sp) : Configuration::SP configuration_sp, DBManager::SP dBManager_sp) : Tango::LogAdapter(deviceImpl_p), m_configuration_sp(configuration_sp), Tango::LogAdapter(deviceImpl_p), m_deviceImpl_p(deviceImpl_p), m_dBManager_sp(dBManager_sp) m_configuration_sp(configuration_sp), m_dBManager_sp(dBManager_sp) { { DEBUG_STREAM << "ProtocolManager::ProtocolManager()" << endl; DEBUG_STREAM << "ProtocolManager::ProtocolManager()" << endl; } } Loading Loading @@ -55,14 +55,17 @@ ResponseSP ProtocolManager::prepareResponse(RequestSP request_sp) { { DEBUG_STREAM << "ProtocolManager::prepareResponse()" << endl; DEBUG_STREAM << "ProtocolManager::prepareResponse()" << endl; m_fileFound = false; m_fileWrapper_sp.reset(); if(!request_sp->IsInitialized()) if(!request_sp->IsInitialized()) throw std::runtime_error("Not initialized request!"); throw std::runtime_error("Not initialized request!"); ResponseSP response_sp(new Response()); std::string username = request_sp->username(); std::string username = request_sp->username(); std::string password = request_sp->password(); std::string password = request_sp->password(); ResponseSP response_sp(new Response()); if(m_configuration_sp->isUserAuthorized(username, password)) if(m_configuration_sp->isUserAuthorized(username, password)) { { std::string schema = request_sp->schema(); std::string schema = request_sp->schema(); Loading Loading @@ -91,8 +94,13 @@ ResponseSP ProtocolManager::prepareResponse(RequestSP request_sp) boost::uint64_t fileSize = boost::uint64_t fileSize = boost::filesystem::file_size(absolutePath); boost::filesystem::file_size(absolutePath); DEBUG_STREAM << "ProtocolManager::prepareResponse() " INFO_STREAM << "ProtocolManager::prepareResponse() " << "file size " << fileSize << endl; << " transfer file " << fileName << " version " << fileVersion << " size " << fileSize << endl; m_fileFound = true; m_fileWrapper_sp = FileWrapper::create(m_deviceImpl_p, absolutePath); response_sp->set_state(Response::REQUEST_ACCEPTED); response_sp->set_state(Response::REQUEST_ACCEPTED); response_sp->set_status("Request accepted"); response_sp->set_status("Request accepted"); Loading Loading @@ -153,6 +161,29 @@ ResponseSP ProtocolManager::prepareResponse(RequestSP request_sp) return response_sp; return response_sp; } } //============================================================================== // ProtocolManager::isFileFound() //============================================================================== bool ProtocolManager::isFileFound() { DEBUG_STREAM << "ProtocolManager::isFileFound()" << endl; return m_fileFound; } //============================================================================== // ProtocolManager::getFileWrapper() //============================================================================== FileWrapper::SP ProtocolManager::getFileWrapper() throw(std::runtime_error) { DEBUG_STREAM << "ProtocolManager::getFileWrapper()" << endl; if(!m_fileWrapper_sp) throw std::runtime_error("File wrapper not created"); return m_fileWrapper_sp; } //============================================================================== //============================================================================== // ProtocolManager::composePath() // ProtocolManager::composePath() //============================================================================== //============================================================================== Loading