return result;
}
+BT_EXPORT_API int bluetooth_read_battery_data(bt_battery_data *data)
+{
+ int result;
+ bt_battery_data *info = NULL;
+
+ BT_CHECK_PARAMETER(data, return);
+
+ BT_INFO("### Requesting battery data");
+ retv_if(bluetooth_check_adapter() != BLUETOOTH_ADAPTER_ENABLED,
+ BLUETOOTH_ADAPTER_DISABLED);
+
+#ifdef TIZEN_FEATURE_BT_DPM
+ retv_if(bluetooth_dpm_is_mode_allowed() == BLUETOOTH_ERROR_PERMISSION_DEINED,
+ BLUETOOTH_ERROR_PERMISSION_DEINED);
+#endif
+
+ BT_INIT_PARAMS();
+ BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+ result = _bt_send_request(BT_BLUEZ_SERVICE, BT_BATTERY_READ_DATA,
+ in_param1, in_param2, in_param3, in_param4, &out_param);
+
+ if (result != BLUETOOTH_ERROR_NONE) {
+ BT_ERR("Error encountered");
+ return result;
+ }
+
+ BT_DBG("Received data from bt-service-adaptation");
+ info = &g_array_index(out_param, bt_battery_data, 0);
+
+ data->session_start_time = info->session_start_time;
+ 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->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_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+ return result;
+}
+
BT_EXPORT_API int bluetooth_disable_adapter(void)
{
int result;
#include "bt-service-pbap.h"
#include "bt-service-oob.h"
+#include "bt-service-battery-monitor.h"
+
#ifdef TIZEN_FEATURE_BT_PAN_NAP
#include "bt-service-network.h"
#endif
static guint owner_sig_id = 0;
static gboolean is_le_intended = FALSE;
-
static cynara *p_cynara;
static cynara_configuration *conf;
{
GSList *l;
invocation_info_t *info;
-
ret_if(NULL == req_info);
ret_if(NULL == req_info->sender);
}
+static int __bt_bm_request_data(_bt_battery_data_t *latest)
+{
+ int ret = _bt_bm_read_data(latest);
+ if (ret == BLUETOOTH_ERROR_NONE)
+ BT_DBG("Received data from battery monitor plugin: %ld %ld %d %d",
+ latest->session_start_time, latest->session_end_time,
+ latest->session_scan_time, latest->session_connected_time);
+ else
+ BT_ERR("Error encountered");
+ return ret;
+}
+
static void __bt_service_method(GDBusConnection *connection,
const gchar *sender,
const gchar *object_path,
case BT_RESET_ADAPTER:
result = _bt_reset_adapter();
break;
+ case BT_BATTERY_READ_DATA: {
+ _bt_battery_data_t data;
+ result = __bt_bm_request_data(&data);
+ g_array_append_vals(*out_param1, &data, sizeof(_bt_battery_data_t));
+ break;
+ }
case BT_CHECK_ADAPTER: {
int enabled = BT_ADAPTER_DISABLED;
result = _bt_check_adapter(&enabled);
case BT_DISABLE_ADAPTER:
case BT_RESET_ADAPTER:
case BT_RECOVER_ADAPTER:
+ case BT_BATTERY_READ_DATA:
case BT_ENABLE_ADAPTER_LE:
case BT_DISABLE_ADAPTER_LE:
case BT_SET_CONNECTABLE:
--- /dev/null
+/*
+ * Bluetooth-frwk
+ *
+ * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Sudipto Bal <sudipto.bal@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <glib.h>
+#include <string.h>
+#include <dlog.h>
+#include <time.h>
+
+#include <oal-event.h>
+
+#include "bt-service-battery-monitor.h"
+#include "bt-service-common.h"
+
+static time_t scan_start = 0;
+static time_t connect_start = 0;
+static int scan_cnt = 0;
+static int connect_cnt = 0;
+static gboolean is_session_started = FALSE;
+
+typedef struct {
+ int type;
+ void *data;
+} bt_service_oal_event_data_t;
+
+_bt_battery_data_t *current_session_data = NULL;
+
+static void __bt_display_session_data()
+{
+ BT_DBG("Displaying session data...");
+ BT_DBG("session_start_time = %ld", current_session_data->session_start_time);
+ BT_DBG("session_end_time = %ld", current_session_data->session_end_time);
+ BT_DBG("session_scan_time = %d", current_session_data->session_scan_time);
+ BT_DBG("session_connected_time = %d", current_session_data->session_connected_time);
+}
+
+/*After reading data, the function resets it*/
+int _bt_bm_read_data(_bt_battery_data_t *data)
+{
+ BT_DBG("");
+
+ if (data == NULL) {
+ BT_ERR("Received NULL pointer in argument, returning...");
+ return BLUETOOTH_ERROR_NO_DATA;
+ }
+
+ data->session_start_time = current_session_data->session_start_time;
+ data->session_end_time = time(NULL);
+ current_session_data->session_start_time = time(NULL);
+ current_session_data->session_end_time = 0;
+
+ data->session_scan_time = current_session_data->session_scan_time;
+ if (scan_cnt) {
+ data->session_scan_time += (uint16_t) (time(NULL) - scan_start);
+ scan_start = time(NULL);
+ }
+
+ data->session_connected_time = current_session_data->session_connected_time;
+ if (connect_cnt) {
+ data->session_connected_time += (uint16_t) (time(NULL) - connect_start);
+ connect_start = time(NULL);
+ }
+ return BLUETOOTH_ERROR_NONE;
+}
+
+void _bt_start_session_time()
+{
+ if (is_session_started == FALSE) {
+ BT_DBG("Bt session starting...");
+ is_session_started = TRUE;
+ current_session_data = g_malloc0(sizeof(_bt_battery_data_t));
+ current_session_data->session_start_time = time(NULL);
+ current_session_data->session_end_time = 0;
+ current_session_data->session_connected_time = 0;
+ current_session_data->session_scan_time = 0;
+ current_session_data->atm_list = NULL;
+ } else {
+ if (current_session_data == NULL)
+ BT_ERR("Session in progress but data structure is not initialized"); //error handling
+ else
+ BT_DBG("Bt session already in progress... Returning");
+ }
+}
+
+void _bt_stop_session_time()
+{
+ if (is_session_started == FALSE) {
+ BT_DBG("BT session not in progress... Returning"); //error handling
+ return;
+ }
+ BT_DBG("Bt session ending...");
+ is_session_started = FALSE;
+ current_session_data->session_end_time = time(NULL);
+ __bt_display_session_data();
+}
+
+void _bt_start_scan_time()
+{
+ if (current_session_data != NULL) {
+ if (scan_cnt == 0) {
+ BT_DBG("Starting scan time");
+ scan_start = time(NULL);
+ }
+ scan_cnt++;
+ } else {
+ BT_ERR("Data structure uninitialized"); //error handling
+ }
+}
+
+void _bt_stop_scan_time()
+{
+ if (scan_cnt == 0 || current_session_data == NULL)
+ BT_ERR("Error encountered, returning..."); //error handling
+ else {
+ scan_cnt--;
+ if(scan_cnt == 0) {
+ time_t temp = time(NULL);
+ current_session_data->session_scan_time += (uint16_t) (temp - scan_start);
+ }
+ }
+}
+
+void _bt_start_connect_time()
+{
+ if (current_session_data != NULL) {
+ if (connect_cnt == 0) {
+ BT_DBG("Starting connect time");
+ connect_start = time(NULL);
+ }
+ connect_cnt++;
+ }
+ else {
+ BT_ERR("Data structure uninitialized"); //error handling
+ }
+}
+
+void _bt_stop_connect_time()
+{
+ if(connect_cnt == 0 || current_session_data == NULL) {
+ BT_ERR("Error encountered, returning..."); //error handling
+ }
+ else {
+ connect_cnt--;
+ if(connect_cnt == 0) {
+ time_t temp = time(NULL);
+ current_session_data->session_connected_time += (uint16_t) (temp - connect_start);
+ }
+ }
+}
+
+void _bt_bm_event_handler(gpointer data)
+{
+ bt_service_oal_event_data_t *oal_event = data;
+ int event_type = oal_event->type;
+
+ switch(event_type) {
+ case OAL_EVENT_ADAPTER_ENABLED:
+ BT_DBG("Handling Adapter Enabled");
+ _bt_start_session_time();
+ break;
+ case OAL_EVENT_ADAPTER_DISABLED:
+ BT_DBG("Handling Adapter Disabled");
+ _bt_stop_session_time();
+ break;
+ case OAL_EVENT_ADAPTER_INQUIRY_STARTED:
+ case OAL_EVENT_BLE_DISCOVERY_STARTED:
+ BT_DBG("Handling Adapter Discovery Start");
+ _bt_start_scan_time();
+ break;
+ case OAL_EVENT_ADAPTER_INQUIRY_FINISHED:
+ case OAL_EVENT_BLE_DISCOVERY_STOPPED:
+ BT_DBG("Handling Adapter Discovery Stop");
+ _bt_stop_scan_time();
+ break;
+ case OAL_EVENT_SOCKET_OUTGOING_CONNECTED:
+ case OAL_EVENT_GATTC_CONNECTION_COMPLETED:
+ BT_DBG("Handling Connection Start");
+ _bt_start_connect_time();
+ break;
+ case OAL_EVENT_SOCKET_DISCONNECTED:
+ case OAL_EVENT_GATTC_DISCONNECTION_COMPLETED:
+ BT_DBG("Handling Connection Stop");
+ _bt_stop_connect_time();
+ break;
+ default:
+ BT_DBG("The event is not currently being handled");
+ }
+}
--- /dev/null
+ /*Bluetooth-frwk
+ *
+ * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Sudipto Bal <sudipto.bal@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef _BT_SERVICE_BATTERY_MONITOR_H_
+#define _BT_SERVICE_BATTERY_MONITOR_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+#include <oal-event.h>
+
+typedef struct {
+ char* app_name;
+ uint16_t rx_bytes;
+ uint16_t tx_bytes;
+} _bt_battery_app_data_t;
+
+typedef struct {
+ time_t session_start_time;
+ time_t session_end_time;
+ uint16_t session_connected_time;
+ uint16_t session_scan_time;
+ GSList *atm_list;
+} _bt_battery_data_t;
+
+void _bt_bm_event_handler(gpointer data);
+
+int _bt_bm_read_data(_bt_battery_data_t *data);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* _BT_SERVICE_BATTERY_MONITOR_H_ */