Unify Framework Lib 1.6.0
|
#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_monitor & | get_instance () |
Get the instance object. More... | |
Private Member Functions | |
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 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, node > | nodes |
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_interface * | interface |
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.
|
privatedelete |
|
private |
Private Constructor as it is a singleton.
|
private |
Private Destructor.
|
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.
|
inlinestatic |
Get the instance object.
|
inline |
Get a reference to the nodes object containing all the nodes.
|
private |
Called from node_state_monitor::on_mqtt_cluster_attributes when an attribute is added to the cluster.
unid | UNID of the node. |
endpoint_id | Endpoint ID. |
cluster_name | Cluster ID. |
attribute | Attribute that is added. |
|
private |
Called from node_state_monitor::on_mqtt_cluster_attributes when an attribute is removed from the cluster.
unid | UNID of the node. |
endpoint_id | Endpoint ID. |
cluster_name | Cluster ID. |
attribute | Attribute that is removed. |
|
private |
Called from node_state_monitor::on_mqtt_cluster_supported_generated_commands_message when supported generated commands are added.
unid | UNID of the node. |
endpoint_id | Endpoint ID. |
cluster_name | Cluster ID. |
jsn | JSON object received (payload). |
|
private |
Called from node_state_monitor::on_mqtt_cluster_supported_generated_commands_message when supported generated commands are removed.
unid | UNID of the node. |
endpoint_id | Endpoint ID. |
cluster_name | Cluster ID. |
|
private |
Called from node_state_monitor::on_mqtt_cluster_supported_commands_message when supported commands are added.
unid | UNID of the node. |
endpoint_id | Endpoint ID. |
cluster_name | Cluster ID. |
jsn | JSON object received (payload). |
|
private |
Called from node_state_monitor::on_mqtt_cluster_supported_commands_message when supported commands are removed.
unid | UNID of the node. |
endpoint_id | Endpoint ID. |
cluster_name | Cluster ID. |
|
staticprivate |
Callback function for when cluster attributes message is received from MQTT.
topic | MQTT Topic |
message | MQTT Message |
message_length | MQTT Message Length. |
|
staticprivate |
Callback function for when cluster supported commands message is received from MQTT.
topic | MQTT Topic |
message | MQTT Message |
message_length | MQTT Message Length. |
|
staticprivate |
Callback function for when cluster supported generated commands message is received from MQTT.
topic | MQTT Topic |
message | MQTT Message |
message_length | MQTT Message Length. |
|
staticprivate |
Callback function for when state messages are received from MQTT.
topic | MQTT Topic |
message | MQTT Message |
message_length | MQTT Message Length |
|
private |
Called from node_state_monitor::on_mqtt_node_state_message when a node is removed.
unid | UNID of node removed |
|
private |
Called from node_state_monitor::on_mqtt_node_state_message when a node state changes.
unid | UNID of node. |
jsn | JSON payload from MQTT. |
|
staticprivate |
Called when timeout occurs for node_state_functional_timer.
|
privatedelete |
|
inline |
Set the interface object.
_interface | Interface object to set. |
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.
t | Threshold |
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.
t | Timeout |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |