5 #include <Poco/Mutex.h>
7 #include "core/AbstractSeeker.h"
8 #include "core/DeviceManager.h"
9 #include "model/DeviceID.h"
10 #include "net/MqttClient.h"
11 #include "net/MACAddress.h"
12 #include "util/BlockingAsyncWork.h"
13 #include "vektiva/VektivaSmarwi.h"
31 typedef Poco::SharedPtr<VektivaSeeker> Ptr;
51 void setMqttClient(MqttClient::Ptr mqttClient);
52 void setStatusMqttClient(MqttClient::Ptr mqttClient);
53 void setReceiveTimeout(
const Poco::Timespan &timeout);
59 const Poco::Timespan &)
override;
64 const Poco::Timespan &)
override;
65 void handleAccept(
const DeviceAcceptCommand::Ptr cmd)
override;
126 const std::string &lastSegment,
127 VektivaSmarwi::Ptr device);
152 VektivaSmarwi::Ptr device);
161 VektivaSmarwi::Ptr device,
201 const std::string &topic,
202 const std::string &lastSegment,
203 const std::string &remoteId =
"",
204 const std::string &macAddr =
"");
212 std::pair<std::string, std::string>
225 Poco::FastMutex m_devicesMutex;
231 Poco::FastMutex m_clientMqttMutex;
236 std::map<DeviceID, VektivaSmarwi::Ptr> m_devices;
241 MqttClient::Ptr m_mqttClient;
248 MqttClient::Ptr m_mqttStatusClient;
249 Poco::Timespan m_receiveTimeout;
void updateDeviceInfo(VektivaSmarwi::Ptr device, const VektivaSmarwiStatus &smarwiStatus)
Function to update any relevant info that can be updated (e.g. IP address)
Definition: VektivaDeviceManager.cpp:389
MqttMessage messageReceivedInTime(const std::string &lastSegment, VektivaSmarwi::Ptr device)
Waits for a specified amount of time for a message with the last segment of the topic equal to lastSe...
Definition: VektivaDeviceManager.cpp:326
void statusMessageAction(MqttMessage &mqttMessage)
Groups all actions that are done when "status" message is received.
Definition: VektivaDeviceManager.cpp:289
void seekLoop(StopControl &) override
Definition: VektivaDeviceManager.cpp:102
Provides searching of Vektiva devices on network via MQTT messages in an own thread.
Definition: VektivaDeviceManager.h:29
AsyncWork< double >::Ptr startSetValue(const DeviceID &id, const ModuleID &module, const double value, const Poco::Timespan &) override
Starts set-value operation in a technology specific way. The method is always called inside a critica...
Definition: VektivaDeviceManager.cpp:246
Vektiva device manager provides an easy way to manage devices that are compatible with implemented in...
Definition: VektivaDeviceManager.h:22
void clearMqttMessageBuffer()
Clears all messages buffered in the MQTT client to assure there are no previous messages when attempt...
Definition: VektivaDeviceManager.cpp:374
AsyncWork::Ptr startDiscovery(const Poco::Timespan &timeout) override
Starts device discovery process in a technology-specific way. This method is always called inside a c...
AsyncWork is an interface allowing to wait until an asynchronous operation finishes. It is also possible to force-stop it by calling cancel().
Definition: AsyncWork.h:21
AbstractSeeker represents an asynchronous process that seeks for new devices in a certain network...
Definition: AbstractSeeker.h:25
Definition: MqttMessage.h:7
void modifyValue(const DeviceID &deviceID, const ModuleID &moduleID, const double value)
Finds a device with the corresponding device ID and attempts to change the state of the selected modu...
Definition: VektivaDeviceManager.cpp:264
StopControl implements the stop mechanism generically.
Definition: StopControl.h:12
Definition: ModuleID.h:12
The class represents the status of the Smarwi device. The status information is obtained by MQTT clie...
Definition: VektivaSmarwiStatus.h:11
void onlineMessageAction(MqttMessage &mqttMessage)
Groups all actions that are done when "online" message is received.
Definition: VektivaDeviceManager.cpp:311
Poco::Timespan duration() const
Definition: AbstractSeeker.cpp:17
void escapeRegexString(std::string ®exString)
Escapes inputted string from regex control characters.
Definition: VektivaDeviceManager.cpp:240
void handleAccept(const DeviceAcceptCommand::Ptr cmd) override
Generic handler of the DeviceAcceptCommand. It might be helpful to override this method in case we ne...
Definition: VektivaDeviceManager.cpp:142
Definition: DeviceManager.h:48
void analyzeMessage(MqttMessage &mqttMessage)
Parses the received message and according to its' content, correct actions are performed.
Definition: VektivaDeviceManager.cpp:280
void dispatchNewDevice(VektivaSmarwi::Ptr device)
Dispatches NewDeviceCommand.
Definition: VektivaDeviceManager.cpp:437
AsyncWork< std::set< DeviceID > >::Ptr startUnpair(const DeviceID &id, const Poco::Timespan &) override
Starts device unpair process in a technology-specific way. This method is always called inside a crit...
Definition: VektivaDeviceManager.cpp:160
std::pair< std::string, std::string > retrieveDeviceInfoFromTopic(const std::string &topic)
Exctracts Remote ID and MAC address from MQTT message' topic.
Definition: VektivaDeviceManager.cpp:190
bool updateDevice(VektivaSmarwi::Ptr newDevice)
New device is being processed. If true is returned, NewDeviceCommand can be dispatched.
Definition: VektivaDeviceManager.cpp:110
void shipSmarwiStatus(const DeviceID &deviceId, const VektivaSmarwiStatus &smarwiStatus)
Sends Smarwi status to the exporters.
Definition: VektivaDeviceManager.cpp:415
Definition: DeviceID.h:17
bool isTopicValid(const std::string &topic, const std::string &lastSegment, const std::string &remoteId="", const std::string &macAddr="")
Function to validate topic in received message Last two parameters are optional and can either specif...
Definition: VektivaDeviceManager.cpp:211
bool receiveStatusMessageAndUpdate(VektivaSmarwi::Ptr device)
When status message is updated, info is parsed and device pointer passed in argument is updated with ...
Definition: VektivaDeviceManager.cpp:396