X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=bt-api%2Fbt-adapter.c;h=fc41fa206a54f80c7728a8967794f19bb2eaed04;hb=a0e93a330aa0362824aa37ab8aebd20a3127a434;hp=feeb85d22432fb4df1fbc16ee3fedbfc75d498a4;hpb=773c4135ce77260742d32ad1f063f2bc732f2240;p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git diff --git a/bt-api/bt-adapter.c b/bt-api/bt-adapter.c index feeb85d..fc41fa2 100644 --- a/bt-api/bt-adapter.c +++ b/bt-api/bt-adapter.c @@ -24,6 +24,20 @@ #include "bt-request-sender.h" #include "bt-event-handler.h" +/* Avoid the build error related to vconf.h's dependency */ +#ifndef VCONFKEY_BATTERY_MONITOR_STATUS +#define VCONFKEY_BATTERY_MONITOR_STATUS "db/bluetooth/bmstatus" +#endif + + +typedef enum { + BT_MONITOR_NONE = -1, + BT_MONITOR_OFF = 0, + BT_MONITOR_ON = 1, +} bt_battery_monitor_state_t; + +static int battery_monitor_state = BT_MONITOR_NONE; + static int __bt_fill_device_list(GArray *out_param2, GPtrArray **dev_list) { int i; @@ -85,6 +99,7 @@ BT_EXPORT_API int bluetooth_enable_adapter(void) int result; BT_INFO_C("### Enable adapter"); + _bt_print_api_caller_name(); retv_if(bluetooth_check_adapter() == BLUETOOTH_ADAPTER_ENABLED, BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED); @@ -104,10 +119,71 @@ BT_EXPORT_API int bluetooth_enable_adapter(void) return result; } +BT_EXPORT_API int bluetooth_set_battery_monitor_state(bool state) +{ + if (vconf_set_bool(VCONFKEY_BATTERY_MONITOR_STATUS, state) != 0) + { + BT_ERR("vconf_set_bool failed"); + return BLUETOOTH_ERROR_INTERNAL; + } + + battery_monitor_state = (state == false) ? BT_MONITOR_OFF : BT_MONITOR_ON; + + return BLUETOOTH_ERROR_NONE; +} + +static void __bt_battery_monitor_status_changed_cb(keynode_t *node, void *data) +{ + gboolean status = FALSE; + int type; + + type = vconf_keynode_get_type(node); + if (type == VCONF_TYPE_BOOL) { + status = vconf_keynode_get_bool(node); + + BT_DBG("Update the monitor state to %d", status); + + battery_monitor_state = (status == FALSE) ? BT_MONITOR_OFF : BT_MONITOR_ON; + } else { + BT_ERR("Invaild vconf key type : %d", type); + return; + } +} + +void _bt_reset_battery_monitor_info(void) +{ + vconf_ignore_key_changed(VCONFKEY_BATTERY_MONITOR_STATUS, + (vconf_callback_fn)__bt_battery_monitor_status_changed_cb); + + _bt_rfcomm_server_reset_timer(); + _bt_rfcomm_client_reset_timer(); + + battery_monitor_state = BT_MONITOR_NONE; +} + +BT_EXPORT_API int bluetooth_get_battery_monitor_state() +{ + int state = 0; + + if (battery_monitor_state != BT_MONITOR_NONE) + return battery_monitor_state; + + if (vconf_get_bool(VCONFKEY_BATTERY_MONITOR_STATUS, &state) != 0) + BT_ERR("vconf_get_bool failed"); + + battery_monitor_state = state; + + if (vconf_notify_key_changed(VCONFKEY_BATTERY_MONITOR_STATUS, + (vconf_callback_fn)__bt_battery_monitor_status_changed_cb, NULL) < 0) + BT_ERR("Unable to register key handler"); + + return state; +} + BT_EXPORT_API int bluetooth_read_battery_data(bt_battery_data *data) { int result; - bt_battery_data *info = NULL; + bt_battery_dbus_data_t *info = NULL; BT_CHECK_PARAMETER(data, return); @@ -115,6 +191,9 @@ BT_EXPORT_API int bluetooth_read_battery_data(bt_battery_data *data) retv_if(bluetooth_check_adapter() != BLUETOOTH_ADAPTER_ENABLED, BLUETOOTH_ADAPTER_DISABLED); + retv_if(bluetooth_get_battery_monitor_state() == FALSE, + BLUETOOTH_ERROR_NOT_SUPPORT); + #ifdef TIZEN_FEATURE_BT_DPM retv_if(bluetooth_dpm_is_mode_allowed() == BLUETOOTH_ERROR_PERMISSION_DEINED, BLUETOOTH_ERROR_PERMISSION_DEINED); @@ -128,11 +207,11 @@ BT_EXPORT_API int bluetooth_read_battery_data(bt_battery_data *data) if (result != BLUETOOTH_ERROR_NONE) { BT_ERR("Error encountered"); + BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); return result; } - BT_DBG("Received data from bt-service-adaptation"); - info = &g_array_index(out_param, bt_battery_data, 0); + info = &g_array_index(out_param, bt_battery_dbus_data_t, 0); data->session_start_time = info->session_start_time; data->session_end_time = info->session_end_time; @@ -140,7 +219,31 @@ BT_EXPORT_API int bluetooth_read_battery_data(bt_battery_data *data) data->session_connected_time = info->session_connected_time; data->atm_list = NULL; - BT_DBG("Received battery data in bt-api: %ld %ld %d %d.", data->session_start_time, data->session_end_time, data->session_scan_time, data->session_connected_time); + BT_DBG("Received battery data in bt-api: %ld %ld %d %d.", + data->session_start_time, data->session_end_time, + data->session_scan_time, data->session_connected_time); + + /*Copying app wise details*/ + int n = NUM_APP_MAX < info->num_app ? NUM_APP_MAX : info->num_app; //Maximum NUM_APP_MAX details will be fetched + + for (int i = 0; i < n; i++) { + bt_battery_app_data *app_data = NULL; + app_data = g_malloc0(sizeof(bt_battery_app_data)); + memcpy(app_data, &(info->app_data[i]), sizeof(bt_battery_app_data)); + data->atm_list = g_slist_append(data->atm_list, app_data); + } + + if (data->atm_list == NULL) { + BT_DBG("No app data transaction in this session"); + BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + return result; + } + + BT_DBG("App-wise data transaction details:"); + for (GSList *l = data->atm_list; l != NULL; l = g_slist_next(l)) { + bt_battery_app_data *t = (bt_battery_app_data *)(l->data); + BT_DBG("%ld %ld %d %d %u", (long int)(t->uid), (long int)(t->pid), t->rx_bytes, t->tx_bytes, t->time); + } BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); @@ -152,6 +255,7 @@ BT_EXPORT_API int bluetooth_disable_adapter(void) int result; BT_INFO_C("### Disable adapter"); + _bt_print_api_caller_name(); BT_CHECK_ENABLED(return); BT_INIT_PARAMS(); @@ -169,7 +273,7 @@ BT_EXPORT_API int bluetooth_recover_adapter(void) { int result; - BT_INFO("Recover adapter"); + BT_INFO_C("### Recover adapter"); BT_CHECK_ENABLED(return); BT_INIT_PARAMS(); @@ -496,7 +600,7 @@ BT_EXPORT_API int bluetooth_is_connectable(gboolean *is_connectable) BT_INIT_PARAMS(); BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); - result = _bt_send_request(BT_BLUEZ_SERVICE, BT_IS_CONNECTABLE, + result = _bt_send_request(BT_BLUEZ_SERVICE, BT_GET_CONNECTABLE, in_param1, in_param2, in_param3, in_param4, &out_param); if (result == BLUETOOTH_ERROR_NONE)