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;
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)
{
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)
{
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);
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;
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;
// 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) {