[Adapt]Implement Health Device Profile in bt-service 03/93103/1
authorAtul Rai <a.rai@samsung.com>
Fri, 14 Oct 2016 09:16:13 +0000 (14:46 +0530)
committerAtul Rai <a.rai@samsung.com>
Mon, 17 Oct 2016 05:14:39 +0000 (10:44 +0530)
This patch adds bt-service implementation for Health Device Profile.

Change-Id: Id6f3173d64e47e36f9c83989591d79636c4fb4ff
Signed-off-by: Atul Rai <a.rai@samsung.com>
bt-api/bt-hdp.c
bt-service-adaptation/CMakeLists.txt
bt-service-adaptation/services/adapter/bt-service-core-adapter.c
bt-service-adaptation/services/bt-request-handler.c
bt-service-adaptation/services/bt-service-event-receiver.c
bt-service-adaptation/services/bt-service-event-sender.c
bt-service-adaptation/services/health/bt-service-hdp.c [new file with mode: 0644]
bt-service-adaptation/services/include/bt-service-event-receiver.h
bt-service-adaptation/services/include/bt-service-hdp.h [new file with mode: 0644]
include/bluetooth-api.h
include/bt-internal-types.h

index e9e35fa..29a8068 100755 (executable)
 #include "bt-common.h"
 #include "bt-internal-types.h"
 
-#define HDP_BUFFER_SIZE 1024
-#define BLUEZ_HDP_MANAGER_INTERFACE  "org.bluez.HealthManager1"
-#define BLUEZ_HDP_DEVICE_INTERFACE  "org.bluez.HealthDevice1"
-#define BLUEZ_HDP_CHANNEL_INTERFACE  "org.bluez.HealthChannel1"
-
-typedef struct {
-       char *obj_channel_path;
-       int fd;
-       guint watch_id;
-} hdp_obj_info_t;
-
-typedef struct {
-       void *app_handle;
-       GSList *obj_info;
-} hdp_app_list_t;
-
-/* Variable for privilege, only for write API,
-  before we should reduce time to bt-service dbus calling
-  -1 : Don't have a permission to access API
-  0 : Initial value, not yet check
-  1 : Have a permission to access API
-*/
-static int privilege_token;
-
-
 /**********************************************************************
 *              Static Functions declaration                            *
 ***********************************************************************/
-static int __bt_hdp_internal_create_application(unsigned int data_type,
-                                               int role,
-                                               bt_hdp_qos_type_t channel_type,
-                                               char **app_handle);
-
-static void __bt_hdp_internal_event_filter(GDBusConnection *connection,
-                                       const gchar *sender_name,
-                                       const gchar *object_path,
-                                       const gchar *interface_name,
-                                       const gchar *signal_name,
-                                       GVariant *parameters,
-                                       gpointer user_data);
-
-static void __bt_hdp_internal_handle_connect(GVariant *parameters);
-
-static void __bt_hdp_internal_handle_disconnect(GVariant *parameters,
-                               const gchar *object_path);
-
-static void __bt_hdp_internal_handle_property_changed(GVariant *parameters);
-
-static int __bt_hdp_internal_add_filter(void);
-
-static int __bt_hdp_internal_acquire_fd(const char *path);
-
-static guint __bt_hdp_internal_watch_fd(int file_desc, const char *path);
-
-static gboolean __bt_hdp_internal_data_received(GIOChannel *gio,
-                                               GIOCondition cond,
-                                               gpointer data);
-
-static int __bt_hdp_internal_destroy_application(const char *app_handle);
-
-static void __bt_hdp_internal_remove_filter(void);
-
-static hdp_app_list_t *__bt_hdp_internal_gslist_find_app_handler(void *app_handle);
-
-static hdp_obj_info_t *__bt_hdp_internal_gslist_obj_find_using_fd(int fd);
-
-static hdp_obj_info_t *__bt_hdp_internal_gslist_obj_find_using_path(const char *obj_channel_path);
-
-/*Global Variables*/
-static GDBusConnection *g_hdp_dus_conn;
-
-static GSList *g_app_list = NULL;
 
 /**********************************************************************
 *                      Health device APIs (HDP)                        *
@@ -108,1102 +39,30 @@ BT_EXPORT_API int bluetooth_hdp_activate(unsigned short data_type,
                                        bt_hdp_qos_type_t channel_type,
                                        char **app_handle)
 {
-       int result = BLUETOOTH_ERROR_NONE;
-
-       BT_DBG("+");
-
-       BT_CHECK_ENABLED(return);
-
-       /*For source role is mandatory */
-       if (role == HDP_ROLE_SOURCE && channel_type == HDP_QOS_ANY) {
-               BT_ERR("For source, type is mandatory - Reliable/Streaming");
-               return BLUETOOTH_ERROR_INVALID_PARAM;
-       }
-
-       if (_bt_check_privilege(BT_BLUEZ_SERVICE, BT_HDP_REGISTER_SINK_APP)
-            == BLUETOOTH_ERROR_PERMISSION_DEINED) {
-               BT_ERR("Don't have a privilege to use this API");
-               return BLUETOOTH_ERROR_PERMISSION_DEINED;
-       }
-
-       result = __bt_hdp_internal_create_application(data_type, role,
-                                               channel_type, app_handle);
-
-       return result;
-}
-
-static void __bt_hdp_obj_info_free(hdp_obj_info_t *info)
-{
-       if (info) {
-               g_source_remove(info->watch_id);
-               close(info->fd);
-               g_free(info->obj_channel_path);
-               g_free(info);
-       }
-}
-
-static int __bt_hdp_internal_create_application(unsigned int data_type,
-                                       int role,
-                                       bt_hdp_qos_type_t channel_type,
-                                       char **app_handle)
-{
-       GDBusProxy *proxy = NULL;
-       GVariant *reply = NULL;
-       GVariantBuilder *builder;
-       const char *svalue;
-       const char *key_type;
-       char *app_path;
-       hdp_app_list_t *list;
-       GError *err = NULL;
-       guint16 value;
-       GDBusConnection *conn;
-       int ret = BLUETOOTH_ERROR_NONE;
-
-       BT_DBG("+");
-
-       conn = _bt_gdbus_get_system_gconn();
-       retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
-       proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
-                                       NULL,
-                                       BT_BLUEZ_NAME,
-                                       "/org/bluez",
-                                       BLUEZ_HDP_MANAGER_INTERFACE,
-                                       NULL, &err);
-
-       if (!proxy) {
-               BT_ERR("Unable to create proxy: %s", err->message);
-               g_clear_error(&err);
-               return BLUETOOTH_ERROR_INTERNAL;
-       }
-
-       builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
-
-       key_type = "DataType";
-       value = (guint16) data_type;
-       g_variant_builder_add(builder, "{sv}",
-                       key_type, g_variant_new("q",
-                               value));
-
-       key_type = "Role";
-       /*0-Source,1-Sink*/
-       svalue = (role == HDP_ROLE_SINK) ? "Sink" : "Source";
-       g_variant_builder_add(builder, "{sv}",
-                       key_type, g_variant_new("s",
-                               svalue));
-
-       key_type = "Description";
-       svalue = "Health Device";
-       g_variant_builder_add(builder, "{sv}",
-                       key_type, g_variant_new("s",
-                               svalue));
-
-       if (role == HDP_ROLE_SOURCE) {
-               key_type = "ChannelType";
-               if (channel_type == HDP_QOS_RELIABLE)
-                       svalue = "reliable";
-               else if (channel_type == HDP_QOS_STREAMING)
-                       svalue = "streaming";
-
-               g_variant_builder_add(builder, "{sv}",
-                       key_type, g_variant_new("s",
-                               svalue));
-       }
-
-       reply = g_dbus_proxy_call_sync(proxy, "CreateApplication",
-                                       g_variant_new("(a{sv})", builder),
-                                       G_DBUS_CALL_FLAGS_NONE, -1,
-                                       NULL, &err);
-
-       g_variant_builder_unref(builder);
-       g_object_unref(proxy);
-
-       if (!reply) {
-               BT_ERR(" HDP:dbus Can't create application");
-               if (err) {
-                       BT_ERR("%s", err->message);
-                       if (g_strrstr(err->message, BT_ACCESS_DENIED_MSG))
-                               ret = BLUETOOTH_ERROR_PERMISSION_DEINED;
-                       else
-                               ret = BLUETOOTH_ERROR_INTERNAL;
-                       g_clear_error(&err);
-               }
-               return ret;
-       }
-
-       g_variant_get(reply, "(&o)", &app_path);
-       BT_DBG("Created health application: %s", (char *)app_path);
-
-       ret = __bt_hdp_internal_add_filter();
-
-       if (ret != BLUETOOTH_ERROR_NONE) {
-               BT_ERR("Funtion failed");
-               return ret;
-       }
-
-       list = g_new0(hdp_app_list_t, 1);
-       list->app_handle = (void *)g_strdup(app_path);
-       *app_handle = list->app_handle;
-
-       g_app_list = g_slist_append(g_app_list, list);
-
-       g_variant_unref(reply);
-       return BLUETOOTH_ERROR_NONE;
-}
-
-static int __bt_hdp_add_filter_subscribe_signal(GDBusConnection *conn,
-               gboolean subscribe)
-{
-       static guint subs_add_filter_id = 0;
-
-       if (conn == NULL)
-               return BLUETOOTH_ERROR_INVALID_PARAM;
-
-       if (subscribe) {
-               if (subs_add_filter_id == 0) {
-                       subs_add_filter_id = g_dbus_connection_signal_subscribe(
-                               conn, NULL, BLUEZ_HDP_DEVICE_INTERFACE,
-                               NULL, NULL, NULL, 0,
-                               __bt_hdp_internal_event_filter, NULL, NULL);
-               }
-       } else {
-               if (subs_add_filter_id > 0) {
-                       g_dbus_connection_signal_unsubscribe(conn,
-                                       subs_add_filter_id);
-                       subs_add_filter_id = 0;
-               }
-       }
-       return BLUETOOTH_ERROR_NONE;
-}
-
-static int __bt_hdp_internal_add_filter(void)
-{
-       BT_DBG("+");
-
-       /*Single process only one signal registration is required */
-       if (g_hdp_dus_conn) {
-               BT_ERR("g_hdp_dus_conn already exist");
-               return BLUETOOTH_ERROR_NONE;
-       }
-
-       g_hdp_dus_conn = _bt_gdbus_get_system_gconn();
-       retv_if(g_hdp_dus_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
-
-       return __bt_hdp_add_filter_subscribe_signal(g_hdp_dus_conn, TRUE);
-
-       BT_DBG("-\n");
-}
-
-static void __bt_hdp_internal_event_filter(GDBusConnection *connection,
-                                       const gchar *sender_name,
-                                       const gchar *object_path,
-                                       const gchar *interface_name,
-                                       const gchar *signal_name,
-                                       GVariant *parameters,
-                                       gpointer user_data)
-{
-       BT_DBG("Path = %s\n", object_path);
-       if (object_path == NULL || g_strcmp0(object_path, "/") == 0)
-               return;
-
-       if (signal_name == NULL)
-               return;
-
-       if (strcasecmp(signal_name, "ChannelConnected") == 0) 
-               __bt_hdp_internal_handle_connect(parameters);
-
-       else if (strcasecmp(signal_name, "ChannelDeleted") == 0)
-               __bt_hdp_internal_handle_disconnect(parameters, object_path);
-
-       else if (strcasecmp(signal_name, "PropertyChanged") == 0)
-               __bt_hdp_internal_handle_property_changed(parameters);
-
-       return;
-}
-
-static void __bt_hdp_internal_handle_connect(GVariant *parameters)
-{
-       BT_DBG("+");
-       const char *obj_channel_path;
-       bt_user_info_t *user_info;
-       int ret;
-
-       BT_INFO("*********Signal - ChannelConnected******\n\n");
-       g_variant_get(parameters, "(&o)", &obj_channel_path);
-
-       BT_INFO("Channel connected, Path = %s", obj_channel_path);
-
-       user_info = _bt_get_user_data(BT_COMMON);
-       if (user_info == NULL || user_info->cb == NULL)
-               return;
-
-       ret = __bt_hdp_internal_acquire_fd(obj_channel_path);
-       if (ret != BLUETOOTH_ERROR_NONE) {
-               _bt_common_event_cb(BLUETOOTH_EVENT_HDP_CONNECTED,
-                               BLUETOOTH_ERROR_CONNECTION_ERROR, NULL,
-                               user_info->cb, user_info->user_data);
-       }
-       BT_DBG("-");
-}
-
-static void __bt_hdp_internal_handle_disconnect(GVariant *parameters,
-                                       const gchar *object_path)
-{
-       const char *obj_channel_path;
-       char address[BT_ADDRESS_STRING_SIZE] = { 0, };
-       bluetooth_device_address_t device_addr = { {0} };
-       bt_hdp_disconnected_t dis_ind;
-       hdp_obj_info_t *info;
-       bt_user_info_t *user_info;
-
-       BT_INFO("+********Signal - ChannelDeleted ******\n\n");
-       BT_DBG("Path = %s", object_path);
-
-       g_variant_get(parameters, "(&o)", &obj_channel_path);
-
-       BT_INFO("Channel Deleted, Path = %s", obj_channel_path);
-
-       info = __bt_hdp_internal_gslist_obj_find_using_path(obj_channel_path);
-       if (!info) {
-               BT_ERR("No obj info for ob_channel_path [%s]\n", obj_channel_path);
-               return;
-       }
-
-       /*Since bluetoothd is not sending the ChannelDeleted signal */
-       _bt_convert_device_path_to_address(object_path, address);
-
-       _bt_convert_addr_string_to_type(device_addr.addr, address);
-
-       dis_ind.channel_id = info->fd;
-       dis_ind.device_address = device_addr;
-
-       user_info = _bt_get_user_data(BT_COMMON);
-
-       if (user_info->cb) {
-               _bt_common_event_cb(BLUETOOTH_EVENT_HDP_DISCONNECTED,
-                               BLUETOOTH_ERROR_NONE, &dis_ind,
-                               user_info->cb, user_info->user_data);
-       }
-
-       BT_DBG(" Removed connection from list\n");
-
-       __bt_hdp_obj_info_free(info);
-
-}
-
-static void __bt_hdp_internal_handle_property_changed(GVariant *parameters)
-{
-       char *property = NULL;
-       GVariant *value = NULL;
-       gsize len;
-       char *obj_main_channel_path = NULL;
-       GVariantIter *property_iter;
-
-       BT_DBG("+*******Signal - PropertyChanged*******\n");
-
-       g_variant_get(parameters, "(a{sv})", &property_iter);
-
-       while (g_variant_iter_loop(property_iter, "{sv}", &property, &value)) {
-               if (g_strcmp0("MainChannel", property) == 0) {
-                       BT_INFO("Property MainChannel received");
-                       obj_main_channel_path = g_variant_dup_string(value, &len);
-                       BT_DBG("Main Channel  Path = %s", obj_main_channel_path);
-                       break;
-               }
-       }
-       g_variant_iter_free(property_iter);
-
-       g_free(property);
-       g_variant_unref(value);
-       g_free(obj_main_channel_path);
-       BT_DBG("-*************\n");
-}
-
-static int __bt_hdp_internal_acquire_fd(const char *path)
-{
-       char address[BT_ADDRESS_STRING_SIZE] = { 0, };
-       bluetooth_device_address_t device_addr = { {0} };
-       const char *property;
-       GVariant *value = NULL;
-       char *type_qos = NULL;
-       char *device = NULL;
-       char *app_handle = NULL;
-       hdp_app_list_t *list = NULL;
-       GDBusProxy *proxy = NULL;
-       GVariant *reply = NULL;
-       GDBusConnection *conn;
-       bt_hdp_connected_t conn_ind;
-       GError *err = NULL;
-       int fd;
-       bt_user_info_t *user_info;
-       char *dev_path;
-       GUnixFDList *out_fd_list;
-       int index;
-       GVariantIter *property_iter;
-       gsize len;
-
-       BT_DBG("+");
-
-       conn = _bt_gdbus_get_system_gconn();
-       retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
-       proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
-                                       NULL,
-                                       BT_BLUEZ_NAME,
-                                       path,
-                                       BLUEZ_HDP_CHANNEL_INTERFACE,
-                                       NULL, &err);
-
-       if (!proxy) {
-               BT_ERR("Unable to create proxy: %s", err->message);
-               g_clear_error(&err);
-               return BLUETOOTH_ERROR_INTERNAL;
-       }
-
-       reply = g_dbus_proxy_call_with_unix_fd_list_sync(proxy,
-                                                   "Acquire",
-                                                   NULL,
-                                                   G_DBUS_CALL_FLAGS_NONE,
-                                                   -1,
-                                                   NULL,
-                                                   &out_fd_list,
-                                                   NULL,
-                                                  &err);
-
-       g_object_unref(proxy);
-
-       if (!reply) {
-               BT_ERR(" HDP:****** dbus Can't create application ****");
-
-               if (err) {
-                       BT_ERR("%s", err->message);;
-                       g_clear_error(&err);
-               }
-
-               return BLUETOOTH_ERROR_INTERNAL;
-       }
-
-       g_variant_get(reply, "(h)", &index);
-       fd = g_unix_fd_list_get(out_fd_list, index, NULL);
-
-       g_variant_unref(reply);
-
-       BT_DBG("File Descriptor = %d, Dev_path = %s \n", fd, path);
-
-       proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
-                                       NULL,
-                                       BT_BLUEZ_NAME,
-                                       path,
-                                       BT_PROPERTIES_INTERFACE,
-                                       NULL, &err);
-
-       if (!proxy) {
-               BT_ERR("Unable to create proxy: %s", err->message);
-               g_clear_error(&err);
-               return BLUETOOTH_ERROR_INTERNAL;
-       }
-
-       dev_path = g_strdup(BLUEZ_HDP_CHANNEL_INTERFACE);
-
-       reply = g_dbus_proxy_call_sync(proxy, "GetAll",
-                               g_variant_new("(s)", dev_path),
-                               G_DBUS_CALL_FLAGS_NONE,
-                               -1,
-                               NULL,
-                               &err);
-
-       g_free(dev_path);
-       g_object_unref(proxy);
-
-       if (!reply) {
-               BT_ERR(" HDP:dbus Can't get the reply");
-
-               if (err) {
-                       BT_ERR("%s", err->message);;
-                       g_clear_error(&err);
-               }
-
-               return BLUETOOTH_ERROR_INTERNAL;
-       }
-
-       g_variant_get(reply, "(a{sv})", &property_iter);
-
-       while (g_variant_iter_loop(property_iter, "{sv}", &property, &value)) {
-               BT_DBG("String received = %s\n", property);
-
-               if (g_strcmp0("Type", property) == 0) {
-                       type_qos = g_variant_dup_string(value, &len);
-               } else if (g_strcmp0("Device", property) == 0) {
-                       device = g_variant_dup_string(value, &len);
-               } else if (g_strcmp0("Application", property) == 0) {
-                       app_handle = g_variant_dup_string(value, &len);
-               }
-       }
-       g_variant_iter_free(property_iter);
-
-       g_variant_unref(reply);
-       BT_DBG("QOS = %s, Device = %s, Apphandler = %s",
-                       type_qos, device, app_handle);
-
-       if (NULL == type_qos || NULL == app_handle) {
-               BT_ERR("Pasing failed\n");
-               goto error;
-       }
-
-       list = __bt_hdp_internal_gslist_find_app_handler((void *)app_handle);
-
-       /*Only process register with app handle receive the Connected event */
-       if (NULL == list) {
-               BT_ERR("**** Could not locate the list for %s*****\n", app_handle);
-               goto error;
-       }
-
-       hdp_obj_info_t *info = g_new0(hdp_obj_info_t, 1);
-       info->fd = fd;
-       info->obj_channel_path = g_strdup(path);
-       info->watch_id = __bt_hdp_internal_watch_fd(fd, info->obj_channel_path);
-       list->obj_info = g_slist_append(list->obj_info, info);
-
-       _bt_convert_device_path_to_address(path, address);
-
-       _bt_convert_addr_string_to_type(device_addr.addr, address);
-
-       conn_ind.app_handle = app_handle;
-       conn_ind.channel_id = fd;
-       conn_ind.device_address = device_addr;
-       conn_ind.type = (g_strcmp0(type_qos, "Reliable") == 0) ?
-                       HDP_QOS_RELIABLE : HDP_QOS_STREAMING;
-
-       BT_DBG("Going to give callback\n");
-
-       user_info = _bt_get_user_data(BT_COMMON);
-
-       if (user_info->cb) {
-               _bt_common_event_cb(BLUETOOTH_EVENT_HDP_CONNECTED,
-                               BLUETOOTH_ERROR_NONE, &conn_ind,
-                               user_info->cb, user_info->user_data);
-       }
-
-       BT_DBG("Updated fd in the list*\n");
-       BT_DBG("-\n");
-
-       g_free(type_qos);
-       g_free(device);
-       g_free(app_handle);
        return BLUETOOTH_ERROR_NONE;
-error:
-       g_free(type_qos);
-       g_free(device);
-       g_free(app_handle);
-       return BLUETOOTH_ERROR_INTERNAL;
-}
-
-static guint __bt_hdp_internal_watch_fd(int file_desc, const char *path)
-{
-       GIOChannel *gio;
-       guint id;
-
-       BT_DBG("+");
-
-       gio = g_io_channel_unix_new(file_desc);
-
-       g_io_channel_set_close_on_unref(gio, TRUE);
-
-       id = g_io_add_watch(gio, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
-                       __bt_hdp_internal_data_received, (void *)path);
-       BT_DBG("-");
-       return id;
-}
-
-
-static void __bt_hdp_internal_handle_disconnect_cb(int sk, const char *path)
-{
-       char address[BT_ADDRESS_STRING_SIZE] = { 0, };
-       bluetooth_device_address_t device_addr = { {0} };
-       bt_hdp_disconnected_t dis_ind;
-       hdp_obj_info_t *info;
-       bt_user_info_t *user_info;
-
-       BT_INFO("******** Socket Error  ******\n");
-
-       info = __bt_hdp_internal_gslist_obj_find_using_path(path);
-       ret_if(info == NULL);
-
-       /*Since bluetoothd is not sending the ChannelDeleted signal */
-       _bt_convert_device_path_to_address(path, address);
-
-       _bt_convert_addr_string_to_type(device_addr.addr, address);
-
-       dis_ind.channel_id = sk;
-       dis_ind.device_address = device_addr;
-
-       user_info = _bt_get_user_data(BT_COMMON);
-
-       if (user_info->cb) {
-               _bt_common_event_cb(BLUETOOTH_EVENT_HDP_DISCONNECTED,
-                               BLUETOOTH_ERROR_NONE, &dis_ind,
-                               user_info->cb, user_info->user_data);
-       }
-
-       BT_DBG(" Removed connection from list\n");
-
-       __bt_hdp_obj_info_free(info);
-}
-
-static gboolean __bt_hdp_internal_data_received(GIOChannel *gio,
-                                       GIOCondition cond, gpointer data)
-{
-       char buff[HDP_BUFFER_SIZE] = { 0, };
-       int sk;
-       int act_read;
-       bt_hdp_data_ind_t data_ind = { 0, };
-       const char *path = (const char *)data;
-       bt_user_info_t *user_info;
-
-       BT_DBG("+");
-
-       sk = g_io_channel_unix_get_fd(gio);
-
-       if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) {
-               BT_DBG("GIOCondition %d.............path = %s\n", cond, path);
-               g_io_channel_shutdown(gio, TRUE, NULL);
-               g_io_channel_unref(gio);
-                __bt_hdp_internal_handle_disconnect_cb(sk, path);
-               return FALSE;
-       }
-
-       act_read = recv(sk, (void *)buff, sizeof(buff), 0);
-
-       if (act_read > 0) {
-               BT_DBG("Received data of %d\n", act_read);
-       } else {
-               BT_ERR("Read failed.....\n");
-               return FALSE;
-       }
-
-       data_ind.channel_id = sk;
-       data_ind.buffer = buff;
-       data_ind.size = act_read;
-
-       user_info = _bt_get_user_data(BT_COMMON);
-
-       if (user_info->cb) {
-               _bt_common_event_cb(BLUETOOTH_EVENT_HDP_DATA_RECEIVED,
-                               BLUETOOTH_ERROR_NONE, &data_ind,
-                               user_info->cb, user_info->user_data);
-       }
-
-       BT_DBG("-\n");
-
-       return TRUE;
 }
 
 BT_EXPORT_API int bluetooth_hdp_deactivate(const char *app_handle)
 {
-       BT_DBG("+");
-
-       BT_CHECK_ENABLED(return);
-       BT_CHECK_PARAMETER(app_handle, return);
-
-       if (_bt_check_privilege(BT_BLUEZ_SERVICE, BT_HDP_UNREGISTER_SINK_APP)
-            == BLUETOOTH_ERROR_PERMISSION_DEINED) {
-               BT_ERR("Don't have a privilege to use this API");
-               return BLUETOOTH_ERROR_PERMISSION_DEINED;
-       }
-
-       return __bt_hdp_internal_destroy_application(app_handle);
-}
-
-static hdp_app_list_t *__bt_hdp_internal_gslist_find_app_handler(void *app_handle)
-{
-       GSList *l;
-
-       retv_if(g_app_list == NULL, NULL);
-
-       BT_DBG("List length = %d\n", g_slist_length(g_app_list));
-
-       for (l = g_app_list; l != NULL; l = l->next) {
-               hdp_app_list_t *list = l->data;
-
-               if (list) {
-                       if (0 == g_strcmp0((char *)list->app_handle,
-                                               (char *)app_handle))
-                               return list;
-               }
-       }
-       return NULL;
-}
-
-static hdp_obj_info_t *__bt_hdp_internal_gslist_obj_find_using_fd(int fd)
-{
-       GSList *l;
-       GSList *iter;
-
-       retv_if(g_app_list == NULL, NULL);
-
-       BT_DBG("List length = %d\n", g_slist_length(g_app_list));
-
-       for (l = g_app_list; l != NULL; l = l->next) {
-               hdp_app_list_t *list = l->data;
-               if (!list)
-                       return NULL;
-
-               for (iter = list->obj_info; iter != NULL; iter = iter->next) {
-                       hdp_obj_info_t *info = iter->data;
-                       if (!info)
-                               return NULL;
-
-                       if (fd == info->fd)
-                               return info;
-               }
-       }
-       return NULL;
-}
-
-static hdp_obj_info_t *__bt_hdp_internal_gslist_obj_find_using_path(const char *obj_channel_path)
-{
-       GSList *l;
-       GSList *iter;
-       hdp_obj_info_t *info = NULL;
-
-       retv_if(g_app_list == NULL, NULL);
-
-       BT_DBG("List length = %d\n", g_slist_length(g_app_list));
-       for (l = g_app_list; l != NULL; l = l->next) {
-               hdp_app_list_t *list = l->data;
-               if (!list)
-                       return NULL;
-
-               for (iter = list->obj_info; iter != NULL; iter = iter->next) {
-                        info = iter->data;
-                       if (!info)
-                               return NULL;
-
-                       if (0 == g_strcmp0(info->obj_channel_path, obj_channel_path)) {
-                               list->obj_info = g_slist_remove(list->obj_info, info);
-                               return info;
-                       }
-               }
-       }
-       return NULL;
-}
-
-static gboolean  __bt_hdp_internal_destroy_application_cb(gpointer data)
-{
-       const char *app_handle;
-       hdp_app_list_t *list = NULL;
-       app_handle = (const char *)data;
-
-       BT_DBG("+");
-
-       list = __bt_hdp_internal_gslist_find_app_handler((void *)app_handle);
-       if (NULL == list) {
-               BT_ERR("**** list not found for %s ******\n", app_handle);
-               return FALSE;
-       }
-
-       g_app_list = g_slist_remove(g_app_list, list);
-
-       g_free(list->app_handle);
-       g_slist_foreach(list->obj_info, (GFunc)__bt_hdp_obj_info_free, NULL);
-       g_free(list);
-
-       BT_DBG("List length = %d\n", g_slist_length(g_app_list));
-
-       if (0 == g_slist_length(g_app_list))
-               __bt_hdp_internal_remove_filter();
-       BT_DBG("-");
-       return FALSE;
-}
-
-static int __bt_hdp_internal_destroy_application(const char *app_handle)
-{
-       GDBusProxy *proxy = NULL;
-       GVariant *reply = NULL;
-       GError *err = NULL;
-       GDBusConnection *conn;
-       int result = BLUETOOTH_ERROR_NONE;
-
-       conn = _bt_gdbus_get_system_gconn();
-       retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
-       proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
-                                       NULL,
-                                       BT_BLUEZ_NAME,
-                                       "/org/bluez",
-                                       BLUEZ_HDP_MANAGER_INTERFACE,
-                                       NULL, &err);
-
-       if (!proxy) {
-               BT_ERR("Unable to create proxy: %s", err->message);
-               g_clear_error(&err);
-               return BLUETOOTH_ERROR_INTERNAL;
-       }
-
-       reply = g_dbus_proxy_call_sync(proxy, "DestroyApplication",
-                               g_variant_new("o", app_handle),
-                               G_DBUS_CALL_FLAGS_NONE,
-                               -1,
-                               NULL,
-                               &err);
-
-       g_object_unref(proxy);
-       if (!reply) {
-               BT_ERR(" HDP:dbus Can't Destroy application");
-
-               if (err) {
-                       BT_ERR("%s", err->message);
-                       if (g_strrstr(err->message, BT_ACCESS_DENIED_MSG))
-                               result  = BLUETOOTH_ERROR_ACCESS_DENIED;
-                       else
-                               result  = BLUETOOTH_ERROR_INTERNAL;
-                       g_clear_error(&err);
-               }
-               return result ;
-       }
-
-       g_variant_unref(reply);
-
-       BT_DBG("Destroyed health application: %s", (char *)app_handle);
-
-       g_idle_add(__bt_hdp_internal_destroy_application_cb,
-                       (gpointer)app_handle);
-
        return BLUETOOTH_ERROR_NONE;
 }
 
-static void __bt_hdp_internal_remove_filter(void)
-{
-       BT_DBG("+");
-
-       ret_if(g_hdp_dus_conn == NULL);
-
-       __bt_hdp_add_filter_subscribe_signal(g_hdp_dus_conn, FALSE);
-
-       g_hdp_dus_conn = NULL;  /*should not unref here, bcz no ++reff */
-
-       BT_DBG("-");
-}
-
 BT_EXPORT_API int bluetooth_hdp_send_data(unsigned int channel_id,
                                            const char *buffer,
                                            unsigned int size)
 {
-       int wbytes = 0;
-       int written = 0;
-       int result;
-
-       BT_DBG("+");
-
-       BT_CHECK_ENABLED(return);
-
-       if ((channel_id == 0) || (NULL == buffer) || (size == 0)) {
-               BT_ERR("Invalid arguments..\n");
-               return BLUETOOTH_ERROR_INVALID_PARAM;
-       }
-
-       switch (privilege_token) {
-       case 0:
-               result = _bt_check_privilege(BT_BLUEZ_SERVICE, BT_HDP_SEND_DATA);
-
-               if (result == BLUETOOTH_ERROR_NONE) {
-                       privilege_token = 1; /* Have a permission */
-               } else if (result == BLUETOOTH_ERROR_PERMISSION_DEINED) {
-                       BT_ERR("Don't have a privilege to use this API");
-                       privilege_token = -1; /* Don't have a permission */
-                       return BLUETOOTH_ERROR_PERMISSION_DEINED;
-               } else {
-                       /* Just break - It is not related with permission error */
-               }
-               break;
-       case 1:
-               /* Already have a privilege */
-               break;
-       case -1:
-               return BLUETOOTH_ERROR_PERMISSION_DEINED;
-       default:
-               /* Invalid privilge token value */
-               return BLUETOOTH_ERROR_INTERNAL;
-       }
-
-       while (wbytes < size) {
-               written = write(channel_id, buffer + wbytes, size - wbytes);
-               if (written <= 0) {
-                       BT_ERR("write failed..\n");
-                       return BLUETOOTH_ERROR_NOT_IN_OPERATION;
-               }
-               wbytes += written;
-       }
-
        return BLUETOOTH_ERROR_NONE;
 }
 
-static void __bt_hdp_connect_request_cb(GDBusProxy *hdp_proxy,
-                               GAsyncResult *res, gpointer user_data)
-{
-       GError *err = NULL;
-       char *obj_connect_path = NULL;
-       bt_hdp_connected_t *conn_ind = user_data;
-       bt_user_info_t *user_info;
-       GVariant *reply = NULL;
-
-       reply = g_dbus_proxy_call_finish(hdp_proxy, res, &err);
-
-       g_object_unref(hdp_proxy);
-
-       if (!reply) {
-               if (err) {
-                       BT_ERR("HDP connection  Dbus Call Error: %s\n", err->message);
-                       g_clear_error(&err);
-               }
-
-               user_info = _bt_get_user_data(BT_COMMON);
-
-               if (user_info->cb) {
-                       _bt_common_event_cb(BLUETOOTH_EVENT_HDP_CONNECTED,
-                                       BLUETOOTH_ERROR_CONNECTION_ERROR, conn_ind,
-                                       user_info->cb, user_info->user_data);
-               }
-       } else {
-               g_variant_get(reply, "(&o)", &obj_connect_path);
-               BT_DBG("Obj Path returned = %s\n", obj_connect_path);
-       }
-       g_free((void *)conn_ind->app_handle);
-       g_free(conn_ind);
-}
-
-
 BT_EXPORT_API int bluetooth_hdp_connect(const char *app_handle,
                        bt_hdp_qos_type_t channel_type,
                        const bluetooth_device_address_t *device_address)
 {
-       GError *err = NULL;
-       GDBusConnection *conn = NULL;
-       GDBusProxy *hdp_proxy = NULL;
-       bt_hdp_connected_t *param;
-       char address[BT_ADDRESS_STRING_SIZE] = { 0 };
-       char default_adapter_path[BT_ADAPTER_OBJECT_PATH_MAX + 1] = { 0 };
-       char *dev_path = NULL;
-       char *role;
-
-       BT_DBG("+");
-
-       BT_CHECK_ENABLED(return);
-       BT_CHECK_PARAMETER(app_handle, return);
-       BT_CHECK_PARAMETER(device_address, return);
-
-       if (_bt_check_privilege(BT_BLUEZ_SERVICE, BT_HDP_CONNECT)
-            == BLUETOOTH_ERROR_PERMISSION_DEINED) {
-               BT_ERR("Don't have a privilege to use this API");
-               return BLUETOOTH_ERROR_PERMISSION_DEINED;
-       }
-
-       if (channel_type == HDP_QOS_RELIABLE) {
-               role = "Reliable";
-       } else if (channel_type == HDP_QOS_STREAMING) {
-               role = "Streaming";
-       } else if (channel_type == HDP_QOS_ANY) {
-               role = "Any";
-       } else {
-               BT_ERR("Invalid channel_type %d", channel_type);
-               return BLUETOOTH_ERROR_ACCESS_DENIED;
-       }
-
-       conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
-
-       if (err) {
-               BT_ERR("ERROR: Can't get on system bus [%s]", err->message);
-               g_clear_error(&err);
-               return BLUETOOTH_ERROR_INTERNAL;
-       }
-
-       /* If the adapter path is wrong, we can think the BT is not enabled. */
-       if (_bt_get_adapter_path(_bt_gdbus_get_system_gconn(),
-                                       default_adapter_path) < 0) {
-               BT_ERR("Could not get adapter path\n");
-               g_object_unref(conn);
-               return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
-       }
-
-       _bt_convert_addr_type_to_string(address,
-                               (unsigned char *)device_address->addr);
-
-       BT_DBG("create conection to %s", address);
-
-       dev_path = g_strdup_printf("%s/dev_%s", default_adapter_path, address);
-
-       if (dev_path == NULL) {
-               g_object_unref(conn);
-               return BLUETOOTH_ERROR_MEMORY_ALLOCATION;
-       }
-
-       g_strdelimit(dev_path, ":", '_');
-
-       BT_DBG("path: %s", dev_path);
-
-       hdp_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
-                                               NULL, BT_BLUEZ_NAME,
-                                               dev_path, BLUEZ_HDP_DEVICE_INTERFACE,
-                                               NULL, NULL);
-       g_object_unref(conn);
-
-       if (hdp_proxy == NULL) {
-               BT_ERR("Failed to get the HDP server proxy\n");
-               g_free(dev_path);
-               return BLUETOOTH_ERROR_NOT_PAIRED;
-       }
-
-       BT_DBG("app path %s\n", app_handle);
-
-       param = g_new0(bt_hdp_connected_t, 1);
-       param->app_handle = g_strdup(app_handle);
-       memcpy(&param->device_address, device_address, BLUETOOTH_ADDRESS_LENGTH);
-       param->type = channel_type;
-
-       g_dbus_proxy_call(hdp_proxy, "CreateChannel",
-                               g_variant_new("(os)", app_handle, role),
-                               G_DBUS_CALL_FLAGS_NONE, -1, NULL,
-                               (GAsyncReadyCallback)__bt_hdp_connect_request_cb,
-                               param);
-
-       g_free(dev_path);
-
        return BLUETOOTH_ERROR_NONE;
 }
 
-static void __bt_hdp_disconnect_request_cb(GDBusProxy *hdp_proxy,
-                       GAsyncResult *res, gpointer user_data)
-{
-       GError *err = NULL;
-       bt_hdp_disconnected_t *disconn_ind = user_data;
-       bt_user_info_t *user_info;
-       GVariant *reply = NULL;
-
-       reply = g_dbus_proxy_call_finish(hdp_proxy, res, &err);
-       g_object_unref(hdp_proxy);
-
-       user_info = _bt_get_user_data(BT_COMMON);
-       if (user_info == NULL || user_info->cb == NULL) {
-               g_free(disconn_ind);
-               if (err) {
-                               g_clear_error(&err);
-                       return;
-               }
-               g_variant_unref(reply);
-               return;
-       }
-
-       if (!reply) {
-               if (err) {
-                       BT_ERR("HDP disconnection Dbus Call Error: %s\n",
-                                                       err->message);
-                       g_clear_error(&err);
-               }
-
-               _bt_common_event_cb(BLUETOOTH_EVENT_HDP_DISCONNECTED,
-                               BLUETOOTH_ERROR_CONNECTION_ERROR, disconn_ind,
-                               user_info->cb, user_info->user_data);
-       } else {
-               _bt_common_event_cb(BLUETOOTH_EVENT_HDP_DISCONNECTED,
-                               BLUETOOTH_ERROR_NONE, disconn_ind,
-                               user_info->cb, user_info->user_data);
-               BT_INFO("HDP disconnection Dbus Call is done\n");
-               g_variant_unref(reply);
-       }
-
-       g_free(disconn_ind);
-}
-
 BT_EXPORT_API int bluetooth_hdp_disconnect(unsigned int channel_id,
                        const bluetooth_device_address_t *device_address)
 {
-       GError *err = NULL;
-       GDBusConnection *conn = NULL;
-       GDBusProxy *hdp_proxy = NULL;
-       char address[BT_ADDRESS_STRING_SIZE] = { 0 };
-       char default_adapter_path[BT_ADAPTER_OBJECT_PATH_MAX + 1] = { 0 };
-       char *dev_path = NULL;
-       bt_hdp_disconnected_t *param;
-
-       BT_DBG("+\n");
-
-       BT_CHECK_ENABLED(return);
-       BT_CHECK_PARAMETER(device_address, return);
-
-       if (_bt_check_privilege(BT_BLUEZ_SERVICE, BT_HDP_DISCONNECT)
-            == BLUETOOTH_ERROR_PERMISSION_DEINED) {
-               BT_ERR("Don't have a privilege to use this API");
-               return BLUETOOTH_ERROR_PERMISSION_DEINED;
-       }
-
-       hdp_obj_info_t *info =
-               __bt_hdp_internal_gslist_obj_find_using_fd(channel_id);
-       if (NULL == info) {
-               BT_ERR("*** Could not locate the list for %d*****\n",
-                                                       channel_id);
-               return BLUETOOTH_ERROR_INVALID_PARAM;
-       }
-
-       conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
-
-       if (err) {
-               BT_ERR("ERROR: Can't get on system bus [%s]", err->message);
-               g_clear_error(&err);
-               return BLUETOOTH_ERROR_INTERNAL;
-       }
-
-       /* If the adapter path is wrong, we can think the BT is not enabled. */
-       if (_bt_get_adapter_path(_bt_gdbus_get_system_gconn(),
-                                       default_adapter_path) < 0) {
-               BT_ERR("Could not get adapter path\n");
-               g_object_unref(conn);
-               return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
-       }
-
-       _bt_convert_addr_type_to_string(address,
-                               (unsigned char *)device_address->addr);
-
-       BT_DBG("create conection to  %s\n", address);
-
-       dev_path = g_strdup_printf("%s/dev_%s", default_adapter_path, address);
-
-       if (dev_path == NULL) {
-               g_object_unref(conn);
-               return BLUETOOTH_ERROR_MEMORY_ALLOCATION;
-       }
-
-       g_strdelimit(dev_path, ":", '_');
-
-       BT_DBG("path  %s\n", dev_path);
-
-       hdp_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
-                                               NULL, BT_BLUEZ_NAME,
-                                               dev_path, BLUEZ_HDP_DEVICE_INTERFACE,
-                                               NULL, NULL);
-
-       g_object_unref(conn);
-
-       if (hdp_proxy == NULL) {
-               BT_ERR("Failed to get the HDP proxy\n");
-               g_free(dev_path);
-               return BLUETOOTH_ERROR_NOT_PAIRED;
-       }
-
-       param = g_new0(bt_hdp_disconnected_t, 1);
-       param->channel_id = channel_id;
-       memcpy(&param->device_address, device_address, BLUETOOTH_ADDRESS_LENGTH);
-
-       g_dbus_proxy_call(hdp_proxy, "DestroyChannel",
-                               g_variant_new("o", info->obj_channel_path),
-                               G_DBUS_CALL_FLAGS_NONE, -1, NULL,
-                               (GAsyncReadyCallback)__bt_hdp_disconnect_request_cb,
-                               param);
-
-       g_free(dev_path);
-       g_free(param);
-       g_object_unref(hdp_proxy);
-
        return BLUETOOTH_ERROR_NONE;
-
 }
index 363e43e..02f0b93 100644 (file)
@@ -20,6 +20,7 @@ marshal.c
 ./services/audio/bt-service-audio.c
 ./services/audio/hf/bt-service-hf.c
 ./services/audio/a2dp_src/bt-service-a2dp-src.c
+./services/health/bt-service-hdp.c
 )
 
 IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
index 6975837..4801676 100644 (file)
@@ -47,6 +47,7 @@
 #endif
 #include "bt-service-hidhost.h"
 #include "bt-service-socket.h"
+#include "bt-service-hdp.h"
 
 /* OAL headers */
 #include <oal-event.h>
@@ -724,6 +725,12 @@ static int __bt_init_profiles()
                return ret;
        }
 
+       ret = _bt_hdp_init();
+       if (ret != BLUETOOTH_ERROR_NONE) {
+               BT_ERR("_bt_hdp_init Failed");
+               return ret;
+       }
+
        return BLUETOOTH_ERROR_NONE;
 }
 
index 985f85b..8dd6c5b 100644 (file)
@@ -16,6 +16,7 @@
  */
 
 #include <string.h>
+#include <stdio.h>
 #include <glib.h>
 #include <dlog.h>
 #include <gio/gio.h>
@@ -37,6 +38,7 @@
 #endif
 #include "bt-service-hidhost.h"
 #include "bt-service-rfcomm.h"
+#include "bt-service-hdp.h"
 
 /* For maintaining Application Sync API call requests */
 GSList *invocation_list = NULL;
@@ -160,7 +162,10 @@ static gboolean __bt_is_sync_function(int service_function)
                        || service_function == BT_GET_BONDED_DEVICES
                        || service_function == BT_GET_BONDED_DEVICE
                        || service_function == BT_IS_SERVICE_USED
-                       || service_function == BT_RFCOMM_LISTEN)
+                       || service_function == BT_RFCOMM_LISTEN
+                       || service_function == BT_HDP_CREATE_APPLICATION
+                       || service_function == BT_HDP_DESTROY_APPLICATION
+                       || service_function == BT_HDP_GET_FD)
                return TRUE;
        else
                return FALSE;
@@ -1204,7 +1209,119 @@ int __bt_bluez_request(int function_name,
               }
               break;
        }
+       case BT_HDP_CREATE_APPLICATION: {
+               unsigned short data_type;
+               bt_hdp_role_type_t role;
+               bt_hdp_qos_type_t channel_type;
+               int *app_id = g_new0(int, 1);
 
+               __bt_service_get_parameters(in_param1,
+                               &data_type, sizeof(short));
+               __bt_service_get_parameters(in_param2,
+                               &role, sizeof(bt_hdp_role_type_t));
+               __bt_service_get_parameters(in_param3,
+                               &channel_type, sizeof(bt_hdp_qos_type_t));
+               sender = (char*)g_dbus_method_invocation_get_sender(context);
+
+               result = _bt_hdp_app_register(role,
+                               channel_type, data_type, sender, app_id);
+               if (result != BLUETOOTH_ERROR_NONE) {
+                       g_array_append_vals(*out_param1, &app_id, sizeof(app_id));
+                       g_free(sender);
+                       g_free(app_id);
+               } else {
+                       _bt_save_invocation_context(context, result, sender,
+                                       function_name, (gpointer)app_id);
+               }
+               break;
+       }
+       case BT_HDP_DESTROY_APPLICATION: {
+               char *app_handle;
+               int *app_id = g_new0(int, 1);
+
+               app_handle = (char *)g_variant_get_data(in_param1);
+               sscanf(app_handle, "health_app_%d", app_id);
+               result = _bt_hdp_app_unregister(*app_id);
+               if (result != BLUETOOTH_ERROR_NONE) {
+                       //g_array_append_vals(*out_param1, app_handle, (strlen(app_handle) + 1));
+                       g_free(app_id);
+               } else {
+                       sender = (char*)g_dbus_method_invocation_get_sender(context);
+                       _bt_save_invocation_context(context, result, sender,
+                                       function_name, (gpointer)app_id);
+               }
+               break;
+       }
+       case BT_HDP_CONNECT: {
+               int app_id = -1;
+               char *app_handle;
+               bt_hdp_qos_type_t channel_type;
+               bluetooth_device_address_t address = { {0} };
+               int *channel_id = g_new0(int, 1);
+
+               app_handle = (char *)g_variant_get_data(in_param1);
+               sscanf(app_handle, "health_app_%d", &app_id);
+
+               __bt_service_get_parameters(in_param2,
+                               &channel_type, sizeof(bt_hdp_qos_type_t));
+               __bt_service_get_parameters(in_param3,
+                               &address, sizeof(bluetooth_device_address_t));
+
+               result = _bt_hdp_connect(app_id, &address, channel_type, channel_id);
+               if (result != BLUETOOTH_ERROR_NONE) {
+                       g_array_append_vals(*out_param1, &address,
+                                       sizeof(bluetooth_device_address_t));
+                       g_free(channel_id);
+               } else {
+                       sender = (char*)g_dbus_method_invocation_get_sender(context);
+                       _bt_save_invocation_context(context, result, sender,
+                                       function_name, (gpointer)channel_id);
+               }
+               break;
+       }
+       case BT_HDP_DISCONNECT: {
+               int *channel_id = g_new0(int, 1);
+               bluetooth_device_address_t address = { {0} };
+
+               __bt_service_get_parameters(in_param1, channel_id, sizeof(int));
+               __bt_service_get_parameters(in_param2,
+                               &address, sizeof(bluetooth_device_address_t));
+
+               result = _bt_hdp_disconnect(*channel_id);
+               if (result != BLUETOOTH_ERROR_NONE) {
+                       g_array_append_vals(*out_param1, &address,
+                                       sizeof(bluetooth_device_address_t));
+                       g_free(channel_id);
+               } else {
+                       sender = (char*)g_dbus_method_invocation_get_sender(context);
+                       _bt_save_invocation_context(context, result, sender,
+                                       function_name, (gpointer)channel_id);
+               }
+               break;
+       }
+       case BT_HDP_GET_FD: {
+               int  *channel_id = g_new0(int, 1);
+
+               __bt_service_get_parameters(in_param1, channel_id, sizeof(int));
+
+               result = _bt_hdp_get_fd(*channel_id);
+               if (result != BLUETOOTH_ERROR_NONE) {
+                       g_free(channel_id);
+               } else {
+                       sender = (char*)g_dbus_method_invocation_get_sender(context);
+                       _bt_save_invocation_context(context, result, sender,
+                                       function_name, (gpointer)channel_id);
+               }
+               break;
+       }
+       case BT_HDP_SEND_DATA: {
+               /*
+                * This call to bt-service is only used for privilege check, so return
+                * BLUETOOTH_ERROR_NONE from here.
+                */
+               result = BLUETOOTH_ERROR_NONE;
+               break;
+       }
        default:
                BT_INFO("UnSupported function [%d]", function_name);
                result = BLUETOOTH_ERROR_NOT_SUPPORT;
@@ -1412,8 +1529,9 @@ gboolean __bt_service_check_privilege(int function_name,
        case BT_HDP_CONNECT:
        case BT_HDP_DISCONNECT:
        case BT_HDP_SEND_DATA:
-       case BT_HDP_REGISTER_SINK_APP:
-       case BT_HDP_UNREGISTER_SINK_APP:
+       case BT_HDP_CREATE_APPLICATION:
+       case BT_HDP_DESTROY_APPLICATION:
+       case BT_HDP_GET_FD:
 
        case BT_DPM_SET_ALLOW_BT_MODE:
        case BT_DPM_GET_ALLOW_BT_MODE:
index 9e4b84e..5de33d4 100644 (file)
@@ -40,6 +40,7 @@ _bt_service_event_handler_callback socket_cb;
 _bt_service_event_handler_callback audio_event_cb;
 _bt_service_event_handler_callback a2dp_source_cb;
 _bt_service_event_handler_callback ag_cb;
+_bt_service_event_handler_callback hdp_cb;
 
 void _bt_service_register_event_handler_callback(
                bt_service_module_t module, _bt_service_event_handler_callback cb)
@@ -73,6 +74,10 @@ void _bt_service_register_event_handler_callback(
                BT_INFO("Register BT_AG_MODULE callback");
                ag_cb = cb;
                break;
+       case BT_HEALTH_MODULE:
+               BT_INFO("Register BT_HEALTH_MODULE callback");
+               hdp_cb = cb;
+               break;
        default:
                BT_INFO("Unknown module");
        }
@@ -97,6 +102,10 @@ void _bt_service_unregister_event_handler_callback(bt_service_module_t module)
                 BT_INFO("Un-Register BT_SOCKET_MODULE Callback");
                 socket_cb = NULL;
                 break;
+       case BT_HEALTH_MODULE:
+               BT_INFO("Un-Register BT_HEALTH_MODULE callback");
+               hdp_cb = NULL;
+               break;
        default:
                BT_INFO("Unknown module");
        }
@@ -189,6 +198,13 @@ void _bt_service_oal_event_receiver(int event_type, gpointer event_data, gsize l
                if (ag_cb)
                        ag_cb(event_type,event_data);
                break;
+       case OAL_EVENT_HDP_APP_REGISTERED:
+       case OAL_EVENT_HDP_APP_UNREGISTERED:
+       case OAL_EVENT_HDP_CHANNEL_CONNECTED:
+       case OAL_EVENT_HDP_CHANNEL_DESTROYED:
+               if (hdp_cb)
+                       hdp_cb(event_type, event_data);
+               break;
        default:
                BT_ERR("Unhandled Event: %d", event_type);
                break;
index f539589..99a912a 100644 (file)
@@ -451,6 +451,9 @@ int _bt_send_event_to_dest(const char* dest, int event_type,
        case BT_DEVICE_EVENT:
                 path = BT_DEVICE_PATH;
                break;
+       case BT_HDP_EVENT:
+               path = BT_HDP_DEVICE_PATH;
+               break;
        default:
                BT_ERR("Unknown event");
                return BLUETOOTH_ERROR_INTERNAL;
@@ -475,6 +478,12 @@ int _bt_send_event_to_dest(const char* dest, int event_type,
        case BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED:
                signal = BT_GATT_CHAR_VAL_CHANGED;
                break;
+       case BLUETOOTH_EVENT_HDP_CONNECTED:
+               signal = BT_HDP_CONNECTED;
+               break;
+       case BLUETOOTH_EVENT_HDP_DISCONNECTED:
+               signal = BT_HDP_DISCONNECTED;
+               break;
        default:
                BT_ERR("Unknown event");
                return BLUETOOTH_ERROR_INTERNAL;
diff --git a/bt-service-adaptation/services/health/bt-service-hdp.c b/bt-service-adaptation/services/health/bt-service-hdp.c
new file mode 100644 (file)
index 0000000..e805fd3
--- /dev/null
@@ -0,0 +1,534 @@
+/*
+ * Bluetooth-frwk
+ *
+ * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Author: Atul Rai <a.rai@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 <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <gio/gunixfdlist.h>
+#include <glib.h>
+#include <dlog.h>
+
+/* OAL headers */
+#include <oal-event.h>
+#include <oal-hdp.h>
+
+/* bt-service headers */
+#include "bt-internal-types.h"
+#include "bt-service-common.h"
+#include "bt-service-util.h"
+#include "bt-service-event-receiver.h"
+#include "bt-service-event.h"
+#include "bt-service-hdp.h"
+
+typedef struct {
+       int fd;
+       void *data;
+} bt_hdp_conn_info_t;
+
+typedef struct {
+       int app_id;
+       char *owner;
+} bt_hdp_app_info_t;
+
+static GSList *app_list;
+static GSList *pending_conn_list;
+
+static bt_hdp_app_info_t *__find_app_by_id(int app_id)
+{
+       GSList *l;
+
+       for (l = app_list; NULL != l; l = g_slist_next(l)) {
+               bt_hdp_app_info_t *app = l->data;
+               if (app && (app->app_id == app_id))
+                       return app;
+       }
+
+       return NULL;
+}
+
+static void __bt_hdp_handle_pending_request_info(int result,
+               int service_function, void *data, unsigned int size)
+{
+       GSList *l;
+       GArray *out_param;
+       invocation_info_t *req_info = NULL;
+
+       ret_if (data == NULL);
+
+       BT_DBG("+");
+
+       for (l = _bt_get_invocation_list(); l != NULL; l = g_slist_next(l)) {
+               req_info = l->data;
+               if (req_info == NULL || req_info->service_function != service_function)
+                       continue;
+
+               switch (service_function) {
+               case BT_HDP_CREATE_APPLICATION:
+               case BT_HDP_DESTROY_APPLICATION: {
+                       int app_id = *((int *)data);
+                       char app_handle[BT_MAX_HANDLE_LENGTH];
+
+                       if (*((int *)req_info->user_data) != app_id)
+                               break;
+
+                       memset(app_handle, 0x00, BT_MAX_HANDLE_LENGTH);
+                       snprintf(app_handle, BT_MAX_HANDLE_LENGTH, "health_app_%d", app_id);
+                       BT_DBG("app_handle: %s", app_handle);
+
+                       out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
+                       g_array_append_vals(out_param, app_handle, BT_MAX_HANDLE_LENGTH);
+                       _bt_service_method_return(req_info->context, out_param, result);
+                       g_free(req_info->user_data);
+                       _bt_free_info_from_invocation_list(req_info);
+                       g_array_free(out_param, TRUE);
+                       break;
+               }
+               case BT_HDP_CONNECT: {
+                       bt_hdp_conn_info_t *info = data;
+                       bt_hdp_connected_t *conn_data = info->data;
+
+                       if (!conn_data)
+                               break;
+
+                       if (*((int *)req_info->user_data) != conn_data->channel_id)
+                               break;
+
+                       out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
+                       g_array_append_vals(out_param, conn_data, sizeof(bt_hdp_connected_t));
+
+                       _bt_service_method_return(req_info->context, out_param, result);
+                       g_free(req_info->user_data);
+                       _bt_free_info_from_invocation_list(req_info);
+                       g_array_free(out_param, TRUE);
+                       break;
+               }
+               case BT_HDP_DISCONNECT: {
+                       bt_hdp_disconnected_t *disconn_data = data;
+
+                       if (*((int *)req_info->user_data) != disconn_data->channel_id)
+                               break;
+
+                       out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
+                       g_array_append_vals(out_param, disconn_data, sizeof(bt_hdp_disconnected_t));
+                       _bt_service_method_return(req_info->context, out_param, result);
+                       g_free(req_info->user_data);
+                       _bt_free_info_from_invocation_list(req_info);
+                       g_array_free(out_param, TRUE);
+                       break;
+               }
+               case BT_HDP_GET_FD: {
+                       GUnixFDList *fd_list = NULL;
+
+                       out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
+                       if (BLUETOOTH_ERROR_NONE == result) {
+                               GError *error = NULL;
+                               bt_hdp_conn_info_t *info = data;
+                               bt_hdp_connected_t *conn_data = info->data;
+
+                               if (*((int *)req_info->user_data) != conn_data->channel_id)
+                                       break;
+
+                               BT_DBG("fd: %d", info->fd);
+
+                               fd_list = g_unix_fd_list_new();
+                               g_unix_fd_list_append(fd_list, info->fd, &error);
+                               g_assert_no_error(error);
+                               close(info->fd);
+                       }
+
+                       _bt_service_method_return_with_unix_fd_list(
+                                       req_info->context, out_param, result, fd_list);
+                       if (fd_list)
+                               g_object_unref(fd_list);
+                       g_array_free(out_param, TRUE);
+                       return;
+               }
+               default:
+                       BT_ERR("Unknown service function");
+                       break;
+               }
+       }
+
+       BT_DBG("-");
+}
+
+static bt_hdp_qos_type_t __convert_oal_ch_type_to_hdp_qos_type(int channel_type)
+{
+       switch (channel_type) {
+       case OAL_CHANNEL_TYPE_RELIABLE:
+               return HDP_QOS_RELIABLE;
+       case OAL_CHANNEL_TYPE_STREAMING:
+               return HDP_QOS_STREAMING;
+       default:
+               return HDP_QOS_ANY;
+       }
+}
+
+static void __handle_hdp_channel_connected(event_hdp_channel_conn_t *event)
+{
+       GVariant *param;
+       bt_hdp_app_info_t *app;
+       bt_hdp_conn_info_t *hdp_conn;
+       bt_hdp_connected_t *conn_info;
+       char address[BT_ADDRESS_STRING_SIZE];
+
+       BT_DBG("+");
+
+       app = __find_app_by_id(event->app_id);
+       ret_if (NULL == app);
+
+       conn_info = g_new0(bt_hdp_connected_t, 1);
+       conn_info->type = __convert_oal_ch_type_to_hdp_qos_type(event->ch_type);
+       conn_info->channel_id = event->channel_id;
+       snprintf(conn_info->app_handle, BT_MAX_HANDLE_LENGTH, "health_app_%d", event->app_id);
+       memcpy(conn_info->device_address.addr, event->address.addr, BLUETOOTH_ADDRESS_LENGTH);
+
+       hdp_conn = g_new0(bt_hdp_conn_info_t, 1);
+       hdp_conn->fd = event->fd;
+       hdp_conn->data = conn_info;
+       pending_conn_list = g_slist_append(pending_conn_list, hdp_conn);
+
+       __bt_hdp_handle_pending_request_info(BLUETOOTH_ERROR_NONE,
+                       BT_HDP_CONNECT, (void *)hdp_conn, sizeof(bt_hdp_conn_info_t));
+
+       _bt_convert_addr_type_to_string(address, event->address.addr);
+       BT_DBG("HDP connected to %s, app_handle: %s", address, conn_info->app_handle);
+
+       param = g_variant_new("(issui)",
+                       BLUETOOTH_ERROR_NONE,
+                       address, conn_info->app_handle,
+                       conn_info->channel_id, conn_info->type);
+       _bt_send_event_to_dest(app->owner,
+               BT_HDP_EVENT, BLUETOOTH_EVENT_HDP_CONNECTED, param);
+
+       BT_DBG("-");
+}
+
+static void __handle_hdp_channel_disconnected(event_hdp_channel_conn_t *event)
+{
+       bt_hdp_app_info_t *app;
+
+
+       BT_DBG("+");
+
+       app = __find_app_by_id(event->app_id);
+       ret_if (NULL == app);
+
+       /* reply to pending requests if any */
+       if (0 > event->fd) {
+               bt_hdp_conn_info_t hdp_conn;
+               bt_hdp_connected_t conn_info;
+
+               BT_DBG("Connect request failed for channel_id: %d", event->channel_id);
+               memset(&conn_info, 0x00, sizeof(bt_hdp_connected_t));
+               conn_info.type = __convert_oal_ch_type_to_hdp_qos_type(event->ch_type);
+               conn_info.channel_id = event->channel_id;
+               snprintf(conn_info.app_handle, BT_MAX_HANDLE_LENGTH, "health_app_%d", event->app_id);
+               memcpy(conn_info.device_address.addr, event->address.addr, BLUETOOTH_ADDRESS_LENGTH);
+
+               hdp_conn.fd = event->fd;
+               hdp_conn.data = &conn_info;
+
+               __bt_hdp_handle_pending_request_info(BLUETOOTH_ERROR_INTERNAL,
+                               BT_HDP_CONNECT, (void *)&hdp_conn, sizeof(bt_hdp_conn_info_t));
+       } else {
+               bt_hdp_disconnected_t disconn_info;
+               char address[BT_ADDRESS_STRING_SIZE];
+               char app_handle[BT_MAX_HANDLE_LENGTH];
+               GVariant *param;
+
+               memset(&disconn_info, 0x00, sizeof(bt_hdp_disconnected_t));
+               disconn_info.channel_id = event->channel_id;
+               memcpy(disconn_info.device_address.addr, event->address.addr, BLUETOOTH_ADDRESS_LENGTH);
+
+               __bt_hdp_handle_pending_request_info(BLUETOOTH_ERROR_NONE,
+                               BT_HDP_DISCONNECT, (void *)&disconn_info, sizeof(bt_hdp_disconnected_t));
+
+               /* Send event to application */
+               _bt_convert_addr_type_to_string(address, event->address.addr);
+               snprintf(app_handle, BT_MAX_HANDLE_LENGTH, "health_app_%d", event->app_id);
+               BT_DBG("HDP disconnected from %s, app_handle: %s", address, app_handle);
+               param = g_variant_new("(isu)",
+                               BLUETOOTH_ERROR_NONE,
+                               address, event->channel_id);
+               _bt_send_event_to_dest(app->owner,
+                               BT_HDP_EVENT, BLUETOOTH_EVENT_HDP_DISCONNECTED, param);
+       }
+
+       BT_DBG("-");
+}
+
+static void __bt_hdp_event_handler(int event_type, gpointer event_data)
+{
+       BT_INFO("OAL event = 0x%x, \n", event_type);
+
+       switch (event_type) {
+       case OAL_EVENT_HDP_APP_REGISTERED: {
+               event_hdp_app_reg_t *app_data = event_data;
+               int result;
+               int app_id;
+
+               ret_if(NULL == event_data);
+               app_id = app_data->app_id;
+               if (OAL_STATUS_SUCCESS != app_data->status) {
+                       bt_hdp_app_info_t *app = __find_app_by_id(app_id);
+                       if (app) {
+                               app_list = g_slist_remove(app_list, app);
+                               g_free(app->owner);
+                               g_free(app);
+                       }
+                       result = BLUETOOTH_ERROR_INTERNAL;
+               } else {
+                       result = BLUETOOTH_ERROR_NONE;
+               }
+
+               BT_DBG("app_id: %d, resut: %d", app_id, result);
+               __bt_hdp_handle_pending_request_info(result,
+                       BT_HDP_CREATE_APPLICATION, (void *)&app_id, sizeof(app_id));
+               break;
+       }
+       case OAL_EVENT_HDP_APP_UNREGISTERED: {
+               event_hdp_app_reg_t *app_data = event_data;
+               int result;
+               int app_id;
+
+               ret_if(NULL == event_data);
+               app_id = app_data->app_id;
+               if (OAL_STATUS_SUCCESS != app_data->status) {
+                       result = BLUETOOTH_ERROR_INTERNAL;
+               } else {
+                       bt_hdp_app_info_t *app = __find_app_by_id(app_id);
+                       if (app) {
+                               app_list = g_slist_remove(app_list, app);
+                               g_free(app->owner);
+                               g_free(app);
+                       }
+                       result = BLUETOOTH_ERROR_NONE;
+               }
+
+               BT_DBG("app_id: %d, resut: %d", app_id, result);
+               __bt_hdp_handle_pending_request_info(result,
+                       BT_HDP_DESTROY_APPLICATION, (void *)&app_id, sizeof(app_id));
+               break;
+       }
+       case OAL_EVENT_HDP_CHANNEL_CONNECTED: {
+               ret_if(NULL == event_data);
+               __handle_hdp_channel_connected((event_hdp_channel_conn_t *)event_data);
+               break;
+       }
+       case OAL_EVENT_HDP_CHANNEL_DESTROYED: {
+               ret_if(NULL == event_data);
+               __handle_hdp_channel_disconnected((event_hdp_channel_conn_t *)event_data);
+               break;
+       }
+       default:
+               BT_ERR("Invalid event:%d\n", event_type);
+               break;
+       }
+}
+
+int _bt_hdp_init(void)
+{
+       BT_DBG("+");
+
+       if(OAL_STATUS_SUCCESS != hdp_init()) {
+               BT_ERR("hdp_init failed");
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       /* Register SOCKET event handler */
+       _bt_service_register_event_handler_callback(BT_HEALTH_MODULE, __bt_hdp_event_handler);
+       BT_DBG("-");
+       return BLUETOOTH_ERROR_NONE;
+}
+
+void _bt_hdp_deinit(void)
+{
+       BT_DBG("+");
+
+       if(OAL_STATUS_SUCCESS != hdp_cleanup())
+               BT_ERR("hdp_cleanup failed");
+
+       /* Un-register SOCKET event handler */
+       _bt_service_unregister_event_handler_callback(BT_HEALTH_MODULE);
+       BT_DBG("-");
+}
+
+int _bt_hdp_app_register(bt_hdp_role_type_t role, bt_hdp_qos_type_t channel_type,
+               unsigned short data_type, char *sender, int *app_id)
+{
+       oal_channel_type_t ch_type;
+       oal_hdp_role_t dev_role;
+       bt_hdp_app_info_t *app;
+
+       BT_DBG("+");
+
+       retv_if (NULL == app_id, BLUETOOTH_ERROR_INVALID_PARAM);
+
+       switch (role) {
+       case HDP_ROLE_SOURCE:
+               dev_role = OAL_HDP_ROLE_SOURCE;
+               break;
+       case HDP_ROLE_SINK:
+               dev_role = OAL_HDP_ROLE_SINK;
+               break;
+       default:
+               BT_ERR("Invalid HDP role");
+               return BLUETOOTH_ERROR_INVALID_PARAM;
+       }
+
+       switch (channel_type) {
+       case HDP_QOS_RELIABLE:
+               ch_type = OAL_CHANNEL_TYPE_RELIABLE;
+               break;
+       case HDP_QOS_STREAMING:
+               ch_type = OAL_CHANNEL_TYPE_STREAMING;
+               break;
+       case HDP_QOS_ANY:
+               ch_type = OAL_CHANNEL_TYPE_ANY;
+               break;
+       default:
+               BT_ERR("Invalid channel type");
+               return BLUETOOTH_ERROR_INVALID_PARAM;
+       }
+
+       *app_id = hdp_register_application(dev_role, ch_type, sender, data_type);
+       if (0 > *app_id) {
+               BT_ERR("hdp_register_application failed");
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       /* Add application to the list */
+       app = g_new0(bt_hdp_app_info_t, 1);
+       app->app_id = *app_id;
+       app->owner = g_strdup(sender);
+       app_list = g_slist_append(app_list, app);
+
+       BT_DBG("-");
+       return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_hdp_app_unregister(int app_id)
+{
+       int ret;
+
+       BT_DBG("+");
+
+       ret = hdp_unregister_application(app_id);
+       if (OAL_STATUS_SUCCESS != ret) {
+               BT_ERR("hdp_unregister_application failed");
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       BT_DBG("-");
+       return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_hdp_connect(int app_id, bluetooth_device_address_t *address,
+               bt_hdp_qos_type_t channel_type, int *channel_id)
+{
+       bt_address_t bd_addr;
+
+       BT_DBG("+");
+
+       retv_if (NULL == address, BLUETOOTH_ERROR_INVALID_PARAM);
+       retv_if (NULL == channel_id, BLUETOOTH_ERROR_INVALID_PARAM);
+
+       memset(&bd_addr, 0x00, sizeof(bt_address_t));
+       memcpy(bd_addr.addr, address->addr, BT_ADDRESS_BYTES_NUM);
+
+       *channel_id = hdp_connect_channel(app_id, &bd_addr);
+       if (0 > *channel_id) {
+               BT_ERR("hdp_connect_channel failed");
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       BT_DBG("-");
+       return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_hdp_disconnect(int channel_id)
+{
+       int ret;
+
+       BT_DBG("+");
+
+       ret = hdp_disconnect_channel(channel_id);
+       if (OAL_STATUS_SUCCESS != ret) {
+               BT_ERR("hdp_disconnect_channel failed");
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       BT_DBG("-");
+       return BLUETOOTH_ERROR_NONE;
+}
+
+gboolean __send_fd(gpointer data)
+{
+       bt_hdp_conn_info_t *info = data;
+
+       BT_DBG("+");
+
+       if (info) {
+               pending_conn_list = g_slist_remove(pending_conn_list, info);
+               __bt_hdp_handle_pending_request_info(BLUETOOTH_ERROR_NONE,
+                               BT_HDP_GET_FD, (void *)info, sizeof(bt_hdp_conn_info_t));
+               g_free(info->data);
+               g_free(info);
+       } else {
+               bt_hdp_conn_info_t info;
+
+               __bt_hdp_handle_pending_request_info(BLUETOOTH_ERROR_INTERNAL,
+                               BT_HDP_GET_FD, (void *)&info, sizeof(bt_hdp_conn_info_t));
+       }
+
+       BT_DBG("-");
+       return FALSE;
+}
+
+int _bt_hdp_get_fd(int channel_id)
+{
+       GSList *l;
+       bt_hdp_conn_info_t *info = NULL;
+       bt_hdp_connected_t *conn_info = NULL;
+
+       BT_DBG("+");
+
+       BT_DBG("channel_id: %d, pending_conn_list: %p", channel_id, pending_conn_list);
+       for (l = pending_conn_list; NULL != l; l = g_slist_next(l)) {
+               info = l->data;
+
+               if (!info)
+                       continue;
+
+               conn_info = (bt_hdp_connected_t *)(info->data);
+               if (conn_info && (conn_info->channel_id == channel_id)) {
+                       BT_DBG("Match found");
+                       break;
+               }
+
+               info = NULL;
+               conn_info = NULL;
+       }
+
+       g_idle_add(__send_fd, info);
+       return BLUETOOTH_ERROR_NONE;
+       BT_DBG("-");
+}
index 61c1a00..7b3b7d2 100644 (file)
@@ -39,7 +39,8 @@ typedef enum {
        BT_A2DP_SINK_MODULE,
        BT_HFP_MODULE,
        BT_AG_MODULE,
-       BT_AUDIO_ALL_MODULE
+       BT_AUDIO_ALL_MODULE,
+       BT_HEALTH_MODULE,
 } bt_service_module_t;
 
 void _bt_service_oal_event_receiver(int event_type, gpointer event_data, gsize len);
diff --git a/bt-service-adaptation/services/include/bt-service-hdp.h b/bt-service-adaptation/services/include/bt-service-hdp.h
new file mode 100644 (file)
index 0000000..dfb0bf9
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Bluetooth-frwk
+ *
+ * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:  Atul Kumar Rai <a.rai@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_HDP_H__
+#define __BT_SERVICE_HDP_H__
+
+#include <glib.h>
+#include <sys/types.h>
+#include "bluetooth-api.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int _bt_hdp_init(void);
+void _bt_hdp_deinit(void);
+int _bt_hdp_app_register(bt_hdp_role_type_t role, bt_hdp_qos_type_t channel_type,
+               unsigned short data_type, char *sender, int *app_id);
+int _bt_hdp_app_unregister(int app_id);
+int _bt_hdp_connect(int app_id, bluetooth_device_address_t *address,
+               bt_hdp_qos_type_t channel_type, int *channel_id);
+int _bt_hdp_disconnect(int channel_id);
+int _bt_hdp_get_fd(int channel_id);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __BT_SERVICE_HDP_H__ */
index c7aa3c7..7bcc6cd 100644 (file)
@@ -1146,8 +1146,9 @@ typedef enum {
 /**
  * Stucture to HDP connected
  */
+#define BT_MAX_HANDLE_LENGTH  50
 typedef struct {
-       const char *app_handle; /**< the application handle */
+       char app_handle[BT_MAX_HANDLE_LENGTH];  /**< the application handle */
        unsigned int channel_id;        /**< the channel id */
        bt_hdp_qos_type_t type; /**< the QOS type */
        bluetooth_device_address_t device_address; /**< the remote address */
index 0709514..64db6e4 100644 (file)
@@ -66,6 +66,7 @@ typedef enum {
 #ifdef GATT_NO_RELAY
        BT_GATT_BLUEZ_EVENT, /* GattValueChanged from bluez directly */
 #endif
+       BT_HDP_EVENT,
        /* Will be added */
 } bt_event_type_t;
 
@@ -278,11 +279,14 @@ typedef enum {
        BT_CONNECT_LE,
        BT_DISCONNECT_LE,
        BT_SET_LE_PRIVACY,
+
        BT_HDP_CONNECT = BT_FUNC_HDP_BASE,
        BT_HDP_DISCONNECT,
        BT_HDP_SEND_DATA,
-       BT_HDP_REGISTER_SINK_APP,
-       BT_HDP_UNREGISTER_SINK_APP,
+       BT_HDP_CREATE_APPLICATION,
+       BT_HDP_DESTROY_APPLICATION,
+       BT_HDP_GET_FD,
+
        BT_GATT_GET_PRIMARY_SERVICES = BT_FUNC_GATT_BASE,
        BT_GATT_DISCOVER_CHARACTERISTICS,
        BT_GATT_SET_PROPERTY_REQUEST,
@@ -391,6 +395,7 @@ typedef struct {
 #define BT_AVRCP_CONTROL_PATH "/org/projectx/bt/avrcp_control"
 #define BT_A2DP_SOURCE_PATH "/org/projectx/bt/a2dp_source"
 #define BT_HID_DEVICE_PATH "/org/projectx/bt/hid_device"
+#define BT_HDP_DEVICE_PATH "/org/projectx/bt/hdp_device"
 
 #define BT_ENABLED "Enabled"
 #define BT_DISABLED "Disabled"
@@ -493,6 +498,8 @@ typedef struct {
 #define BT_IPSP_DISCONNECTED "IpspDisconnected"
 #define BT_IPSP_BT_INTERFACE_INFO "IpspBtInterfaceInfo"
 #define BT_LE_DATA_LENGTH_CHANGED "LEDataLengthChanged"
+#define BT_HDP_CONNECTED "HDPConnected"
+#define BT_HDP_DISCONNECTED "HDPDisconnected"
 
 #ifdef __cplusplus
 }