Skip to content
Snippets Groups Projects
Commit 8a290cac authored by clohr's avatar clohr
Browse files

nouveaux schémas

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/C/branches/version-0.7@2291 b32b6428-25c9-4566-ad07-03861ab6144f
parent 8cf2892e
Branches
No related tags found
No related merge requests found
......@@ -78,12 +78,8 @@ cbor_item_t *get_cbor_values(device_t *device) {
if (np->attribute) {
if (np->attribute->name)
cbor_map_add(crow, (struct cbor_pair){ cbor_move(cbor_build_string("name")), cbor_move(cbor_build_string(np->attribute->name)) });
if (np->attribute->type)
cbor_map_add(crow, (struct cbor_pair){ cbor_move(cbor_build_string("type")), cbor_move(cbor_build_string(json_object_to_json_string_ext(np->attribute->type, JSON_C_TO_STRING_PLAIN|JSON_C_TO_STRING_NOZERO))) });
if (np->attribute->unit)
cbor_map_add(crow, (struct cbor_pair){ cbor_move(cbor_build_string("unit")), cbor_move(cbor_build_string(np->attribute->unit)) });
if (np->attribute->description)
cbor_map_add(crow, (struct cbor_pair){ cbor_move(cbor_build_string("description")), cbor_move(cbor_build_string(np->attribute->description)) });
if (np->attribute->type && np->attribute->type->name)
cbor_map_add(crow, (struct cbor_pair){ cbor_move(cbor_build_string("type")), cbor_move(cbor_build_string(np->attribute->type->name)) });
} else {
if (np->key)
cbor_map_add(crow, (struct cbor_pair){ cbor_move(cbor_build_string("name")), cbor_move(cbor_build_string(np->key)) });
......@@ -97,9 +93,9 @@ cbor_item_t *get_cbor_values(device_t *device) {
/* serialize values of attributes of a device into json */
struct json_object *get_json_values(device_t *device) {
struct json_object *jarray = json_object_new_array();
struct json_object *jrow;
json_object *get_json_values(device_t *device) {
json_object *jarray = json_object_new_array();
json_object *jrow;
val_t *np = NULL;
TAILQ_FOREACH(np, &(device->vals), entries) {
......@@ -107,12 +103,8 @@ struct json_object *get_json_values(device_t *device) {
if (np->attribute) {
if (np->attribute->name)
json_object_object_add(jrow, "name", json_object_new_string(np->attribute->name));
if (np->attribute->type)
json_object_object_add(jrow, "type", json_object_get(np->attribute->type));
if (np->attribute->unit)
json_object_object_add(jrow, "unit", json_object_new_string(np->attribute->unit));
if (np->attribute->description)
json_object_object_add(jrow, "description", json_object_new_string(np->attribute->description));
if (np->attribute->type && np->attribute->type->name)
json_object_object_add(jrow, "type", json_object_new_string(np->attribute->type->name));
} else {
if (np->key)
json_object_object_add(jrow, "name", json_object_new_string(np->key));
......@@ -135,7 +127,7 @@ cbor_item_t *get_cbor_values_by_addr(devices_t *devices, const uuid_t *addr) {
/* get (json) values of attributes of a device by addr */
struct json_object *get_json_values_by_addr(devices_t *devices, const uuid_t *addr) {
json_object *get_json_values_by_addr(devices_t *devices, const uuid_t *addr) {
device_t *device = select_device(devices, addr);
if (device)
return get_json_values(device);
......@@ -230,8 +222,8 @@ cbor_item_t *get_cbor_kvs(device_t *device) {
/* serialize KVs-map of a device in json */
struct json_object *get_json_map(device_t *device) {
struct json_object *jmap = json_object_new_object();
json_object *get_json_map(device_t *device) {
json_object *jmap = json_object_new_object();
kv_t *np = NULL;
TAILQ_FOREACH(np, &(device->map), entries)
......@@ -250,7 +242,7 @@ cbor_item_t *get_cbor_kvs_by_addr(devices_t *devices, const uuid_t *addr) {
/* get (json) KVs-map of a device by addr */
struct json_object *get_json_kvs_by_addr(devices_t *devices, const uuid_t *addr) {
json_object *get_json_kvs_by_addr(devices_t *devices, const uuid_t *addr) {
device_t *device = select_device(devices, addr);
if (device)
return get_json_map(device);
......@@ -429,9 +421,9 @@ cbor_item_t *get_cbor_devices(devices_t *devices, const char *key) {
/* get (json) devices (having a given key in its map, or all) */
struct json_object *get_json_devices(devices_t *devices, const char *key) {
struct json_object *jarray = json_object_new_array();
struct json_object *jrow;
json_object *get_json_devices(devices_t *devices, const char *key) {
json_object *jarray = json_object_new_array();
json_object *jrow;
device_t *np = NULL;
char uuid[37];
......@@ -481,8 +473,8 @@ cbor_item_t *get_cbor_device(device_t *device) {
/* serialize a null terminatied list of strings into json */
struct json_object *strings2json(char **list) {
struct json_object *jarray = json_object_new_array();
json_object *strings2json(char **list) {
json_object *jarray = json_object_new_array();
char **idx;
for (idx = list; *idx != NULL; idx++)
json_object_array_add(jarray, json_object_new_string(*idx));
......@@ -491,8 +483,8 @@ struct json_object *strings2json(char **list) {
/* serialize a device into json */
struct json_object *get_json_device(device_t *device) {
struct json_object *jobj = json_object_new_object();
json_object *get_json_device(device_t *device) {
json_object *jobj = json_object_new_object();
char uuid[37];
uuid_unparse(device->devinfo.addr, uuid);
......@@ -544,7 +536,7 @@ cbor_item_t *get_cbor_device_by_addr(devices_t *devices, const uuid_t *addr) {
}
/* get a (json) device by addr */
struct json_object *get_json_device_by_addr(devices_t *devices, const uuid_t *addr) {
json_object *get_json_device_by_addr(devices_t *devices, const uuid_t *addr) {
device_t *device = select_device(devices, addr);
if (device)
return get_json_device(device);
......@@ -590,6 +582,3 @@ void delete_device(devices_t *devices, device_t *device) {
delete_values(&(device->vals));
free(device);
}
......@@ -75,13 +75,13 @@ void update_value(vals_t *vals, schema_t *schema,
cbor_item_t *get_cbor_values(device_t *device);
/* serialize values of attributes of a device into json */
struct json_object *get_json_values(device_t *device);
json_object *get_json_values(device_t *device);
/* get (cbor) values of attributes of a device by addr */
cbor_item_t *get_cbor_values_by_addr(devices_t *devices, const uuid_t *addr);
/* get (json) values of attributes of a device by addr */
struct json_object *get_json_values_by_addr(devices_t *devices, const uuid_t *addr);
json_object *get_json_values_by_addr(devices_t *devices, const uuid_t *addr);
/* delete the list of values */
void delete_values(vals_t *vals);
......@@ -106,13 +106,13 @@ void insert_kv(map_t *map, const char *key, const char *value);
cbor_item_t *get_cbor_kvs(device_t *device);
/* serialize KVs-map of a device in json */
struct json_object *get_json_map(device_t *device);
json_object *get_json_map(device_t *device);
/* get (cbor) KVs-map of a device by addr */
cbor_item_t *get_cbor_kvs_by_addr(devices_t *devices, const uuid_t *addr);
/* get (json) KVs-map of a device by addr */
struct json_object *get_json_kvs_by_addr(devices_t *devices, const uuid_t *addr);
json_object *get_json_kvs_by_addr(devices_t *devices, const uuid_t *addr);
/* delete a key-value in the map */
void delete_kv(map_t *map, const char *key);
......@@ -142,19 +142,19 @@ void update_description(device_t *device, cbor_item_t *cdescription);
cbor_item_t *get_cbor_devices(devices_t *devices, const char *key);
/* get (json) devices (having a given key in its map, or all) */
struct json_object *get_json_devices(devices_t *devices, const char *key);
json_object *get_json_devices(devices_t *devices, const char *key);
/* serialize a device into cbor */
cbor_item_t *get_cbor_device(device_t *device);
/* serialize a device into json */
struct json_object *get_json_device(device_t *device);
json_object *get_json_device(device_t *device);
/* get a (cbor) device by addr */
cbor_item_t *get_cbor_device_by_addr(devices_t *devices, const uuid_t *addr);
/* get a (json) device by addr */
struct json_object *get_json_device_by_addr(devices_t *devices, const uuid_t *addr);
json_object *get_json_device_by_addr(devices_t *devices, const uuid_t *addr);
/* delete a device */
void delete_device(devices_t * devices, device_t *device);
......
......@@ -80,8 +80,6 @@ attribute_t *select_schema_attribute(schema_t *schema, const char *name) {
attribute_t *insert_attribute(attributes_t *attributes, const char *name) {
attribute_t *attribute = (attribute_t *)malloc(sizeof(attribute_t));
attribute->name = strdup(name);
attribute->description = NULL;
attribute->unit = NULL;
attribute->type = NULL;
TAILQ_INSERT_TAIL(attributes, attribute, entries);
return attribute;
......@@ -98,32 +96,6 @@ attribute_t *add_attribute(attributes_t *attributes, const char *name) {
}
/* serialize an attribute into cbor */
cbor_item_t *get_cbor_attribute(attribute_t *attribute) {
cbor_item_t *cattribute = cbor_new_indefinite_map();
if (attribute->description)
cbor_map_add(cattribute, (struct cbor_pair){ cbor_move(cbor_build_string("description")), cbor_move(cbor_build_string(attribute->description)) });
if (attribute->unit)
cbor_map_add(cattribute, (struct cbor_pair){ cbor_move(cbor_build_string("unit")), cbor_move(cbor_build_string(attribute->unit)) });
if (attribute->type)
cbor_map_add(cattribute, (struct cbor_pair){ cbor_move(cbor_build_string("type")), cbor_move(cbor_build_string(json_object_to_json_string_ext(attribute->type, JSON_C_TO_STRING_PLAIN|JSON_C_TO_STRING_NOZERO))) });
return cattribute;
}
/* serialize an attribute into json */
struct json_object *get_json_attribute(attribute_t *attribute) {
struct json_object *jattribute = json_object_new_object();
if (attribute->description)
json_object_object_add(jattribute, "description", json_object_new_string(attribute->description));
if (attribute->unit)
json_object_object_add(jattribute, "unit", json_object_new_string(attribute->unit));
if (attribute->type)
json_object_object_add(jattribute, "type", json_object_get(attribute->type));
return jattribute;
}
/* serialize attributes of a schema into cbor, including extended schemas recursively */
cbor_item_t *get_cbor_attributes(schema_t *schema) {
if (schema == NULL)
......@@ -131,30 +103,39 @@ cbor_item_t *get_cbor_attributes(schema_t *schema) {
else {
cbor_item_t *cattributes = get_cbor_attributes(schema->extends);
attribute_t *attribute;
TAILQ_FOREACH(attribute, &(schema->attributes), entries)
xAAL_cbor_map_update(cattributes, attribute->name, get_cbor_attribute(attribute));
TAILQ_FOREACH(attribute, &(schema->attributes), entries) {
if (attribute->type && attribute->type->name)
xAAL_cbor_map_update(cattributes, attribute->name, cbor_build_string(attribute->type->name));
else
xAAL_cbor_map_update(cattributes, attribute->name, cbor_build_string(""));
}
return cattributes;
}
}
/* serialize attributes of a schema into json, including extended schemas recursively */
struct json_object *get_json_attributes(schema_t *schema) {
json_object *get_json_attributes(schema_t *schema) {
if (schema == NULL)
return json_object_new_object();
else {
struct json_object *jattributes = get_json_attributes(schema->extends);
json_object *jattributes = get_json_attributes(schema->extends);
attribute_t *attribute;
TAILQ_FOREACH(attribute, &(schema->attributes), entries) {
if (json_object_object_get_ex(jattributes, attribute->name, NULL))
json_object_object_del(jattributes, attribute->name);
json_object_object_add(jattributes, attribute->name, get_json_attribute(attribute));
if (attribute->type && attribute->type->name)
json_object_object_add(jattributes, attribute->name, json_object_new_string(attribute->type->name));
else
json_object_object_add(jattributes, attribute->name, json_object_new_string(""));
}
return jattributes;
}
}
//// ICICICI
/* update an attribute */
void update_cbor_attribute(attributes_t *attributes, const char *name, cbor_item_t *cattribute) {
attribute_t *attribute = add_attribute(attributes, name);
......@@ -192,8 +173,8 @@ void update_cbor_attribute(attributes_t *attributes, const char *name, cbor_item
/* (json) update an attribute */
void update_json_attribute(attributes_t *attributes, const char *name, struct json_object *jattribute) {
struct json_object *jdescription, *junit, *jtype;
void update_json_attribute(attributes_t *attributes, const char *name, json_object *jattribute) {
json_object *jdescription, *junit, *jtype;
attribute_t *attribute = add_attribute(attributes, name);
if ( json_object_object_get_ex(jattribute, "description", &jdescription)
......@@ -281,8 +262,8 @@ cbor_item_t *get_cbor_parameter(parameter_t *parameter) {
/* serialize a parameter into json */
struct json_object *get_json_parameter(parameter_t *parameter) {
struct json_object *jparameter = json_object_new_object();
json_object *get_json_parameter(parameter_t *parameter) {
json_object *jparameter = json_object_new_object();
if (parameter->description)
json_object_object_add(jparameter, "description", json_object_new_string(parameter->description));
if (parameter->unit)
......@@ -316,8 +297,8 @@ cbor_item_t *get_cbor_parameters(parameters_t *parameters) {
/* serialize parameters into json */
struct json_object *get_json_parameters(parameters_t *parameters) {
struct json_object *jparameters = json_object_new_object();
json_object *get_json_parameters(parameters_t *parameters) {
json_object *jparameters = json_object_new_object();
parameter_t *parameter;
TAILQ_FOREACH(parameter, parameters, entries)
......@@ -373,8 +354,8 @@ void update_cbor_parameter(parameters_t *parameters, const char *name, cbor_item
/* (json) update a parameter */
void update_json_parameter(parameters_t *parameters, const char *name, struct json_object *jparameter) {
struct json_object *jdescription, *junit, *jtype, *jdir;
void update_json_parameter(parameters_t *parameters, const char *name, json_object *jparameter) {
json_object *jdescription, *junit, *jtype, *jdir;
parameter_t *parameter = add_parameter(parameters, name);
const char *direction = NULL;
......@@ -445,8 +426,8 @@ cbor_item_t *get_cbor_method(method_t *method) {
/* serialize a method into json */
struct json_object *get_json_method(method_t *method) {
struct json_object *jmethod = json_object_new_object();
json_object *get_json_method(method_t *method) {
json_object *jmethod = json_object_new_object();
if (method->description)
json_object_object_add(jmethod, "description", json_object_new_string(method->description));
......@@ -470,11 +451,11 @@ cbor_item_t *get_cbor_methods(schema_t *schema) {
/* serialize methods of a schema into json, including extended schemas recursively */
struct json_object *get_json_methods(schema_t *schema) {
json_object *get_json_methods(schema_t *schema) {
if (schema == NULL)
return json_object_new_object();
else {
struct json_object *jmethods = get_json_methods(schema->extends);
json_object *jmethods = get_json_methods(schema->extends);
method_t *method;
TAILQ_FOREACH(method, &(schema->methods), entries) {
if (json_object_object_get_ex(jmethods, method->name, NULL))
......@@ -519,8 +500,8 @@ void update_cbor_method(methods_t *methods, const char *name, cbor_item_t *cmeth
/* (json) update a method */
void update_json_method(methods_t *methods, const char *name, struct json_object *jmethod) {
struct json_object *jdescription, *jparameters;
void update_json_method(methods_t *methods, const char *name, json_object *jmethod) {
json_object *jdescription, *jparameters;
method_t *method = add_method(methods, name);
if ( json_object_object_get_ex(jmethod, "description", &jdescription)
......@@ -574,8 +555,8 @@ cbor_item_t *get_cbor_notification(notification_t *notification) {
/* serialize a notification into json */
struct json_object *get_json_notification(notification_t *notification) {
struct json_object *jnotification = json_object_new_object();
json_object *get_json_notification(notification_t *notification) {
json_object *jnotification = json_object_new_object();
if (notification->description)
json_object_object_add(jnotification, "description", json_object_new_string(notification->description));
......@@ -599,11 +580,11 @@ cbor_item_t *get_cbor_notifications(schema_t *schema) {
/* serialize notifications of a schema into json, including extended schemas recursively */
struct json_object *get_json_notifications(schema_t *schema) {
json_object *get_json_notifications(schema_t *schema) {
if (schema == NULL)
return json_object_new_object();
else {
struct json_object *jnotifications = get_json_notifications(schema->extends);
json_object *jnotifications = get_json_notifications(schema->extends);
notification_t *notification;
TAILQ_FOREACH(notification, &(schema->notifications), entries) {
if (json_object_object_get_ex(jnotifications, notification->name, NULL))
......@@ -647,8 +628,8 @@ void update_cbor_notification(notifications_t *notifications, const char *name,
/* (json) update a notification */
void update_json_notification(notifications_t *notifications, const char *name, struct json_object *jnotification) {
struct json_object *jdescription, *jparameters;
void update_json_notification(notifications_t *notifications, const char *name, json_object *jnotification) {
json_object *jdescription, *jparameters;
notification_t *notification = add_notification(notifications, name);
if ( json_object_object_get_ex(jnotification, "description", &jdescription)
......@@ -751,8 +732,8 @@ cbor_item_t *get_cbor_schema(schema_t *schema) {
/* serialize a schema into json */
struct json_object *get_json_schema(schema_t *schema) {
struct json_object *jschema = json_object_new_object();
json_object *get_json_schema(schema_t *schema) {
json_object *jschema = json_object_new_object();
if (schema->title)
json_object_object_add(jschema, "title", json_object_new_string(schema->title));
......@@ -790,7 +771,7 @@ cbor_item_t *get_cbor_schema_by_devType(schemas_t *schemas, const char *devType)
/* get a (json) schema by devType*/
struct json_object *get_json_schema_by_devType(schemas_t *schemas, const char *devType) {
json_object *get_json_schema_by_devType(schemas_t *schemas, const char *devType) {
schema_t *np;
TAILQ_FOREACH(np, schemas, entries)
......@@ -897,8 +878,8 @@ void update_cbor_schema(schemas_t *schemas, cbor_item_t *cschema) {
/* (json) update a schema */
void update_json_schema(schemas_t *schemas, struct json_object *jschema) {
struct json_object *jtitle, *jdescription, *jlang, *jdoc, *jref, *jlicense,
void update_json_schema(schemas_t *schemas, json_object *jschema) {
json_object *jtitle, *jdescription, *jlang, *jdoc, *jref, *jlicense,
*jextends, *jattributes, *jmethods, *jnotifications;
schema_t *schema;
......@@ -964,4 +945,3 @@ void update_json_schema(schemas_t *schemas, struct json_object *jschema) {
update_json_notification(&(schema->notifications), key, val);
}
}
......@@ -31,34 +31,28 @@
* Section Definition of Data Structures
*/
typedef TAILQ_HEAD(attributeshead, attributeentry) attributes_t;
typedef struct attributeentry {
typedef TAILQ_HEAD(datamodelhead, datamodelentry) datamodel_t;
typedef struct datamodelentry {
char *description;
char *name;
char *unit;
struct json_object *type;
TAILQ_ENTRY(attributeentry) entries;
} attribute_t;
char *cddl;
TAILQ_ENTRY(datamodelentry) entries;
} datatype_t;
typedef enum { in, out, inout } direction_t;
typedef TAILQ_HEAD(parametershead, parameterentry) parameters_t;
typedef struct parameterentry {
char *description;
typedef TAILQ_HEAD(attributeshead, attributesentry) attributes_t;
typedef struct attributesentry {
char *name;
char *unit;
struct json_object *type;
direction_t direction;
TAILQ_ENTRY(parameterentry) entries;
} parameter_t;
datatype_t *type;
TAILQ_ENTRY(attributesentry) entries;
} attribute_t;
typedef TAILQ_HEAD(methodshead, methodentry) methods_t;
typedef struct methodentry {
char *description;
char *name;
parameters_t parameters;
attributes_t in;
attributes_t out;
TAILQ_ENTRY(methodentry) entries;
} method_t;
......@@ -67,7 +61,7 @@ typedef TAILQ_HEAD(notificationshead, notificationentry) notifications_t;
typedef struct notificationentry {
char *description;
char *name;
parameters_t parameters;
attributes_t out;
TAILQ_ENTRY(notificationentry) entries;
} notification_t;
......@@ -84,11 +78,37 @@ typedef struct schemaentry {
attributes_t attributes;
methods_t methods;
notifications_t notifications;
datamodel_t datamodel;
TAILQ_ENTRY(schemaentry) entries;
} schema_t;
/*
* Section DataModel
*/
/* select a data type by its name */
datatype_t *select_datatype(datamodel_t *datamodel, const char *name);
/* select a data type by its name in a schema or in extended ones */
datatype_t *select_schema_datatype(schema_t *schema, const char *name);
/* insert a data type (its name) */
datatype_t *insert_datatype(datamodel_t *datamodel, const char *name);
/* select or insert a data type (its name) */
datatype_t *add_insert_datatype(datamodel_t *datamodel, const char *name);
/* serialize a data type into cbor */
cbor_item_t *get_cbor_datatype(datatype_t *datatype);
/* serialize a data type into json */
json_object *get_json_datatype(datatype_t *datatype);
/*
* Section Attributes
*/
......@@ -112,52 +132,25 @@ attribute_t *add_attribute(attributes_t *attributes, const char *name);
cbor_item_t *get_cbor_attribute(attribute_t *attribute);
/* serialize an attribute into json */
struct json_object *get_json_attribute(attribute_t *attribute);
json_object *get_json_attribute(attribute_t *attribute);
/* serialize attributes of a schema into cbor, including extended schemas recursively */
cbor_item_t *get_cbor_attributes(schema_t *schema);
/* serialize attributes of a schema into json, including extended schemas recursively */
struct json_object *get_json_attributes(schema_t *schema);
json_object *get_json_attributes(schema_t *schema);
/* (cbor) update an attribute */
void update_cbor_attribute(attributes_t *attributes, const char *name, cbor_item_t *cattribute);
/* (json) update an attribute */
void update_json_attribute(attributes_t *attributes, const char *name, struct json_object *jattribute);
void update_json_attribute(attributes_t *attributes, const char *name, json_object *jattribute);
/* attribute (of any.any) that are supposed to be "internal", others are "public" */
bool public_attribute(const char *name);
/*
* Section Parameters
*/
/* select or insert a parameter (its name) */
parameter_t *add_parameter(parameters_t *parameters, const char *name);
/* serialize a parameter into cbor */
cbor_item_t *get_cbor_parameter(parameter_t *parameter);
/* serialize a parameter into json */
struct json_object *get_json_parameter(parameter_t *parameter);
/* serialize parameters into cbor */
cbor_item_t *get_cbor_parameters(parameters_t *parameters);
/* serialize parameters into json */
struct json_object *get_json_parameters(parameters_t *parameters);
/* (cbor) update a parameter */
void update_cbor_parameter(parameters_t *parameters, const char *name, cbor_item_t *cparameter);
/* (json) update a parameter */
void update_json_parameter(parameters_t *parameters, const char *name, struct json_object *jparameter);
/*
* Section Methods
*/
......@@ -173,19 +166,19 @@ method_t *add_method(methods_t *methods, const char *name);
cbor_item_t *get_cbor_method(method_t *method);
/* serialize a method into json */
struct json_object *get_json_method(method_t *method);
json_object *get_json_method(method_t *method);
/* serialize methods of a schema into cbor, including extended schemas recursively */
cbor_item_t *get_cbor_methods(schema_t *schema);
/* serialize methods of a schema into json, including extended schemas recursively */
struct json_object *get_json_methods(schema_t *schema);
json_object *get_json_methods(schema_t *schema);
/* (cbor) update a method */
void update_cbor_method(methods_t *methods, const char *name, cbor_item_t *cmethod);
/* (json) update a method */
void update_json_method(methods_t *methods, const char *name, struct json_object *jmethod);
void update_json_method(methods_t *methods, const char *name, json_object *jmethod);
......@@ -204,19 +197,19 @@ notification_t *add_notification(notifications_t *notifications, const char *nam
cbor_item_t *get_cbor_notification(notification_t *notification);
/* serialize a notification into json */
struct json_object *get_json_notification(notification_t *notification);
json_object *get_json_notification(notification_t *notification);
/* serialize notifications of a schema into cbor, including extended schemas recursively */
cbor_item_t *get_cbor_notifications(schema_t *schema);
/* serialize notifications of a schema into json, including extended schemas recursively */
struct json_object *get_json_notifications(schema_t *schema);
json_object *get_json_notifications(schema_t *schema);
/* (cbor) update a notification */
void update_notification(notifications_t *notifications, const char *name, cbor_item_t *cnotification);
/* (json) update a notification */
void update_json_notification(notifications_t *notifications, const char *name, struct json_object *jnotification);
void update_json_notification(notifications_t *notifications, const char *name, json_object *jnotification);
......@@ -237,19 +230,19 @@ schema_t *add_schema(schemas_t *schemas, const char *title);
cbor_item_t *get_cbor_schema(schema_t *schema);
/* serialize a schema into json */
struct json_object *get_json_schema(schema_t *schema);
json_object *get_json_schema(schema_t *schema);
/* get a (cbor) schema by devType*/
cbor_item_t *get_cbor_schema_by_devType(schemas_t *schemas, const char *devType);
/* get a (json) schema by devType*/
struct json_object *get_json_schema_by_devType(schemas_t *schemas, const char *devType);
json_object *get_json_schema_by_devType(schemas_t *schemas, const char *devType);
/* (cbor) update a schema */
void update_cbor_schema(schemas_t *schemas, cbor_item_t *cschema);
/* (json) update a schema */
void update_json_schema(schemas_t *schemas, struct json_object *jschema);
void update_json_schema(schemas_t *schemas, json_object *jschema);
#endif
......@@ -239,8 +239,8 @@ cbor_item_t *get_cbor_methods_of_device(db_t *db, const uuid_t *addr) {
/* get (json) methods of a device */
struct json_object *get_json_methods_of_device(db_t *db, const uuid_t *addr) {
struct json_object *jmethods;
json_object *get_json_methods_of_device(db_t *db, const uuid_t *addr) {
json_object *jmethods;
device_t *device;
schema_t *schema;
char **um;
......
......@@ -66,7 +66,7 @@ void update_device(db_t *db, cbor_item_t *cdevice);
cbor_item_t *get_cbor_methods_of_device(db_t *db, const uuid_t *addr);
/* get (json) methods of a device */
struct json_object *get_json_methods_of_device(db_t *db, const uuid_t *addr);
json_object *get_json_methods_of_device(db_t *db, const uuid_t *addr);
/*
......
......@@ -128,7 +128,7 @@ void parse_cmdline(int argc, char **argv, options_t *opts) {
/* Read a config file (json format) */
void read_config(options_t *opts) {
struct json_object *jconf, *jaddr, *jport, *jhops, *jpassphrase, *juuid,
json_object *jconf, *jaddr, *jport, *jhops, *jpassphrase, *juuid,
*jconffile, *jimmutable, *jlogfile, *jlockfile,
*juid, *jgid, *jverbose, *jhttpport, *jhttpiface,
*jresourcepath, *jdb, *jdaemon;
......@@ -232,7 +232,7 @@ void read_config(options_t *opts) {
/* Re-write config file (json format) */
void write_config(options_t *opts) {
struct json_object *jconf;
json_object *jconf;
char uuid[37];
if (opts->immutable)
......
......@@ -335,7 +335,7 @@ try_to_reuse:
bool serve_http_json(struct lws *wsi, struct json_object *jobj) {
bool serve_http_json(struct lws *wsi, json_object *jobj) {
const char *json = json_object_to_json_string_ext(jobj, JSON_C_TO_STRING_PLAIN|JSON_C_TO_STRING_NOZERO);
unsigned char buffer[4096 + LWS_PRE];
unsigned char *p, *end, *start;
......@@ -387,7 +387,7 @@ bool serve_http_cbor(struct lws *wsi, cbor_item_t *item) {
#define STREAM_PREFIX "data: "
#define STREAM_SUFFIX "\r\n\r\n"
bool serve_http_json_stream(struct lws *wsi, struct json_object *jobj) {
bool serve_http_json_stream(struct lws *wsi, json_object *jobj) {
const char *json = json_object_to_json_string_ext(jobj, JSON_C_TO_STRING_PLAIN|JSON_C_TO_STRING_NOZERO);
char buf[ strlen(STREAM_PREFIX) + strlen(json) + strlen(STREAM_SUFFIX) + 1];
......
......@@ -31,7 +31,7 @@
struct per_session_data__http {
struct json_object *janswer;
json_object *janswer;
cbor_item_t *canswer;
bool complete;
char *post_msg;
......@@ -42,13 +42,13 @@ struct per_session_data__http {
int callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len);
bool serve_http_json(struct lws *wsi, struct json_object *jobj);
bool serve_http_json(struct lws *wsi, json_object *jobj);
bool serve_http_cbor(struct lws *wsi, cbor_item_t *item);
bool hdr_http_stream(struct lws *wsi);
bool serve_http_json_stream(struct lws *wsi, struct json_object *jobj);
bool serve_http_json_stream(struct lws *wsi, json_object *jobj);
bool serve_http_cbor_stream(struct lws *wsi, cbor_item_t *item);
......
......@@ -61,7 +61,7 @@ int callback_xaal_ctl(struct lws *wsi, enum lws_callback_reasons reason, void *u
case LWS_CALLBACK_RECEIVE: {
struct json_object *jinput;
json_object *jinput;
enum json_tokener_error jerr;
jinput = json_tokener_parse_ex(pss->tok, in, len);
......@@ -141,7 +141,7 @@ int callback_xaal_dump(struct lws *wsi, enum lws_callback_reasons reason, void *
bool serve_ws_stream(struct lws *wsi, struct json_object *jobj) {
bool serve_ws_stream(struct lws *wsi, json_object *jobj) {
const char *json = json_object_to_json_string_ext(jobj, JSON_C_TO_STRING_PLAIN|JSON_C_TO_STRING_NOZERO);
char buf[ LWS_PRE + strlen(json) + 1 ];
char *p = &buf[LWS_PRE];
......
......@@ -24,12 +24,12 @@
struct per_session_data__xaal_dump {
struct json_object *janswer;
json_object *janswer;
};
struct per_session_data__xaal_ctl {
struct json_object *janswer;
json_object *janswer;
struct json_tokener *tok;
};
......@@ -38,7 +38,7 @@ int callback_xaal_ctl(struct lws *wsi, enum lws_callback_reasons reason, void *u
int callback_xaal_dump(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len);
bool serve_ws_stream(struct lws *wsi, struct json_object *jobj);
bool serve_ws_stream(struct lws *wsi, json_object *jobj);
#endif
......@@ -99,16 +99,16 @@ bool reply_getAttributes(const xAAL_businfo_t *bus, const xAAL_devinfo_t *me,
/* Manage getKeysValues replies and
keysValuesChanged notifications (metadatadb.any) */
bool receive_keysValues(cbor_item_t *cqueryBody, db_t *db) {
bool receive_keysValues(cbor_item_t *creplyBody, db_t *db) {
cbor_item_t *cdev, *cmap;
uuid_t dev;
device_t *device;
cdev = xAAL_cbor_map_get(cqueryBody, "device");
cdev = xAAL_cbor_map_get(creplyBody, "device");
if ( !xAAL_cbor_is_uuid(cdev, &dev) )
return false;
cmap = xAAL_cbor_map_get(cqueryBody, "map");
cmap = xAAL_cbor_map_get(creplyBody, "map");
if ( !cbor_isa_map(cmap) )
return false;
......@@ -128,8 +128,8 @@ bool request_getKeysValues(const xAAL_businfo_t *bus, const xAAL_devinfo_t *me,
/* manage getDeviceAttribute relies from cache */
bool receive_cachedDeviceAttribute(cbor_item_t *cqueryBody, db_t *db) {
/* manage getDeviceAttribute replies from cache */
bool receive_cachedDeviceAttribute(cbor_item_t *creplyBody, db_t *db) {
cbor_item_t *cvalue, *cdate;
char *attribute;
uuid_t dev;
......@@ -138,10 +138,10 @@ bool receive_cachedDeviceAttribute(cbor_item_t *cqueryBody, db_t *db) {
schema_t *schema;
size_t len;
if ( !xAAL_cbor_is_uuid(xAAL_cbor_map_get(cqueryBody, "device"), &dev) )
if ( !xAAL_cbor_is_uuid(xAAL_cbor_map_get(creplyBody, "device"), &dev) )
return false;
attribute = xAAL_cbor_string_dup(xAAL_cbor_map_get(cqueryBody, "attribute"), &len);
attribute = xAAL_cbor_string_dup(xAAL_cbor_map_get(creplyBody, "attribute"), &len);
if ( !attribute )
return false;
......@@ -150,13 +150,13 @@ bool receive_cachedDeviceAttribute(cbor_item_t *cqueryBody, db_t *db) {
return false;
}
cvalue = xAAL_cbor_map_get(cqueryBody, "value");
cvalue = xAAL_cbor_map_get(creplyBody, "value");
if ( !cvalue ) {
free(attribute);
return false;
}
cdate = xAAL_cbor_map_get(cqueryBody, "date");
cdate = xAAL_cbor_map_get(creplyBody, "date");
if ( cdate && cbor_is_int(cdate) )
date = cbor_get_int(cdate);
else
......@@ -166,8 +166,8 @@ bool receive_cachedDeviceAttribute(cbor_item_t *cqueryBody, db_t *db) {
schema = add_schema(&(db->schemas), device->devinfo.devType);
update_value(&(device->vals), schema, attribute, cvalue, date);
{ /* send attribute to http streams */
struct json_object *jobj, *jattributes, *jattr;
{ /* send attribute to http json streams */
json_object *jobj, *jattributes, *jattr;
char uuid[37];
jobj = json_object_new_object();
......@@ -186,6 +186,9 @@ bool receive_cachedDeviceAttribute(cbor_item_t *cqueryBody, db_t *db) {
streams_json_feed(&(db->jattrreqs), jobj);
}
{ /* send attribute to http cbor streams */
streams_cbor_feed(&(db->cattrreqs), creplyBody);
}
return true;
}
......@@ -193,7 +196,7 @@ bool receive_cachedDeviceAttribute(cbor_item_t *cqueryBody, db_t *db) {
/* manage getDeviceAttributes replies from cache */
bool receive_cachedDeviceAttributes(cbor_item_t *cqueryBody, db_t *db) {
bool receive_cachedDeviceAttributes(cbor_item_t *creplyBody, db_t *db) {
cbor_item_t *cattributes, *cattribute, *cvalue, *cdate;
char *name;
uuid_t dev;
......@@ -202,10 +205,10 @@ bool receive_cachedDeviceAttributes(cbor_item_t *cqueryBody, db_t *db) {
schema_t *schema;
size_t sz, i, len;
if ( !xAAL_cbor_is_uuid(xAAL_cbor_map_get(cqueryBody, "device"), &dev) )
if ( !xAAL_cbor_is_uuid(xAAL_cbor_map_get(creplyBody, "device"), &dev) )
return false;
cattributes = xAAL_cbor_map_get(cqueryBody, "attributes");
cattributes = xAAL_cbor_map_get(creplyBody, "attributes");
if ( !cattributes || !cbor_isa_array(cattributes) )
return false;
......@@ -239,9 +242,12 @@ bool receive_cachedDeviceAttributes(cbor_item_t *cqueryBody, db_t *db) {
update_value(&(device->vals), schema, name, cvalue, date);
}
/* send attributes to http streams */
streams_json_feed(&(db->jattrreqs), xAAL_cbor2json(cqueryBody));
/* send attributes to http json streams */
streams_json_feed(&(db->jattrreqs), xAAL_cbor2json(creplyBody));
/* send attributes to http cbor streams */
streams_cbor_feed(&(db->cattrreqs), creplyBody);
return true;
}
......@@ -267,14 +273,14 @@ bool request_getExpandedSchema(const xAAL_businfo_t *bus, const xAAL_devinfo_t *
/* manage a getSchema or getExpandedSchema reply */
bool receive_schema(cbor_item_t *cqueryBody, db_t *db) {
struct json_object *jschema;
bool receive_schema(cbor_item_t *creplyBody, db_t *db) {
json_object *jschema;
struct json_tokener *tok;
enum json_tokener_error jerr;
char *schema;
size_t len;
schema = xAAL_cbor_string_dup(xAAL_cbor_map_get(cqueryBody, "schema"), &len);
schema = xAAL_cbor_string_dup(xAAL_cbor_map_get(creplyBody, "schema"), &len);
if (!schema)
return false;
......@@ -294,19 +300,19 @@ bool receive_schema(cbor_item_t *cqueryBody, db_t *db) {
/* manage a getDescription reply */
bool receive_getDescription(const uuid_t *dev, cbor_item_t *cqueryBody, db_t *db) {
bool receive_getDescription(const uuid_t *dev, cbor_item_t *creplyBody, db_t *db) {
device_t *device;
device = add_device(&(db->devices), dev);
update_description(device, cqueryBody);
update_description(device, creplyBody);
return true;
}
/* manage attributesChange notification or getAttributes reply */
bool receive_deviceAttributes(const uuid_t *dev, const char *devType, cbor_item_t *cqueryBody, db_t *db) {
struct json_object *jobj, *jattributes, *jattr;
bool receive_deviceAttributes(const uuid_t *dev, const char *devType, cbor_item_t *creplyBody, db_t *db) {
json_object *jattributes, *jattr;
char uuid[37], *attribute;
time_t now = time(NULL);
device_t *device;
......@@ -325,12 +331,12 @@ bool receive_deviceAttributes(const uuid_t *dev, const char *devType, cbor_item_
schema = add_schema(&(db->schemas), strdup(devType));
if ( !cqueryBody || !cbor_isa_map(cqueryBody) )
if ( !creplyBody || !cbor_isa_map(creplyBody) )
return true; /* no attributes !? */
jattributes = json_object_new_array();
pairs = cbor_map_handle(cqueryBody);
sz = cbor_map_size(cqueryBody);
pairs = cbor_map_handle(creplyBody);
sz = cbor_map_size(creplyBody);
for (i = 0; i < sz; i++) {
attribute = xAAL_cbor_string_dup(pairs[i].key, &len);
update_value(&(device->vals), schema, attribute, pairs[i].value, now);
......@@ -344,14 +350,22 @@ bool receive_deviceAttributes(const uuid_t *dev, const char *devType, cbor_item_
free(attribute);
}
/* send attributes to http streams */
jobj = json_object_new_object();
uuid_unparse(*dev, uuid);
json_object_object_add(jobj, "device", json_object_new_string(uuid));
json_object_object_add(jobj, "attributes", jattributes);
{ /* send attributes to http json streams */
json_object *jobj = json_object_new_object();
uuid_unparse(*dev, uuid);
json_object_object_add(jobj, "device", json_object_new_string(uuid));
json_object_object_add(jobj, "attributes", jattributes);
streams_json_feed(&(db->jattrreqs), jobj);
streams_json_feed(&(db->jattrreqs), jobj);
}
{ /* send attributes to http cbor streams */
cbor_item_t *cobj = cbor_new_definite_map(2);
cbor_map_add(cobj, (struct cbor_pair){ cbor_move(cbor_build_string("device")), cbor_move(cbor_build_bytestring(*dev, 16)) });
cbor_map_add(cobj, (struct cbor_pair){ cbor_move(cbor_build_string("attributes")), creplyBody });
streams_cbor_feed(&(db->cattrreqs), cobj);
}
return true;
}
......@@ -386,18 +400,16 @@ bool request_getCachedAttributes(const xAAL_businfo_t *bus, const xAAL_devinfo_t
}
/// ICICICI
/* Rebuild a virtual xAAL message to display from the cipherd one */
struct json_object *rebuild_json_msg(cbor_item_t *ctargets,
json_object *rebuild_json_msg(cbor_item_t *ctargets,
const uuid_t *source, char *devType,
xAAL_msgType_t msgType, char *action,
cbor_item_t *cbody) {
struct json_object *jmsg, *jheader;
json_object *jmsg, *jheader;
char uuid[37];
jheader = json_object_new_object();
// json_object_object_add(jheader, "targets", json_object_get(jtargets)); A convertir !
json_object_object_add(jheader, "targets", xAAL_cbor2json(ctargets));
uuid_unparse(*source, uuid);
json_object_object_add(jheader, "source", json_object_new_string(uuid));
json_object_object_add(jheader, "devType", json_object_new_string(devType));
......@@ -406,7 +418,7 @@ struct json_object *rebuild_json_msg(cbor_item_t *ctargets,
jmsg = json_object_new_object();
json_object_object_add(jmsg, "header", jheader);
// json_object_object_add(jmsg, "body", json_object_get(jbody)); A convertir !
json_object_object_add(jmsg, "body", xAAL_cbor2json(cbody));
return jmsg;
}
......@@ -566,7 +578,7 @@ void checking_schema(const xAAL_businfo_t *bus, const xAAL_devinfo_t *me, db_t *
}
/* send get(Device)Attributes on missing values */
/* send get(Device)Attributes to caches on missing values */
void checking_attributes(const xAAL_businfo_t *bus, const xAAL_devinfo_t *me, db_t *db) {
cbor_item_t *ctargets = cbor_new_indefinite_array();
size_t len = strlen("cache.");
......@@ -706,7 +718,6 @@ bool ws_xAAL_json_request(const xAAL_businfo_t *bus, const xAAL_devinfo_t *me, j
uuid_t uuid;
const char *action;
int sz, i;
bool ret;
if ( !json_object_object_get_ex(jinput, "targets", &jtargets)
|| !json_object_is_type(jtargets, json_type_array)
......@@ -740,7 +751,7 @@ bool ws_xAAL_json_request(const xAAL_businfo_t *bus, const xAAL_devinfo_t *me, j
/* Expect: { "targets":[<*uuid>], "action":"<string>", "body":{<object>} } */
/* Return: (json)({ "success": true|false }) */
json_object *post_xAAL_json_request(const xAAL_businfo_t *bus, const xAAL_devinfo_t *me, const char *msg, size_t len) {
struct json_object *jinput, *janswer;
json_object *jinput, *janswer;
struct json_tokener *tok;
enum json_tokener_error jerr;
......@@ -832,7 +843,7 @@ cbor_item_t *post_xAAL_cbor_request(const xAAL_businfo_t *bus, const xAAL_devinf
void streams_json_feed(reqs_t *reqs, json_object *jobj) {
req_t *req;
struct per_session_data__generic {
struct json_object *janswer;
json_object *janswer;
} *user_space;
TAILQ_FOREACH(req, reqs, entries) {
......
......@@ -42,7 +42,7 @@ void callback_checking(const xAAL_businfo_t *bus, const xAAL_devinfo_t *me, db_t
cbor_item_t *post_xAAL_cbor_request(const xAAL_businfo_t *bus, const xAAL_devinfo_t *me, const unsigned char *msg, size_t len);
/* Send an xAAL request given by the web (json) API */
struct json_object *post_xAAL_json_request(const xAAL_businfo_t *bus, const xAAL_devinfo_t *me, const char *msg, size_t len);
json_object *post_xAAL_json_request(const xAAL_businfo_t *bus, const xAAL_devinfo_t *me, const char *msg, size_t len);
/* Send an xAAL request given by the WebSocket (cbor) API */
bool ws_xAAL_cbor_request(const xAAL_businfo_t *bus, const xAAL_devinfo_t *me, cbor_item_t *cinput);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment