In January 2021 we will introduce a 10 GB quota for project repositories. Higher limits for individual projects will be available on request. Please see https://doku.lrz.de/display/PUBLIC/GitLab for more information.

Commit df2120b4 authored by Micha Müller's avatar Micha Müller

Pusher SensorGroupTemplate: Also replace partial template specialization with...

Pusher SensorGroupTemplate: Also replace partial template specialization with derived SensorGroupTemplate for entities
parent 1b2b109a
This diff is collapsed.
//================================================================================
// Name : SensorGroupTemplateEntity.h
// Author : Micha Mueller
// Contact : info@dcdb.it
// Copyright : Leibniz Supercomputing Centre
// Description : Interface template for sensor group functionality with entities.
//================================================================================
//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 2019-2019 Leibniz Supercomputing Centre
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//================================================================================
#ifndef DCDBPUSHER_INCLUDES_SENSORGROUPTEMPLATEENTITY_H_
#define DCDBPUSHER_INCLUDES_SENSORGROUPTEMPLATEENTITY_H_
#include "SensorGroupTemplate.h"
#include "EntityInterface.h"
/**
* @brief Interface template for sensor group implementations with entities.
*
* @details This is a derived template of SensorGroupTemplate.
* Internal usage of _baseSensors is not synchronized via
* acquireSensors()/releaseSensors() as it is only accessed (e.g. in
* (de-)constructor) when no other caller is expected to access
* _baseSensors.
*
* @ingroup pusherplugins
*/
template <class S, class E>
class SensorGroupTemplateEntity : public SensorGroupTemplate<S> {
//the template shall only be instantiated for classes which derive from EntityInterface
static_assert(std::is_base_of<EntityInterface, E>::value, "E must derive from EntityInterface!");
protected:
//mention all required parent attributes and functions here to avoid compiler errors
using SensorGroupInterface::_disabled;
using SensorGroupInterface::_groupName;
using SensorGroupInterface::_interval;
using SensorGroupInterface::_keepRunning;
using SensorGroupInterface::_pendingTasks;
using SensorGroupInterface::_timer;
using SensorGroupInterface::lg;
using SensorGroupInterface::nextReadingTime;
using SensorGroupTemplate<S>::_sensors;
public:
SensorGroupTemplateEntity(const std::string groupName)
: SensorGroupTemplate<S>(groupName),
_entity(nullptr) {}
SensorGroupTemplateEntity(const SensorGroupTemplateEntity &other)
: SensorGroupTemplate<S>(other),
_entity(other._entity) {}
virtual ~SensorGroupTemplateEntity() {}
SensorGroupTemplateEntity &operator=(const SensorGroupTemplateEntity &other) {
SensorGroupTemplate<S>::operator=(other);
_entity = other._entity;
return *this;
}
void setEntity(E *entity) { _entity = entity; }
E *const getEntity() const { return _entity; }
/**
* @brief Initialize the sensor group.
*
* @details This method must not be overwritten. See execOnInit() if custom
* actions are required during initialization. Initializes
* associated sensors and entity.
*
* @param io IO service to initialize the timer with.
*/
virtual void init(boost::asio::io_service &io) final override {
if (!_entity) {
LOG(error) << "No entity set for group " << _groupName << "! Cannot initialize group";
return;
}
SensorGroupInterface::init(io);
for (auto s : _sensors) {
s->initSensor(_interval);
}
_entity->init(io);
this->execOnInit();
}
/**
* @brief Start the sensor group (i.e. start collecting data).
*
* @details This method must not be overwritten. See execOnStart() if custom
* actions are required during startup.
*/
virtual void start() final override {
if (_disabled) {
return;
}
if (_keepRunning) {
//we have been started already
LOG(info) << "Sensorgroup " << _groupName << " already running.";
return;
}
if (!this->execOnStart()) {
LOG(error) << "Sensorgroup " << _groupName << ": Startup failed.";
return;
}
if (_entity) {
if (!_entity->isDisabled()) {
_keepRunning = true;
_pendingTasks++;
_timer->async_wait(_entity->getStrand()->wrap(std::bind(&SensorGroupTemplateEntity::readAsync, this)));
LOG(info) << "Sensorgroup " << _groupName << " started.";
}
} else {
LOG(error) << "No entity set for group " << _groupName << "! Cannot start polling.";
}
}
protected:
/**
* @brief Asynchronous callback if _timer expires.
*
* @details Issues a read() and sets the timer again if _keepRunning is true.
*/
void readAsync() final override {
this->read();
if (_timer && _keepRunning && !_disabled && !_entity->isDisabled()) {
_timer->expires_at(timestamp2ptime(nextReadingTime()));
_pendingTasks++;
_timer->async_wait(_entity->getStrand()->wrap(std::bind(&SensorGroupTemplateEntity::readAsync, this)));
}
_pendingTasks--;
}
E *_entity; ///< Entity this group is associated to
};
#endif /* DCDBPUSHER_INCLUDES_SENSORGROUPTEMPLATEENTITY_H_ */
......@@ -35,7 +35,16 @@ cat << EOF > ${PLUGIN_NAME}SensorGroup.cpp
#include "timestamp.h"
${PLUGIN_NAME}SensorGroup::${PLUGIN_NAME}SensorGroup(const std::string& name) :
SensorGroupTemplate(name) {
EOF
if [ "$enableEntities" = true ]
then
echo " SensorGroupTemplateEntity(name) {" >> ${PLUGIN_NAME}SensorGroup.cpp
else
echo " SensorGroupTemplate(name) {" >> ${PLUGIN_NAME}SensorGroup.cpp
fi
cat << EOF >> ${PLUGIN_NAME}SensorGroup.cpp
/*
* TODO
* Construct attributes
......@@ -43,7 +52,16 @@ ${PLUGIN_NAME}SensorGroup::${PLUGIN_NAME}SensorGroup(const std::string& name) :
}
${PLUGIN_NAME}SensorGroup::${PLUGIN_NAME}SensorGroup(const ${PLUGIN_NAME}SensorGroup& other) :
SensorGroupTemplate(other) {
EOF
if [ "$enableEntities" = true ]
then
echo " SensorGroupTemplateEntity(other) {" >> ${PLUGIN_NAME}SensorGroup.cpp
else
echo " SensorGroupTemplate(other) {" >> ${PLUGIN_NAME}SensorGroup.cpp
fi
cat << EOF >> ${PLUGIN_NAME}SensorGroup.cpp
/*
* TODO
* Copy construct attributes
......
......@@ -33,8 +33,16 @@ cat << EOF > ${PLUGIN_NAME}SensorGroup.h
#ifndef ${PLUGIN_NAME_UPC}_${PLUGIN_NAME_UPC}SENSORGROUP_H_
#define ${PLUGIN_NAME_UPC}_${PLUGIN_NAME_UPC}SENSORGROUP_H_
#include "../../includes/SensorGroupTemplate.h"
EOF
if [ "$enableEntities" = true ]
then
echo "#include \"../../includes/SensorGroupTemplateEntity.h\"" >> ${PLUGIN_NAME}SensorGroup.h
else
echo "#include \"../../includes/SensorGroupTemplate.h\"" >> ${PLUGIN_NAME}SensorGroup.h
fi
cat << EOF >> ${PLUGIN_NAME}SensorGroup.h
#include "${PLUGIN_NAME}SensorBase.h"
/**
......@@ -46,7 +54,7 @@ EOF
if [ "$enableEntities" = true ]
then
echo "class ${PLUGIN_NAME}SensorGroup : public SensorGroupTemplate<${PLUGIN_NAME}SensorBase, ${PLUGIN_NAME}${ENTITY_NAME}> {" >> ${PLUGIN_NAME}SensorGroup.h
echo "class ${PLUGIN_NAME}SensorGroup : public SensorGroupTemplateEntity<${PLUGIN_NAME}SensorBase, ${PLUGIN_NAME}${ENTITY_NAME}> {" >> ${PLUGIN_NAME}SensorGroup.h
else
echo "class ${PLUGIN_NAME}SensorGroup : public SensorGroupTemplate<${PLUGIN_NAME}SensorBase> {" >> ${PLUGIN_NAME}SensorGroup.h
fi
......
......@@ -30,11 +30,11 @@
#include <functional>
BACnetSensorGroup::BACnetSensorGroup(const std::string &name)
: SensorGroupTemplate(name), _deviceInstance(0) {
: SensorGroupTemplateEntity(name), _deviceInstance(0) {
}
BACnetSensorGroup::BACnetSensorGroup(const BACnetSensorGroup &other)
: SensorGroupTemplate(other),
: SensorGroupTemplateEntity(other),
_deviceInstance(other._deviceInstance) {}
BACnetSensorGroup::~BACnetSensorGroup() {}
......
......@@ -28,7 +28,7 @@
#ifndef BACNETSENSORGROUP_H_
#define BACNETSENSORGROUP_H_
#include "../../includes/SensorGroupTemplate.h"
#include "../../includes/SensorGroupTemplateEntity.h"
#include "BACnetSensorBase.h"
/**
......@@ -36,7 +36,7 @@
*
* @ingroup bacnet
*/
class BACnetSensorGroup : public SensorGroupTemplate<BACnetSensorBase, BACnetClient> {
class BACnetSensorGroup : public SensorGroupTemplateEntity<BACnetSensorBase, BACnetClient> {
public:
BACnetSensorGroup(const std::string &name);
......
......@@ -34,11 +34,11 @@
#include <iostream>
IPMISensorGroup::IPMISensorGroup(const std::string &name)
: SensorGroupTemplate(name) {
: SensorGroupTemplateEntity(name) {
}
IPMISensorGroup::IPMISensorGroup(const IPMISensorGroup &other)
: SensorGroupTemplate(other) {
: SensorGroupTemplateEntity(other) {
}
IPMISensorGroup::~IPMISensorGroup() {}
......
......@@ -28,7 +28,7 @@
#ifndef IPMISENSORGROUP_H_
#define IPMISENSORGROUP_H_
#include "../../includes/SensorGroupTemplate.h"
#include "../../includes/SensorGroupTemplateEntity.h"
#include "IPMISensorBase.h"
/**
......@@ -36,7 +36,7 @@
*
* @ingroup ipmi
*/
class IPMISensorGroup : public SensorGroupTemplate<IPMISensorBase, IPMIHost> {
class IPMISensorGroup : public SensorGroupTemplateEntity<IPMISensorBase, IPMIHost> {
public:
IPMISensorGroup(const std::string &name);
......
......@@ -33,11 +33,11 @@
#include <boost/property_tree/xml_parser.hpp>
PDUSensorGroup::PDUSensorGroup(const std::string &name)
: SensorGroupTemplate(name) {
: SensorGroupTemplateEntity(name) {
}
PDUSensorGroup::PDUSensorGroup(const PDUSensorGroup &other)
: SensorGroupTemplate(other),
: SensorGroupTemplateEntity(other),
_request(other._request) {}
PDUSensorGroup::~PDUSensorGroup() {}
......
......@@ -28,7 +28,7 @@
#ifndef SRC_SENSORS_PDU_PDUSENSORGROUP_H_
#define SRC_SENSORS_PDU_PDUSENSORGROUP_H_
#include "../../includes/SensorGroupTemplate.h"
#include "../../includes/SensorGroupTemplateEntity.h"
#include "PDUSensorBase.h"
/**
......@@ -36,7 +36,7 @@
*
* @ingroup pdu
*/
class PDUSensorGroup : public SensorGroupTemplate<PDUSensorBase, PDUUnit> {
class PDUSensorGroup : public SensorGroupTemplateEntity<PDUSensorBase, PDUUnit> {
public:
PDUSensorGroup(const std::string &name);
......
......@@ -28,11 +28,11 @@
#include "SNMPSensorGroup.h"
SNMPSensorGroup::SNMPSensorGroup(const std::string &name)
: SensorGroupTemplate(name) {
: SensorGroupTemplateEntity(name) {
}
SNMPSensorGroup::SNMPSensorGroup(const SNMPSensorGroup &other)
: SensorGroupTemplate(other) {
: SensorGroupTemplateEntity(other) {
}
SNMPSensorGroup::~SNMPSensorGroup() {}
......
......@@ -28,7 +28,7 @@
#ifndef SNMPSENSORGROUP_H_
#define SNMPSENSORGROUP_H_
#include "../../includes/SensorGroupTemplate.h"
#include "../../includes/SensorGroupTemplateEntity.h"
#include "SNMPSensorBase.h"
/**
......@@ -36,7 +36,7 @@
*
* @ingroup snmp
*/
class SNMPSensorGroup : public SensorGroupTemplate<SNMPSensorBase, SNMPConnection> {
class SNMPSensorGroup : public SensorGroupTemplateEntity<SNMPSensorBase, SNMPConnection> {
public:
SNMPSensorGroup(const std::string &name);
......
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