Commit 0a64654a authored by Micha Müller's avatar Micha Müller
Browse files

Minor improvement to SensorGroup: move common logic to SensorGroupInterface

parent 983fedbb
......@@ -117,7 +117,7 @@ public:
void setInterval(unsigned interval) { _interval = interval; }
///@}
///@name Interface methods
///@name Publicly accessible interface methods (implemented in SensorGroupTemplate)
///@{
/**
* @brief Initialize the sensor group.
......@@ -178,20 +178,47 @@ public:
LOG_VAR(ll) << " minValues: " << _minValues;
LOG_VAR(ll) << " interval: " << _interval;
}
///@}
protected:
///@name Internal methods (implemented in a plugin's SensorGroup)
///@{
/**
* @brief Read data for all sensors once.
*/
virtual void read() = 0;
/**
* @brief Asynchronous callback if _timer expires.
* @brief Implement plugin specific actions to initialize a group here.
*
* @details If a derived class (i.e. a plugin group) requires further custom
* actions for initialization, this should be implemented here.
* %initGroup() is appropriately called during init().
*/
virtual void execOnInit() { /* do nothing if not overwritten */ }
/**
* @brief Implement plugin specific actions to start a group here.
*
* @details If a derived class (i.e. a plugin group) requires further custom
* actions to start polling data (e.g. open a file descriptor),
* this should be implemented here. %startGroup() is appropriately
* called during start().
*
* @details Issues a read() and sets the timer again if _keepRunning is true.
* @return True on success, false otherwise.
*/
virtual void readAsync() = 0;
virtual bool execOnStart() { return true; }
/**
* @brief Implement plugin specific actions to stop a group here.
*
* @details If a derived class (i.e. a plugin group) requires further custom
* actions to stop polling data (e.g. close a file descriptor),
* this should be implemented here. %stopGroup() is appropriately
* called during stop().
*/
virtual void execOnStop() { /* do nothing if not overwritten */ }
/**
* @brief Print information about plugin specific group attributes (or
......@@ -208,7 +235,6 @@ protected:
///@name Utility methods
///@{
public:
/**
* @brief Does a busy wait until all dispatched handlers are finished
* (_pendingTasks == 0).
......@@ -231,7 +257,6 @@ public:
LOG(warning) << "Group " << _groupName << " will not finish! Skipping it";
}
protected:
/**
* @brief Calculate timestamp for the next reading.
*
......
......@@ -238,9 +238,8 @@ protected:
* @brief Asynchronous callback if _timer expires.
*
* @details Issues a read() and sets the timer again if _keepRunning is true.
* Not intended to be overwritten.
*/
void readAsync() final override {
void readAsync() {
this->read();
if (_timer && _keepRunning) {
_timer->expires_at(timestamp2ptime(nextReadingTime()));
......@@ -250,42 +249,6 @@ protected:
_pendingTasks--;
}
//TODO move common logic to interface
///@name Can be overwritten
///@{
/**
* @brief Implement plugin specific actions to initialize a group here.
*
* @details If a derived class (i.e. a plugin group) requires further custom
* actions for initialization, this should be implemented here.
* %execOnInit() is appropriately called by this template during
* init().
*/
virtual void execOnInit() { /* do nothing if not overwritten */ }
/**
* @brief Implement plugin specific actions to start a group here.
*
* @details If a derived class (i.e. a plugin group) requires further custom
* actions to start polling data (e.g. open a file descriptor),
* this should be implemented here. %execOnStart() is appropriately
* called by this template during start().
*
* @return True on success, false otherwise.
*/
virtual bool execOnStart() { return true; }
/**
* @brief Implement plugin specific actions to stop a group here.
*
* @details If a derived class (i.e. a plugin group) requires further custom
* actions to stop polling data (e.g. close a file descriptor),
* this should be implemented here. %execOnStop() is appropriately
* called by this template during stop().
*/
virtual void execOnStop() { /* do nothing if not overwritten */ }
///@}
std::vector<S_Ptr> _sensors; ///< Sensors associated with this group
std::vector<SBasePtr> _baseSensors; ///< Maintain vector with SensorBase pointers for fast getSensors() implementation
E* _entity; ///< Entity this group is associated to
......@@ -475,9 +438,8 @@ protected:
* @brief Asynchronous callback if _timer expires.
*
* @details Issues a read() and sets the timer again if _keepRunning is true.
* Not intended to be overwritten.
*/
void readAsync() final override {
void readAsync() {
this->read();
if (_timer && _keepRunning) {
_timer->expires_at(timestamp2ptime(nextReadingTime()));
......@@ -487,41 +449,6 @@ protected:
_pendingTasks--;
}
///@name Can be overwritten
///@{
/**
* @brief Implement plugin specific actions to initialize a group here.
*
* @details If a derived class (i.e. a plugin group) requires further custom
* actions for initialization, this should be implemented here.
* %initGroup() is appropriately called by this template during
* init().
*/
virtual void execOnInit() { /* do nothing if not overwritten */ }
/**
* @brief Implement plugin specific actions to start a group here.
*
* @details If a derived class (i.e. a plugin group) requires further custom
* actions to start polling data (e.g. open a file descriptor),
* this should be implemented here. %startGroup() is appropriately
* called by this template during start().
*
* @return True on success, false otherwise.
*/
virtual bool execOnStart() { return true; }
/**
* @brief Implement plugin specific actions to stop a group here.
*
* @details If a derived class (i.e. a plugin group) requires further custom
* actions to stop polling data (e.g. close a file descriptor),
* this should be implemented here. %stopGroup() is appropriately
* called by this template during stop().
*/
virtual void execOnStop() { /* do nothing if not overwritten */ }
///@}
std::vector<S_Ptr> _sensors; ///< Sensors associated with this group
std::vector<SBasePtr> _baseSensors; ///< Maintain vector with SensorBase pointers for fast getSensors() implementation
};
......
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