runtime-info: added process Memory and CPU usage APIs
[platform/core/api/runtime-info.git] / src / runtime_info_vconf.c
index f2db3ef..e9c8e38 100644 (file)
 
 #define LOG_TAG "CAPI_SYSTEM_RUNTIME_INFO"
 
+#define CHECK_VCONF_RESULT(ret) \
+       do { \
+               if (ret < 0) { \
+                       ret = vconf_get_ext_errno(); \
+                       if (ret == VCONF_ERROR_FILE_NO_ENT) \
+                               ret = RUNTIME_INFO_ERROR_NOT_SUPPORTED; \
+                       else \
+                               ret = RUNTIME_INFO_ERROR_IO_ERROR; \
+               } else { \
+                       ret = RUNTIME_INFO_ERROR_NONE; \
+               } \
+       } while (0);
+
 int runtime_info_vconf_get_value_int(const char *vconf_key, int *value)
 {
-       return vconf_get_int(vconf_key, value);
+       int ret = vconf_get_int(vconf_key, value);
+       CHECK_VCONF_RESULT(ret);
+       return ret;
 }
 
-int runtime_info_vconf_get_value_bool(const char *vconf_key, bool *value)
+int runtime_info_vconf_get_value_bool(const char *vconf_key, int *value)
 {
-       return vconf_get_bool(vconf_key, (int *)value);
+       int ret = vconf_get_bool(vconf_key, value);
+       CHECK_VCONF_RESULT(ret);
+       return ret;
 }
 
 int runtime_info_vconf_get_value_double(const char *vconf_key, double *value)
 {
-       return vconf_get_dbl(vconf_key, value);
+       int ret = vconf_get_dbl(vconf_key, value);
+       CHECK_VCONF_RESULT(ret);
+       return ret;
 }
 
 int runtime_info_vconf_get_value_string(const char *vconf_key, char **value)
 {
        char *str_value = NULL;
+       int ret;
 
        str_value = vconf_get_str(vconf_key);
-
-       if (str_value != NULL) {
-               *value = str_value;
-               return 0;
-       } else {
-               return -1;
+       if (!str_value) {
+               ret = -1;
+               CHECK_VCONF_RESULT(ret);
+               return ret;
        }
+
+       *value = str_value;
+       return RUNTIME_INFO_ERROR_NONE;
 }
 
 typedef void (*runtime_info_vconf_event_cb)(keynode_t *node, void *event_data);
@@ -117,16 +138,16 @@ static runtime_info_vconf_event_cb runtime_info_vconf_get_event_cb_slot(int slot
 int runtime_info_vconf_set_event_cb(const char *vconf_key, runtime_info_key_e runtime_info_key, int slot)
 {
        runtime_info_vconf_event_cb vconf_event_cb;
+       int ret;
 
        vconf_event_cb = runtime_info_vconf_get_event_cb_slot(slot);
 
        if (vconf_event_cb == NULL)
                return RUNTIME_INFO_ERROR_IO_ERROR;
 
-       if (vconf_notify_key_changed(vconf_key, vconf_event_cb, (void *)runtime_info_key))
-               return RUNTIME_INFO_ERROR_IO_ERROR;
-
-       return RUNTIME_INFO_ERROR_NONE;
+       ret = vconf_notify_key_changed(vconf_key, vconf_event_cb, (void *)runtime_info_key);
+       CHECK_VCONF_RESULT(ret);
+       return ret;
 }
 
 void runtime_info_vconf_unset_event_cb(const char *vconf_key, int slot)