Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
The container registry cleanup task is now completed and the registry can be used normally.
Open sidebar
dcdb
dcdb
Commits
c3da3320
Commit
c3da3320
authored
Jun 18, 2019
by
Micha Müller
Browse files
Improvements and fixes for SensorGroupTemplate
parent
9965c8a0
Changes
1
Hide whitespace changes
Inline
Side-by-side
dcdbpusher/includes/SensorGroupTemplate.h
View file @
c3da3320
...
@@ -35,6 +35,7 @@
...
@@ -35,6 +35,7 @@
#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.
*
*
...
@@ -54,7 +55,6 @@ class SensorGroupTemplate : public SensorGroupInterface {
...
@@ -54,7 +55,6 @@ class SensorGroupTemplate : public SensorGroupInterface {
protected:
protected:
using
S_Ptr
=
std
::
shared_ptr
<
S
>
;
using
S_Ptr
=
std
::
shared_ptr
<
S
>
;
using
E_Ptr
=
std
::
shared_ptr
<
E
>
;
public:
public:
SensorGroupTemplate
(
const
std
::
string
groupName
)
:
SensorGroupTemplate
(
const
std
::
string
groupName
)
:
...
@@ -73,6 +73,10 @@ public:
...
@@ -73,6 +73,10 @@ public:
}
}
virtual
~
SensorGroupTemplate
()
{
virtual
~
SensorGroupTemplate
()
{
if
(
_keepRunning
)
{
stop
();
}
_sensors
.
clear
();
_sensors
.
clear
();
_baseSensors
.
clear
();
_baseSensors
.
clear
();
}
}
...
@@ -93,6 +97,9 @@ public:
...
@@ -93,6 +97,9 @@ public:
return
*
this
;
return
*
this
;
}
}
void
setEntity
(
E
*
entity
)
{
_entity
=
entity
;
}
E
*
const
getEntity
()
const
{
return
_entity
;
}
/**
/**
* @brief Initialize the sensor group.
* @brief Initialize the sensor group.
*
*
...
@@ -132,7 +139,10 @@ public:
...
@@ -132,7 +139,10 @@ public:
return
;
return
;
}
}
this
->
execOnStart
();
if
(
!
this
->
execOnStart
())
{
LOG
(
error
)
<<
"Sensorgroup "
<<
_groupName
<<
": Startup failed."
;
return
;
}
if
(
_entity
)
{
if
(
_entity
)
{
_keepRunning
=
true
;
_keepRunning
=
true
;
...
@@ -151,9 +161,15 @@ public:
...
@@ -151,9 +161,15 @@ public:
* actions are required during shutdown.
* actions are required during shutdown.
*/
*/
virtual
void
stop
()
final
override
{
virtual
void
stop
()
final
override
{
if
(
!
_keepRunning
)
{
LOG
(
info
)
<<
"Sensorgroup "
<<
_groupName
<<
" already stopped."
;
return
;
}
_keepRunning
=
false
;
_keepRunning
=
false
;
//cancel any outstanding readAsync()
//cancel any outstanding readAsync()
_timer
->
cancel
();
_timer
->
cancel
();
wait
();
this
->
execOnStop
();
this
->
execOnStop
();
LOG
(
info
)
<<
"Sensorgroup "
<<
_groupName
<<
" stopped."
;
LOG
(
info
)
<<
"Sensorgroup "
<<
_groupName
<<
" stopped."
;
...
@@ -186,6 +202,7 @@ public:
...
@@ -186,6 +202,7 @@ public:
virtual
std
::
vector
<
SBasePtr
>&
getSensors
()
final
override
{
return
_baseSensors
;
}
virtual
std
::
vector
<
SBasePtr
>&
getSensors
()
final
override
{
return
_baseSensors
;
}
//TODO only call this printMethod!
//TODO only call this printMethod!
//TODO refactor: use printGroupConfig in derived classes
/**
/**
* @brief Print SensorGroup configuration.
* @brief Print SensorGroup configuration.
*
*
...
@@ -203,6 +220,12 @@ public:
...
@@ -203,6 +220,12 @@ public:
//print plugin specific group attributes
//print plugin specific group attributes
this
->
printConfig
(
ll
);
this
->
printConfig
(
ll
);
if
(
_entity
)
{
LOG_VAR
(
ll
)
<<
" Entity "
<<
_entity
->
getEntityName
();
}
else
{
LOG_VAR
(
ll
)
<<
" No entity set!"
;
}
//print associated sensors
//print associated sensors
LOG_VAR
(
ll
)
<<
" Sensors:"
;
LOG_VAR
(
ll
)
<<
" Sensors:"
;
for
(
auto
s
:
_sensors
)
{
for
(
auto
s
:
_sensors
)
{
...
@@ -229,6 +252,7 @@ protected:
...
@@ -229,6 +252,7 @@ protected:
_pendingTasks
--
;
_pendingTasks
--
;
}
}
//TODO move common logic to interface
///@name Can be overwritten
///@name Can be overwritten
///@{
///@{
/**
/**
...
@@ -239,7 +263,7 @@ protected:
...
@@ -239,7 +263,7 @@ protected:
* %initGroup() is appropriately called by this template during
* %initGroup() 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 */
}
/**
/**
* @brief Implement plugin specific actions to start a group here.
* @brief Implement plugin specific actions to start a group here.
...
@@ -248,8 +272,10 @@ protected:
...
@@ -248,8 +272,10 @@ protected:
* 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. %startGroup() is appropriately
* called by this template during start().
* called by this template during start().
*
* @return True on success, false otherwise.
*/
*/
virtual
void
execOnStart
()
{
/* do nothing if not overwritten */
}
;
virtual
bool
execOnStart
()
{
return
true
;
}
/**
/**
* @brief Implement plugin specific actions to stop a group here.
* @brief Implement plugin specific actions to stop a group here.
...
@@ -259,15 +285,15 @@ protected:
...
@@ -259,15 +285,15 @@ protected:
* this should be implemented here. %stopGroup() is appropriately
* this should be implemented here. %stopGroup() 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 */
}
///@}
///@}
std
::
vector
<
S_Ptr
>
_sensors
;
///< Sensors associated with this group
std
::
vector
<
S_Ptr
>
_sensors
;
///< Sensors associated with this group
std
::
vector
<
SBasePtr
>
_baseSensors
;
///< Maintain vector with SensorBase pointers for fast getSensors() implementation
std
::
vector
<
SBasePtr
>
_baseSensors
;
///< Maintain vector with SensorBase pointers for fast getSensors() implementation
E
_Ptr
_entity
;
///< Entity this group is associated to
E
*
_entity
;
///< Entity this group is associated to
};
};
//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.
...
@@ -303,6 +329,10 @@ public:
...
@@ -303,6 +329,10 @@ public:
}
}
virtual
~
SensorGroupTemplate
()
{
virtual
~
SensorGroupTemplate
()
{
if
(
_keepRunning
)
{
stop
();
}
_sensors
.
clear
();
_sensors
.
clear
();
_baseSensors
.
clear
();
_baseSensors
.
clear
();
}
}
...
@@ -353,7 +383,10 @@ public:
...
@@ -353,7 +383,10 @@ public:
return
;
return
;
}
}
this
->
execOnStart
();
if
(
!
this
->
execOnStart
())
{
LOG
(
error
)
<<
"Sensorgroup "
<<
_groupName
<<
": Startup failed."
;
return
;
}
_keepRunning
=
true
;
_keepRunning
=
true
;
_pendingTasks
++
;
_pendingTasks
++
;
...
@@ -368,9 +401,15 @@ public:
...
@@ -368,9 +401,15 @@ public:
* actions are required during shutdown.
* actions are required during shutdown.
*/
*/
virtual
void
stop
()
final
override
{
virtual
void
stop
()
final
override
{
if
(
!
_keepRunning
)
{
LOG
(
info
)
<<
"Sensorgroup "
<<
_groupName
<<
" already stopped."
;
return
;
}
_keepRunning
=
false
;
_keepRunning
=
false
;
//cancel any outstanding readAsync()
//cancel any outstanding readAsync()
_timer
->
cancel
();
_timer
->
cancel
();
wait
();
this
->
execOnStop
();
this
->
execOnStop
();
LOG
(
info
)
<<
"Sensorgroup "
<<
_groupName
<<
" stopped."
;
LOG
(
info
)
<<
"Sensorgroup "
<<
_groupName
<<
" stopped."
;
...
@@ -456,7 +495,7 @@ protected:
...
@@ -456,7 +495,7 @@ protected:
* %initGroup() is appropriately called by this template during
* %initGroup() 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 */
}
/**
/**
* @brief Implement plugin specific actions to start a group here.
* @brief Implement plugin specific actions to start a group here.
...
@@ -465,8 +504,10 @@ protected:
...
@@ -465,8 +504,10 @@ protected:
* 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. %startGroup() is appropriately
* called by this template during start().
* called by this template during start().
*
* @return True on success, false otherwise.
*/
*/
virtual
void
execOnStart
()
{
/* do nothing if not overwritten */
}
;
virtual
bool
execOnStart
()
{
return
true
;
}
/**
/**
* @brief Implement plugin specific actions to stop a group here.
* @brief Implement plugin specific actions to stop a group here.
...
@@ -476,7 +517,7 @@ protected:
...
@@ -476,7 +517,7 @@ protected:
* this should be implemented here. %stopGroup() is appropriately
* this should be implemented here. %stopGroup() 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 */
}
///@}
///@}
std
::
vector
<
S_Ptr
>
_sensors
;
///< Sensors associated with this group
std
::
vector
<
S_Ptr
>
_sensors
;
///< Sensors associated with this group
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment