/*
- * Bluetooth-frwk
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Hocheol Seo <hocheol.seo@samsung.com>
- * Girishashok Joshi <girish.joshi@samsung.com>
- * Chanyeol Park <chanyeol.park@samsung.com>
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
*/
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus.h>
#include <glib.h>
#include <dlog.h>
-
+#include <gio/gio.h>
#include "bluetooth-api.h"
#include "bt-internal-types.h"
#include "bt-service-common.h"
#include "bt-service-event.h"
-static DBusConnection *event_conn;
-static DBusConnection *hf_local_term_event_conn;
+static GDBusConnection *event_conn;
+static GDBusConnection *hf_local_term_event_conn;
-int _bt_send_event(int event_type, int event, int type, ...)
+#ifdef TIZEN_FEATURE_BT_HPS
+int _bt_send_to_hps(void)
{
- BT_DBG("+");
+ gboolean ret = FALSE;
+ GError *error = NULL;
+
+ BT_DBG(" ");
+
+ retv_if(event_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ ret = g_dbus_connection_emit_signal(event_conn, NULL,
+ "/org/projectx/httpproxy",
+ "org.projectx.httpproxy_service",
+ BT_LE_ENABLED,
+ NULL, &error);
+ if (!ret) {
+ if (error != NULL) {
+ BT_ERR("D-Bus API failure: errCode[%x], \
+ message[%s]",
+ error->code, error->message);
+ g_clear_error(&error);
+ }
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ return BLUETOOTH_ERROR_NONE;
+}
+#endif
- DBusMessage *msg;
+int _bt_send_event(int event_type, int event, GVariant *param)
+{
char *path;
char *signal;
- va_list arguments;
+ GDBusMessage *msg1 = NULL;
retv_if(event_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
case BT_HID_EVENT:
path = BT_HID_PATH;
break;
+ case BT_HID_DEVICE_EVENT:
+ path = BT_HID_DEVICE_PATH;
+ break;
case BT_HEADSET_EVENT:
path = BT_HEADSET_PATH;
break;
case BT_OPP_SERVER_EVENT:
path = BT_OPP_SERVER_PATH;
break;
+ case BT_MAP_CLIENT_EVENT:
+ path = BT_MAP_CLIENT_PATH;
+ break;
case BT_PBAP_CLIENT_EVENT:
path = BT_PBAP_CLIENT_PATH;
break;
case BT_RFCOMM_SERVER_EVENT:
path = BT_RFCOMM_SERVER_PATH;
break;
+ case BT_A2DP_SOURCE_EVENT:
+ path = BT_A2DP_SOURCE_PATH;
+ break;
+ case BT_OTP_EVENT:
+ path = BT_OTP_PATH;
+ break;
default:
BT_ERR("Unknown event");
return BLUETOOTH_ERROR_INTERNAL;
switch (event) {
case BLUETOOTH_EVENT_ENABLED:
signal = BT_ENABLED;
+ BT_INFO_C("### BT Enabled");
break;
case BLUETOOTH_EVENT_DISABLED:
signal = BT_DISABLED;
+ BT_INFO_C("### BT Disabled");
break;
case BLUETOOTH_EVENT_LE_ENABLED:
signal = BT_LE_ENABLED;
case BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND:
signal = BT_DEVICE_FOUND;
break;
- case BLUETOOTH_EVENT_REMOTE_DEVICE_DISAPPEARED:
- signal = BT_DEVICE_DISAPPEARED;
- break;
case BLUETOOTH_EVENT_DISCOVERY_FINISHED:
signal = BT_DISCOVERY_FINISHED;
break;
case BLUETOOTH_EVENT_RAW_RSSI:
signal = BT_RAW_RSSI_EVENT;
break;
+ case BLUETOOTH_EVENT_SUPPORTED_PROFILE_TRUSTED:
+ signal = BT_SUPPORTED_PROFILE_TRUSTED;
+ break;
+ case BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY:
+ signal = BT_KBD_PASSKEY_DISPLAY_REQ_RECEIVED;
+ break;
+ case BLUETOOTH_EVENT_PIN_REQUEST:
+ signal = BT_PIN_REQ_RECEIVED;
+ break;
+ case BLUETOOTH_EVENT_PASSKEY_REQUEST:
+ signal = BT_PASSKEY_REQ_RECEIVED;
+ break;
+ case BLUETOOTH_EVENT_PASSKEY_CONFIRM_REQUEST:
+ signal = BT_PASSKEY_CFM_REQ_RECEIVED;
+ break;
case BLUETOOTH_EVENT_SERVICE_SEARCHED:
signal = BT_SERVICE_SEARCHED;
break;
signal = BT_INPUT_DISCONNECTED;
BT_INFO_C("Disconnected [HID]");
break;
+ case BLUETOOTH_HID_DEVICE_CONNECTED:
+ signal = BT_INPUT_HID_DEVICE_CONNECTED;
+ BT_INFO_C("Connected [HIDDevice]");
+ break;
+ case BLUETOOTH_HID_DEVICE_DISCONNECTED:
+ signal = BT_INPUT_HID_DEVICE_DISCONNECTED;
+ BT_INFO_C("Disconnected [HIDDevice]");
+ break;
case BLUETOOTH_PBAP_CONNECTED:
signal = BT_PBAP_CONNECTED;
BT_INFO_C("Connected [PBAP Client]");
break;
+ case BLUETOOTH_PBAP_DISCONNECTED:
+ signal = BT_PBAP_DISCONNECTED;
+ BT_INFO_C("Disconnected [PBAP Client]");
+ break;
case BLUETOOTH_PBAP_PHONEBOOK_SIZE:
signal = BT_PBAP_PHONEBOOK_SIZE;
break;
signal = BT_STEREO_HEADSET_DISCONNECTED;
BT_INFO_C("Disconnected [A2DP]");
break;
+ case BLUETOOTH_EVENT_AV_SOURCE_CONNECTED:
+ signal = BT_A2DP_SOURCE_CONNECTED;
+ BT_INFO_C("Connected [A2DP Source]");
+ break;
+ case BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED:
+ signal = BT_A2DP_SOURCE_DISCONNECTED;
+ BT_INFO_C("Disconnected [A2DP Source]");
+ break;
case BLUETOOTH_EVENT_AG_AUDIO_CONNECTED:
signal = BT_SCO_CONNECTED;
BT_INFO_C("Connected [SCO]");
signal = BT_OPP_DISCONNECTED;
BT_INFO_C("Disconnected [OPP]");
break;
+ case BLUETOOTH_EVENT_MAP_CONNECTED:
+ signal = BT_MAP_CONNECTED;
+ BT_INFO_C("Connected [MAP]");
+ break;
+ case BLUETOOTH_EVENT_MAP_DISCONNECTED:
+ signal = BT_MAP_DISCONNECTED;
+ BT_INFO_C("Disconnected [MAP]");
+ break;
+ case BLUETOOTH_EVENT_MAP_LIST_FOLDERS_COMPLETE:
+ signal = BT_MAP_LIST_FOLDERS_COMPLETE;
+ BT_INFO_C("Completed list folders operation[MAP]");
+ break;
+ case BLUETOOTH_EVENT_MAP_LIST_FILTER_FIELD_COMPLETE:
+ signal = BT_MAP_FILTER_FIELDS_COMPLETE;
+ BT_INFO_C("Completed list filters field operation[MAP]");
+ break;
+ case BLUETOOTH_EVENT_MAP_LIST_MESSAGES_COMPLETE:
+ signal = BT_MAP_LIST_MESSAGES_COMPLETE;
+ BT_INFO_C("Completed list messages operation [MAP]");
+ break;
+ case BLUETOOTH_EVENT_MAP_GET_MESSAGE_COMPLETE:
+ signal = BT_MAP_GET_MESSAGE_COMPLETE;
+ BT_INFO_C("Completed get message operation [MAP]");
+ break;
+ case BLUETOOTH_EVENT_MAP_PUSH_MESSAGE_COMPLETE:
+ signal = BT_MAP_PUSH_MESSAGE_COMPLETE;
+ BT_INFO_C("Completed push message operation [MAP]");
+ break;
case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_CONNECTED:
signal = BT_TRANSFER_CONNECTED;
break;
break;
case BLUETOOTH_EVENT_GATT_CONNECTED:
signal = BT_GATT_CONNECTED;
+ BT_INFO_C("### Connected [GATT]");
break;
case BLUETOOTH_EVENT_GATT_DISCONNECTED:
signal = BT_GATT_DISCONNECTED;
+ BT_INFO_C("### Disconnected [GATT]");
+ break;
+ case BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED:
+ signal = BT_GATT_REQ_ATT_MTU_CHANGED;
+ break;
+ case BLUETOOTH_EVENT_IPSP_INIT_STATE_CHANGED:
+ signal = BT_IPSP_INITIALIZED;
+ break;
+ case BLUETOOTH_EVENT_IPSP_CONNECTED:
+ signal = BT_IPSP_CONNECTED;
+ break;
+ case BLUETOOTH_EVENT_IPSP_DISCONNECTED:
+ signal = BT_IPSP_DISCONNECTED;
+ break;
+ case BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED:
+ signal = BT_GATT_CHAR_VAL_CHANGED;
+ break;
+ case BLUETOOTH_EVENT_LE_DATA_LENGTH_CHANGED:
+ signal = BT_LE_DATA_LENGTH_CHANGED;
+ break;
+ case BLUETOOTH_EVENT_PXP_PROPERTY_CHANGED:
+ signal = BT_PXP_PROPERTY_CHANGED;
+ break;
+ case BLUETOOTH_EVENT_OTP_SERVER_STATE_CHANGED:
+ signal = BT_OTP_SERVER_STATE_CHANGED;
break;
default:
BT_ERR("Unknown event");
BT_DBG("Path : %s", path);
BT_INFO_C("Signal : %s", signal);
- msg = dbus_message_new_signal(path, BT_EVENT_SERVICE,
- signal);
+ msg1 = g_dbus_message_new_signal(path, BT_EVENT_SERVICE, signal);
+ g_dbus_message_set_body(msg1, param);
+ if (!g_dbus_connection_send_message(event_conn, msg1, G_DBUS_SEND_MESSAGE_FLAGS_NONE, 0, NULL))
+ BT_ERR("Error while sending");
- if (msg == NULL) {
- BT_ERR("Message is NULL");
- return BLUETOOTH_ERROR_INTERNAL;
- }
+ g_object_unref(msg1);
- if (type) {
- /* Set the arguments of the dbus message */
- va_start(arguments, type);
-
- if (!dbus_message_append_args_valist(msg, type, arguments)) {
- dbus_message_unref(msg);
- va_end(arguments);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- va_end(arguments);
- }
-
- if (!dbus_connection_send(event_conn, msg, NULL)) {
- BT_ERR("send failed");
- dbus_message_unref(msg);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- dbus_connection_flush(event_conn);
- dbus_message_unref(msg);
-
- BT_DBG("-");
+#ifdef TIZEN_FEATURE_BT_HPS
+ if (g_strcmp0(signal, BT_LE_ENABLED) == 0)
+ _bt_send_to_hps();
+#endif
return BLUETOOTH_ERROR_NONE;
}
-int _bt_send_event_to_dest(const char* dest, int event_type, int event, int type, ...)
+int _bt_send_event_to_dest(const char* dest, int event_type,
+ int event, GVariant *param)
{
- BT_DBG("+");
-
- DBusMessage *msg;
char *path;
char *signal;
- va_list arguments;
+ GError *error = NULL;
retv_if(event_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
case BT_ADAPTER_EVENT:
path = BT_ADAPTER_PATH;
break;
+ case BT_LE_ADAPTER_EVENT:
+ path = BT_LE_ADAPTER_PATH;
+ break;
+ case BT_DEVICE_EVENT:
+ path = BT_DEVICE_PATH;
+ break;
+ case BT_TDS_EVENT:
+ path = BT_TDS_PATH;
+ break;
+ case BT_OTP_EVENT:
+ path = BT_OTP_PATH;
+ break;
default:
BT_ERR("Unknown event");
return BLUETOOTH_ERROR_INTERNAL;
case BLUETOOTH_EVENT_ADVERTISING_STOPPED:
signal = BT_ADVERTISING_STOPPED;
break;
+ case BLUETOOTH_EVENT_PASSKEY_NOTIFICATION:
+ signal = BT_PASSKEY_NOTIFICATION;
+ break;
+ case BLUETOOTH_EVENT_LE_DISCOVERY_STARTED:
+ signal = BT_LE_DISCOVERY_STARTED;
+ break;
+ case BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND:
+ signal = BT_LE_DEVICE_FOUND;
+ break;
+ case BLUETOOTH_EVENT_LE_DISCOVERY_FINISHED:
+ signal = BT_LE_DISCOVERY_FINISHED;
+ break;
+ case BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED:
+ signal = BT_GATT_CHAR_VAL_CHANGED;
+ break;
+ case BLUETOOTH_EVENT_TDS_ACTIVATION_REQUESTED:
+ signal = BT_TDS_ACTIVATION_REQUESTED;
+ break;
+ case BLUETOOTH_EVENT_TDS_TRANSPORT_DATA_RECEIVED:
+ signal = BT_TDS_TRANSPORT_DATA_RECEIVED;
+ break;
+ case BLUETOOTH_EVENT_TDS_ACTIVATION_INDICATION:
+ signal = BT_TDS_ACTIVATION_INDICATION;
+ break;
+ case BLUETOOTH_EVENT_TDS_CONTROL_POINT_ENABLED:
+ signal = BT_TDS_CONTROL_POINT_ENABLED;
+ break;
+ case BLUETOOTH_EVENT_TDS_ACTIVATION_RESULT:
+ signal = BT_TDS_ACTIVATION_RESULT;
+ break;
+ case BLUETOOTH_EVENT_OTP_READ_CHAR_VAL:
+ signal = BT_OTP_READ_CHAR_VAL;
+ break;
+ case BLUETOOTH_EVENT_OTP_NOTIFICATION_ENABLED:
+ signal = BT_OTP_NOTIFICATION_ENABLED;
+ break;
+ case BLUETOOTH_EVENT_OTP_WRITE_CHAR_VAL:
+ signal = BT_OTP_WRITE_CHAR_VAL;
+ break;
+ case BLUETOOTH_EVENT_OTP_INDICATION:
+ signal = BT_OTP_INDICATION;
+ break;
default:
BT_ERR("Unknown event");
return BLUETOOTH_ERROR_INTERNAL;
}
- BT_DBG("Path : %s", path);
BT_INFO_C("Signal : %s", signal);
- msg = dbus_message_new_signal(path, BT_EVENT_SERVICE,
- signal);
-
- if (msg == NULL) {
- BT_ERR("Message is NULL");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- if (dbus_message_set_destination(msg, dest) == FALSE)
- BT_ERR("Setting destination is failed");
-
- if (type) {
- /* Set the arguments of the dbus message */
- va_start(arguments, type);
-
- if (!dbus_message_append_args_valist(msg, type, arguments)) {
- dbus_message_unref(msg);
- va_end(arguments);
- return BLUETOOTH_ERROR_INTERNAL;
+ if (!g_dbus_connection_emit_signal(event_conn, dest, path, BT_EVENT_SERVICE,
+ signal, param, &error)) {
+ BT_ERR("Error while sending Signal: %s", signal);
+ if (error) {
+ BT_ERR("Error Code [%d], Error Message [%s]",
+ error->code, error->message);
+ g_clear_error(&error);
}
-
- va_end(arguments);
}
- if (!dbus_connection_send(event_conn, msg, NULL)) {
- BT_ERR("send failed");
- dbus_message_unref(msg);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- dbus_connection_flush(event_conn);
- dbus_message_unref(msg);
-
- BT_DBG("-");
-
return BLUETOOTH_ERROR_NONE;
}
int _bt_send_hf_local_term_event(char *address)
{
- DBusMessage *msg;
- char *signal = BT_HF_LOCAL_TERM;
+ GError *error = NULL;
retv_if(hf_local_term_event_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
- msg = dbus_message_new_signal(BT_HF_LOCAL_TERM_EVENT_PATH,
- BT_HF_LOCAL_TERM_EVENT_INTERFACE, signal);
- if (msg == NULL) {
- BT_ERR("Message is NULL\n");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- dbus_message_append_args(msg, DBUS_TYPE_STRING, &address, DBUS_TYPE_INVALID);
-
- if (!dbus_connection_send(hf_local_term_event_conn, msg, NULL)) {
- BT_ERR("send failed\n");
- dbus_message_unref(msg);
- return BLUETOOTH_ERROR_INTERNAL;
+ if (!g_dbus_connection_emit_signal(hf_local_term_event_conn, NULL,
+ BT_HF_LOCAL_TERM_EVENT_PATH,
+ BT_HF_LOCAL_TERM_EVENT_INTERFACE,
+ BT_HF_LOCAL_TERM, g_variant_new("s", address),
+ &error)) {
+ BT_ERR("Error while sending Signal: %s", signal);
+ if (error) {
+ BT_ERR("Error Code [%d], Error Message [%s]",
+ error->code, error->message);
+ g_clear_error(&error);
+ }
}
- dbus_connection_flush(hf_local_term_event_conn);
- dbus_message_unref(msg);
-
return BLUETOOTH_ERROR_NONE;
}
/* To send the event from service daemon to application*/
int _bt_init_service_event_sender(void)
{
- DBusConnection *conn;
- DBusError err;
- int ret;
+ GDBusConnection *conn;
+ GError *err = NULL;
if (event_conn) {
BT_ERR("Event handler is already exist");
return BLUETOOTH_ERROR_INTERNAL;
}
- conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, NULL);
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- dbus_error_init(&err);
+ conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
- ret = dbus_bus_request_name(conn, BT_EVENT_SERVICE,
- DBUS_NAME_FLAG_REPLACE_EXISTING, &err);
-
- if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
- if (dbus_error_is_set(&err) == TRUE) {
- BT_ERR(" Sudha 112 Event init failed \n \n, %s", err.message);
- dbus_error_free(&err);
+ if (conn == NULL) {
+ BT_ERR("conn == NULL");
+ if (err) {
+ BT_ERR("Code[%d], Message[%s]",
+ err->code, err->message);
+ g_clear_error(&err);
}
+
return BLUETOOTH_ERROR_INTERNAL;
}
event_conn = conn;
-
return BLUETOOTH_ERROR_NONE;
}
void _bt_deinit_service_event_sender(void)
{
if (event_conn) {
- dbus_connection_close(event_conn);
+ g_object_unref(event_conn);
event_conn = NULL;
}
}
int _bt_init_hf_local_term_event_sender(void)
{
- DBusConnection *conn;
- DBusError err;
- int ret;
+ GDBusConnection *conn;
+ GError *err = NULL;
if (hf_local_term_event_conn) {
- BT_ERR(" Sudha Event handler is already exist");
+ BT_ERR("Event handler is already exist");
return BLUETOOTH_ERROR_INTERNAL;
}
- conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, NULL);
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- dbus_error_init(&err);
+ conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
- ret = dbus_bus_request_name(conn, BT_HF_LOCAL_TERM_EVENT_INTERFACE,
- DBUS_NAME_FLAG_REPLACE_EXISTING, &err);
-
- if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
- if (dbus_error_is_set(&err) == TRUE) {
- BT_ERR("Sudha Event init failed \n, %s ", err.message);
- dbus_error_free(&err);
+ if (conn == NULL) {
+ BT_ERR("conn == NULL");
+ if (err) {
+ BT_ERR("Code[%d], Message[%s]",
+ err->code, err->message);
+ g_clear_error(&err);
}
+
return BLUETOOTH_ERROR_INTERNAL;
}
void _bt_deinit_hf_local_term_event_sender(void)
{
if (hf_local_term_event_conn) {
- dbus_connection_close(hf_local_term_event_conn);
+ g_object_unref(hf_local_term_event_conn);
hf_local_term_event_conn = NULL;
}
}
+
+int _bt_send_dump_signal(char *signal)
+{
+ GError *error = NULL;
+ int32_t pid = getpid();
+
+ retv_if(event_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ if (!g_dbus_connection_emit_signal(event_conn, NULL,
+ BT_DUMP_SERVICE_PATH,
+ BT_DUMP_SERVICE_INTERFACE,
+ signal, g_variant_new("(i)", pid),
+ &error)) {
+ BT_ERR("Error while sending Signal: %s", signal);
+ if (error) {
+ BT_ERR("Error Code [%d], Error Message [%s]",
+ error->code, error->message);
+ g_clear_error(&error);
+ }
+ }
+
+ return BLUETOOTH_ERROR_NONE;
+}
+