Loading src/FileWrapper.cpp +29 −13 Original line number Diff line number Diff line Loading @@ -11,30 +11,30 @@ FileWrapper::FileWrapper(Tango::DeviceImpl* deviceImpl_p, std::string fileName, boost::uint64_t totalFileSize) throw(std::logic_error) : Tango::LogAdapter(deviceImpl_p), m_storagePath(storagePath), m_filePath(filePath), m_fileVersion(fileVersion), m_fileName(fileName), m_totalFileSize(totalFileSize) m_expectedFileSize(totalFileSize) { DEBUG_STREAM << "FileWrapper::FileWrapper()" << endl; boost::filesystem::path destPath(storagePath); m_outputFilePath /= storagePath; destPath /= filePath; m_outputFilePath /= filePath; std::stringstream fileStream; fileStream << "/" << fileVersion; destPath /= fileStream.str(); m_outputFilePath /= fileStream.str(); if(!boost::filesystem::exists(destPath)) boost::filesystem::create_directories(destPath); if(!boost::filesystem::exists(m_outputFilePath)) boost::filesystem::create_directories(m_outputFilePath); if(!boost::filesystem::is_directory(destPath)) if(!boost::filesystem::is_directory(m_outputFilePath)) throw std::logic_error("Destination path \'" + destPath.string() + "\' is not a directory" ); + m_outputFilePath.string() + "\' is not a directory" ); destPath /= fileName; m_outputFilePath /= fileName; m_outputFileStream.open(destPath.string(), std::ios::binary); m_outputFileStream.open(m_outputFilePath.string(), std::ios::binary); } //============================================================================== Loading Loading @@ -122,7 +122,7 @@ bool FileWrapper::isBad() //============================================================================== bool FileWrapper::isCompleted() { return (boost::uint64_t)m_outputFileStream.tellp() >= m_totalFileSize; return (boost::uint64_t)m_outputFileStream.tellp() >= m_expectedFileSize; } //============================================================================== Loading @@ -130,15 +130,31 @@ bool FileWrapper::isCompleted() //============================================================================== boost::uint64_t FileWrapper::getLeftToWrite() { return m_totalFileSize - (boost::uint64_t)m_outputFileStream.tellp(); return m_expectedFileSize - (boost::uint64_t)m_outputFileStream.tellp(); } //============================================================================== // FileWrapper::read() // FileWrapper::write() //============================================================================== void FileWrapper::write(std::vector<char>& writeBuff, boost::uint64_t& recvBytes) { m_outputFileStream.write(&writeBuff[0], (std::streamsize)recvBytes); } //============================================================================== // FileWrapper::cleanUp() //============================================================================== void FileWrapper::cleanUp() { DEBUG_STREAM << "FileWrapper::cleanUp()" << endl; if(m_outputFileStream.is_open()) m_outputFileStream.close(); boost::system::error_code errorCode; if(boost::filesystem::exists(m_outputFilePath)) boost::filesystem::remove(m_outputFilePath, errorCode); } } //namespace src/FileWrapper.h +11 −3 Original line number Diff line number Diff line Loading @@ -64,6 +64,11 @@ public: virtual void write(std::vector<char>&, boost::uint64_t&); //------------------------------------------------------------------------------ // [Public] Clean up method //------------------------------------------------------------------------------ virtual void cleanUp(); protected: //------------------------------------------------------------------------------ // [Protected] Class variables Loading @@ -80,10 +85,13 @@ protected: //File name property const std::string m_fileName; //Input file size boost::uint64_t m_totalFileSize; //Expected file size boost::uint64_t m_expectedFileSize; //Output file path boost::filesystem::path m_outputFilePath; //Input file stream //Output file stream std::ofstream m_outputFileStream; }; Loading Loading
src/FileWrapper.cpp +29 −13 Original line number Diff line number Diff line Loading @@ -11,30 +11,30 @@ FileWrapper::FileWrapper(Tango::DeviceImpl* deviceImpl_p, std::string fileName, boost::uint64_t totalFileSize) throw(std::logic_error) : Tango::LogAdapter(deviceImpl_p), m_storagePath(storagePath), m_filePath(filePath), m_fileVersion(fileVersion), m_fileName(fileName), m_totalFileSize(totalFileSize) m_expectedFileSize(totalFileSize) { DEBUG_STREAM << "FileWrapper::FileWrapper()" << endl; boost::filesystem::path destPath(storagePath); m_outputFilePath /= storagePath; destPath /= filePath; m_outputFilePath /= filePath; std::stringstream fileStream; fileStream << "/" << fileVersion; destPath /= fileStream.str(); m_outputFilePath /= fileStream.str(); if(!boost::filesystem::exists(destPath)) boost::filesystem::create_directories(destPath); if(!boost::filesystem::exists(m_outputFilePath)) boost::filesystem::create_directories(m_outputFilePath); if(!boost::filesystem::is_directory(destPath)) if(!boost::filesystem::is_directory(m_outputFilePath)) throw std::logic_error("Destination path \'" + destPath.string() + "\' is not a directory" ); + m_outputFilePath.string() + "\' is not a directory" ); destPath /= fileName; m_outputFilePath /= fileName; m_outputFileStream.open(destPath.string(), std::ios::binary); m_outputFileStream.open(m_outputFilePath.string(), std::ios::binary); } //============================================================================== Loading Loading @@ -122,7 +122,7 @@ bool FileWrapper::isBad() //============================================================================== bool FileWrapper::isCompleted() { return (boost::uint64_t)m_outputFileStream.tellp() >= m_totalFileSize; return (boost::uint64_t)m_outputFileStream.tellp() >= m_expectedFileSize; } //============================================================================== Loading @@ -130,15 +130,31 @@ bool FileWrapper::isCompleted() //============================================================================== boost::uint64_t FileWrapper::getLeftToWrite() { return m_totalFileSize - (boost::uint64_t)m_outputFileStream.tellp(); return m_expectedFileSize - (boost::uint64_t)m_outputFileStream.tellp(); } //============================================================================== // FileWrapper::read() // FileWrapper::write() //============================================================================== void FileWrapper::write(std::vector<char>& writeBuff, boost::uint64_t& recvBytes) { m_outputFileStream.write(&writeBuff[0], (std::streamsize)recvBytes); } //============================================================================== // FileWrapper::cleanUp() //============================================================================== void FileWrapper::cleanUp() { DEBUG_STREAM << "FileWrapper::cleanUp()" << endl; if(m_outputFileStream.is_open()) m_outputFileStream.close(); boost::system::error_code errorCode; if(boost::filesystem::exists(m_outputFilePath)) boost::filesystem::remove(m_outputFilePath, errorCode); } } //namespace
src/FileWrapper.h +11 −3 Original line number Diff line number Diff line Loading @@ -64,6 +64,11 @@ public: virtual void write(std::vector<char>&, boost::uint64_t&); //------------------------------------------------------------------------------ // [Public] Clean up method //------------------------------------------------------------------------------ virtual void cleanUp(); protected: //------------------------------------------------------------------------------ // [Protected] Class variables Loading @@ -80,10 +85,13 @@ protected: //File name property const std::string m_fileName; //Input file size boost::uint64_t m_totalFileSize; //Expected file size boost::uint64_t m_expectedFileSize; //Output file path boost::filesystem::path m_outputFilePath; //Input file stream //Output file stream std::ofstream m_outputFileStream; }; Loading