Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
dcdb
dcdb
Commits
038f1ab7
Commit
038f1ab7
authored
Sep 28, 2018
by
Micha Mueller
Browse files
Make template maps store only pointers for clear memory management
parent
d7e398c1
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/headers/ConfiguratorTemplate.h
View file @
038f1ab7
...
...
@@ -55,26 +55,36 @@ class ConfiguratorTemplate : public ConfiguratorInterface {
static_assert
(
std
::
is_base_of
<
SensorGroupTemplate
,
SGroup
>::
value
,
"SGroup must derive from SensorGroupTemplate!"
);
protected:
typedef
std
::
map
<
std
::
string
,
SGroup
>
sGroupMap_t
;
typedef
std
::
map
<
std
::
string
,
SEntity
>
sEntityMap_t
;
typedef
std
::
map
<
std
::
string
,
SGroup
*
>
sGroupMap_t
;
typedef
std
::
map
<
std
::
string
,
SEntity
*
>
sEntityMap_t
;
public:
ConfiguratorTemplate
()
:
_entityName
(
"entity"
),
_groupName
(
"group"
),
_se
nsor
Name
(
"sensor"
),
_
ba
seName
(
"sensor"
),
_cfgPath
(
""
),
_mqttPrefix
(
""
),
_cacheInterval
(
900000
)
{}
ConfiguratorTemplate
(
const
ConfiguratorTemplate
&
)
=
delete
;
virtual
~
ConfiguratorTemplate
()
{
for
(
auto
g
:
_sensorGroups
)
{
delete
g
;
}
for
(
auto
tg
:
_templateSensorGroups
)
{
delete
tg
;
}
for
(
auto
te
:
_templateSensorEntitys
)
{
delete
te
;
}
_templateSensorGroups
.
clear
();
_templateSensorEntitys
.
clear
();
}
ConfiguratorTemplate
&
operator
=
(
const
ConfiguratorTemplate
&
)
=
delete
;
/**
* Read in the given configuration
*
...
...
@@ -98,23 +108,16 @@ public:
if
(
boost
::
iequals
(
tempVal
.
first
,
_entityName
))
{
//TODO
}
else
if
(
boost
::
iequals
(
tempVal
.
first
,
_groupName
))
{
LOG
(
debug
)
<<
"Template
Group
\"
"
<<
tempVal
.
second
.
data
()
<<
"
\"
"
;
LOG
(
debug
)
<<
"Template
"
<<
_groupName
<<
"
\"
"
<<
tempVal
.
second
.
data
()
<<
"
\"
"
;
if
(
!
tempVal
.
second
.
empty
())
{
SGroup
group
(
tempVal
.
second
.
data
());
if
(
readSensorGroup
(
group
,
tempVal
.
second
))
{
BOOST_FOREACH
(
boost
::
property_tree
::
iptree
::
value_type
&
sBaseVal
,
tempVal
.
second
)
{
if
(
boost
::
iequals
(
sBaseVal
.
first
,
_baseName
))
{
SBase
*
sensor
=
new
SBase
(
sBaseVal
.
second
.
data
());
if
(
readSensorBase
(
*
sensor
,
sBaseVal
.
second
))
{
group
.
pushBackSensor
(
sensor
);
}
else
{
LOG
(
warning
)
<<
"Template sensor
\"
"
<<
group
.
getName
()
<<
"::"
<<
sBaseVal
.
second
.
data
()
<<
"
\"
has bad values! Ignoring..."
;
}
}
SGroup
*
group
=
new
SGroup
(
tempVal
.
second
.
data
());
if
(
readSensorGroup
(
*
group
,
tempVal
.
second
))
{
auto
ret
=
_templateSensorGroups
.
insert
(
std
::
pair
<
std
::
string
,
SGroup
*>
(
group
->
getName
(),
group
));
if
(
!
ret
.
second
)
{
LOG
(
warning
)
<<
"Template "
<<
_groupName
<<
" "
<<
group
->
getName
()
<<
" already exists! Omitting..."
;
}
_templateSensorGroups
.
insert
(
std
::
pair
<
std
::
string
,
SGroup
>
(
group
.
getName
(),
group
));
}
else
{
LOG
(
warning
)
<<
"Template
group
\"
"
<<
tempVal
.
second
.
data
()
<<
"
\"
has bad values! Ignoring..."
;
LOG
(
warning
)
<<
"Template
"
<<
_groupName
<<
"
\"
"
<<
tempVal
.
second
.
data
()
<<
"
\"
has bad values! Ignoring..."
;
}
}
}
//else if (boost::iequals(tempVal.first, _baseName)) {//TODO allow for template sensors? even useful?}
...
...
@@ -123,24 +126,24 @@ public:
//TODO read actual entitys/groups/bases. How to handle defaults?
//read template groups
boost
::
optional
<
boost
::
property_tree
::
iptree
&>
tempSens
=
cfg
.
get_child_optional
(
"groupTemplates"
);
if
(
tempSens
)
{
BOOST_FOREACH
(
boost
::
property_tree
::
iptree
::
value_type
&
groupVal
,
cfg
.
get_child
(
"groupTemplates"
))
{
if
(
STRCMP
(
groupVal
,
"group"
))
{
LOG
(
debug
)
<<
"Template
Group
\"
"
<<
groupVal
.
second
.
data
()
<<
"
\"
"
;
if
(
!
groupVal
.
second
.
empty
())
{
//TODO
SGroup
group
(
groupVal
.
second
.
data
());
if
(
readSensorGroup
(
group
,
groupVal
.
second
))
{
_templateSensorGroups
.
insert
(
std
::
pair
<
std
::
string
,
SGroup
>
(
group
.
getName
(),
group
));
}
else
{
LOG
(
warning
)
<<
"Template
group
\"
"
<<
groupVal
.
second
.
data
()
<<
"
\"
has bad values! Ignoring..."
;
}
}
}
}
}
//
//read template groups
//
boost::optional<boost::property_tree::iptree&> tempSens = cfg.get_child_optional("groupTemplates");
//
if (tempSens) {
//
BOOST_FOREACH(boost::property_tree::iptree::value_type &groupVal, cfg.get_child("groupTemplates")) {
//
if (STRCMP(groupVal, "group")) {
//
LOG(debug) << "Template
" << _groupName << "
\"" << groupVal.second.data() << "\"";
//
if (!groupVal.second.empty()) {
//
//TODO
//
SGroup group(groupVal.second.data());
//
if(readSensorGroup(group, groupVal.second)) {
//
_templateSensorGroups.insert(std::pair<std::string, SGroup>(group.getName(), group));
//
} else {
//
LOG(warning) << "Template
" << _groupName << "
\"" << groupVal.second.data() << "\" has bad values! Ignoring...";
//
}
//
}
//
}
//
}
//
}
//read in plugin specific stuff (including actual sensors)
return
derivedReadConfig
(
cfg
);
...
...
@@ -165,13 +168,19 @@ public:
//clean up plugin specific stuff
derivedReReadConfig
();
//clean up sensors
and group
s
//clean up sensors
/groups and template
s
for
(
auto
g
:
_sensorGroups
)
{
delete
g
;
}
for
(
auto
tg
:
_templateSensorGroups
)
{
delete
tg
;
}
for
(
auto
te
:
_templateSensorEntitys
)
{
delete
te
;
}
_sensorGroups
.
clear
();
_templateSensorGroups
.
clear
();
_templateSensorEntitys
.
clear
();
//back to the very beginning
return
readConfig
(
_cfgPath
);
...
...
@@ -239,9 +248,12 @@ protected:
}
else
if
(
STRCMP
(
val
,
"sensor"
))
{
SBase
*
sensor
=
new
SBase
(
val
.
second
.
data
());
if
(
readSensorBase
(
*
sensor
,
val
.
second
))
{
sGroup
.
pushBackSensor
(
sensor
);
auto
ret
=
sGroup
.
pushBackSensor
(
sensor
);
if
(
!
ret
.
second
)
{
LOG
(
warning
)
<<
_baseName
<<
" "
<<
sensor
->
getName
()
<<
" already exists! Omitting..."
;
}
}
else
{
LOG
(
warning
)
<<
"Sensor
"
<<
sGroup
.
getGroupName
()
<<
"::"
<<
sensor
->
getName
()
<<
" could not be read! Omitting"
;
LOG
(
warning
)
<<
_baseName
<<
"
"
<<
sGroup
.
getGroupName
()
<<
"::"
<<
sensor
->
getName
()
<<
" could not be read! Omitting"
;
}
}
}
...
...
src/headers/SensorGroupTemplate.h
View file @
038f1ab7
...
...
@@ -21,18 +21,44 @@ public:
SensorGroupTemplate
(
const
std
::
string
groupName
)
:
SensorGroupInterface
(
groupName
)
{}
SensorGroupTemplate
(
const
SensorGroupTemplate
&
other
)
:
SensorGroupInterface
(
other
)
{
for
(
auto
s
:
other
.
_sensors
)
{
S
*
sensor
=
new
S
(
s
);
_sensors
.
push_back
(
sensor
);
_baseSensors
.
push_back
(
sensor
);
}
}
virtual
~
SensorGroupTemplate
()
{
for
(
auto
s
:
_sensors
)
{
delete
s
;
}
}
SensorGroupTemplate
&
operator
=
(
const
SensorGroupTemplate
&
other
)
{
SensorGroupInterface
::
operator
=
(
other
);
for
(
auto
s
:
_sensors
)
{
delete
s
;
}
_sensors
.
clear
();
_baseSensors
.
clear
();
for
(
auto
s
:
other
.
_sensors
)
{
S
*
sensor
=
new
S
(
s
);
_sensors
.
push_back
(
sensor
);
_baseSensors
.
push_back
(
sensor
);
}
return
*
this
;
}
virtual
void
pushBackSensor
(
SensorBase
*
s
)
override
{
if
(
S
*
dSensor
=
dynamic_cast
<
S
*>
(
s
))
{
_sensors
.
push_back
(
dSensor
);
_baseSensors
.
push_back
(
s
);
}
else
{
LOG
(
warning
)
<<
"
Sensorg
roup "
<<
_groupName
<<
": Type mismatch when storing sensor! Sensor omitted"
;
LOG
(
warning
)
<<
"
G
roup "
<<
_groupName
<<
": Type mismatch when storing sensor! Sensor omitted"
;
}
}
...
...
src/sensors/sysfs/SysfsConfigurator.h
View file @
038f1ab7
...
...
@@ -22,7 +22,7 @@ public:
SysfsConfigurator
()
{
_entityName
=
"host"
;
_groupName
=
"group"
;
_se
nsor
Name
=
"sensor"
;
_
ba
seName
=
"sensor"
;
}
virtual
~
SysfsConfigurator
()
{}
...
...
Write
Preview
Markdown
is supported
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