Lines Matching refs:topic

33 	struct mqtt_sn_topic *topic;  member
215 struct mqtt_sn_topic *topic) in mqtt_sn_publish_find_topic() argument
220 if (pub->topic == topic) { in mqtt_sn_publish_find_topic()
230 struct mqtt_sn_topic *topic; in mqtt_sn_topic_create() local
232 if (k_mem_slab_alloc(&topics, (void **)&topic, K_NO_WAIT)) { in mqtt_sn_topic_create()
237 memset(topic, 0, sizeof(*topic)); in mqtt_sn_topic_create()
244 if (name->size > sizeof(topic->name)) { in mqtt_sn_topic_create()
249 memcpy(topic->name, name->data, name->size); in mqtt_sn_topic_create()
250 topic->namelen = name->size; in mqtt_sn_topic_create()
252 mqtt_sn_con_init(&topic->con); in mqtt_sn_topic_create()
254 return topic; in mqtt_sn_topic_create()
260 struct mqtt_sn_topic *topic; in mqtt_sn_topic_find_name() local
262 SYS_SLIST_FOR_EACH_CONTAINER(&client->topic, topic, next) { in mqtt_sn_topic_find_name()
263 if (topic->namelen == topic_name->size && in mqtt_sn_topic_find_name()
264 memcmp(topic->name, topic_name->data, topic_name->size) == 0) { in mqtt_sn_topic_find_name()
265 return topic; in mqtt_sn_topic_find_name()
275 struct mqtt_sn_topic *topic; in mqtt_sn_topic_find_msg_id() local
277 SYS_SLIST_FOR_EACH_CONTAINER(&client->topic, topic, next) { in mqtt_sn_topic_find_msg_id()
278 if (topic->con.msg_id == msg_id) { in mqtt_sn_topic_find_msg_id()
279 return topic; in mqtt_sn_topic_find_msg_id()
286 static void mqtt_sn_topic_destroy(struct mqtt_sn_client *client, struct mqtt_sn_topic *topic) in mqtt_sn_topic_destroy() argument
291 while ((pub = mqtt_sn_publish_find_topic(client, topic)) != NULL) { in mqtt_sn_topic_destroy()
296 sys_slist_find_and_remove(&client->topic, &topic->next); in mqtt_sn_topic_destroy()
301 struct mqtt_sn_topic *topic; in mqtt_sn_topic_destroy_all() local
305 while ((next = sys_slist_get(&client->topic)) != NULL) { in mqtt_sn_topic_destroy_all()
306 topic = SYS_SLIST_CONTAINER(next, topic, next); in mqtt_sn_topic_destroy_all()
308 while ((pub = mqtt_sn_publish_find_topic(client, topic)) != NULL) { in mqtt_sn_topic_destroy_all()
313 k_mem_slab_free(&topics, (void *)topic); in mqtt_sn_topic_destroy_all()
406 static void mqtt_sn_do_subscribe(struct mqtt_sn_client *client, struct mqtt_sn_topic *topic, in mqtt_sn_do_subscribe() argument
411 if (!client || !topic) { in mqtt_sn_do_subscribe()
420 p.params.subscribe.msg_id = topic->con.msg_id; in mqtt_sn_do_subscribe()
421 p.params.subscribe.qos = topic->qos; in mqtt_sn_do_subscribe()
422 p.params.subscribe.topic_type = topic->type; in mqtt_sn_do_subscribe()
424 switch (topic->type) { in mqtt_sn_do_subscribe()
426 p.params.subscribe.topic.topic_name.data = topic->name; in mqtt_sn_do_subscribe()
427 p.params.subscribe.topic.topic_name.size = topic->namelen; in mqtt_sn_do_subscribe()
431 p.params.subscribe.topic.topic_id = topic->topic_id; in mqtt_sn_do_subscribe()
434 LOG_ERR("Unexpected topic type %d", topic->type); in mqtt_sn_do_subscribe()
441 static void mqtt_sn_do_unsubscribe(struct mqtt_sn_client *client, struct mqtt_sn_topic *topic) in mqtt_sn_do_unsubscribe() argument
445 if (!client || !topic) { in mqtt_sn_do_unsubscribe()
454 p.params.unsubscribe.msg_id = topic->con.msg_id; in mqtt_sn_do_unsubscribe()
455 p.params.unsubscribe.topic_type = topic->type; in mqtt_sn_do_unsubscribe()
456 switch (topic->type) { in mqtt_sn_do_unsubscribe()
458 p.params.unsubscribe.topic.topic_name.data = topic->name; in mqtt_sn_do_unsubscribe()
459 p.params.unsubscribe.topic.topic_name.size = topic->namelen; in mqtt_sn_do_unsubscribe()
463 p.params.unsubscribe.topic.topic_id = topic->topic_id; in mqtt_sn_do_unsubscribe()
466 LOG_ERR("Unexpected topic type %d", topic->type); in mqtt_sn_do_unsubscribe()
473 static void mqtt_sn_do_register(struct mqtt_sn_client *client, struct mqtt_sn_topic *topic) in mqtt_sn_do_register() argument
477 if (!client || !topic) { in mqtt_sn_do_register()
486 p.params.reg.msg_id = topic->con.msg_id; in mqtt_sn_do_register()
487 switch (topic->type) { in mqtt_sn_do_register()
489 LOG_HEXDUMP_INF(topic->name, topic->namelen, "Registering topic"); in mqtt_sn_do_register()
490 p.params.reg.topic.data = topic->name; in mqtt_sn_do_register()
491 p.params.reg.topic.size = topic->namelen; in mqtt_sn_do_register()
494 LOG_ERR("Unexpected topic type %d", topic->type); in mqtt_sn_do_register()
514 LOG_INF("Publishing to topic ID %d", pub->topic->topic_id); in mqtt_sn_do_publish()
520 p.params.publish.topic_id = pub->topic->topic_id; in mqtt_sn_do_publish()
521 p.params.publish.topic_type = pub->topic->type; in mqtt_sn_do_publish()
590 LOG_HEXDUMP_DBG(pub->topic->name, pub->topic->namelen, in process_pubs()
603 switch (pub->topic->state) { in process_pubs()
642 struct mqtt_sn_topic *topic; in process_topics() local
647 SYS_SLIST_FOR_EACH_CONTAINER(&client->topic, topic, next) { in process_topics()
648 LOG_HEXDUMP_DBG(topic->name, topic->namelen, "Processing topic"); in process_topics()
650 if (topic->con.last_attempt == 0) { in process_topics()
654 next_attempt = topic->con.last_attempt + T_RETRY_MSEC; in process_topics()
659 switch (topic->state) { in process_topics()
661 if (!topic->con.retries--) { in process_topics()
667 mqtt_sn_do_subscribe(client, topic, dup); in process_topics()
668 topic->con.last_attempt = now; in process_topics()
672 if (!topic->con.retries--) { in process_topics()
678 mqtt_sn_do_register(client, topic); in process_topics()
679 topic->con.last_attempt = now; in process_topics()
683 if (!topic->con.retries--) { in process_topics()
688 mqtt_sn_do_unsubscribe(client, topic); in process_topics()
689 topic->con.last_attempt = now; in process_topics()
995 struct mqtt_sn_topic *topic; in mqtt_sn_subscribe() local
1007 topic = mqtt_sn_topic_find_name(client, topic_name); in mqtt_sn_subscribe()
1008 if (!topic) { in mqtt_sn_subscribe()
1009 topic = mqtt_sn_topic_create(topic_name); in mqtt_sn_subscribe()
1010 if (!topic) { in mqtt_sn_subscribe()
1014 topic->qos = qos; in mqtt_sn_subscribe()
1015 topic->state = MQTT_SN_TOPIC_STATE_SUBSCRIBING; in mqtt_sn_subscribe()
1016 sys_slist_append(&client->topic, &topic->next); in mqtt_sn_subscribe()
1030 struct mqtt_sn_topic *topic; in mqtt_sn_unsubscribe() local
1042 topic = mqtt_sn_topic_find_name(client, topic_name); in mqtt_sn_unsubscribe()
1043 if (!topic) { in mqtt_sn_unsubscribe()
1048 topic->state = MQTT_SN_TOPIC_STATE_UNSUBSCRIBING; in mqtt_sn_unsubscribe()
1049 mqtt_sn_con_init(&topic->con); in mqtt_sn_unsubscribe()
1063 struct mqtt_sn_topic *topic; in mqtt_sn_publish() local
1080 topic = mqtt_sn_topic_find_name(client, topic_name); in mqtt_sn_publish()
1081 if (!topic) { in mqtt_sn_publish()
1082 topic = mqtt_sn_topic_create(topic_name); in mqtt_sn_publish()
1083 if (!topic) { in mqtt_sn_publish()
1087 topic->qos = qos; in mqtt_sn_publish()
1088 topic->state = MQTT_SN_TOPIC_STATE_REGISTERING; in mqtt_sn_publish()
1089 sys_slist_append(&client->topic, &topic->next); in mqtt_sn_publish()
1100 pub->topic = topic; in mqtt_sn_publish()
1224 response.params.willtopic.topic.data = client->will_topic.data; in handle_willtopicreq()
1225 response.params.willtopic.topic.size = client->will_topic.size; in handle_willtopicreq()
1243 struct mqtt_sn_topic *topic; in handle_register() local
1245 topic = mqtt_sn_topic_create(&p->topic); in handle_register()
1246 if (!topic) { in handle_register()
1250 topic->state = MQTT_SN_TOPIC_STATE_REGISTERED; in handle_register()
1251 topic->topic_id = p->topic_id; in handle_register()
1252 topic->type = MQTT_SN_TOPIC_TYPE_NORMAL; in handle_register()
1254 sys_slist_append(&client->topic, &topic->next); in handle_register()
1265 struct mqtt_sn_topic *topic = mqtt_sn_topic_find_msg_id(client, p->msg_id); in handle_regack() local
1267 if (!topic) { in handle_regack()
1273 topic->state = MQTT_SN_TOPIC_STATE_REGISTERED; in handle_regack()
1274 topic->topic_id = p->topic_id; in handle_regack()
1361 struct mqtt_sn_topic *topic = mqtt_sn_topic_find_msg_id(client, p->msg_id); in handle_suback() local
1363 if (!topic) { in handle_suback()
1369 topic->state = MQTT_SN_TOPIC_STATE_SUBSCRIBED; in handle_suback()
1370 topic->topic_id = p->topic_id; in handle_suback()
1371 topic->qos = p->qos; in handle_suback()
1379 struct mqtt_sn_topic *topic = mqtt_sn_topic_find_msg_id(client, p->msg_id); in handle_unsuback() local
1381 if (!topic || topic->state != MQTT_SN_TOPIC_STATE_UNSUBSCRIBING) { in handle_unsuback()
1386 mqtt_sn_topic_destroy(client, topic); in handle_unsuback()
1545 struct mqtt_sn_topic *topic; in mqtt_sn_get_topic_name() local
1551 SYS_SLIST_FOR_EACH_CONTAINER(&client->topic, topic, next) { in mqtt_sn_get_topic_name()
1552 if (topic->topic_id == id) { in mqtt_sn_get_topic_name()
1553 topic_name->data = (const uint8_t *)topic->name; in mqtt_sn_get_topic_name()
1554 topic_name->size = topic->namelen; in mqtt_sn_get_topic_name()