Commit 8aab4e4e authored by Micha Mueller's avatar Micha Mueller
Browse files

Various fixes to compile with std::shared_ptr

parent 07149b15
......@@ -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
......
......@@ -207,13 +207,18 @@ 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 = 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() << " had a type mismatch when casting! Omitting";
}
} else {
sensor = std::make_shared<SBase>(val.second.data());
if (readSensorBase(*sensor, val.second)) {
......@@ -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 = 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";
delete group;
}
} else {
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);
}
......
......@@ -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 {
......
......@@ -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
......
Supports Markdown
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