NVIDIA DeepStream SDK API Reference

8.0 Release
includes/nvds_mqtt_proto.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: LicenseRef-NvidiaProprietary
4  *
5  * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
6  * property and proprietary rights in and to this material, related
7  * documentation and any modifications thereto. Any use, reproduction,
8  * disclosure or distribution of this material and related documentation
9  * without an express license agreement from NVIDIA CORPORATION or
10  * its affiliates is strictly prohibited.
11  */
12 
13 #include "mqtt_protocol.h"
14 #include "mosquitto.h"
15 
16 #include <mutex>
17 #include <unordered_map>
18 #include <errno.h>
19 #include "glib.h"
20 #include <string.h>
21 #include <string>
22 #include "nvds_msgapi.h"
23 #include "nvds_utils.h"
24 
25 using namespace std;
26 
27 #define MAX_FIELD_LEN 1024
28 #define DEFAULT_LOOP_TIMEOUT 2000
29 #define DEFAULT_KEEP_ALIVE 60
30 /* Message details:
31  * send_callback = user callback func
32  * user_ptr = user pointer passed by async send
33  */
36  void *user_ptr;
37 };
38 
39 /* Details of mqtt connection handle:
40  * mosq : mosquitto client object
41  * sub_callback : user subscription callback func
42  * connect_cb : user connection callback func
43  * user_ctx : user pointer passed by sub
44  * username: username for login to server
45  * password: password for login to server
46  * client_id: name of MQTT client
47  * loop_timeout : time in ms for the call to loop to wait for network activity
48  * keep_alive : number of seconds after which broker should send PING if no messages have been exchanged
49  * subscription_on : Flag to check if subscription is ON
50  * send_msg_info_map : map message info to id assigned by mosquitto broker
51  * map_lock : mutex lock for accessing above map
52  * enable_tls : flag to check if TLS encryption is enabled by the broker
53  * cafile : path to a TLS certificate authority file
54  * capath : path to a directory containing TLS CA files
55  * certfile : path to the client TLS certificate file
56  * keyfile : path to the client TLS key file
57  * disconnect : bool for checking if disconnect has been called
58  * set_threaded : bool for setting mosquitto_threaded_set in proto adaptor
59  */
60 typedef struct {
61  struct mosquitto *mosq = NULL;
64  void* user_ctx;
65  char connection_str[MAX_FIELD_LEN] = {0};
66  char username[MAX_FIELD_LEN] = {0};
67  char password[MAX_FIELD_LEN] = {0};
68  char client_id[MAX_FIELD_LEN] = {0};
69  int loop_timeout = DEFAULT_LOOP_TIMEOUT;
70  int keep_alive = DEFAULT_KEEP_ALIVE;
71  bool subscription_on = false;
72  std::unordered_map<int , send_msg_info_t> send_msg_info_map;
73  std::mutex map_lock;
74  bool enable_tls = false;
75  char cafile[MAX_FIELD_LEN] = {0};
76  char capath[MAX_FIELD_LEN] = {0};
77  char certfile[MAX_FIELD_LEN] = {0};
78  char keyfile[MAX_FIELD_LEN] = {0};
79  bool disconnect = false;
80  bool set_threaded = true;
82 
84 void mosq_mqtt_log_callback(struct mosquitto *mosq, void *obj, int level, const char *str);
85 void my_disconnect_callback(struct mosquitto *mosq, void *obj, int rc, const mosquitto_property *properties);
86 void my_connect_callback(struct mosquitto *mosq, void *obj, int result, int flags, const mosquitto_property *properties);
87 void my_publish_callback(struct mosquitto *mosq, void *obj, int mid, int reason_code, const mosquitto_property *properties);
88 bool is_valid_mqtt_connection_str(char *connection_str, string &burl, string &bport);
send_msg_info_t
Definition: includes/nvds_mqtt_proto.h:34
nvds_msgapi.h
DEFAULT_LOOP_TIMEOUT
#define DEFAULT_LOOP_TIMEOUT
Definition: includes/nvds_mqtt_proto.h:28
nvds_msgapi_connect_cb_t
void(* nvds_msgapi_connect_cb_t)(NvDsMsgApiHandle h_ptr, NvDsMsgApiEventType ds_evt)
Type definition for a "handle" callback.
Definition: nvds_msgapi.h:98
NvDsMqttClientHandle::user_ctx
void * user_ctx
Definition: includes/nvds_mqtt_proto.h:64
my_disconnect_callback
void my_disconnect_callback(struct mosquitto *mosq, void *obj, int rc, const mosquitto_property *properties)
NvDsMsgApiErrorType
NvDsMsgApiErrorType
Defines completion codes for operations in the messaging API.
Definition: nvds_msgapi.h:57
mosq_mqtt_log_callback
void mosq_mqtt_log_callback(struct mosquitto *mosq, void *obj, int level, const char *str)
nvds_mqtt_read_config
NvDsMsgApiErrorType nvds_mqtt_read_config(NvDsMqttClientHandle *mh, char *config_path)
is_valid_mqtt_connection_str
bool is_valid_mqtt_connection_str(char *connection_str, string &burl, string &bport)
nvds_utils.h
MAX_FIELD_LEN
#define MAX_FIELD_LEN
Definition: includes/nvds_mqtt_proto.h:27
NvDsMqttClientHandle::send_msg_info_map
std::unordered_map< int, send_msg_info_t > send_msg_info_map
Definition: includes/nvds_mqtt_proto.h:72
send_msg_info_t::user_ptr
void * user_ptr
Definition: includes/nvds_mqtt_proto.h:36
NvDsMqttClientHandle
Definition: includes/nvds_mqtt_proto.h:60
my_publish_callback
void my_publish_callback(struct mosquitto *mosq, void *obj, int mid, int reason_code, const mosquitto_property *properties)
DEFAULT_KEEP_ALIVE
#define DEFAULT_KEEP_ALIVE
Definition: includes/nvds_mqtt_proto.h:29
NvDsMqttClientHandle::map_lock
std::mutex map_lock
Definition: includes/nvds_mqtt_proto.h:73
my_connect_callback
void my_connect_callback(struct mosquitto *mosq, void *obj, int result, int flags, const mosquitto_property *properties)
NvDsMqttClientHandle::sub_callback
nvds_msgapi_subscribe_request_cb_t sub_callback
Definition: includes/nvds_mqtt_proto.h:62
nvds_msgapi_send_cb_t
void(* nvds_msgapi_send_cb_t)(void *user_ptr, NvDsMsgApiErrorType completion_flag)
Type definition for a "send" callback.
Definition: nvds_msgapi.h:71
NvDsMqttClientHandle::connect_cb
nvds_msgapi_connect_cb_t connect_cb
Definition: includes/nvds_mqtt_proto.h:63
nvds_msgapi_subscribe_request_cb_t
void(* nvds_msgapi_subscribe_request_cb_t)(NvDsMsgApiErrorType flag, void *msg, int msg_len, char *topic, void *user_ptr)
Type definition for callback registered during subscribe.
Definition: nvds_msgapi.h:87
send_msg_info_t::send_callback
nvds_msgapi_send_cb_t send_callback
Definition: includes/nvds_mqtt_proto.h:35