Zigbee Protocol Controller 1.6.0
unify::node_state_monitor::node_state_monitor Class Reference

#include <unify_node_state_monitor.hpp>

Public Member Functions

const std::unordered_map< std::string, node > & get_nodes () const
 Get a reference to the nodes object containing all the nodes. More...
 
void set_node_state_functional_threshold (clock_time_t t)
 Set the node state functional threshold. More...
 
void set_node_state_functional_timeout_time (clock_time_t t)
 Set the node state functional timeout time. More...
 
void set_interface (node_state_monitor_interface *_interface)
 Set the interface object. More...
 

Static Public Member Functions

static node_state_monitorget_instance ()
 Get the instance object. More...
 

Private Member Functions

nodeemplace_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 return a reference to that instead. More...
 
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. More...
 
void on_node_removed (const std::string &unid)
 Called from node_state_monitor::on_mqtt_node_state_message when a node is removed. More...
 
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. More...
 
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 cluster. More...
 
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 are added. More...
 
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 are removed. More...
 
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 generated commands are added. More...
 
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 generated commands are removed. More...
 
 node_state_monitor (const node_state_monitor &)=delete
 
node_state_monitor const & operator= (const node_state_monitor &)=delete
 
 node_state_monitor ()
 
 ~node_state_monitor ()
 

Static Private Member Functions

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. More...
 
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. More...
 
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. More...
 
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. More...
 
static void on_node_state_functional_timeout (void *context)
 

Private Attributes

std::unordered_map< std::string, nodenodes
 
std::unordered_set< std::string > nodes_pending_node_added
 
struct ctimer node_state_functional_timer
 
clock_time_t node_state_functional_threshold = DEFAULT_NODE_STATE_FUNCTIONAL_THRESHOLD
 
clock_time_t node_state_functional_timeout_time = DEFAULT_NODE_STATE_FUNCTIONAL_TIMEOUT
 
node_state_monitor_interfaceinterface
 

Detailed Description

The role of the node state monitor is to subscribe to the ucl/by-unid/<unid>/State topic. It will check when nodes a are changing state, and create node object, populated with endpoint, state and security information. When a new node is found / deleted or updated a callback is fired containing the node object. The node state monitor should only fire a callback once all information has been collected.

Because it is not possible to determine if all MQTT topics for a given node is received, when a NetworkStatus: "Online Functional" is received, the node_state_monitor delays the node_state_monitor_interface::on_unify_node_added callback for node_state_monitor::node_state_functional_threshold time, assuming that all MQTT topics related to the node_state is received within this time. The time for this may be configured using node_state_monitor::set_node_state_functional_threshold.

Constructor & Destructor Documentation

◆ node_state_monitor() [1/2]

unify::node_state_monitor::node_state_monitor::node_state_monitor ( const node_state_monitor )
privatedelete

◆ node_state_monitor() [2/2]

unify::node_state_monitor::node_state_monitor::node_state_monitor ( )
private

Private Constructor as it is a singleton.

◆ ~node_state_monitor()

unify::node_state_monitor::node_state_monitor::~node_state_monitor ( )
private

Private Destructor.

Member Function Documentation

◆ emplace_node()

node & unify::node_state_monitor::node_state_monitor::emplace_node ( const std::string &  unid)
private

Create a new node in the node map and return a reference to it. If the unid alredy exist in the map return a reference to that instead.

◆ get_instance()

static node_state_monitor & unify::node_state_monitor::node_state_monitor::get_instance ( )
inlinestatic

Get the instance object.

Returns
node_state_monitor&.

◆ get_nodes()

const std::unordered_map< std::string, node > & unify::node_state_monitor::node_state_monitor::get_nodes ( ) const
inline

Get a reference to the nodes object containing all the nodes.

Returns
const std::unordered_map<std::string, node>& map of all nodes.

◆ on_cluster_attribute_added()

void unify::node_state_monitor::node_state_monitor::on_cluster_attribute_added ( const std::string &  unid,
endpoint_id_t  endpoint_id,
const std::string &  cluster_name,
const std::string &  attribute 
)
private

Called from node_state_monitor::on_mqtt_cluster_attributes when an attribute is added to the cluster.

Parameters
unidUNID of the node.
endpoint_idEndpoint ID.
cluster_nameCluster ID.
attributeAttribute that is added.

◆ on_cluster_attribute_removed()

void unify::node_state_monitor::node_state_monitor::on_cluster_attribute_removed ( const std::string &  unid,
endpoint_id_t  endpoint_id,
const std::string &  cluster_name,
const std::string &  attribute 
)
private

Called from node_state_monitor::on_mqtt_cluster_attributes when an attribute is removed from the cluster.

Parameters
unidUNID of the node.
endpoint_idEndpoint ID.
cluster_nameCluster ID.
attributeAttribute that is removed.

◆ on_cluster_generated_commands_added()

void unify::node_state_monitor::node_state_monitor::on_cluster_generated_commands_added ( const std::string &  unid,
endpoint_id_t  endpoint_id,
const std::string &  cluster_name,
const nlohmann::json &  jsn 
)
private

Called from node_state_monitor::on_mqtt_cluster_supported_generated_commands_message when supported generated commands are added.

Parameters
unidUNID of the node.
endpoint_idEndpoint ID.
cluster_nameCluster ID.
jsnJSON object received (payload).

◆ on_cluster_generated_commands_removed()

void unify::node_state_monitor::node_state_monitor::on_cluster_generated_commands_removed ( const std::string &  unid,
endpoint_id_t  endpoint_id,
const std::string &  cluster_name 
)
private

Called from node_state_monitor::on_mqtt_cluster_supported_generated_commands_message when supported generated commands are removed.

Parameters
unidUNID of the node.
endpoint_idEndpoint ID.
cluster_nameCluster ID.

◆ on_cluster_supported_commands_added()

void unify::node_state_monitor::node_state_monitor::on_cluster_supported_commands_added ( const std::string &  unid,
endpoint_id_t  endpoint_id,
const std::string &  cluster_name,
const nlohmann::json &  jsn 
)
private

Called from node_state_monitor::on_mqtt_cluster_supported_commands_message when supported commands are added.

Parameters
unidUNID of the node.
endpoint_idEndpoint ID.
cluster_nameCluster ID.
jsnJSON object received (payload).

◆ on_cluster_supported_commands_removed()

void unify::node_state_monitor::node_state_monitor::on_cluster_supported_commands_removed ( const std::string &  unid,
endpoint_id_t  endpoint_id,
const std::string &  cluster_name 
)
private

Called from node_state_monitor::on_mqtt_cluster_supported_commands_message when supported commands are removed.

Parameters
unidUNID of the node.
endpoint_idEndpoint ID.
cluster_nameCluster ID.

◆ on_mqtt_cluster_attributes()

static void unify::node_state_monitor::node_state_monitor::on_mqtt_cluster_attributes ( const char *  topic,
const char *  message,
const size_t  message_length 
)
staticprivate

Callback function for when cluster attributes message is received from MQTT.

Parameters
topicMQTT Topic
messageMQTT Message
message_lengthMQTT Message Length.

◆ on_mqtt_cluster_supported_commands_message()

static void unify::node_state_monitor::node_state_monitor::on_mqtt_cluster_supported_commands_message ( const char *  topic,
const char *  message,
const size_t  message_length 
)
staticprivate

Callback function for when cluster supported commands message is received from MQTT.

Parameters
topicMQTT Topic
messageMQTT Message
message_lengthMQTT Message Length.

◆ on_mqtt_cluster_supported_generated_commands_message()

static void unify::node_state_monitor::node_state_monitor::on_mqtt_cluster_supported_generated_commands_message ( const char *  topic,
const char *  message,
const size_t  message_length 
)
staticprivate

Callback function for when cluster supported generated commands message is received from MQTT.

Parameters
topicMQTT Topic
messageMQTT Message
message_lengthMQTT Message Length.

◆ on_mqtt_node_state_message()

static void unify::node_state_monitor::node_state_monitor::on_mqtt_node_state_message ( const char *  topic,
const char *  message,
const size_t  message_length 
)
staticprivate

Callback function for when state messages are received from MQTT.

Parameters
topicMQTT Topic
messageMQTT Message
message_lengthMQTT Message Length

◆ on_node_removed()

void unify::node_state_monitor::node_state_monitor::on_node_removed ( const std::string &  unid)
private

Called from node_state_monitor::on_mqtt_node_state_message when a node is removed.

Parameters
unidUNID of node removed

◆ on_node_state_changed()

void unify::node_state_monitor::node_state_monitor::on_node_state_changed ( const std::string &  unid,
const nlohmann::json &  jsn 
)
private

Called from node_state_monitor::on_mqtt_node_state_message when a node state changes.

Parameters
unidUNID of node.
jsnJSON payload from MQTT.

◆ on_node_state_functional_timeout()

static void unify::node_state_monitor::node_state_monitor::on_node_state_functional_timeout ( void *  context)
staticprivate

Called when timeout occurs for node_state_functional_timer.

◆ operator=()

node_state_monitor const & unify::node_state_monitor::node_state_monitor::operator= ( const node_state_monitor )
privatedelete

◆ set_interface()

void unify::node_state_monitor::node_state_monitor::set_interface ( node_state_monitor_interface _interface)
inline

Set the interface object.

Parameters
_interfaceInterface object to set.

◆ set_node_state_functional_threshold()

void unify::node_state_monitor::node_state_monitor::set_node_state_functional_threshold ( clock_time_t  t)

Set the node state functional threshold.

The threshold is the time a node shall have been without change after NetworkStatus "Online Functional" is received, before the on_unify_node_added is called.

Default value is DEFAULT_NODE_STATE_FUNCTIONAL_THRESHOLD.

Parameters
tThreshold

◆ set_node_state_functional_timeout_time()

void unify::node_state_monitor::node_state_monitor::set_node_state_functional_timeout_time ( clock_time_t  t)

Set the node state functional timeout time.

This is the timeout for monitoring the threshold set_node_state_functional_threshold.

Default value is DEFAULT_NODE_STATE_FUNCTIONAL_TIMEOUT.

Parameters
tTimeout

Member Data Documentation

◆ interface

node_state_monitor_interface* unify::node_state_monitor::node_state_monitor::interface
private

◆ node_state_functional_threshold

clock_time_t unify::node_state_monitor::node_state_monitor::node_state_functional_threshold = DEFAULT_NODE_STATE_FUNCTIONAL_THRESHOLD
private

◆ node_state_functional_timeout_time

clock_time_t unify::node_state_monitor::node_state_monitor::node_state_functional_timeout_time = DEFAULT_NODE_STATE_FUNCTIONAL_TIMEOUT
private

◆ node_state_functional_timer

struct ctimer unify::node_state_monitor::node_state_monitor::node_state_functional_timer
private

◆ nodes

std::unordered_map<std::string, node> unify::node_state_monitor::node_state_monitor::nodes
private

◆ nodes_pending_node_added

std::unordered_set<std::string> unify::node_state_monitor::node_state_monitor::nodes_pending_node_added
private

The documentation for this class was generated from the following file: