handle-queued-nag-messages.c

来自「MANTIS是由科罗拉多大学开发的传感器网络嵌入式操作系统。 这是mantis」· C语言 代码 · 共 108 行

C
108
字号
#include <string.h>#include <glib.h>#include "bionet.h"#include "libbionet-internal.h"void bionet_handle_queued_nag_messages(void) {    do {        xmlDoc *xml;        xmlNode *root;        xml = g_slist_nth_data(libbionet_queued_messages_from_nag, 0);        if (xml == NULL) return;        libbionet_queued_messages_from_nag = g_slist_remove(libbionet_queued_messages_from_nag, xml);        root = xmlDocGetRootElement(xml);        if (strcmp(root->name, "node") == 0) {            bionet_node_t *node;            if (libbionet_callback_new_node == NULL) {                g_log(BIONET_LOG_DOMAIN, G_LOG_LEVEL_INFO, "dropping <node> request from NAG: no callback registered");                xmlFreeDoc(xml);                continue;            }            node = libbionet_parse_node_from_xml(root);            xmlFreeDoc(xml);            if (node != NULL) {                libbionet_callback_new_node(node);            }        } else if (strcmp(root->name, "lost-node") == 0) {            char *hab_type, *hab_id, *node_id;            if (libbionet_callback_lost_node == NULL) {                g_log(BIONET_LOG_DOMAIN, G_LOG_LEVEL_INFO, "dropping <lost-node> request from NAG: no callback registered");                xmlFreeDoc(xml);                continue;            }            hab_type = xmlGetProp(root, "hab-type");            if (hab_type == NULL) {                g_log(BIONET_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "got <lost-node> with no hab-type");                xmlFreeDoc(xml);                return;            }            hab_id = xmlGetProp(root, "hab-id");            if (hab_id == NULL) {                g_log(BIONET_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "got <lost-node> with no hab-id");                xmlFree(hab_type);                xmlFreeDoc(xml);                return;            }            node_id = xmlGetProp(root, "node-id");            if (node_id == NULL) {                g_log(BIONET_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "got <lost-node> with no node-id");                xmlFree(hab_type);                xmlFree(hab_id);                xmlFreeDoc(xml);                return;            }            libbionet_callback_lost_node(hab_type, hab_id, node_id);            xmlFree(hab_type);            xmlFree(hab_id);            xmlFree(node_id);            xmlFreeDoc(xml);        } else if (strcmp(root->name, "resource") == 0) {            bionet_resource_t *resource;            if (libbionet_callback_resource_value == NULL) {                g_log(BIONET_LOG_DOMAIN, G_LOG_LEVEL_INFO, "dropping <resource> request from NAG: no callback registered");                xmlFreeDoc(xml);                continue;            }            resource = libbionet_parse_resource(root);            xmlFreeDoc(xml);            if (resource == NULL) {                return;            }            libbionet_callback_resource_value(resource);        } else {            g_log(BIONET_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "unhandled message from NAG: %s", root->name);            xmlFreeDoc(xml);        }    } while (1);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?