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);
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);
}
runtime_info_item->event_subscription = event_subscription;
- runtime_info_item->event_subscription->most_recent_value = NULL;
}
runtime_info_item->event_subscription->changed_cb = callback;
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)