⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parse-resource.c

📁 MANTIS是由科罗拉多大学开发的传感器网络嵌入式操作系统。 这是mantis的0.9.5版本的源码。
💻 C
字号:
#include <string.h>#include <glib.h>#include "bionet.h"#include "libbionet-internal.h"#include "bionet-util.h"bionet_resource_t *libbionet_parse_resource(xmlNode *x) {    // these are optional    char *hab_type=NULL, *hab_id=NULL, *node_id=NULL;    // these are required    char *resource_id=NULL, *flavor=NULL, *type=NULL, *value=NULL, *time=NULL;    bionet_resource_t *resource = NULL;    if (x->type != XML_ELEMENT_NODE) {        g_log(BIONET_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "invalid XML element type passed to libbionet_parse_resource()");        return NULL;    }    if (strcmp(x->name, "resource") != 0) {        g_log(BIONET_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "non-<resource> XML element passed to libbionet_parse_resource()");        return NULL;    }    // these can be NULL so we dont have to check them    hab_type = xmlGetProp(x, "hab-type");    hab_id   = xmlGetProp(x, "hab-id");    node_id  = xmlGetProp(x, "node-id");    resource_id = xmlGetProp(x, "id");    if (resource_id == NULL) {        g_log(BIONET_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "got <resource> with no Resource-ID");        goto cleanup;    }    type = xmlGetProp(x, "type");    if (type == NULL) {        g_log(BIONET_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "got <resource> with no Type");        goto cleanup;    }    flavor = xmlGetProp(x, "flavor");    if (flavor == NULL) {        g_log(BIONET_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "got <resource> with no Flavor");        goto cleanup;    }    value = xmlGetProp(x, "value");    if (value == NULL) {        g_log(BIONET_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "got <resource> with no Value");        goto cleanup;    }    time = xmlGetProp(x, "time");    if (time == NULL) {        g_log(BIONET_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "got <resource> with no Time");        goto cleanup;    }    resource = bionet_resource_new_with_valuestr_timestr(        hab_type,        hab_id,        node_id,        type,        flavor,        resource_id,        value,        time    );cleanup:    if (hab_type != NULL)    xmlFree(hab_type);    if (hab_id != NULL)      xmlFree(hab_id);    if (node_id != NULL)     xmlFree(node_id);    if (resource_id != NULL) xmlFree(resource_id);    if (flavor != NULL)      xmlFree(flavor);    if (type != NULL)        xmlFree(type);    if (value != NULL)       xmlFree(value);    if (time != NULL)        xmlFree(time);    return resource;}

⌨️ 快捷键说明

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