static int battery_monitor_check_time_interval(time_t *start_time, time_t *end_time)
{
ENTER;
+
+ BM_CHECK_INPUT_PARAM(start_time);
+ BM_CHECK_INPUT_PARAM(end_time);
+
time_t now;
+ /* get current time */
time(&now);
if (now == -1) {
_ERR("Time failed");
}
_DBG("current time [%ld]", now);
+
if (*start_time >= 0 && *start_time < *end_time) {
if ((*start_time >= (now - tmin)) && (*end_time <= now))
_INFO("Time Checked");
return BATTERY_MONITOR_ERROR_NONE;
}
-BM_API int battery_monitor_usage_data_get_power_usage_per_resource(battery_usage_data_h result, battery_monitor_resource_id_e resource, double *usage)
+BM_API int battery_monitor_usage_data_get_power_usage_per_resource(battery_usage_data_h result,
+ battery_monitor_resource_id_e resource, double *usage)
{
ENTER;
_ERR("Unknown resource id specified");
return BATTERY_MONITOR_ERROR_INVALID_PARAMETER;
}
+
int error_code = BATTERY_MONITOR_ERROR_NONE;
+
error_code = battery_monitor_resource_id_is_supported(resource);
if (error_code != BATTERY_MONITOR_ERROR_NONE) {
_ERR("Not Supported Resource ID");
return BATTERY_MONITOR_ERROR_NONE;
}
-BM_API int battery_monitor_get_power_usage_by_app_for_all_resources(const char* appid, time_t from, time_t to, battery_usage_data_h *result)
+BM_API int battery_monitor_get_power_usage_by_app_for_all_resources(const char* appid,
+ time_t from, time_t to, battery_usage_data_h *result)
{
ENTER;
+
CHECK_BATTERY_FEATURE_SUPPORTED(BATTERY_FEATURE);
+
BM_CHECK_INPUT_PARAM(appid);
BM_CHECK_INPUT_PARAM(result);
- int error_code = BATTERY_MONITOR_ERROR_NONE;
- error_code = battery_monitor_check_time_interval(&from, &to);
+ int error_code = battery_monitor_check_time_interval(&from, &to);
if (error_code != BATTERY_MONITOR_ERROR_NONE) {
_ERR("Invalid Time Interval: Invalid Params");
return BATTERY_MONITOR_ERROR_INVALID_PARAMETER;
}
- long long int start_time = from; long long int end_time = to;
- _INFO("Consumption requested for [%s] for start_time(s) [%lld] and end_time(s) [%lld]", appid, start_time, end_time);
+ long long int start_time = from, end_time = to;
+
+ _INFO("Consumption requested for [%s] for start_time(s) [%lld] and end_time(s) [%lld]", \
+ appid, start_time, end_time);
+
GError *error = NULL;
bm_server = battery_monitor_get_instance();
+
BM_CATCH_ERROR((bm_server != NULL), {}, BATTERY_MONITOR_ERROR_PERMISSION_DENIED, "Failed to get dbus.");
GVariant *handle_variant = NULL;
_INFO("before IPC call - get_usage_handle_by_app_id_for_all_resource_id_custom_interval_sync()");
- bool is_success = battery_monitor_call_get_usage_handle_by_app_id_for_all_resource_id_custom_interval_sync(bm_server, appid, start_time, end_time,
- (int)getuid(), &handle_variant, NULL, &error);
+
+ bool is_success = \
+ battery_monitor_call_get_usage_handle_by_app_id_for_all_resource_id_custom_interval_sync(bm_server, \
+ appid, start_time, end_time, (int)getuid(), &handle_variant, NULL, &error);
battery_monitor_release_instance();
+
_INFO("after IPC call - get_usage_handle_by_app_id_for_all_resource_id_custom_interval_sync()");
BM_CATCH_ERROR((is_success != false), {}, battery_monitor_get_error_code(is_success, error), "Failed to get dbus.");
+
g_clear_error(&error);
+
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, data_handle);
+
g_variant_unref(handle_variant);
_INFO("after un-marshal data");
return error_code;
}
-BM_API int battery_monitor_get_power_usage_by_app_per_resource(const char* appid, battery_monitor_resource_id_e resource,
- time_t from, time_t to, double *usage)
+BM_API int battery_monitor_get_power_usage_by_app_per_resource(const char* appid,
+ battery_monitor_resource_id_e resource, time_t from, time_t to, double *usage)
{
ENTER;
return BATTERY_MONITOR_ERROR_INVALID_PARAMETER;
}
- int error_code = BATTERY_MONITOR_ERROR_NONE;
- error_code = battery_monitor_resource_id_is_supported(resource);
+ int error_code = battery_monitor_resource_id_is_supported(resource);
if (error_code != BATTERY_MONITOR_ERROR_NONE) {
_ERR("Not Supported Resource ID");
return BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND;
return BATTERY_MONITOR_ERROR_INVALID_PARAMETER;
}
- long long int start_time = from; long long int end_time = to;
+ long long int start_time = from, end_time = to;
double battery_consumption = 0;
GError *error = NULL;
- _INFO("Consumption requested for [%s], resource_id(%d) for start_time(s) [%lld] and end_time(s) [%lld]", appid, resource, start_time, end_time);
+ _INFO("Consumption requested for [%s], \
+ resource_id(%d) for start_time(s) [%lld] and end_time(s) [%lld]", \
+ appid, resource, start_time, end_time);
+
bm_server = battery_monitor_get_instance();
+
BM_CATCH_ERROR((bm_server != NULL), {}, BATTERY_MONITOR_ERROR_PERMISSION_DENIED, "Failed to get dbus.");
- _INFO("before IPC call - app_id(%s), resource_id(%d), start_time(%lld), end_time(%lld)", appid, resource, start_time, end_time);
+ _INFO("before IPC call - app_id(%s), \
+ resource_id(%d), start_time(%lld), end_time(%lld)", \
+ appid, resource, start_time, end_time);
- bool is_success = battery_monitor_call_get_mah_usage_by_app_id_for_resource_id_custom_interval_sync(bm_server, appid, resource,
+ bool is_success = \
+ battery_monitor_call_get_mah_usage_by_app_id_for_resource_id_custom_interval_sync(bm_server, appid, resource,
start_time, end_time, (int)getuid(), &battery_consumption, NULL, &error);
battery_monitor_release_instance();
BM_CHECK_INPUT_PARAM(appid);
BM_CHECK_INPUT_PARAM(usage);
- int error_code = BATTERY_MONITOR_ERROR_NONE;
- error_code = battery_monitor_check_time_interval(&from, &to);
+ int error_code = battery_monitor_check_time_interval(&from, &to);
if (error_code != BATTERY_MONITOR_ERROR_NONE) {
_ERR("Invalid Time Interval: Invalid Params");
return BATTERY_MONITOR_ERROR_INVALID_PARAMETER;
}
- long long int start_time = from; long long int end_time = to;
+ long long int start_time = from, end_time = to;
double battery_consumption = 0;
GError *error = NULL;
_INFO("Consumption requested for app_id [%s] for start_time(s) [%lld] and end_time(s) [%lld]", appid, start_time, end_time);
+
bm_server = battery_monitor_get_instance();
+
BM_CATCH_ERROR((bm_server != NULL), {}, BATTERY_MONITOR_ERROR_PERMISSION_DENIED, "Failed to get dbus.");
_INFO("before IPC call - app_id(%s), start_time (%lld), end_time (%lld)", appid, start_time, end_time);
- bool is_success = battery_monitor_call_get_total_mah_usage_by_app_id_custom_interval_sync(bm_server, appid, start_time, end_time,
- (int)getuid(), &battery_consumption, NULL, &error);
+ bool is_success = \
+ battery_monitor_call_get_total_mah_usage_by_app_id_custom_interval_sync(bm_server, \
+ appid, start_time, end_time, (int)getuid(), &battery_consumption, NULL, &error);
battery_monitor_release_instance();
return BATTERY_MONITOR_ERROR_INVALID_PARAMETER;
}
- int error_code = BATTERY_MONITOR_ERROR_NONE;
- error_code = battery_monitor_resource_id_is_supported(resource);
+ int error_code = battery_monitor_resource_id_is_supported(resource);
if (error_code != BATTERY_MONITOR_ERROR_NONE) {
_ERR("Not Supported Resource ID");
return BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND;
return BATTERY_MONITOR_ERROR_INVALID_PARAMETER;
}
- long long int start_time = from; long long int end_time = to;
+ long long int start_time = from, end_time = to;
double battery_consumption = 0;
GError *error = NULL;
- _INFO("Consumption requested for resource_id [%d] for start_time(s) [%lld] and end_time(s) [%lld]", resource, start_time, end_time);
+ _INFO("Consumption requested for resource_id [%d] for start_time(s) [%lld] and end_time(s) [%lld]", \
+ resource, start_time, end_time);
+
bm_server = battery_monitor_get_instance();
BM_CATCH_ERROR((bm_server != NULL), {}, BATTERY_MONITOR_ERROR_PERMISSION_DENIED, "Failed to get dbus.");
_INFO("before IPC call - resource_id(%d), start_time (%lld), end_time (%lld)", resource, start_time, end_time);
- bool is_success = battery_monitor_call_get_total_mah_usage_by_resource_id_custom_interval_sync(bm_server, resource, start_time,
- end_time, (int)getuid(), &battery_consumption, NULL, &error);
+ bool is_success = \
+ battery_monitor_call_get_total_mah_usage_by_resource_id_custom_interval_sync(bm_server,
+ resource, start_time, end_time, (int)getuid(), &battery_consumption, NULL, &error);
battery_monitor_release_instance();