Commit 284bb2b8 authored by Micha Mueller's avatar Micha Mueller
Browse files

BACnet plugin: Change BACnetClient* --> std::shared_ptr<BACnetClient>

parent 8aab4e4e
......@@ -17,11 +17,7 @@ BACnetConfigurator::BACnetConfigurator() {
_baseName = "property";
}
BACnetConfigurator::~BACnetConfigurator() {
if (_bacClient) {
delete _bacClient;
}
}
BACnetConfigurator::~BACnetConfigurator() {}
void BACnetConfigurator::sensorBase(BACnetSensorBase& s, CFG_VAL config) {
ADD {
......@@ -40,10 +36,7 @@ void BACnetConfigurator::sensorGroup(BACnetSensorGroup& s, CFG_VAL config) {
}
void BACnetConfigurator::global(CFG_VAL config) {
if(_bacClient) {
delete _bacClient;
}
_bacClient = new BACnetClient();
_bacClient = std::make_shared<BACnetClient>();
std::string address_cache, interface;
unsigned port = 47808, timeout = 1000, apdu_timeout = 200, apdu_retries = 0;
......@@ -74,7 +67,6 @@ void BACnetConfigurator::global(CFG_VAL config) {
_bacClient->init(interface, address_cache, port, timeout, apdu_timeout, apdu_retries);
} catch (const std::exception& e) {
LOG(error) << "Could not initialize BACnetClient: " << e.what();
delete _bacClient;
_bacClient = nullptr;
return;
}
......
......@@ -27,7 +27,7 @@ protected:
void global(CFG_VAL config) override;
private:
BACnetClient* _bacClient;
BACnetClientPtr _bacClient;
};
extern "C" ConfiguratorInterface* create() {
......
......@@ -11,6 +11,8 @@
#include "BACnetSensorBase.h"
#include "../../includes/SensorGroupTemplate.h"
using BACnetClientPtr = std::shared_ptr<BACnetClient>;
class BACnetSensorGroup: public SensorGroupTemplate<BACnetSensorBase> {
public:
......@@ -21,8 +23,8 @@ public:
void start() override;
void stop() override;
void setBACnetClient(BACnetClient* bacClient) { _bacClient = bacClient; }
BACnetClient* const getBACnetClient() const { return _bacClient; }
void setBACnetClient(BACnetClientPtr bacClient) { _bacClient = bacClient; }
BACnetClientPtr const getBACnetClient() const { return _bacClient; }
void setDeviceInstance(const std::string& deviceInstance) { _deviceInstance = stoul(deviceInstance); }
uint32_t getDeviceInstance() const { return _deviceInstance; }
......@@ -31,7 +33,7 @@ private:
void read() override;
void readAsync() override;
BACnetClient* _bacClient;
BACnetClientPtr _bacClient;
uint32_t _deviceInstance;
};
......
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