From f6d0a5f936069ee23f483195ac3ed03651803326 Mon Sep 17 00:00:00 2001 From: Valerio Pastore Date: Fri, 12 Jan 2024 17:35:17 +0100 Subject: [PATCH 1/2] adding doxygen --- include/Redis_Provider.h | 138 +++++++++++++++++++++++++++++---------- src/Redis_Provider.cpp | 11 ++-- 2 files changed, 110 insertions(+), 39 deletions(-) diff --git a/include/Redis_Provider.h b/include/Redis_Provider.h index 601ca1f..7c6a038 100755 --- a/include/Redis_Provider.h +++ b/include/Redis_Provider.h @@ -1,8 +1,4 @@ -/* - * - * Created on: Mar 1, 2021 - * Author: astrisw - */ + #pragma once @@ -13,54 +9,128 @@ namespace inaf::oasbo::Providers { +/** + * @brief The RedisProvider class is a concrete implementation of the BaseProvider class. + * It provides functionality to write data to a Redis server. + * Check Base_Provider.h for more information. + */ class RedisProvider: public BaseProvider { protected: redisContext *context = nullptr; + /** + * @brief Default constructor for RedisProvider. + */ RedisProvider(); + + /** + * @brief Constructor for RedisProvider. + * @param ip The IP address of the Redis server. + * @param port The port number of the Redis server. + * @param key The key used to access the Redis server. + */ RedisProvider(std::string ip, int port, std::string key); public: - std::string ip; - int port; - std::string key; + std::string ip; /**< The IP address of the Redis server. */ + int port; /**< The port number of the Redis server. */ + std::string key; /**< The key used to access the Redis server. */ + + int write(Packets::BasePacket&) override; + + int write(Packets::BasePacket&, std::string dest) override; - int write(PacketLib::BasePacket&) override; - int write(PacketLib::BasePacket&, std::string dest) override; void setDest(std::string dest) override; + + std::string getDest() override; + + int close() override; + + int open() override; + + bool isOpen() override; + + /** + * @brief Destructor for RedisProvider. + */ ~RedisProvider(); friend class RedisProviderBuilder; }; +/** + * @brief The RedisProviderBuilder class is used to build RedisProvider objects. + */ class RedisProviderBuilder { - protected: - RedisProvider *provider; - - public: - std::string config_target { "redisprovider" }; - std::string ip_key { "ip" }; - std::string port_key { "port" }; - std::string redis_key_key { "key" }; - - RedisProviderBuilder(); - RedisProviderBuilder(std::string ip, int port, std::string topic); - ~RedisProviderBuilder(); - - void reset(); - - RedisProviderBuilder* configFrom(Configurators::BaseConfigurator &conf); - - RedisProviderBuilder* setIp(std::string ip); - - RedisProviderBuilder* setPort(int port); +protected: + RedisProvider *provider; - RedisProviderBuilder* setKey(std::string key); +public: + std::string config_target { "redisprovider" }; + std::string ip_key { "ip" }; + std::string port_key { "port" }; + std::string redis_key_key { "key" }; + + /** + * @brief Default constructor for RedisProviderBuilder. + */ + RedisProviderBuilder(); + + /** + * @brief Constructor for RedisProviderBuilder. + * @param ip The IP address of the Redis server. + * @param port The port number of the Redis server. + * @param topic The topic to write packets to. + */ + RedisProviderBuilder(std::string ip, int port, std::string topic); + + /** + * @brief Destructor for RedisProviderBuilder. + */ + ~RedisProviderBuilder(); + + /** + * @brief Resets the builder to its initial state. + */ + void reset(); + + /** + * @brief Configures the builder from a BaseConfigurator object. + * @param conf The BaseConfigurator object to configure from. + * @return A pointer to the RedisProviderBuilder object. + */ + RedisProviderBuilder* configFrom(Configurators::BaseConfigurator &conf); + + /** + * @brief Sets the IP address of the Redis server. + * @param ip The IP address to set. + * @return A pointer to the RedisProviderBuilder object. + */ + RedisProviderBuilder* setIp(std::string ip); + + /** + * @brief Sets the port number of the Redis server. + * @param port The port number to set. + * @return A pointer to the RedisProviderBuilder object. + */ + RedisProviderBuilder* setPort(int port); + + /** + * @brief Sets the key used to access the Redis server. + * @param key The key to set. + * @return A pointer to the RedisProviderBuilder object. + */ + RedisProviderBuilder* setKey(std::string key); + + /** + * @brief Gets the built RedisProvider object. + * @return A pointer to the built RedisProvider object. + */ + RedisProvider* getProvider(); +}; - RedisProvider* getProvider(); - }; -} +} // namespace inaf::oasbo::Providers diff --git a/src/Redis_Provider.cpp b/src/Redis_Provider.cpp index 07f33c5..e1933b9 100755 --- a/src/Redis_Provider.cpp +++ b/src/Redis_Provider.cpp @@ -15,11 +15,11 @@ RedisProvider::RedisProvider(std::string ip, int port, std::string key) : ip(ip), port(port), key(key) { } -int RedisProvider::write(PacketLib::BasePacket &packet) { +int RedisProvider::write(Packets::BasePacket &packet) { return write(packet, this->key); } -int RedisProvider::write(PacketLib::BasePacket &packet, std::string key) { +int RedisProvider::write(Packets::BasePacket &packet, std::string key) { if (!isOpen()) { if (context) { time_t now = time(nullptr); @@ -36,10 +36,10 @@ int RedisProvider::write(PacketLib::BasePacket &packet, std::string key) { return -1; } - uint size = packet.getHeaderSize() + packet.getPayloadSize() + uint packet_size = packet.getHeaderSize() + packet.getPayloadSize() + packet.getTailSize(); redisReply *r = (redisReply*) redisCommand(context, "LPUSH %s %b", - key.c_str(), (char*) packet.getPointerToMemory(), size); + key.c_str(), (char*) packet.getPointerToMemory(), packet_size); if (r == NULL) { // Error executing Redis command return -1; @@ -54,7 +54,7 @@ int RedisProvider::write(PacketLib::BasePacket &packet, std::string key) { return -1; } freeReplyObject(r); - return size; + return packet_size; } int RedisProvider::open() { @@ -113,6 +113,7 @@ bool RedisProvider::isOpen() { return (context != nullptr && !context->err); } +// dest must be in the form ip:port/key void RedisProvider::setDest(std::string dest) { std::regex pattern( R"((\d+\.\d+\.\d+\.\d+):(\d+)/(.+))"); -- GitLab From a5b2a882f9bbc8d092bcd332769f10a1e86e3303 Mon Sep 17 00:00:00 2001 From: valerio pastore Date: Fri, 12 Jan 2024 18:43:39 +0100 Subject: [PATCH 2/2] . --- deps/Base-DAQ | 2 +- include/Redis_Provider.h | 5 ----- src/Redis_Provider.cpp | 1 - 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/deps/Base-DAQ b/deps/Base-DAQ index 8a0ea2d..a00f9a2 160000 --- a/deps/Base-DAQ +++ b/deps/Base-DAQ @@ -1 +1 @@ -Subproject commit 8a0ea2d0e699863df5fe1c91caf2d7b0855957be +Subproject commit a00f9a27afbf5f75dab7db2368b9b9b6fcb395e1 diff --git a/include/Redis_Provider.h b/include/Redis_Provider.h index 7c6a038..5bde551 100755 --- a/include/Redis_Provider.h +++ b/include/Redis_Provider.h @@ -1,5 +1,4 @@ - #pragma once #include @@ -42,16 +41,12 @@ public: void setDest(std::string dest) override; - std::string getDest() override; - int close() override; - int open() override; - bool isOpen() override; /** diff --git a/src/Redis_Provider.cpp b/src/Redis_Provider.cpp index e1933b9..9a2d7c3 100755 --- a/src/Redis_Provider.cpp +++ b/src/Redis_Provider.cpp @@ -5,7 +5,6 @@ #include #include - using namespace inaf::oasbo::Providers; RedisProvider::RedisProvider() : RedisProvider("127.0.0.1", 6379, "Astri_ADAS_key") { -- GitLab