diff options
author | Abhishek Vijay <abhishek.v@samsung.com> | 2020-07-24 13:12:02 +0530 |
---|---|---|
committer | Abhishek Vijay <abhishek.v@samsung.com> | 2020-07-24 13:12:02 +0530 |
commit | ba82207e9397977ee54313a7ad963a8658fd7769 (patch) | |
tree | bdb80ba0d4a25a93a224c91d1332a9b66b279191 /src | |
parent | 42fcc5033bb79433bf7bacff39572a8c65078091 (diff) | |
download | batterymonitor-ba82207e9397977ee54313a7ad963a8658fd7769.tar.gz batterymonitor-ba82207e9397977ee54313a7ad963a8658fd7769.tar.bz2 batterymonitor-ba82207e9397977ee54313a7ad963a8658fd7769.zip |
[Non-ACR] add error checks, change API for battery-infosubmit/tizen/20200727.072441submit/tizen/20200724.104859accepted/tizen/unified/20200727.131952
Change-Id: I2061ff00ffcf94235295e393b8034c78d7246969
Signed-off-by: Abhishek Vijay <abhishek.v@samsung.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/battery_dump/bm_listeners.c | 125 |
1 files changed, 92 insertions, 33 deletions
diff --git a/src/battery_dump/bm_listeners.c b/src/battery_dump/bm_listeners.c index 6061d41..400e74c 100644 --- a/src/battery_dump/bm_listeners.c +++ b/src/battery_dump/bm_listeners.c @@ -39,8 +39,10 @@ struct timeval prev_event_time; display_state_e display_flag = DISPLAY_STATE_SCREEN_OFF; static int listener_hsp = -1; + static int bt_adaptor = 0; static int location_flag = 0; +/* hsp variables */ static int bt_hsp = 0; static int bt_connected_hsp = 0; static int bt_scan_hsp = 0; @@ -71,13 +73,13 @@ static int use_ptr = 0; static TapiHandle *handle = NULL; GHashTable *app_list = NULL; -#define DBUS_DEVICED "org.tizen.system.deviced" -#define DBUS_DEVICED_PATH "/Org/Tizen/System/DeviceD/Display" -#define DBUS_DEVICED_IFACE "org.tizen.system.deviced.display" -#define DBUS_DEVICED_PL_MEMBER "PowerLock" -#define DBUS_DEVICED_PU_MEMBER "PowerUnlock" -#define DBUS_DEVICED_SLEEP_MEMBER "sleep" -#define DBUS_DEVICED_WAKEUP_MEMBER "wakeup" +#define DBUS_DEVICED "org.tizen.system.deviced" +#define DBUS_DEVICED_PATH "/Org/Tizen/System/DeviceD/Display" +#define DBUS_DEVICED_IFACE "org.tizen.system.deviced.display" +#define DBUS_DEVICED_PL_MEMBER "PowerLock" +#define DBUS_DEVICED_PU_MEMBER "PowerUnlock" +#define DBUS_DEVICED_SLEEP_MEMBER "sleep" +#define DBUS_DEVICED_WAKEUP_MEMBER "wakeup" static int bd_listener_set_appId_info(char *app_id) { @@ -100,7 +102,7 @@ static int bd_listener_set_battery_info() ENTER; struct device_battery_info info; - int ret = device_battery_get_info(&info); + int ret = device_battery_get_info_direct(&info); if (ret == DEVICE_ERROR_NONE) { data_obj->battery_level = info.capacity; if (data_obj->battery_level < 0) @@ -989,10 +991,25 @@ void* bd_listener_event_consumer() { ENTER; + int error, error_flag = 0; + while (1) { - pthread_mutex_lock(&battery_lister_mutex); - while (buff_count == 0) - pthread_cond_wait(&fill, &battery_lister_mutex); + error = pthread_mutex_lock(&battery_lister_mutex); + if (error) { + _ERR("failed to get lock"); + error_flag = 1; + break; + } + + while (buff_count == 0) { + error = pthread_cond_wait(&fill, &battery_lister_mutex); + if (error) { + _ERR("failed to condition-wait"); + pthread_mutex_unlock(&battery_lister_mutex); + error_flag = 1; + break; + } + } bd_listener_create_event_data(events_buf[use_ptr].type, events_buf[use_ptr].val, events_buf[use_ptr].app); @@ -1002,24 +1019,58 @@ void* bd_listener_event_consumer() use_ptr = (use_ptr + 1) % MAX_BUFF; buff_count--; - pthread_cond_signal(&empty); - pthread_mutex_unlock(&battery_lister_mutex); + error = pthread_cond_signal(&empty); + if (error) { + _ERR("failed to condition-signal"); + pthread_mutex_unlock(&battery_lister_mutex); + error_flag = 1; + break; + } + + error = pthread_mutex_unlock(&battery_lister_mutex); + if (error) { + _ERR("failed to release lock"); + error_flag = 1; + break; + } } + + if (error_flag) { + _ERR("error in consumer thread"); + /* error mitigation needed */ + } + EXIT; + return NULL; } void* bd_listener_event_producer(void *data) { ENTER; - event_pool *event = (event_pool*) data; - if (event == NULL) + + if (data == NULL) { + _ERR("invalid input param"); return NULL; + } + + int error; - pthread_mutex_lock(&battery_lister_mutex); + event_pool *event = (event_pool*)data; - //this should be removed, conditional wait is costly - while (buff_count == MAX_BUFF) - pthread_cond_wait(&empty, &battery_lister_mutex); + error = pthread_mutex_lock(&battery_lister_mutex); + if (error) { + _ERR("failed to acquire lock"); + goto END; + } + + while (buff_count == MAX_BUFF) { + error = pthread_cond_wait(&empty, &battery_lister_mutex); + if (error) { + _ERR("failed to condition-wait"); + pthread_mutex_unlock(&battery_lister_mutex); + goto END; + } + } events_buf[fill_ptr].type = event->type; events_buf[fill_ptr].val = event->val; @@ -1031,9 +1082,22 @@ void* bd_listener_event_producer(void *data) buff_count++; - pthread_cond_signal(&fill); - pthread_mutex_unlock(&battery_lister_mutex); + error = pthread_cond_signal(&fill); + if (error) { + _ERR("failed to condition-signal"); + pthread_mutex_unlock(&battery_lister_mutex); + goto END; + } + error = pthread_mutex_unlock(&battery_lister_mutex); + if (error) { + _ERR("failed to release lock"); + goto END; + } + + _INFO("event_producer success - type[%d], val[%d]", event->type, event->val); + +END: BM_FREE(event); EXIT; @@ -1943,19 +2007,14 @@ static int bd_initialize_data_items() // Hash table initialize for application list app_list = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); - if (data_obj != NULL) { - _WARN(" History data object already exits"); - return BATTERY_MONITOR_ERROR_NONE; - } - data_obj = (history_item_s *)calloc(1, sizeof(history_item_s)); - if (data_obj) { - data_obj->state_1 = 0; - data_obj->state_2 = 0; - data_obj->event_code = ET_NONE; - data_obj->event_tag = NULL; + if (data_obj == NULL) { + data_obj = (history_item_s *)calloc(1, sizeof(history_item_s)); + if (!data_obj) { + _ERR("object creation fails"); + return BATTERY_MONITOR_ERROR_OUT_OF_MEMORY; + } } else { - _ERR(" history_item_s data object creation fails "); - return BATTERY_MONITOR_ERROR_OUT_OF_MEMORY; + _INFO("data object is available"); } if (bd_listener_set_battery_info() != DEVICE_ERROR_NONE) { |