27#ifndef UNIFY_NODE_STATE_MONITOR_H
28#define UNIFY_NODE_STATE_MONITOR_H
34#include <unordered_map>
35#include <unordered_set>
36#include <nlohmann/json.hpp>
70 explicit cluster(
const std::string &name) :
91 std::unordered_map<std::string, cluster>
clusters;
141 explicit node(
const std::string &_unid) :
unid(_unid)
241 const std::unordered_map<std::string, node> &
get_nodes()
const
277 interface = _interface;
282 std::unordered_map<std::string, node>
nodes;
305 const size_t message_length);
316 const char *topic,
const char *message,
const size_t message_length);
327 const char *topic,
const char *message,
const size_t message_length);
339 const size_t message_length);
355 const nlohmann::json &jsn);
375 const std::string &cluster_name,
376 const std::string &attribute);
389 const std::string &cluster_name,
390 const std::string &attribute);
404 const std::string &cluster_name,
405 const nlohmann::json &jsn);
418 const std::string &cluster_name);
432 const std::string &cluster_name,
433 const nlohmann::json &jsn);
446 const std::string &cluster_name);
Unify Cluster.
Definition: unify_node_state_monitor.hpp:55
std::unordered_set< std::string > generated_commands
Definition: unify_node_state_monitor.hpp:64
std::unordered_set< std::string > supported_commands
Definition: unify_node_state_monitor.hpp:62
std::string cluster_name
Definition: unify_node_state_monitor.hpp:58
cluster(const std::string &name)
Construct a new cluster object.
Definition: unify_node_state_monitor.hpp:70
std::unordered_set< std::string > attributes
Definition: unify_node_state_monitor.hpp:60
std::string to_string() const
Get a string representation of the cluster.
Unify Endpoint.
Definition: unify_node_state_monitor.hpp:85
std::unordered_map< std::string, cluster > clusters
Definition: unify_node_state_monitor.hpp:91
endpoint_id_t endpoint_id
Definition: unify_node_state_monitor.hpp:88
cluster & emplace_cluster(const std::string &cluster_name)
Create a new cluster in the cluster map and return a reference to it. If the cluster_name already exi...
std::string to_string() const
Get a string representation of the endpoint.
endpoint(endpoint_id_t id)
Construct a new endpoint object.
Definition: unify_node_state_monitor.hpp:97
Interface class for the node_state_monitor.
Definition: unify_node_state_monitor.hpp:171
virtual void on_unify_node_state_changed(const node &node)=0
Unify Node state changed.
virtual void on_unify_node_removed(const std::string &unid)=0
Unify Node is removed.
virtual ~node_state_monitor_interface()=default
virtual void on_unify_node_added(const node &node)=0
Unify Node is added.
Definition: unify_node_state_monitor.hpp:222
void on_cluster_supported_commands_removed(const std::string &unid, endpoint_id_t endpoint_id, const std::string &cluster_name)
Called from node_state_monitor::on_mqtt_cluster_supported_commands_message when supported commands ar...
void on_node_state_changed(const std::string &unid, const nlohmann::json &jsn)
Called from node_state_monitor::on_mqtt_node_state_message when a node state changes.
void set_node_state_functional_threshold(clock_time_t t)
Set the node state functional threshold.
clock_time_t node_state_functional_threshold
Definition: unify_node_state_monitor.hpp:290
node_state_monitor const & operator=(const node_state_monitor &)=delete
node_state_monitor(const node_state_monitor &)=delete
void on_cluster_attribute_removed(const std::string &unid, endpoint_id_t endpoint_id, const std::string &cluster_name, const std::string &attribute)
Called from node_state_monitor::on_mqtt_cluster_attributes when an attribute is removed from the clus...
static node_state_monitor & get_instance()
Get the instance object.
Definition: unify_node_state_monitor.hpp:229
void on_cluster_generated_commands_added(const std::string &unid, endpoint_id_t endpoint_id, const std::string &cluster_name, const nlohmann::json &jsn)
Called from node_state_monitor::on_mqtt_cluster_supported_generated_commands_message when supported g...
void set_node_state_functional_timeout_time(clock_time_t t)
Set the node state functional timeout time.
void on_cluster_attribute_added(const std::string &unid, endpoint_id_t endpoint_id, const std::string &cluster_name, const std::string &attribute)
Called from node_state_monitor::on_mqtt_cluster_attributes when an attribute is added to the cluster.
struct ctimer node_state_functional_timer
Definition: unify_node_state_monitor.hpp:286
const std::unordered_map< std::string, node > & get_nodes() const
Get a reference to the nodes object containing all the nodes.
Definition: unify_node_state_monitor.hpp:241
node_state_monitor_interface * interface
Definition: unify_node_state_monitor.hpp:295
static void on_mqtt_cluster_supported_generated_commands_message(const char *topic, const char *message, const size_t message_length)
Callback function for when cluster supported generated commands message is received from MQTT.
void on_cluster_supported_commands_added(const std::string &unid, endpoint_id_t endpoint_id, const std::string &cluster_name, const nlohmann::json &jsn)
Called from node_state_monitor::on_mqtt_cluster_supported_commands_message when supported commands ar...
std::unordered_map< std::string, node > nodes
Definition: unify_node_state_monitor.hpp:282
static void on_mqtt_cluster_supported_commands_message(const char *topic, const char *message, const size_t message_length)
Callback function for when cluster supported commands message is received from MQTT.
static void on_mqtt_cluster_attributes(const char *topic, const char *message, const size_t message_length)
Callback function for when cluster attributes message is received from MQTT.
static void on_node_state_functional_timeout(void *context)
void on_node_removed(const std::string &unid)
Called from node_state_monitor::on_mqtt_node_state_message when a node is removed.
std::unordered_set< std::string > nodes_pending_node_added
Definition: unify_node_state_monitor.hpp:284
node & emplace_node(const std::string &unid)
Create a new node in the node map and return a reference to it. If the unid alredy exist in the map r...
static void on_mqtt_node_state_message(const char *topic, const char *message, const size_t message_length)
Callback function for when state messages are received from MQTT.
clock_time_t node_state_functional_timeout_time
Definition: unify_node_state_monitor.hpp:293
void set_interface(node_state_monitor_interface *_interface)
Set the interface object.
Definition: unify_node_state_monitor.hpp:275
void on_cluster_generated_commands_removed(const std::string &unid, endpoint_id_t endpoint_id, const std::string &cluster_name)
Called from node_state_monitor::on_mqtt_cluster_supported_generated_commands_message when supported g...
Unify Node.
Definition: unify_node_state_monitor.hpp:120
std::string to_string() const
Get a string representation of the node.
node(const std::string &_unid)
Construct a new node object.
Definition: unify_node_state_monitor.hpp:141
std::unordered_map< endpoint_id_t, endpoint > endpoints
Definition: unify_node_state_monitor.hpp:130
endpoint & emplace_endpoint(endpoint_id_t endpoint_id)
Create a new endpoint in the endpoint map and return a reference to it. If the endpoint_id alredy exi...
uint32_t state
Definition: unify_node_state_monitor.hpp:125
clock_time_t last_update
Definition: unify_node_state_monitor.hpp:132
std::string unid
Definition: unify_node_state_monitor.hpp:123
uint32_t security_info
Definition: unify_node_state_monitor.hpp:127
CCIF clock_time_t clock_time(void)
Definition: clock.c:75
#define CLOCK_SECOND
Definition: clock.h:131
Definition: unify_node_state_monitor.hpp:38
static constexpr clock_time_t DEFAULT_NODE_STATE_FUNCTIONAL_TIMEOUT
Definition: unify_node_state_monitor.hpp:49
uint16_t endpoint_id_t
Definition: unify_node_state_monitor.hpp:40
static constexpr clock_time_t DEFAULT_NODE_STATE_FUNCTIONAL_THRESHOLD
Definition: unify_node_state_monitor.hpp:45