* @retval #BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND Record Not found
* @retval #BATTERY_MONITOR_ERROR_INTERNAL Internal Error
*/
-int battery_monitor_get_usage_by_app_id_for_all_resource_id(char *app_id, battery_monitor_duration_type_e duration, battery_monitor_h handle);
+int battery_monitor_get_usage_by_app_id_for_all_resource_id(char *app_id, battery_monitor_duration_type_e duration, battery_monitor_h *handle);
/**
* @brief Gets the battery-percent by an app-id for a specific resource.
* @brief Structure for total battery consumption
* @since_tizen 5.5
*/
-struct battery_monitor_total_consumption_s {
+typedef struct _battery_monitor_total_consumption_s {
int ble_val; /**< Battery consumption by BLE(Bluetooth Low Energy) */
int wifi_val; /**< Battery consumption by Wi-Fi */
int cpu_val; /**< Battery consumption by CPU */
int gps_val; /**< Battery consumption by GPS */
int hrm_val; /**< Battery consumption by HRM(Heart Rate Monitor) sensor */
int bat_val; /**< Total battery consumption/ Change in battery level */
-};
+} battery_monitor_total_consumption_s;
#ifdef __cplusplus
int battery_monitor_get_error_code(bool is_success, GError *error);
-void unmarshal_serialized_data(GVariant *handle, battery_monitor_h data_handle);
+void unmarshal_serialized_data(GVariant *handle, battery_monitor_total_consumption_s *data_handle);
#ifdef __cplusplus
}
BM_CHECK_INPUT_PARAM(handle);
- battery_monitor_h data_handle = (battery_monitor_h)calloc(1, sizeof(struct battery_monitor_total_consumption_s));
+ battery_monitor_total_consumption_s *data_handle = \
+ (battery_monitor_total_consumption_s *)calloc(1, sizeof(battery_monitor_total_consumption_s));
- if (data_handle == NULL) {
- _ERR("Memory Allocation Failed");
- return BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
- }
+ BM_RETURN_VAL((data_handle != NULL), {}, BATTERY_MONITOR_ERROR_OUT_OF_MEMORY, "memory allocation failed");
data_handle->ble_val = 0;
data_handle->wifi_val = 0;
data_handle->hrm_val = 0;
data_handle->bat_val = 0;
- *handle = data_handle;
+ *handle = (battery_monitor_h)data_handle;
EXIT;
return BATTERY_MONITOR_ERROR_NONE;
return BATTERY_MONITOR_ERROR_INVALID_PARAMETER;
}
+ battery_monitor_total_consumption_s *data_handle = \
+ (battery_monitor_total_consumption_s *)handle;
+
switch (resource_id) {
case BATTERY_MONITOR_RESOURCE_ID_BLE:
- *battery_usage = handle->ble_val;
+ *battery_usage = data_handle->ble_val;
break;
case BATTERY_MONITOR_RESOURCE_ID_WIFI:
- *battery_usage = handle->wifi_val;
+ *battery_usage = data_handle->wifi_val;
break;
case BATTERY_MONITOR_RESOURCE_ID_CPU:
- *battery_usage = handle->cpu_val;
+ *battery_usage = data_handle->cpu_val;
break;
case BATTERY_MONITOR_RESOURCE_ID_DISPLAY:
- *battery_usage = handle->dp_val;
+ *battery_usage = data_handle->dp_val;
break;
case BATTERY_MONITOR_RESOURCE_ID_DEVICE_NETWORK:
- *battery_usage = handle->dn_val;
+ *battery_usage = data_handle->dn_val;
break;
case BATTERY_MONITOR_RESOURCE_ID_GPS_SENSOR:
- *battery_usage = handle->gps_val;
+ *battery_usage = data_handle->gps_val;
break;
case BATTERY_MONITOR_RESOURCE_ID_HRM_SENSOR:
- *battery_usage = handle->hrm_val;
+ *battery_usage = data_handle->hrm_val;
break;
case BATTERY_MONITOR_RESOURCE_ID_BATTERY:
- *battery_usage = handle->bat_val;
+ *battery_usage = data_handle->bat_val;
break;
default:
break;
return BATTERY_MONITOR_ERROR_NONE;
}
-BM_API int battery_monitor_get_usage_by_app_id_for_all_resource_id(char* app_id, battery_monitor_duration_type_e duration, battery_monitor_h handle)
+BM_API int battery_monitor_get_usage_by_app_id_for_all_resource_id(char* app_id, battery_monitor_duration_type_e duration, battery_monitor_h *handle)
{
ENTER;
CHECK_BATTERY_FEATURE_SUPPORTED(BATTERY_FEATURE);
BM_CHECK_INPUT_PARAM(app_id);
- BM_CHECK_INPUT_PARAM(handle);
+ BM_CHECK_INPUT_PARAM(*handle);
BM_RETURN_VAL((duration < BATTERY_MONITOR_DURATION_TYPE_MAX), {}, BATTERY_MONITOR_ERROR_INVALID_PARAMETER, "invalid duration");
_INFO("total consumption requested for [%s] for duration [%d]", app_id, duration);
BM_CATCH_ERROR((is_success != false), {}, battery_monitor_get_error_code(is_success, error), "Failed to get dbus.");
g_clear_error(&error);
- battery_monitor_h resource_handle = handle;
+ battery_monitor_total_consumption_s *data_handle = \
+ (battery_monitor_total_consumption_s *)calloc(1, sizeof(battery_monitor_total_consumption_s));
+
+ BM_RETURN_VAL((data_handle != NULL), {}, BATTERY_MONITOR_ERROR_OUT_OF_MEMORY, "memory allocation failed");
_INFO("before un-marshal data");
- unmarshal_serialized_data(handle_variant, resource_handle);
+ unmarshal_serialized_data(handle_variant, data_handle);
g_variant_unref(handle_variant);
_INFO("after un-marshal data");
+ *handle = (battery_monitor_h)data_handle;
+
_INFO("battery_get_usage_by_app_id_for_all_resource_id() - SUCCESS");
EXIT;
return BATTERY_MONITOR_ERROR_NONE;
}
-void unmarshal_serialized_data(GVariant *handle, battery_monitor_h data_handle)
+void unmarshal_serialized_data(GVariant *handle, battery_monitor_total_consumption_s *data_handle)
{
ENTER;
if (!handle) {
- _ERR("null handle received");
+ _ERR("invalid variant handle");
+ return;
+ }
+
+ if (!data_handle) {
+ _ERR("invalid data handle");
return;
}
gchar *key = NULL;
GVariant *value = NULL;
- battery_monitor_h data = data_handle;
+ battery_monitor_total_consumption_s *data = data_handle;
while (g_variant_iter_loop(&iter, "{sv}", &key, &value)) {
if (g_strcmp0(key, BATTERY_MONITOR_BLE_DATA_ID) == 0) {
battery_monitor_h data_handle = NULL;
- error_code = battery_monitor_create(&data_handle);
- if (error_code != BATTERY_MONITOR_ERROR_NONE) {
- testapp_print(" \n Memory Allocation failed \n");
- return FALSE;
- }
-
testapp_print("\n Input AppID using Look Up table:\n");
if (0 >= scanf("%s", app_name)) {
testapp_print("Invalid input ");
return FALSE;
}
- error_code = battery_monitor_get_usage_by_app_id_for_all_resource_id(app_name, duration, data_handle);
+ error_code = battery_monitor_get_usage_by_app_id_for_all_resource_id(app_name, duration, &data_handle);
if (error_code == BATTERY_MONITOR_ERROR_NONE) {
testapp_print ("Valid Handle Received, Value of error_code is [%d] \n", error_code);
battery_usage = -1;
error_code = battery_monitor_get_usage_for_resource_id(data_handle, id, &battery_usage);
- if (error_code != BATTERY_MONITOR_ERROR_NONE)
+ if (error_code != BATTERY_MONITOR_ERROR_NONE) {
testapp_print ("Error Received, Value of error_code is [%d] \n", error_code);
+ continue;
+ }
- else {
- switch (id) {
- case BATTERY_MONITOR_RESOURCE_ID_BLE:
- testapp_print ("Resource ID : BT App Usage Value = [%d] \n", battery_usage);
- break;
- case BATTERY_MONITOR_RESOURCE_ID_WIFI:
- testapp_print ("Resource ID : WIFI App Usage Value = [%d] \n", battery_usage);
- break;
- case BATTERY_MONITOR_RESOURCE_ID_CPU:
- testapp_print ("Resource ID : CPU App Usage Value = [%d] \n", battery_usage);
- break;
- case BATTERY_MONITOR_RESOURCE_ID_DISPLAY:
- testapp_print ("Resource ID : DISPLAY App Usage Value = [%d] \n", battery_usage);
- break;
- case BATTERY_MONITOR_RESOURCE_ID_DEVICE_NETWORK:
- testapp_print ("Resource ID : DEVICE NETWORK App Usage Value = [%d] \n", battery_usage);
- break;
- case BATTERY_MONITOR_RESOURCE_ID_GPS_SENSOR:
- testapp_print ("Resource ID : GPS App Usage Value = [%d] \n", battery_usage);
- break;
- case BATTERY_MONITOR_RESOURCE_ID_HRM_SENSOR:
- testapp_print ("Resource ID : HRM App Usage Value = [%d] \n", battery_usage);
- break;
-
- default:
- break;
- }
+ switch (id) {
+ case BATTERY_MONITOR_RESOURCE_ID_BLE:
+ testapp_print ("Resource ID : BT App Usage Value = [%d] \n", battery_usage);
+ break;
+ case BATTERY_MONITOR_RESOURCE_ID_WIFI:
+ testapp_print ("Resource ID : WIFI App Usage Value = [%d] \n", battery_usage);
+ break;
+ case BATTERY_MONITOR_RESOURCE_ID_CPU:
+ testapp_print ("Resource ID : CPU App Usage Value = [%d] \n", battery_usage);
+ break;
+ case BATTERY_MONITOR_RESOURCE_ID_DISPLAY:
+ testapp_print ("Resource ID : DISPLAY App Usage Value = [%d] \n", battery_usage);
+ break;
+ case BATTERY_MONITOR_RESOURCE_ID_DEVICE_NETWORK:
+ testapp_print ("Resource ID : DEVICE NETWORK App Usage Value = [%d] \n", battery_usage);
+ break;
+ case BATTERY_MONITOR_RESOURCE_ID_GPS_SENSOR:
+ testapp_print ("Resource ID : GPS App Usage Value = [%d] \n", battery_usage);
+ break;
+ case BATTERY_MONITOR_RESOURCE_ID_HRM_SENSOR:
+ testapp_print ("Resource ID : HRM App Usage Value = [%d] \n", battery_usage);
+ break;
+ default:
+ break;
}
}
}