diff --git a/deps/Base-DAQ b/deps/Base-DAQ index 8a0ea2d0e699863df5fe1c91caf2d7b0855957be..a00f9a27afbf5f75dab7db2368b9b9b6fcb395e1 160000 --- a/deps/Base-DAQ +++ b/deps/Base-DAQ @@ -1 +1 @@ -Subproject commit 8a0ea2d0e699863df5fe1c91caf2d7b0855957be +Subproject commit a00f9a27afbf5f75dab7db2368b9b9b6fcb395e1 diff --git a/include/File_Archiver.h b/include/File_Archiver.h index b598beb7dc0cef4c49b55b1b57ce64859417caff..2fbb4c0395a12ff9ad2e91fb5e8063de7c0ae747 100755 --- a/include/File_Archiver.h +++ b/include/File_Archiver.h @@ -1,33 +1,37 @@ - #pragma once #include #include #include +/** + * @brief The namespace inaf::oasbo::Archivers contains classes related to file archiving. + */ namespace inaf::oasbo::Archivers { +/** + * @brief The FileArchiver class is a derived class of BaseArchiver and provides functionality for archiving packets into files. + */ class FileArchiver: public BaseArchiver { protected: - std::ofstream *myfile = nullptr; - bool _open; - std::string computeFileName(std::string fileName); - std::string resolveEnvVar(std::string path); - FileArchiver(std::string dest); - FileArchiver(std::string parent, std::string dest); - FileArchiver(); + std::ofstream *myfile = nullptr; /**< Pointer to the output file stream. */ + bool _open; /**< Flag indicating if the file is open. */ + std::string computeFileName(std::string fileName); /**< Computes the file name based on the given file name. */ + std::string resolveEnvVar(std::string path); /**< Resolves environment variables in the given path. */ + FileArchiver(std::string dest); /**< Constructs a FileArchiver object with the given destination. */ + FileArchiver(std::string parent, std::string dest); /**< Constructs a FileArchiver object with the given parent and destination. */ + FileArchiver(); /**< Default constructor for FileArchiver. */ public: - std::string parentPath; + std::string parentPath; /**< The parent path of the file. */ - int write(PacketLib::BasePacket&) override; - int write(PacketLib::BasePacket&, std::string dest) override; + int write(Packets::BasePacket&) override; /**< Writes the given packet to the file. */ + int write(Packets::BasePacket&, std::string dest) override; /**< Writes the given packet to the specified destination. */ - int close() override; - int open() override; - bool is_open() override; - void setDest(std::string) override; - void updateDest() override; - std::string getDest() override; + int close() override; /**< Closes the file. */ + int open() override; /**< Opens the file. */ + bool is_open() override; /**< Checks if the file is open. */ + void setDest(std::string) override; /**< Sets the file destination of the packets. */ + std::string getDest() override; /**< Gets the destination. */ ~FileArchiver() { close(); } @@ -36,28 +40,30 @@ public: }; - +/** + * @brief The FileArchiverBuilder class is responsible for building FileArchiver objects. + */ class FileArchiverBuilder { protected: - FileArchiver *arch; + FileArchiver *arch; /**< Pointer to the FileArchiver object being built. */ public: - std::string config_target { "filearchiver" }; - std::string file_name_key { "file_name" }; - std::string archive_path_key { "archive_path" }; + std::string config_target { "filearchiver" }; /**< The configuration target for the FileArchiver. */ + std::string file_name_key { "file_name" }; /**< The key for the file name configuration. */ + std::string archive_path_key { "archive_path" }; /**< The key for the archive path configuration. */ - FileArchiverBuilder(); - FileArchiverBuilder(std::string dest); - FileArchiverBuilder(std::string parent, std::string dest); + FileArchiverBuilder(); /**< Default constructor for FileArchiverBuilder. */ + FileArchiverBuilder(std::string dest); /**< Constructs a FileArchiverBuilder object with the given destination. */ + FileArchiverBuilder(std::string parent, std::string dest); /**< Constructs a FileArchiverBuilder object with the given parent and destination. */ ~FileArchiverBuilder(); - void reset(); + void reset(); /**< Resets the FileArchiverBuilder object. */ - FileArchiverBuilder* configFrom(Configurators::BaseConfigurator &conf); + FileArchiverBuilder* configFrom(Configurators::BaseConfigurator &conf); /**< Configures the FileArchiverBuilder from the given configurator. */ - FileArchiverBuilder* setParent(std::string parent); + FileArchiverBuilder* setParent(std::string parent); /**< Sets the parent path for the FileArchiver. */ - FileArchiverBuilder* setDest(std::string dest); + FileArchiverBuilder* setDest(std::string dest); /**< Sets the destination for the FileArchiver. */ - FileArchiver* getArchiver(); + FileArchiver* getArchiver(); /**< Gets the built FileArchiver object. */ }; } diff --git a/src/Builder.cpp b/src/Builder.cpp index 89d1a5a66ad6a05dbdfcb1c70f04b3cd1f513c6d..b79d57ba0b3284c38f66bdde96a5d4d222b0e2dd 100644 --- a/src/Builder.cpp +++ b/src/Builder.cpp @@ -19,15 +19,16 @@ void FileArchiverBuilder::reset() { this->arch = new FileArchiver(); } -FileArchiverBuilder* FileArchiverBuilder::configFrom(Configurators::BaseConfigurator &conf) { +FileArchiverBuilder* FileArchiverBuilder::configFrom( + Configurators::BaseConfigurator &conf) { conf.readConfigFromSource(config_target); std::map params = conf.getConfig(); - std::string key = config_target+"_"+archive_path_key; + std::string key = config_target + "_" + archive_path_key; if (params.count(key) > 0) arch->parentPath = params[key]; - key = config_target+"_"+file_name_key; + key = config_target + "_" + file_name_key; if (params.count(key) > 0) arch->setDest(params[key]); return this; diff --git a/src/File_Archiver.cpp b/src/File_Archiver.cpp index e8a86d27364a1e86a26921e369a972765f0bfeac..bbf7241fa8badbf92bbfc06a73b4564835d54f27 100755 --- a/src/File_Archiver.cpp +++ b/src/File_Archiver.cpp @@ -11,25 +11,24 @@ using namespace inaf::oasbo::Archivers; #endif FileArchiver::FileArchiver(std::string parent, std::string dest) : - _open(false), parentPath(parent){ - std::string filename = computeFileName(parent+"/"+dest).append(".raw"); + _open(false), parentPath(parent) { + std::string filename = computeFileName(parent + "/" + dest).append(".raw"); this->dest = filename; } FileArchiver::FileArchiver(std::string dest) : - FileArchiver(FILEARCH_CONFIG, - dest) { + FileArchiver(FILEARCH_CONFIG, dest) { } FileArchiver::FileArchiver() : - FileArchiver(FILEARCH_CONFIG, - ".tmp") { + FileArchiver(FILEARCH_CONFIG, ".tmp") { } -int FileArchiver::write(PacketLib::BasePacket &pack) { +int FileArchiver::write(Packets::BasePacket &pack) { if (myfile == nullptr || !myfile->is_open()) { - time_t now = time(nullptr); - std::cerr << "[" << std::put_time(localtime(&now), "%Y-%m-%d %H:%M:%S") <<"]\t[File Archiver]\t" << " File not opened" << std::endl; + time_t now = time(nullptr); + std::cerr << "[" << std::put_time(localtime(&now), "%Y-%m-%d %H:%M:%S") + << "]\t[File Archiver]\t" << " File not opened" << std::endl; return -1; } myfile->write((char*) pack.getPointerToMemory(), @@ -37,7 +36,7 @@ int FileArchiver::write(PacketLib::BasePacket &pack) { return 1; } -int FileArchiver::write(PacketLib::BasePacket &pack, std::string dest) { +int FileArchiver::write(Packets::BasePacket &pack, std::string dest) { namespace fs = std::filesystem; dest = resolveEnvVar(dest); fs::path dest_path(dest); @@ -57,7 +56,7 @@ int FileArchiver::open() { if (myfile != nullptr) delete myfile; this->myfile = new std::ofstream(this->dest, std::ios::binary); - if(myfile->good()){ + if (myfile->good()) { _open = true; } return _open; @@ -73,7 +72,6 @@ int FileArchiver::close() { return 1; } - bool FileArchiver::is_open() { return _open; } @@ -83,7 +81,7 @@ std::string FileArchiver::getDest() { } void FileArchiver::setDest(std::string dest) { - this->dest = computeFileName(this->parentPath+"/"+dest).append(".raw"); + this->dest = computeFileName(this->parentPath + "/" + dest).append(".raw"); } std::string FileArchiver::computeFileName(std::string dest) { @@ -110,7 +108,6 @@ std::string FileArchiver::computeFileName(std::string dest) { return dest_path.string(); } - std::string FileArchiver::resolveEnvVar(std::string path) { // resolve env var if present if (path.at(0) == '$') { @@ -129,6 +126,3 @@ std::string FileArchiver::resolveEnvVar(std::string path) { return path; } -void FileArchiver::updateDest() { - -}