int sysfs_get_int(char *path, int *val);
const char *get_string_from_object(json_object *obj, const char *key);
-const int get_int_from_object(json_object *obj, const char *key);
-const double get_double_from_object(json_object *obj, const char *key);
-const int get_boolean_from_object(json_object *obj, const char *key);
+int get_int_from_object(json_object *obj, const char *key, int *data);
+int get_double_from_object(json_object *obj, const char *key, double *data);
+int get_boolean_from_object(json_object *obj, const char *key, bool *data);
json_object *get_object_from_object(json_object *obj, const char *key);
int get_property(json_object *obj, const char *key, int type, bool mandatory,
return json_object_get_string(tmp);
}
-const int get_int_from_object(json_object *obj, const char *key)
+int get_int_from_object(json_object *obj, const char *key, int *data)
{
json_object *tmp = NULL;
if (!json_object_object_get_ex(obj, key, &tmp))
return -EINVAL;
- return json_object_get_int(tmp);
+ *data = json_object_get_int(tmp);
+
+ return 0;
}
-const double get_double_from_object(json_object *obj, const char *key)
+int get_double_from_object(json_object *obj, const char *key, double *data)
{
json_object *tmp = NULL;
if (!json_object_object_get_ex(obj, key, &tmp))
return -EINVAL;
- return json_object_get_double(tmp);
+ *data = json_object_get_double(tmp);
+
+ return 0;
}
-const int get_boolean_from_object(json_object *obj, const char *key)
+int get_boolean_from_object(json_object *obj, const char *key, bool *data)
{
json_object *tmp = NULL;
if (!json_object_object_get_ex(obj, key, &tmp))
return -EINVAL;
- return (int)json_object_get_boolean(tmp);
+ *data = json_object_get_boolean(tmp);
+
+ return 0;
}
json_object *get_object_from_object(json_object *obj, const char *key)
int type, bool mandatory, void *data)
{
int ret = 0;
- int val_int;
- double val_double;
const char *val_str;
+ bool val_bool;
switch (type) {
case DATA_TYPE_INT:
- val_int = get_int_from_object(obj, key);
- if (val_int < 0)
- ret = val_int;
- else
- *(int *)data = val_int;
+ ret = get_int_from_object(obj, key, (int *)data);
+ if (ret < 0)
+ *(int *)data = ret;
break;
case DATA_TYPE_DOUBLE:
- val_double = get_double_from_object(obj, key);
- if (val_double < 0)
- ret = -EINVAL;
- else
- *(double *)data = val_double;
- break;
+ ret = get_double_from_object(obj, key, (double *)data);
+ if (ret < 0)
+ *(double *)data = (double)ret;
case DATA_TYPE_STRING:
val_str = get_string_from_object(obj, key);
if (!val_str)
snprintf((char *)data, BUFF_MAX, "%s", val_str);
break;
case DATA_TYPE_BOOLEAN:
- val_int = get_int_from_object(obj, key);
- if (val_int < 0)
- ret = val_int;
+ ret = get_boolean_from_object(obj, key, (bool *)&val_bool);
+ if (ret < 0)
+ *(bool *)data = true;
else
- *(int *)data = val_int;
+ *(bool *)data = val_bool;
break;
default:
ret = -EINVAL;