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
8aab4e4e
Commit
8aab4e4e
authored
Nov 24, 2018
by
Micha Mueller
Browse files
Various fixes to compile with std::shared_ptr
parent
07149b15
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/MQTTPusher.cpp
View file @
8aab4e4e
...
...
@@ -126,7 +126,7 @@ void MQTTPusher::sendReadings(SensorBase& s, reading_t* reads, std::size_t& tota
//totalCount+= count;
totalCount
+=
1
;
#ifdef DEBUG
LOGM
(
debug
)
<<
"Sending "
<<
count
<<
" values from "
<<
s
->
getName
();
LOGM
(
debug
)
<<
"Sending "
<<
count
<<
" values from "
<<
s
.
getName
();
#endif
#if DEBUG
...
...
src/includes/ConfiguratorTemplate.h
View file @
8aab4e4e
...
...
@@ -207,12 +207,17 @@ public:
SB_Ptr
sensor
;
//perhaps one sensor is already present because it was copied from the template group
if
(
group
->
getSensors
().
size
()
!=
0
)
{
sensor
=
static_pointer_cast
<
SB_Ptr
::
element_type
>
(
group
->
getSensors
()[
0
]);
sensor
->
setName
(
val
.
second
.
data
());
if
(
readSensorBase
(
*
sensor
,
val
.
second
))
{
storeSensorGroup
(
group
);
sensor
=
std
::
dynamic_pointer_cast
<
SBase
>
(
group
->
getSensors
()[
0
]);
//check if cast was successful (sensor != nullptr)
if
(
sensor
)
{
sensor
->
setName
(
val
.
second
.
data
());
if
(
readSensorBase
(
*
sensor
,
val
.
second
))
{
storeSensorGroup
(
group
);
}
else
{
LOG
(
warning
)
<<
"Single "
<<
_baseName
<<
" "
<<
val
.
second
.
data
()
<<
" could not be read! Omitting"
;
}
}
else
{
LOG
(
warning
)
<<
"Single "
<<
_baseName
<<
" "
<<
val
.
second
.
data
()
<<
"
could not be read
! Omitting"
;
LOG
(
warning
)
<<
"Single "
<<
_baseName
<<
" "
<<
val
.
second
.
data
()
<<
"
had a type mismatch when casting
! Omitting"
;
}
}
else
{
sensor
=
std
::
make_shared
<
SBase
>
(
val
.
second
.
data
());
...
...
@@ -230,8 +235,8 @@ public:
}
}
//read of config finished. Now we build the mqtt-topic for every sensor
for
(
auto
g
:
_sensorGroups
)
{
for
(
auto
s
:
g
->
getSensors
())
{
for
(
const
auto
&
g
:
_sensorGroups
)
{
for
(
const
auto
&
s
:
g
->
getSensors
())
{
s
->
setMqtt
(
_mqttPrefix
+
g
->
getMqttPart
()
+
s
->
getMqtt
());
LOG
(
debug
)
<<
g
->
getGroupName
()
<<
"::"
<<
s
->
getName
()
<<
" using MQTT-topic
\"
"
<<
s
->
getMqtt
()
<<
"
\"
"
;
}
...
...
@@ -497,13 +502,17 @@ protected:
SB_Ptr
sensor
;
//perhaps one sensor is already present because it was copied from the template group
if
(
group
->
getSensors
().
size
()
!=
0
)
{
sensor
=
static_pointer_cast
<
SBase
>
(
group
->
getSensors
()[
0
]);
sensor
->
setName
(
val
.
second
.
data
());
if
(
readSensorBase
(
*
sensor
,
val
.
second
))
{
storeSensorGroup
(
group
);
sensor
=
std
::
dynamic_pointer_cast
<
SBase
>
(
group
->
getSensors
()[
0
]);
//check if cast was successful (sensor != nullptr)
if
(
sensor
)
{
sensor
->
setName
(
val
.
second
.
data
());
if
(
readSensorBase
(
*
sensor
,
val
.
second
))
{
storeSensorGroup
(
group
);
}
else
{
LOG
(
warning
)
<<
"Single "
<<
_baseName
<<
" "
<<
val
.
second
.
data
()
<<
" could not be read! Omitting"
;
}
}
else
{
LOG
(
warning
)
<<
"Single "
<<
_baseName
<<
" "
<<
val
.
second
.
data
()
<<
" could not be read! Omitting"
;
delete
group
;
LOG
(
warning
)
<<
"Single "
<<
_baseName
<<
" "
<<
val
.
second
.
data
()
<<
" had a type mismatch when casting! Omitting"
;
}
}
else
{
sensor
=
std
::
make_shared
<
SBase
>
(
val
.
second
.
data
());
...
...
@@ -512,12 +521,10 @@ protected:
storeSensorGroup
(
group
);
}
else
{
LOG
(
warning
)
<<
"Single "
<<
_baseName
<<
" "
<<
val
.
second
.
data
()
<<
" could not be read! Omitting"
;
delete
group
;
}
}
}
else
{
LOG
(
warning
)
<<
"Single "
<<
_baseName
<<
"
\"
"
<<
val
.
second
.
data
()
<<
"
\"
has bad values! Ignoring..."
;
delete
group
;
}
}
}
...
...
@@ -525,7 +532,7 @@ protected:
}
if
(
!
isTemplate
)
{
for
(
auto
g
:
_sensorGroups
)
{
for
(
const
auto
&
g
:
_sensorGroups
)
{
if
(
isEntityOfGroup
(
sEntity
,
*
g
))
{
finalizeGroup
(
*
g
);
}
...
...
src/includes/SensorGroupTemplate.h
View file @
8aab4e4e
...
...
@@ -56,9 +56,8 @@ public:
}
virtual
void
pushBackSensor
(
SBasePtr
s
)
override
{
//Undefined behavior will arise if a ptr type != S_Ptr is given to static_pointer_cast
//Use dynamic_pointer_cast instead if this is a problem
if
(
S_Ptr
dSensor
=
static_pointer_cast
<
S_Ptr
::
element_type
>
(
s
))
{
//check if dynamic cast returns nullptr
if
(
S_Ptr
dSensor
=
std
::
dynamic_pointer_cast
<
S
>
(
s
))
{
_sensors
.
push_back
(
dSensor
);
_baseSensors
.
push_back
(
s
);
}
else
{
...
...
src/sensors/procfs/ProcfsConfigurator.cpp
View file @
8aab4e4e
...
...
@@ -164,7 +164,7 @@ void ProcfsConfigurator::sensorGroup(ProcfsSensorGroup& sGroup, CFG_VAL config)
// Adding the sensors corresponding to availableMetrics
for
(
int
i
=
0
;
i
<
numMetrics
;
i
++
)
{
ProcfsSBPtr
sensor
=
static_pointer_cast
<
ProcfsSBPtr
>
(
sGroup
.
getSensors
().
at
(
i
));
ProcfsSBPtr
sensor
=
std
::
static_pointer_cast
<
ProcfsSBPtr
::
element_type
>
(
sGroup
.
getSensors
().
at
(
i
));
if
(
autoMQTT
)
sensor
->
setMqtt
(
increaseMqtt
(
mqttStart
,
metricsCounter
->
at
(
sensor
->
getCPUId
()
+
1
)
++
));
// If the metric does not refer to a specific CPU core, the topic is prefix + default mqttPart + suffix
// The suffix is increased automatically through the metricsCounter vector
...
...
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