static gboolean _muse_msg_is_mem_ptr_valid(gpointer ptr);
static void _muse_msg_json_factory_args(json_object *jobj, va_list ap);
static json_object *_muse_msg_json_find_obj(json_object *jobj, const char *find_key);
+static gboolean _muse_msg_json_get_obj_value(json_object *obj, muse_core_msg_type_e m_type, void *data);
static int _muse_get_valid_fd_count(int *fds)
{
return NULL;
}
+static gboolean _muse_msg_json_get_obj_value(json_object *obj, muse_core_msg_type_e m_type, void *data)
+{
+ int j_type, idx, len;
+ int *int_data;
+
+ muse_return_val_if_fail(obj, FALSE);
+ muse_return_val_if_fail(data, FALSE);
+
+ j_type = json_object_get_type(obj);
+ switch (j_type) {
+ case json_type_null:
+ LOGD("json_type_null");
+ break;
+ case json_type_double:
+ *(double *)data = json_object_get_double(obj);
+ break;
+ case json_type_int:
+ if (m_type == MUSE_TYPE_ANY || m_type == MUSE_TYPE_INT) {
+ *(int32_t *)data = json_object_get_int(obj);
+ } else if (m_type == MUSE_TYPE_INT64) {
+ *(int64_t *)data = json_object_get_int64(obj);
+ } else if (m_type == MUSE_TYPE_POINTER) {
+ if (!_muse_msg_is_mem_ptr_valid(obj)) {
+ LOGE("memory pointer is not valid");
+ return FALSE;
+ }
+ if (sizeof(intptr_t) == 8)
+ *(intptr_t *)data = json_object_get_int64(obj);
+ else
+ *(intptr_t *)data = json_object_get_int(obj);
+ } else if (m_type == MUSE_TYPE_DOUBLE) {
+ *(double *)data = json_object_get_double(obj);
+ }
+ break;
+ case json_type_object:
+ break;
+ case json_type_string:
+ strncpy((char *)data, json_object_get_string(obj), strlen(json_object_get_string(obj)));
+ break;
+ case json_type_array:
+ int_data = (int *)data;
+ len = json_object_array_length(obj);
+ for (idx = 0; idx < len; idx++)
+ int_data[idx] = json_object_get_int(json_object_array_get_idx(obj, idx));
+ break;
+ default:
+ LOGE("The value (%d) of json type is invalid", j_type);
+ break;
+ }
+
+ return TRUE;
+}
+
void muse_core_log_cmd_info(char *cmd)
{
FILE *fp;
bool muse_core_msg_deserialize(const char *key, char *buf, int *parse_len, muse_core_msg_parse_err_e *err, muse_core_msg_type_e m_type, void *data)
{
- int j_type, idx, len;
- int *int_data;
- json_object *val = NULL, *jobj = NULL;
+ json_object *obj = NULL, *jobj = NULL;
+ bool ret = false;
muse_return_val_if_fail(key, false);
muse_return_val_if_fail(buf, false);
jobj = _muse_msg_json_tokener_parse_len(buf, parse_len, err);
if (!jobj) {
LOGE("jobj is NULL");
- goto out;
+ g_mutex_unlock(&msg_lock);
+ return false;
}
- val = _muse_msg_json_find_obj(jobj, key);
- if (!val) {
+ obj = _muse_msg_json_find_obj(jobj, key);
+ if (!obj) {
LOGE("\"%s\" key is not founded", key);
- goto out;
+ json_object_put(jobj);
+ g_mutex_unlock(&msg_lock);
+ return false;
}
- j_type = json_object_get_type(val);
- switch (j_type) {
- case json_type_null:
- LOGD("json_type_null");
- break;
- case json_type_boolean:
- LOGD("json_type_boolean (%s) value: %d", key, json_object_get_boolean(val));
- break;
- case json_type_double:
- *(double *)data = json_object_get_double(val);
- break;
- case json_type_int:
- if (m_type == MUSE_TYPE_ANY || m_type == MUSE_TYPE_INT) {
- *(int32_t *)data = json_object_get_int(val);
- } else if (m_type == MUSE_TYPE_INT64) {
- *(int64_t *)data = json_object_get_int64(val);
- } else if (m_type == MUSE_TYPE_POINTER) {
- if (!_muse_msg_is_mem_ptr_valid(val)) {
- LOGE("memory pointer is not valid");
- goto out;
- }
- if (sizeof(intptr_t) == 8)
- *(intptr_t *)data = json_object_get_int64(val);
- else
- *(intptr_t *)data = json_object_get_int(val);
- } else if (m_type == MUSE_TYPE_DOUBLE) {
- *(double *)data = json_object_get_double(val);
- }
- break;
- case json_type_object:
- break;
- case json_type_string:
- strncpy((char *)data, json_object_get_string(val), strlen(json_object_get_string(val)));
- break;
- case json_type_array:
- int_data = (int *)data;
- len = json_object_array_length(val);
- for (idx = 0; idx < len; idx++)
- int_data[idx] = json_object_get_int(json_object_array_get_idx(val, idx));
- break;
- default:
- LOGE("The value (%d) of json type is invalid", j_type);
- break;
- }
+ ret = (bool)_muse_msg_json_get_obj_value(obj, m_type, data);
json_object_put(jobj);
g_mutex_unlock(&msg_lock);
- return true;
-
-out:
- if (jobj)
- json_object_put(jobj);
-
- g_mutex_unlock(&msg_lock);
-
- return false;
+ return ret;
}
void muse_core_msg_free(char *msg)
bool muse_core_msg_object_get_value(const char *key, void *jobj, muse_core_msg_type_e m_type, void *data)
{
- int j_type, idx, len;
- int *int_data;
- json_object *val;
+ json_object *obj;
+ bool ret = false;
muse_return_val_if_fail(key, false);
muse_return_val_if_fail(jobj, false);
g_mutex_lock(&msg_lock);
- val = _muse_msg_json_find_obj((json_object *)jobj, key);
- if (!val) {
+ obj = _muse_msg_json_find_obj((json_object *)jobj, key);
+ if (!obj) {
LOGE("\"%s\" key is not found", key);
- goto out;
- }
-
- j_type = json_object_get_type(val);
- switch (j_type) {
- case json_type_null:
- LOGD("json_type_null");
- break;
- case json_type_boolean:
- LOGD("json_type_boolean (%s) value: %d", key, json_object_get_boolean(val));
- break;
- case json_type_double:
- *(double *)data = json_object_get_double(val);
- break;
- case json_type_int:
- if (m_type == MUSE_TYPE_ANY || m_type == MUSE_TYPE_INT) {
- *(int32_t *)data = json_object_get_int(val);
- } else if (m_type == MUSE_TYPE_INT64) {
- *(int64_t *)data = json_object_get_int64(val);
- } else if (m_type == MUSE_TYPE_POINTER) {
- if (!_muse_msg_is_mem_ptr_valid(val)) {
- LOGE("memory pointer is not valid");
- goto out;
- }
- if (sizeof(intptr_t) == 8)
- *(intptr_t *)data = json_object_get_int64(val);
- else
- *(intptr_t *)data = json_object_get_int(val);
- } else if (m_type == MUSE_TYPE_DOUBLE) {
- *(double *)data = json_object_get_double(val);
- }
- break;
- case json_type_object:
- break;
- case json_type_string:
- strncpy((char *)data, json_object_get_string(val), strlen(json_object_get_string(val)));
- break;
- case json_type_array:
- int_data = (int *)data;
- len = json_object_array_length(val);
- for (idx = 0; idx < len; idx++)
- int_data[idx] = json_object_get_int(json_object_array_get_idx(val, idx));
- break;
- default:
- LOGE("The value (%d) of json type is invalid", j_type);
- break;
+ g_mutex_unlock(&msg_lock);
+ return false;
}
- g_mutex_unlock(&msg_lock);
+ ret = (bool)_muse_msg_json_get_obj_value(obj, m_type, data);
- return true;
-
-out:
g_mutex_unlock(&msg_lock);
- return false;
+ return ret;
}
void muse_core_msg_object_free(void *jobj)