Commit b049cedc authored by whmaizmy's avatar whmaizmy Committed by 黄振令

【修改内容】子设备login成功后,发送mqtt 订阅主题

【提交人】黄振令
parent c21ebf96
...@@ -51,6 +51,12 @@ void KK_Sendto_CloudData(void *data,int len) ...@@ -51,6 +51,12 @@ void KK_Sendto_CloudData(void *data,int len)
#define KK_FILTER_REGISTER_TOPIC_REPLY "/thing/sub/register_reply" #define KK_FILTER_REGISTER_TOPIC_REPLY "/thing/sub/register_reply"
#define KK_FILTER_LOGIN_TOPIC "/thing/combine/login" #define KK_FILTER_LOGIN_TOPIC "/thing/combine/login"
#define KK_FILTER_LOGIN_TOPIC_REPLY "/thing/combine/login_reply" #define KK_FILTER_LOGIN_TOPIC_REPLY "/thing/combine/login_reply"
#define KK_FILTER_SET_TOPIC "/thing/service/property/set"
#define KK_FILTER_SET_TOPIC_REPLY "/thing/service/property/set_reply"
#define KK_FILTER_EVENT_POST_TOPIC "/thing/event/property/post"
#define KK_FILTER_EVENT_POST_REPLY "/thing/event/property/post_reply"
static int _check_invalid_topic(char* topic) static int _check_invalid_topic(char* topic)
{ {
...@@ -70,6 +76,13 @@ static int _check_invalid_topic(char* topic) ...@@ -70,6 +76,13 @@ static int _check_invalid_topic(char* topic)
strstr(topic,KK_FILTER_LOGIN_TOPIC_REPLY) == NULL){ strstr(topic,KK_FILTER_LOGIN_TOPIC_REPLY) == NULL){
return 1; return 1;
} }
else if(strstr(topic, KK_FILTER_SET_TOPIC_REPLY) != NULL){
return 1;
}
else if(strstr(topic, KK_FILTER_EVENT_POST_TOPIC) != NULL && \
strstr(topic,KK_FILTER_LOGIN_TOPIC_REPLY) == NULL){
return 1;
}
return 0; return 0;
} }
void KK_Sendto_DevData(const char *topic,const char *data) void KK_Sendto_DevData(const char *topic,const char *data)
......
{
"schema":"https://iotx-tsl.oss-ap-southeast-1.aliyuncs.com/schema.json",
"productType":"gw",
"profile":{
"type":"KONKE_ZIGBEE_Gateway"
},
"properties":[
{
"identifier":"NetChannelState",
"dataType":{
"specs":{
"0":"关闭",
"1":"打开"
},
"type":"bool"
},
"name":"组网通道状态",
"accessMode":"rw",
"required":true
},
{
"identifier":"WhiteListState",
"dataType":{
"specs":{
"0":"关闭",
"1":"打开"
},
"type":"bool"
},
"name":"白名单状态",
"accessMode":"rw",
"required":false
},
{
"identifier":"OnlineDetectionState",
"dataType":{
"specs":{
"0":"关闭",
"1":"打开"
},
"type":"bool"
},
"name":"在线侦测开关状态",
"accessMode":"rw",
"required":false
},
{
"identifier":"SN",
"dataType":{
"specs":{
"length":"50"
},
"type":"text"
},
"name":"设备SN",
"accessMode":"r",
"required":false
},
{
"identifier":"IPAddress",
"dataType":{
"specs":{
"length":"255"
},
"type":"text"
},
"name":"IP地址",
"accessMode":"r",
"required":false
},
{
"identifier":"MACAddress",
"dataType":{
"specs":{
"length":"128"
},
"type":"text"
},
"name":"MAC地址",
"accessMode":"r",
"required":false
},
{
"identifier":"Port",
"dataType":{
"specs":{
"min":"0",
"max":"65535",
"step":"1"
},
"type":"int"
},
"name":"网关通信端口号",
"accessMode":"r",
"required":false
},
{
"identifier":"Version",
"dataType":{
"specs":{
"length":"255"
},
"type":"text"
},
"name":"版本",
"accessMode":"r",
"required":false
}],
"services":[
{
"outputData":[
],
"identifier":"set",
"inputData":[
{
"identifier":"NetChannelState",
"dataType":{
"specs":{
"0":"关闭",
"1":"打开"
},
"type":"bool"
},
"name":"组网通道状态"
},
{
"identifier":"WhiteListState",
"dataType":{
"specs":{
"0":"关闭",
"1":"打开"
},
"type":"bool"
},
"name":"白名单状态"
},
{
"identifier":"OnlineDetectionState",
"dataType":{
"specs":{
"0":"关闭",
"1":"打开"
},
"type":"bool"
},
"name":"在线侦测开关状态"
}],
"method":"thing.service.property.set",
"name":"set",
"required":true,
"callType":"async",
"desc":"属性设置"
},
{
"outputData":[
{
"identifier":"NetChannelState",
"dataType":{
"specs":{
"0":"关闭",
"1":"打开"
},
"type":"bool"
},
"name":"组网通道状态"
},
{
"identifier":"WhiteListState",
"dataType":{
"specs":{
"0":"关闭",
"1":"打开"
},
"type":"bool"
},
"name":"白名单状态"
},
{
"identifier":"OnlineDetectionState",
"dataType":{
"specs":{
"0":"关闭",
"1":"打开"
},
"type":"bool"
},
"name":"在线侦测开关状态"
},
{
"identifier":"SN",
"dataType":{
"specs":{
"length":"50"
},
"type":"text"
},
"name":"设备SN"
},
{
"identifier":"IPAddress",
"dataType":{
"specs":{
"length":"255"
},
"type":"text"
},
"name":"IP地址"
},
{
"identifier":"MACAddress",
"dataType":{
"specs":{
"length":"128"
},
"type":"text"
},
"name":"MAC地址"
},
{
"identifier":"Port",
"dataType":{
"specs":{
"min":"0",
"max":"65535",
"step":"1"
},
"type":"int"
},
"name":"网关通信端口号"
},
{
"identifier":"Version",
"dataType":{
"specs":{
"length":"255"
},
"type":"text"
},
"name":"版本",
"accessMode":"r"
}],
"identifier":"get",
"inputData":[
"NetChannelState",
"WhiteListState",
"OnlineDetectionState",
"SN",
"IPAddress",
"MACAddress",
"Port",
"Version"],
"method":"thing.service.property.get",
"name":"get",
"required":true,
"callType":"async",
"desc":"属性获取"
},
{
"outputData":[
],
"identifier":"restoreFactory",
"inputData":[
],
"method":"thing.service.restoreFactory",
"name":"restoreFactory",
"required":false,
"callType":"async",
"desc":"恢复出厂设置"
},
{
"outputData":[
],
"identifier":"addWhiteList",
"inputData":[
{
"identifier":"Devices",
"dataType":{
"specs":{
"item":{
"specs":[
{
"identifier":"MACAddress",
"dataType":{
"specs":{
"length":"128"
},
"type":"text"
},
"name":"MAC地址"
},
{
"identifier":"ProductId",
"dataType":{
"specs":{
"length":"2048"
},
"type":"text"
},
"name":"产品id"
}],
"type":"struct"
},
"size":"512"
},
"type":"array"
},
"name":"设备列表"
}],
"method":"thing.service.addWhiteList",
"name":"添加设备白名单",
"required":false,
"callType":"async"
},
{
"outputData":[
],
"identifier":"deleteWhiteList",
"inputData":[
{
"identifier":"Devices",
"dataType":{
"specs":{
"item":{
"specs":[
{
"identifier":"MACAddress",
"dataType":{
"specs":{
"length":"128"
},
"type":"text"
},
"name":"MAC地址"
}],
"type":"struct"
},
"size":"512"
},
"type":"array"
},
"name":"设备列表"
}],
"method":"thing.service.deleteWhiteList",
"name":"删除白名单",
"required":false,
"callType":"async"
},
{
"outputData":[
],
"inputData":[
],
"identifier":"getWhiteList",
"method":"thing.service.getWhiteList",
"name":"获取白名单列表",
"required":false,
"callType":"async"
}],
"events":[
{
"outputData":[
{
"identifier":"NetChannelState",
"dataType":{
"specs":{
"0":"关闭",
"1":"打开"
},
"type":"bool"
},
"name":"组网通道状态"
},
{
"identifier":"WhiteListState",
"dataType":{
"specs":{
"0":"关闭",
"1":"打开"
},
"type":"bool"
},
"name":"白名单状态"
},
{
"identifier":"OnlineDetectionState",
"dataType":{
"specs":{
"0":"关闭",
"1":"打开"
},
"type":"bool"
},
"name":"在线侦测开关状态"
},
{
"identifier":"SN",
"dataType":{
"specs":{
"length":"50"
},
"type":"text"
},
"name":"设备SN"
},
{
"identifier":"IPAddress",
"dataType":{
"specs":{
"length":"255"
},
"type":"text"
},
"name":"IP地址"
},
{
"identifier":"MACAddress",
"dataType":{
"specs":{
"length":"128"
},
"type":"text"
},
"name":"MAC地址"
},
{
"identifier":"Port",
"dataType":{
"specs":{
"min":"0",
"max":"65535",
"step":"1"
},
"type":"int"
},
"name":"网关通信端口号"
}],
"identifier":"property",
"method":"thing.event.property.post",
"name":"property",
"type":"info",
"required":true,
"desc":"属性上报"
},
{
"outputData":[
],
"identifier":"whiteListAddedNotification",
"method":"thing.event.whiteListAddedNotification.post",
"name":"添加设备白名单通知",
"type":"info",
"required":false
},
{
"outputData":[
],
"identifier":"whiteListDeletedNotification",
"method":"thing.event.whiteListDeletedNotification.post",
"name":"删除设备白名单通知",
"type":"info",
"required":false
},
{
"outputData":[
{
"identifier":"Devices",
"dataType":{
"specs":{
"item":{
"specs":[
{
"identifier":"SN",
"dataType":{
"specs":{
"length":"50"
},
"type":"text"
},
"name":"设备sn"
},
{
"identifier":"deviceId",
"dataType":{
"specs":{
"length":"128"
},
"type":"text"
},
"name":"设备ID"
},
{
"identifier":"MACAddress",
"dataType":{
"specs":{
"length":"128"
},
"type":"text"
},
"name":"MAC地址"
},
{
"identifier":"ProductId",
"dataType":{
"specs":{
"length":"2048"
},
"type":"text"
},
"name":"产品id"
}],
"type":"struct"
},
"size":"512"
},
"type":"array"
},
"name":"设备列表"
}],
"identifier":"getWhiteListNotification",
"method":"thing.event.getWhiteList.post",
"name":"getWhiteList",
"type":"info",
"required":false,
"desc":"获取白名单通知消息"
},
{
"outputData":[
],
"identifier":"restoreFactoryNotification",
"method":"thing.event.restoreFactoryNotification.post",
"name":"恢复出厂通知消息",
"type":"info",
"required":false
},
{
"outputData":[
{
"identifier":"ErrorCode",
"dataType":{
"specs":{
"0":"正常"
},
"type":"enum"
},
"name":"故障代码"
}],
"identifier":"error",
"method":"thing.event.error.post",
"name":"故障上报",
"type":"error",
"required":false
}]
}
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "kk_dm_api.h" #include "kk_dm_api.h"
#include "kk_tsl_common.h" #include "kk_tsl_common.h"
#include "kk_dm_mng.h" #include "kk_dm_mng.h"
#include "com_api.h"
static dm_api_ctx_t g_dm_api_ctx; static dm_api_ctx_t g_dm_api_ctx;
...@@ -244,4 +244,47 @@ int iotx_dm_connect(_IN_ iotx_dm_event_callback cb) ...@@ -244,4 +244,47 @@ int iotx_dm_connect(_IN_ iotx_dm_event_callback cb)
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
int iotx_dm_subscribe(_IN_ int devid)
{
int res = 0, dev_type = 0;
char product_key[PRODUCT_KEY_MAXLEN] = {0};
char device_name[DEVICE_NAME_MAXLEN] = {0};
char device_secret[DEVICE_SECRET_MAXLEN] = {0};
if (devid < 0) {
return INVALID_PARAMETER;
}
dm_mgr_dev_node_t *node = NULL;
_dm_api_lock();
res = dm_mgr_search_dev_by_devid(devid, &node);
if (res != SUCCESS_RETURN) {
_dm_api_unlock();
return FAIL_RETURN;
}
_dm_api_unlock();
//send app to subscribe mqtt
const char subscribe_cmd[] =
"{\"cmd\":\"subscribe\",\"data\":{\"productType\":\"%s\",\"productCode\":\"%s\"}}";
int len = strlen(subscribe_cmd) + strlen(node->product_key) + strlen(node->device_name) + 1;
void* buf = malloc(len);
if (buf){
HAL_Snprintf(buf, len, subscribe_cmd, node->product_key, node->device_name);
kk_ipc_send(IPC_MID2APP, buf, len);
free(buf);
}else{
printf("\n [%d][%s] malloc faild kk_ipc_send \n", __LINE__, __FUNCTION__);
return FAIL_RETURN;
}
printf("\n [%d][%s] [%d] send app to subscribe mqtt \n", __LINE__, __FUNCTION__, HAL_UptimeMs());
return SUCCESS_RETURN;
}
...@@ -244,9 +244,11 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data) ...@@ -244,9 +244,11 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
kk_mid_subdev_add("a1OYuSallan","allanWno8yDdsjCX15iq",""); kk_mid_subdev_add("a1OYuSallan","allanWno8yDdsjCX15iq","");
}else{ }else{
printf("rrr topic: [%s] ,payload= %s \n",topic->valuestring,payload->valuestring ); printf("rrr topic: [%s] ,payload= %s \n",topic->valuestring,payload->valuestring );
if (strpbrk(payload->valuestring, "register_reply") != NULL){
if (strstr(topic->valuestring, "register_reply") != NULL){
//====todo====== //====todo======
//get devicececret and save it //get devicececret and save it
printf(" topic:register_reply \n");
dm_msg_response_payload_t response; dm_msg_response_payload_t response;
res = dm_msg_response_parse((char *)payload->valuestring, strlen(payload->valuestring)+1, &response); res = dm_msg_response_parse((char *)payload->valuestring, strlen(payload->valuestring)+1, &response);
if (res != SUCCESS_RETURN) { if (res != SUCCESS_RETURN) {
...@@ -257,9 +259,10 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data) ...@@ -257,9 +259,10 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
_iotx_linkkit_upstream_callback_remove(atoi(response.id.value), response.code.value_int); _iotx_linkkit_upstream_callback_remove(atoi(response.id.value), response.code.value_int);
_iotx_linkkit_upstream_mutex_unlock(); _iotx_linkkit_upstream_mutex_unlock();
}else if (strpbrk(topic, "add_reply") != NULL){ }else if (strstr(topic->valuestring, "add_reply") != NULL){
//====todo====== //====todo======
// //
printf(" topic:add_reply \n");
dm_msg_response_payload_t response; dm_msg_response_payload_t response;
res = dm_msg_response_parse((char *)payload->valuestring, strlen(payload->valuestring)+1, &response); res = dm_msg_response_parse((char *)payload->valuestring, strlen(payload->valuestring)+1, &response);
if (res != SUCCESS_RETURN) { if (res != SUCCESS_RETURN) {
...@@ -270,9 +273,10 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data) ...@@ -270,9 +273,10 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
_iotx_linkkit_upstream_callback_remove(atoi(response.id.value), response.code.value_int); _iotx_linkkit_upstream_callback_remove(atoi(response.id.value), response.code.value_int);
_iotx_linkkit_upstream_mutex_unlock(); _iotx_linkkit_upstream_mutex_unlock();
}else if (strpbrk(topic, "login_reply") != NULL){ }else if (strstr(topic->valuestring, "login_reply") != NULL){
//====todo====== //====todo======
// //
printf(" topic:login_reply \n");
dm_msg_response_payload_t response; dm_msg_response_payload_t response;
res = dm_msg_response_parse((char *)payload->valuestring, strlen(payload->valuestring)+1, &response); res = dm_msg_response_parse((char *)payload->valuestring, strlen(payload->valuestring)+1, &response);
if (res != SUCCESS_RETURN) { if (res != SUCCESS_RETURN) {
...@@ -282,9 +286,12 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data) ...@@ -282,9 +286,12 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
_iotx_linkkit_upstream_mutex_lock(); _iotx_linkkit_upstream_mutex_lock();
_iotx_linkkit_upstream_callback_remove(atoi(response.id.value), response.code.value_int); _iotx_linkkit_upstream_callback_remove(atoi(response.id.value), response.code.value_int);
_iotx_linkkit_upstream_mutex_unlock(); _iotx_linkkit_upstream_mutex_unlock();
}else if (strstr(topic->valuestring, "thing/service/property/set") != NULL){
printf("set property 222222222222222 \n");
kk_tsl_service_property_set(topic->valuestring, payload->valuestring, strlen(payload->valuestring), NULL);
}else{ }else{
printf("Error 222222222222222 \n"); printf("Error 222222222222222 \n");
//kk_tsl_service_property_set(topic->valuestring, payload->valuestring, strlen(payload->valuestring), NULL);
} }
} }
...@@ -1442,20 +1449,13 @@ static int _iotx_linkkit_subdev_login(int devid) ...@@ -1442,20 +1449,13 @@ static int _iotx_linkkit_subdev_login(int devid)
} }
_iotx_linkkit_upstream_mutex_unlock(); _iotx_linkkit_upstream_mutex_unlock();
//send app to subscribe mqtt
const char subscribe_cmd[] =
"{\"cmd\":\"subscribe\",\"productKey\":\"%s\",\"deviceName\":\"%s\",\"clientId\":\"%s\",\"timestamp\":\"%s\",\"signMethod\":\"%s\",\"sign\":\"%s\",\"cleanSession\":\"%s\"}";
kk_ipc_send(IPC_MID2APP, subscribe_cmd, strlen(subscribe_cmd) + 1);
printf("\n [%d][%s] [%d] allan kk_ipc_send \n", __LINE__, __FUNCTION__, HAL_UptimeMs());
/*res = iotx_dm_subscribe(devid); res = iotx_dm_subscribe(devid);
if (res != SUCCESS_RETURN) { if (res != SUCCESS_RETURN) {
return FAIL_RETURN; return FAIL_RETURN;
} }
iotx_dm_send_aos_active(devid); /*iotx_dm_send_aos_active(devid);
callback = iotx_event_callback(ITE_INITIALIZE_COMPLETED); callback = iotx_event_callback(ITE_INITIALIZE_COMPLETED);
if (callback) { if (callback) {
((int (*)(const int))callback)(devid); ((int (*)(const int))callback)(devid);
......
#ifndef _INFRA_LIST_H_
#define _INFRA_LIST_H_
#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) || defined(__GNUC__)) && \
!defined(inline) && !defined(__cplusplus)
#define inline __inline
#endif
#ifdef __cplusplus
extern "C" {
#endif
/*
* Get offset of a member variable.
*
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the variable within the struct.
*/
#define aos_offsetof(type, member) ((int)&(((type *)0)->member))
/*
* Get the struct for this entry.
*
* @param[in] ptr the list head to take the element from.
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the variable within the struct.
*/
#define aos_container_of(ptr, type, member) \
((type *) ((char *) (ptr) - aos_offsetof(type, member)))
/* for double link list */
typedef struct dlist_s {
struct dlist_s *prev;
struct dlist_s *next;
} dlist_t;
static inline void __dlist_add(dlist_t *node, dlist_t *prev, dlist_t *next)
{
node->next = next;
node->prev = prev;
//printf("[%s][%d]node->name:%d\n",__FUNCTION__,__LINE__);
prev->next = node;
next->prev = node;
}
/*
* Get the struct for this entry.
*
* @param[in] addr the list head to take the element from.
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the dlist_t within the struct.
*/
#define dlist_entry(addr, type, member) \
((type *)((long)addr - aos_offsetof(type, member)))
static inline void dlist_add(dlist_t *node, dlist_t *queue)
{
__dlist_add(node, queue, queue->next);
}
static inline void dlist_add_tail(dlist_t *node, dlist_t *queue)
{
__dlist_add(node, queue->prev, queue);
}
static inline void dlist_del(dlist_t *node)
{
dlist_t *prev = node->prev;
dlist_t *next = node->next;
prev->next = next;
next->prev = prev;
}
static inline void dlist_init(dlist_t *node)
{
node->next = node->prev = node;
}
static inline void INIT_AOS_DLIST_HEAD(dlist_t *list)
{
list->next = list;
list->prev = list;
}
static inline int dlist_empty(const dlist_t *head)
{
return head->next == head;
}
/*
* Initialise the list.
*
* @param[in] list the list to be inited.
*/
#define AOS_DLIST_INIT(list) {&(list), &(list)}
/*
* Get the first element from a list
*
* @param[in] ptr the list head to take the element from.
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the dlist_t within the struct.
*/
#define dlist_first_entry(ptr, type, member) \
dlist_entry((ptr)->next, type, member)
/*
* Iterate over a list.
*
* @param[in] pos the &struct dlist_t to use as a loop cursor.
* @param[in] head he head for your list.
*/
#define dlist_for_each(pos, head) \
for (pos = (head)->next; pos != (head); pos = pos->next)
/*
* Iterate over a list safe against removal of list entry.
*
* @param[in] pos the &struct dlist_t to use as a loop cursor.
* @param[in] n another &struct dlist_t to use as temporary storage.
* @param[in] head he head for your list.
*/
#define dlist_for_each_safe(pos, n, head) \
for (pos = (head)->next, n = pos->next; pos != (head); \
pos = n, n = pos->next)
/*
* Iterate over list of given type.
*
* @param[in] queue he head for your list.
* @param[in] node the &struct dlist_t to use as a loop cursor.
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the dlist_t within the struct.
*/
#define dlist_for_each_entry(queue, node, type, member) \
for (node = aos_container_of((queue)->next, type, member); \
&node->member != (queue); \
node = aos_container_of(node->member.next, type, member))
/*
* Iterate over list of given type safe against removal of list entry.
*
* @param[in] queue the head for your list.
* @param[in] n the type * to use as a temp.
* @param[in] node the type * to use as a loop cursor.
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the dlist_t within the struct.
*/
#define dlist_for_each_entry_safe(queue, n, node, type, member) \
for (node = aos_container_of((queue)->next, type, member), \
n = (queue)->next ? (queue)->next->next : NULL; \
&node->member != (queue); \
node = aos_container_of(n, type, member), n = n ? n->next : NULL)
/*
* Get the struct for this entry.
* @param[in] ptr the list head to take the element from.
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the variable within the struct.
*/
#define list_entry(ptr, type, member) \
aos_container_of(ptr, type, member)
/*
* Iterate backwards over list of given type.
*
* @param[in] pos the type * to use as a loop cursor.
* @param[in] head he head for your list.
* @param[in] member the name of the dlist_t within the struct.
* @param[in] type the type of the struct this is embedded in.
*/
#define dlist_for_each_entry_reverse(pos, head, member, type) \
for (pos = list_entry((head)->prev, type, member); \
&pos->member != (head); \
pos = list_entry(pos->member.prev, type, member))
/*
* Get the list length.
*
* @param[in] queue the head for your list.
*/
static inline int __dlist_entry_number(dlist_t *queue)
{
int num;
dlist_t *cur = queue;
for (num = 0; cur->next != queue; cur = cur->next, num++)
;
return num;
}
/*
* Get the list length.
*
* @param[in] queue the head for your list.
*/
#define dlist_entry_number(head) \
__dlist_entry_number(head)
/*
* Initialise the list.
*
* @param[in] name the list to be initialized.
*/
#define AOS_DLIST_HEAD_INIT(name) { &(name), &(name) }
/*
* Initialise the list.
*
* @param[in] name the list to be initialized.
*/
#define AOS_DLIST_HEAD(name) \
dlist_t name = AOS_DLIST_HEAD_INIT(name)
/* for single link list */
typedef struct slist_s {
struct slist_s *next;
} slist_t;
static inline void slist_add(slist_t *node, slist_t *head)
{
node->next = head->next;
head->next = node;
}
static inline void slist_add_tail(slist_t *node, slist_t *head)
{
while (head->next) {
head = head->next;
}
slist_add(node, head);
}
static inline void slist_del(slist_t *node, slist_t *head)
{
while (head->next) {
if (head->next == node) {
head->next = node->next;
break;
}
head = head->next;
}
}
static inline int slist_empty(const slist_t *head)
{
return !head->next;
}
static inline void slist_init(slist_t *head)
{
head->next = 0;
}
/*
* Iterate over list of given type.
*
* @param[in] queue he head for your list.
* @param[in] node the type * to use as a loop cursor.
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the slist_t within the struct.
*/
#define slist_for_each_entry(queue, node, type, member) \
for (node = aos_container_of((queue)->next, type, member); \
&node->member; \
node = aos_container_of(node->member.next, type, member))
/*
* Iterate over list of given type safe against removal of list entry.
*
* @param[in] queue the head for your list.
* @param[in] tmp the type * to use as a temp.
* @param[in] node the type * to use as a loop cursor.
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the slist_t within the struct.
*/
#define slist_for_each_entry_safe(queue, tmp, node, type, member) \
for (node = aos_container_of((queue)->next, type, member), \
tmp = (queue)->next ? (queue)->next->next : NULL; \
&node->member; \
node = aos_container_of(tmp, type, member), tmp = tmp ? tmp->next : tmp)
/*
* Initialise the list.
*
* @param[in] name the list to be initialized.
*/
#define AOS_SLIST_HEAD_INIT(name) {0}
/*
* Initialise the list.
*
* @param[in] name the list to be initialized.
*/
#define AOS_SLIST_HEAD(name) \
slist_t name = AOS_SLIST_HEAD_INIT(name)
/*
* Get the struct for this entry.
* @param[in] addr the list head to take the element from.
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the slist_t within the struct.
*/
#define slist_entry(addr, type, member) ( \
addr ? (type *)((long)addr - aos_offsetof(type, member)) : (type *)addr \
)
/*
* Get the first element from a list.
*
* @param[in] ptr the list head to take the element from.
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the slist_t within the struct.
*/
#define slist_first_entry(ptr, type, member) \
slist_entry((ptr)->next, type, member)
/*
* Get the list length.
*
* @param[in] queue the head for your list.
*/
static inline int slist_entry_number(slist_t *queue)
{
int num;
slist_t *cur = queue;
for (num = 0; cur->next; cur = cur->next, num++)
;
return num;
}
#ifndef offset_of
#define offset_of aos_offsetof
#endif
#ifndef container_of
#define container_of aos_container_of
#endif
#define LIST_HEAD AOS_DLIST_HEAD
#define LIST_HEAD_INIT AOS_DLIST_INIT
#define INIT_LIST_HEAD INIT_AOS_DLIST_HEAD
#define LIST_INIT AOS_DLIST_INIT
#define list_head dlist_s
#define list_head_t dlist_t
#define list_add dlist_add
#define list_add_tail dlist_add_tail
#define list_del dlist_del
#define list_empty dlist_empty
#define list_entry_number dlist_entry_number
#define list_first_entry dlist_first_entry
#define list_for_each dlist_for_each
#define list_for_each_entry_reverse dlist_for_each_entry_reverse
#define list_for_each_safe dlist_for_each_safe
#define list_init dlist_init
#define list_for_each_entry(pos, head, member, type) \
dlist_for_each_entry(head, pos, type, member)
#define list_for_each_entry_safe(pos, n, head, member, type) \
for (pos = list_entry((head)->next, type, member), \
n = list_entry(pos->member.next, type, member); \
&pos->member != (head); \
pos = n, n = list_entry(n->member.next, type, member))
#define list_next_entry(pos, member, type) \
list_entry((pos)->member.next, type, member)
static inline void list_del_init(struct list_head *entry)
{
list_del(entry);
INIT_LIST_HEAD(entry);
}
static inline int list_is_last(const struct list_head *list,
const struct list_head *head)
{
return list->next == head;
}
typedef struct propertyInfo
{
char name[50];
char identifier[50];
struct list_head list;
}propertyInfo_t;
#ifdef __cplusplus
}
#endif
#endif /* AOS_LIST_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment