X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Futils-json.h;h=9d495f8b391bf06021035dcc89f49165ce6e4682;hb=0257e4d58a25d328a971423d5fe5289d9985d046;hp=97783475fba11db03648f17663bea7eea2054a40;hpb=bb15844347ed0d53a795d24dce7035ab27df4e53;p=src%2Fapp-framework-main.git diff --git a/src/utils-json.h b/src/utils-json.h index 9778347..9d495f8 100644 --- a/src/utils-json.h +++ b/src/utils-json.h @@ -16,17 +16,51 @@ limitations under the License. */ -int j_object(struct json_object *obj, const char *key, struct json_object **value); -int j_string(struct json_object *obj, const char *key, const char **value); -int j_boolean(struct json_object *obj, const char *key, int *value); -int j_integer(struct json_object *obj, const char *key, int *value); +/* + * predicates on types + */ +#define j_is_string(o) (json_object_get_type(o) == json_type_string) +#define j_is_boolean(o) (json_object_get_type(o) == json_type_boolean) +#define j_is_integer(o) (json_object_get_type(o) == json_type_int) -extern const char *j_get_string(struct json_object *obj, const char *key, const char *defval); -extern int j_get_boolean(struct json_object *obj, const char *key, int defval); -extern int j_get_integer(struct json_object *obj, const char *key, int defval); +/* + * Read the value if object is of the good type and return true. + * Returns false if the type is not correct. + */ +extern int j_read_string(struct json_object *obj, const char **value); +extern int j_read_boolean(struct json_object *obj, int *value); +extern int j_read_integer(struct json_object *obj, int *value); +/* + * Get the value of the type or the default value if the type does not match. + */ +extern const char *j_string(struct json_object *obj, const char *defval); +extern int j_boolean(struct json_object *obj, int defval); +extern int j_integer(struct json_object *obj, int defval); + +/* + * Read the value of the entry of key in object if exist and of the good type and return true. + * Returns false if the key does not exist or if the type is not correct. + */ +extern int j_read_object_at(struct json_object *obj, const char *key, struct json_object **value); +extern int j_read_string_at(struct json_object *obj, const char *key, const char **value); +extern int j_read_boolean_at(struct json_object *obj, const char *key, int *value); +extern int j_read_integer_at(struct json_object *obj, const char *key, int *value); + +/* + * Get the value of the key of type or the default value if the key or type does not match. + */ +extern const char *j_string_at(struct json_object *obj, const char *key, const char *defval); +extern int j_boolean_at(struct json_object *obj, const char *key, int defval); +extern int j_integer_at(struct json_object *obj, const char *key, int defval); + +/* + * Adds a keyed value (of type) and returns true if done or false in case of error + */ extern int j_add(struct json_object *obj, const char *key, struct json_object *val); extern int j_add_string(struct json_object *obj, const char *key, const char *val); extern int j_add_boolean(struct json_object *obj, const char *key, int val); extern int j_add_integer(struct json_object *obj, const char *key, int val); +extern struct json_object *j_add_new_array(struct json_object *obj, const char *key); +extern struct json_object *j_add_new_object(struct json_object *obj, const char *key);