Skip to content

Commit 7682f34

Browse files
committed
Add callback to mqtt_list_subscribe_topic
This will allow user to use the information as per application requirement. passing handler as NULL will have same behaviour as previous API. Signed-off-by: Ajay Bhargav <[email protected]>
1 parent d14a301 commit 7682f34

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

mqttclient/mqttclient.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,8 +1468,7 @@ int mqtt_publish(mqtt_client_t* c, const char* topic_filter, mqtt_message_t* msg
14681468
RETURN_ERROR(rc);
14691469
}
14701470

1471-
1472-
int mqtt_list_subscribe_topic(mqtt_client_t* c)
1471+
int mqtt_list_subscribe_topic(mqtt_client_t* c, topiclist_hanndler_t handler)
14731472
{
14741473
int i = 0;
14751474

@@ -1488,6 +1487,8 @@ int mqtt_list_subscribe_topic(mqtt_client_t* c)
14881487
/* determine whether a node already exists by mqtt topic, but wildcards are not supported */
14891488
if (NULL != msg_handler->topic_filter) {
14901489
MQTT_LOG_I("mqtt-client:%d %s() -[%d] subscribe topic: %s", __LINE__, __FUNCTION__, ++i ,msg_handler->topic_filter);
1490+
if (handler)
1491+
handler(msg_handler->topic_filter, msg_handler->qos);
14911492
}
14921493
}
14931494

mqttclient/mqttclient.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ typedef struct message_data {
6565
typedef void (*interceptor_handler_t)(void* client, message_data_t* msg);
6666
typedef void (*message_handler_t)(void* client, message_data_t* msg);
6767
typedef void (*reconnect_handler_t)(void* client, void* reconnect_date);
68+
typedef void (*topiclist_hanndler_t)(const char *topicname, mqtt_qos_t qos);
6869

6970
typedef struct message_handlers {
7071
mqtt_list_t list;
@@ -170,7 +171,7 @@ int mqtt_keep_alive(mqtt_client_t* c);
170171
int mqtt_subscribe(mqtt_client_t* c, const char* topic_filter, mqtt_qos_t qos, message_handler_t msg_handler);
171172
int mqtt_unsubscribe(mqtt_client_t* c, const char* topic_filter);
172173
int mqtt_publish(mqtt_client_t* c, const char* topic_filter, mqtt_message_t* msg);
173-
int mqtt_list_subscribe_topic(mqtt_client_t* c);
174+
int mqtt_list_subscribe_topic(mqtt_client_t* c, topiclist_hanndler_t handler);
174175
int mqtt_set_will_options(mqtt_client_t* c, char *topic, mqtt_qos_t qos, uint8_t retained, char *message);
175176

176177
#ifdef __cplusplus

0 commit comments

Comments
 (0)