Handle the obex agent using tizen OPP feature
[platform/core/connectivity/bluetooth-frwk.git] / bt-api / bt-adapter.c
index e345387..4fa9b51 100644 (file)
 #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;
@@ -112,21 +121,62 @@ BT_EXPORT_API int bluetooth_enable_adapter(void)
 
 BT_EXPORT_API int bluetooth_set_battery_monitor_state(bool state)
 {
-       BT_INFO("Setting vconf key");
-       if (vconf_set_int(VCONFKEY_BATTERY_MONITOR_STATUS, state) != 0)
+       if (vconf_set_bool(VCONFKEY_BATTERY_MONITOR_STATUS, state) != 0)
        {
-               BT_ERR("vconf_set_int failed");
+               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;
-       BT_INFO("Getting vconf key value");
-       if (vconf_get_int(VCONFKEY_BATTERY_MONITOR_STATUS, &state) != 0)
-               BT_ERR("vconf_get_int failed");
+
+       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;
 }
 
@@ -137,7 +187,6 @@ BT_EXPORT_API int bluetooth_read_battery_data(bt_battery_data *data)
 
        BT_CHECK_PARAMETER(data, return);
 
-       BT_INFO("### Requesting battery data");
        retv_if(bluetooth_check_adapter() != BLUETOOTH_ADAPTER_ENABLED,
                                BLUETOOTH_ADAPTER_DISABLED);
 
@@ -167,6 +216,9 @@ BT_EXPORT_API int bluetooth_read_battery_data(bt_battery_data *data)
        data->session_end_time = info->session_end_time;
        data->session_scan_time = info->session_scan_time;
        data->session_connected_time = info->session_connected_time;
+       data->tx_time = info->tx_time;
+       data->rx_time = info->rx_time;
+       data->idle_time = info->idle_time;
        data->atm_list = NULL;
 
        BT_DBG("Received battery data in bt-api: %ld %ld %d %d.",
@@ -192,7 +244,7 @@ BT_EXPORT_API int bluetooth_read_battery_data(bt_battery_data *data)
        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", (long int)(t->uid), (long int)(t->pid), t->rx_bytes, t->tx_bytes);
+               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);
@@ -455,6 +507,7 @@ BT_EXPORT_API int bluetooth_start_discovery(unsigned short max_response,
                                            unsigned int classOfDeviceMask)
 {
        int result;
+       uid_t uid = getuid();
 
        BT_CHECK_ENABLED(return);
 
@@ -464,6 +517,7 @@ BT_EXPORT_API int bluetooth_start_discovery(unsigned short max_response,
        g_array_append_vals(in_param1, &max_response, sizeof(unsigned short));
        g_array_append_vals(in_param2, &discovery_duration, sizeof(unsigned short));
        g_array_append_vals(in_param3, &classOfDeviceMask, sizeof(unsigned int));
+       g_array_append_vals(in_param4, &uid, sizeof(uid_t));
 
        result = _bt_send_request(BT_BLUEZ_SERVICE, BT_START_DISCOVERY,
                in_param1, in_param2, in_param3, in_param4, &out_param);
@@ -550,7 +604,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)