From: Kichan Kwon Date: Fri, 11 Nov 2016 08:24:11 +0000 (+0900) Subject: Set recent value to current value when callback is added X-Git-Tag: submit/tizen/20161113.015118^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=edd4a85f8f8b9d00b2a7fa7b8ffb658d90633231;p=platform%2Fcore%2Fapi%2Fruntime-info.git Set recent value to current value when callback is added - Until now, initial recent value is NULL - Therefore, when key is changed, callback always called - It is usually correct, but we have to do exception handling - If value is set 0 -> 1, most keys are considered to be changed - But USB connection isn't changed (0,1=false, 2=true) Change-Id: If78913539a4eb8c27dad5de40413e0edd5fc24ff Signed-off-by: Kichan Kwon Signed-off-by: taeyoung --- diff --git a/src/runtime_info.c b/src/runtime_info.c index 4fc9471..237895b 100644 --- a/src/runtime_info.c +++ b/src/runtime_info.c @@ -335,6 +335,7 @@ API int runtime_info_set_changed_cb(runtime_info_key_e key, runtime_info_changed runtime_info_item_h runtime_info_item; runtime_info_func_set_event_cb set_event_cb; bool subscribe_event = false; + int ret; if (callback == NULL) { LOGE("INVALID_PARAMETER(0x%08x)", RUNTIME_INFO_ERROR_INVALID_PARAMETER); @@ -357,7 +358,7 @@ API int runtime_info_set_changed_cb(runtime_info_key_e key, runtime_info_changed subscribe_event = true; runtime_info_event_subscription_h event_subscription; - event_subscription = malloc(sizeof(runtime_info_event_subscription_s)); + event_subscription = calloc(1, sizeof(runtime_info_event_subscription_s)); if (event_subscription == NULL) { LOGE("OUT_OF_MEMORY(0x%08x)", RUNTIME_INFO_ERROR_OUT_OF_MEMORY); @@ -365,7 +366,6 @@ API int runtime_info_set_changed_cb(runtime_info_key_e key, runtime_info_changed } runtime_info_item->event_subscription = event_subscription; - runtime_info_item->event_subscription->most_recent_value = NULL; } runtime_info_item->event_subscription->changed_cb = callback; @@ -373,13 +373,35 @@ API int runtime_info_set_changed_cb(runtime_info_key_e key, runtime_info_changed if (runtime_info_item->event_subscription->most_recent_value != NULL) free(runtime_info_item->event_subscription->most_recent_value); - runtime_info_item->event_subscription->most_recent_value = NULL; - if (subscribe_event == true) - return set_event_cb(); - else + if (!subscribe_event) return RUNTIME_INFO_ERROR_NONE; + + ret = set_event_cb(); + if (ret != RUNTIME_INFO_ERROR_NONE) { + _E("Failed to set event hadler (%d)", ret); + return ret; + } + + runtime_info_item->event_subscription->most_recent_value = + calloc(1, sizeof(runtime_info_value_u)); + if (!runtime_info_item->event_subscription->most_recent_value) { + LOGE("OUT_OF_MEMORY(0x%08x)", RUNTIME_INFO_ERROR_OUT_OF_MEMORY); + runtime_info_item->unset_event_cb(); + return RUNTIME_INFO_ERROR_OUT_OF_MEMORY; + } + + ret = runtime_info_item->get_value(runtime_info_item->event_subscription->most_recent_value); + if (ret != RUNTIME_INFO_ERROR_NONE) { + LOGE("Failed to get current value (%d)", ret); + runtime_info_item->unset_event_cb(); + free(runtime_info_item->event_subscription->most_recent_value); + runtime_info_item->event_subscription->most_recent_value = NULL; + return ret; + } + + return RUNTIME_INFO_ERROR_NONE; } API int runtime_info_unset_changed_cb(runtime_info_key_e key)