Commit 983fedbb authored by Micha Müller's avatar Micha Müller
Browse files

Bunch of fixes and improvement:

- Update/improve doxygen documentation
- Unify function name scheme of entity with SensorGroups
- Squash some TODOs
parent 64cdead1
...@@ -47,7 +47,6 @@ ...@@ -47,7 +47,6 @@
#define DEFAULT_CACHE_INTERVAL 900000 #define DEFAULT_CACHE_INTERVAL 900000
//TODO doxygen: cross reference both templates?
/** /**
* @brief Abstract interface defining plugin configurator functionality. * @brief Abstract interface defining plugin configurator functionality.
* *
......
...@@ -44,16 +44,18 @@ ...@@ -44,16 +44,18 @@
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
//TODO cross reference partial template specialization in doxygen docs
/** /**
* @brief Interface template for plugin configurator implementations. * @brief Interface template for plugin configurator implementations with
* entities.
* *
* @details There is a partial template specialization for SEntity = nullptr_t, * @details There is a partial template specialization for SEntity = nullptr_t,
* i.e. for plugins without entities. Common code is moved to * i.e. for plugins without entities, see
* ConfiguratorInterface if possible. If not, common code has to be * ConfiguratorTemplate<SBase, SGroup, nullptr_t>. Common code is moved
* duplicated and maintained twice here and in the template * to ConfiguratorInterface if possible. If not, common code has to be
* specialization. However, having two templates for cases with and * duplicated and maintained twice here and in
* without entities allows for easier derived plugin configurators. * ConfiguratorTemplate<SBase, SGroup, nullptr_t>. However, having two
* templates for cases with and without entities allows for simplified
* derived plugin configurators.
* *
* @ingroup pusherplugins * @ingroup pusherplugins
*/ */
...@@ -671,16 +673,16 @@ protected: ...@@ -671,16 +673,16 @@ protected:
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//TODO cross reference partial template specialization in doxygen docs
/** /**
* @brief Partial interface template specialization for plugin configurator * @brief Partial interface template specialization for plugin configurator
* implementations. * implementations without entities.
* *
* @details There is a general template for plugins with entities. Common code * @details There is a general template for plugins with entities, see
* is moved to ConfiguratorInterface if possible. If not, common code * ConfiguratorTemplate. Common code is moved to ConfiguratorInterface
* has to be duplicated and maintained twice here and in the general * if possible. If not, common code has to be duplicated and maintained
* template. However, having two templates for cases with and * twice here and in ConfiguratorTemplate. However, having two
* without entities allows for easier derived plugin configurators. * templates for cases with and without entities allows for simplified
* derived plugin configurators.
* *
* @ingroup pusherplugins * @ingroup pusherplugins
*/ */
......
...@@ -91,17 +91,16 @@ public: ...@@ -91,17 +91,16 @@ public:
return *this; return *this;
} }
//TODO refactor getEntityName -> getName()
///@name Getters ///@name Getters
///@{ ///@{
const std::string& getEntityName() const { return _name; } const std::string& getName() const { return _name; }
const std::string& getMqttPart() const { return _mqttPart; } const std::string& getMqttPart() const { return _mqttPart; }
const std::unique_ptr<strand>& getStrand() const { return _strand; } const std::unique_ptr<strand>& getStrand() const { return _strand; }
///@} ///@}
///@name Setters ///@name Setters
///@{ ///@{
void setEntityName(const std::string& name) { _name = name; } void setName(const std::string& name) { _name = name; }
void setMqttPart(const std::string& mqttPart) { void setMqttPart(const std::string& mqttPart) {
_mqttPart = mqttPart; _mqttPart = mqttPart;
//sanitize mqttPart into uniform /xxxx format //sanitize mqttPart into uniform /xxxx format
...@@ -114,50 +113,56 @@ public: ...@@ -114,50 +113,56 @@ public:
} }
///@} ///@}
//TODO refactor naming scheme uniform to SensorGroup
/** /**
* @brief Initialize this entity. * @brief Initialize this entity.
* *
* @details Initializes base class and subsequently calls init(). * @details This method must not be overwritten. See execOnInit() if custom
* actions are required during initialization. Initializes
* associated base class and subsequently calls execOnInit().
* *
* @param io IO service to initialize _strand with. * @param io IO service to initialize _strand with.
*/ */
void initEntity(boost::asio::io_service& io) { void init(boost::asio::io_service& io) {
if (!_strand) { if (!_strand) {
_strand.reset(new strand(io)); _strand.reset(new strand(io));
} }
this->init(); this->execOnInit();
} }
/** /**
* @brief Print complete configuration of this entity. * @brief Print configuration of this entity.
* *
* @details Prints configuration of base class and subsequently calls * @details Prints configuration of base class and subsequently calls
* derived printConfig(). * printEntityConfig().
* *
* @param ll Log severity level to be used from logger. * @param ll Log severity level to be used from logger.
*/ */
void printEntityConfig(LOG_LEVEL ll) { void printConfig(LOG_LEVEL ll) {
LOG_VAR(ll) << " " << "Entity " << _name; LOG_VAR(ll) << " " << "Entity " << _name;
if (_mqttPart != "") { if (_mqttPart != "") {
LOG_VAR(ll) << eInd << "MQTT part: " << _mqttPart; LOG_VAR(ll) << eInd << "MQTT part: " << _mqttPart;
} }
this->printConfig(ll); this->printEntityConfig(ll);
} }
protected:
/** /**
* @brief Initialize derived class (if necessary). * @brief Implement plugin specific actions to initialize an entity here.
*
* @details If a derived class (i.e. a plugin entity) requires further custom
* actions for initialization, this should be implemented here.
* %execOnInit() is appropriately called by this template during
* init().
*/ */
virtual void init() { /* do nothing if not overwritten */ }; virtual void execOnInit() { /* do nothing if not overwritten */ }
/** /**
* @brief Print configuration of derived class. * @brief Print configuration of derived class.
* *
* @param ll Log severity level to be used from logger. * @param ll Log severity level to be used from logger.
*/ */
virtual void printConfig(LOG_LEVEL ll) = 0; virtual void printEntityConfig(LOG_LEVEL ll) { /* do nothing if not overwritten */ }
protected:
std::string _name; /**< Name of the entity */ std::string _name; /**< Name of the entity */
std::string _mqttPart; /**< Partial MQTT topic identifying this entity */ std::string _mqttPart; /**< Partial MQTT topic identifying this entity */
......
...@@ -102,7 +102,16 @@ public: ...@@ -102,7 +102,16 @@ public:
///@name Setters ///@name Setters
///@{ ///@{
void setGroupName(const std::string& groupName) { _groupName = groupName; } void setGroupName(const std::string& groupName) { _groupName = groupName; }
void setMqttPart(const std::string& mqttPart) { _mqttPart = mqttPart; } void setMqttPart(const std::string& mqttPart) {
_mqttPart = mqttPart;
//sanitize mqttPart into uniform /xxxx format
if (_mqttPart.front() != '/') {
_mqttPart.insert(0, "/");
}
if (_mqttPart.back() == '/') {
_mqttPart.erase(_mqttPart.size()-1);
}
}
void setSync(bool sync) { _sync = sync; } void setSync(bool sync) { _sync = sync; }
void setMinValues(unsigned minValues) { _minValues = minValues; } void setMinValues(unsigned minValues) { _minValues = minValues; }
void setInterval(unsigned interval) { _interval = interval; } void setInterval(unsigned interval) { _interval = interval; }
...@@ -247,6 +256,7 @@ protected: ...@@ -247,6 +256,7 @@ protected:
} }
///@} ///@}
//TODO unify naming scheme: _groupName --> _name (also refactor getter+setter)
std::string _groupName; ///< String name of this group std::string _groupName; ///< String name of this group
std::string _mqttPart; ///< MQTT part identifying this group std::string _mqttPart; ///< MQTT part identifying this group
bool _sync; ///< Should the timer (i.e. the read cycle of this groups) be synchronized with other groups? bool _sync; ///< Should the timer (i.e. the read cycle of this groups) be synchronized with other groups?
......
...@@ -35,15 +35,15 @@ ...@@ -35,15 +35,15 @@
#include <vector> #include <vector>
#include <memory> #include <memory>
//TODO cross reference partial template specialization in doxygen docs
/** /**
* @brief Interface template for sensor group implementations with entities. * @brief Interface template for sensor group implementations with entities.
* *
* @details There is a partial template specialization for E = nullptr_t, i.e. * @details There is a partial template specialization for E = nullptr_t, i.e.
* for groups without entities. Common code has to be duplicated and * for groups without entities, see SensorGroupTemplate<S, nullptr_t>.
* maintained twice here and in the template specialization. However, * Common code has to be duplicated and maintained twice here and in
* having two templates for cases with and without entities greatly * the SensorGroupTemplate<S, nullptr_t>. However, having two templates
* reduces code duplication in derived plugin sensor groups. * for cases with and without entities greatly reduces code duplication
* in derived plugin sensor groups.
* *
* @ingroup pusherplugins * @ingroup pusherplugins
*/ */
...@@ -121,7 +121,7 @@ public: ...@@ -121,7 +121,7 @@ public:
s->initSensor(_interval); s->initSensor(_interval);
} }
_entity->initEntity(io); _entity->init(io);
this->execOnInit(); this->execOnInit();
} }
...@@ -219,7 +219,7 @@ public: ...@@ -219,7 +219,7 @@ public:
this->printGroupConfig(ll); this->printGroupConfig(ll);
if (_entity) { if (_entity) {
LOG_VAR(ll) << " Entity " << _entity->getEntityName(); LOG_VAR(ll) << " Entity " << _entity->getName();
} else { } else {
LOG_VAR(ll) << " No entity set!"; LOG_VAR(ll) << " No entity set!";
} }
...@@ -258,7 +258,7 @@ protected: ...@@ -258,7 +258,7 @@ protected:
* *
* @details If a derived class (i.e. a plugin group) requires further custom * @details If a derived class (i.e. a plugin group) requires further custom
* actions for initialization, this should be implemented here. * actions for initialization, this should be implemented here.
* %initGroup() is appropriately called by this template during * %execOnInit() is appropriately called by this template during
* init(). * init().
*/ */
virtual void execOnInit() { /* do nothing if not overwritten */ } virtual void execOnInit() { /* do nothing if not overwritten */ }
...@@ -268,7 +268,7 @@ protected: ...@@ -268,7 +268,7 @@ protected:
* *
* @details If a derived class (i.e. a plugin group) requires further custom * @details If a derived class (i.e. a plugin group) requires further custom
* actions to start polling data (e.g. open a file descriptor), * actions to start polling data (e.g. open a file descriptor),
* this should be implemented here. %startGroup() is appropriately * this should be implemented here. %execOnStart() is appropriately
* called by this template during start(). * called by this template during start().
* *
* @return True on success, false otherwise. * @return True on success, false otherwise.
...@@ -280,7 +280,7 @@ protected: ...@@ -280,7 +280,7 @@ protected:
* *
* @details If a derived class (i.e. a plugin group) requires further custom * @details If a derived class (i.e. a plugin group) requires further custom
* actions to stop polling data (e.g. close a file descriptor), * actions to stop polling data (e.g. close a file descriptor),
* this should be implemented here. %stopGroup() is appropriately * this should be implemented here. %execOnStop() is appropriately
* called by this template during stop(). * called by this template during stop().
*/ */
virtual void execOnStop() { /* do nothing if not overwritten */ } virtual void execOnStop() { /* do nothing if not overwritten */ }
...@@ -297,16 +297,15 @@ protected: ...@@ -297,16 +297,15 @@ protected:
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//TODO cross reference general template in doxygen docs
/** /**
* @brief Interface partial template specialization for sensor group * @brief Interface partial template specialization for sensor group
* implementations without entities. * implementations without entities.
* *
* @details There is a general template for groups with entities. Common code * @details There is a general template for groups with entities, see
* has to be duplicated and maintained twice here and in the general * SensorGroupTemplate. Common code has to be duplicated and maintained
* template. However, having two templates for cases with and without * twice here and in SensorGroupTemplate. However, having two templates
* entities greatly reduces code duplication in derived plugin sensor * for cases with and without entities greatly reduces code duplication
* groups. * in derived plugin sensor groups.
* *
* @ingroup pusherplugins * @ingroup pusherplugins
*/ */
......
...@@ -298,7 +298,7 @@ void BACnetClient::rejectHandler(BACNET_ADDRESS * src, uint8_t invokeId, uint8_t ...@@ -298,7 +298,7 @@ void BACnetClient::rejectHandler(BACNET_ADDRESS * src, uint8_t invokeId, uint8_t
throw std::runtime_error(str + errorMsg); throw std::runtime_error(str + errorMsg);
} }
void BACnetClient::printConfig(LOG_LEVEL ll) { void BACnetClient::printEntityConfig(LOG_LEVEL ll) {
LOG_VAR(ll) << eInd << "Timeout: " << _timeout; LOG_VAR(ll) << eInd << "Timeout: " << _timeout;
} }
...@@ -33,17 +33,16 @@ ...@@ -33,17 +33,16 @@
#include "bacnet/bacenum.h" #include "bacnet/bacenum.h"
#include "bacnet/datalink.h" #include "bacnet/datalink.h"
/*
* NOTE
* Had to make some member variables static because of BACnet Stack handler
* function requirements. This should be no problem as we are using only one
* instance of BACnetClient with serialized access (_strand). One should ensure
* to keep the single instance property in the future.
*/
/** /**
* @brief Client to handle BACnet protocol communication. Only one instance * @brief Client to handle BACnet protocol communication. Only one instance
* allowed! * allowed!
* *
* @details Had to make some member variables static because of BACnet Stack
* handler function requirements. This should be no problem as we are
* using only one instance of BACnetClient with serialized access
* (_strand). One should ensure to keep the single instance property in
* the future.
*
* @ingroup bacnet * @ingroup bacnet
*/ */
class BACnetClient : public EntityInterface { class BACnetClient : public EntityInterface {
...@@ -55,12 +54,18 @@ public: ...@@ -55,12 +54,18 @@ public:
virtual ~BACnetClient(); virtual ~BACnetClient();
BACnetClient& operator=(const BACnetClient& other) = delete; BACnetClient& operator=(const BACnetClient& other) = delete;
/**
* Override C++'s name hiding
*/
using EntityInterface::init;
/** /**
* @brief Initialize datalink layer and address cache. * @brief Initialize datalink layer and address cache.
* *
* @details We assume BACnet/IP protocol is used. Also you need to compile * @details We assume BACnet/IP protocol is used. Also you need to compile
* with environment variable BACNET_ADDRESS_CACHE_FILE set to * with environment variable BACNET_ADDRESS_CACHE_FILE set to
* enable initialization of address cache from file "address_cache". * enable initialization of address cache from file "address_cache".
* Overloads EntityInterface::init().
* *
* @param interface Name of network interface to use. * @param interface Name of network interface to use.
* @param address_cache (Path and) filename of the address cache file where * @param address_cache (Path and) filename of the address cache file where
...@@ -105,7 +110,7 @@ public: ...@@ -105,7 +110,7 @@ public:
* *
* @param ll Log severity level to be used from logger. * @param ll Log severity level to be used from logger.
*/ */
void printConfig(LOG_LEVEL ll) override; void printEntityConfig(LOG_LEVEL ll) override;
private: private:
......
...@@ -320,7 +320,7 @@ void IPMIHost::increaseErrorCount() { ...@@ -320,7 +320,7 @@ void IPMIHost::increaseErrorCount() {
} }
} }
void IPMIHost::printConfig(LOG_LEVEL ll) { void IPMIHost::printEntityConfig(LOG_LEVEL ll) {
LOG_VAR(ll) << eInd << "IPMIHost: " << getHostName(); LOG_VAR(ll) << eInd << "IPMIHost: " << getHostName();
LOG_VAR(ll) << eInd << "UserName: " << getUserName(); LOG_VAR(ll) << eInd << "UserName: " << getUserName();
#ifdef DEBUG #ifdef DEBUG
......
...@@ -77,7 +77,7 @@ public: ...@@ -77,7 +77,7 @@ public:
const std::string& getUserName() const { return _userName; } const std::string& getUserName() const { return _userName; }
uint64_t getDelayNextReadUntil() const { return _delayNextReadUntil; } uint64_t getDelayNextReadUntil() const { return _delayNextReadUntil; }
void printConfig(LOG_LEVEL ll) override; void printEntityConfig(LOG_LEVEL ll) final override;
private: private:
/* Open/close connection to BMC (sets/destroys _ipmiCtx) */ /* Open/close connection to BMC (sets/destroys _ipmiCtx) */
......
...@@ -54,7 +54,7 @@ PDUUnit& PDUUnit::operator=(const PDUUnit& other) { ...@@ -54,7 +54,7 @@ PDUUnit& PDUUnit::operator=(const PDUUnit& other) {
return *this; return *this;
} }
void PDUUnit::init() { void PDUUnit::execOnInit() {
SSL_library_init(); SSL_library_init();
SSL_load_error_strings(); SSL_load_error_strings();
ERR_load_BIO_strings(); ERR_load_BIO_strings();
...@@ -123,7 +123,3 @@ bool PDUUnit::sendRequest(const std::string& request, std::string& response) { ...@@ -123,7 +123,3 @@ bool PDUUnit::sendRequest(const std::string& request, std::string& response) {
return true; return true;
} }
void PDUUnit::printConfig(LOG_LEVEL ll) {
LOG_VAR(ll) << eInd << "PDUUnit (Host): " << getHost();
}
...@@ -74,8 +74,7 @@ public: ...@@ -74,8 +74,7 @@ public:
*/ */
bool sendRequest(const std::string& request, std::string& response); bool sendRequest(const std::string& request, std::string& response);
void init() override; void execOnInit() final override;
void printConfig(LOG_LEVEL ll) override;
private: private:
SSL_CTX* _ctx; SSL_CTX* _ctx;
......
...@@ -103,7 +103,7 @@ SNMPConnection& SNMPConnection::operator=(const SNMPConnection& other) { ...@@ -103,7 +103,7 @@ SNMPConnection& SNMPConnection::operator=(const SNMPConnection& other) {
return *this; return *this;
} }
void SNMPConnection::init() { void SNMPConnection::execOnInit() {
if(_isInitialized) { if(_isInitialized) {
return; return;
} }
...@@ -253,7 +253,7 @@ int64_t SNMPConnection::get(const oid* const OID, size_t OIDLen) { ...@@ -253,7 +253,7 @@ int64_t SNMPConnection::get(const oid* const OID, size_t OIDLen) {
return ret; return ret;
} }
void SNMPConnection::printConfig(LOG_LEVEL ll) { void SNMPConnection::printEntityConfig(LOG_LEVEL ll) {
LOG_VAR(ll) << eInd << "Connection (Host): " << getHost(); LOG_VAR(ll) << eInd << "Connection (Host): " << getHost();
LOG_VAR(ll) << eInd << "Port: " << getPort(); LOG_VAR(ll) << eInd << "Port: " << getPort();
LOG_VAR(ll) << eInd << "OIDPrefix: " << getOIDPrefix(); LOG_VAR(ll) << eInd << "OIDPrefix: " << getOIDPrefix();
......
...@@ -154,20 +154,20 @@ public: ...@@ -154,20 +154,20 @@ public:
return std::string("unknown"); return std::string("unknown");
} }
} }
long int getVersion() const { return _version; } long int getVersion() const { return _version; }
void printConfig(LOG_LEVEL ll) override; void printEntityConfig(LOG_LEVEL ll) final override;
/** /**
* Initializes the connection. Must be called once before the connection can be used * Initializes the connection. Must be called once before the connection can be used
*/ */
void init() override; void execOnInit() final override;
/** /**
* Open SNMP Session. Must be called once before issuing a get() call. * Open SNMP Session. Must be called once before issuing a get() call.
*/ */
bool open(); bool open();
/** /**
* Close SNMP Session. * Close SNMP Session.
*/ */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment