[Core] Sync bt-core from tizen branch 57/150157/1
authorAtul Rai <a.rai@samsung.com>
Thu, 14 Sep 2017 11:47:24 +0000 (17:17 +0530)
committerAtul Rai <a.rai@samsung.com>
Thu, 14 Sep 2017 11:47:24 +0000 (17:17 +0530)
Change-Id: I9613c114aaaf06086b9981cc8f8159f9756a0316
Signed-off-by: Atul Rai <a.rai@samsung.com>
bt-core/CMakeLists.txt
bt-core/bt-core-adapter.c
bt-core/bt-core-adapter.xml [deleted file]
bt-core/bt-core-dbus-handler.c
bt-core/bt-request-service.xml [deleted file]
bt-core/include/bt-core-dbus-handler.h

index 6eaf4ff..fa24aa7 100644 (file)
@@ -23,7 +23,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(pkgs REQUIRED dbus-1 dbus-glib-1 dlog vconf gio-2.0 gio-unix-2.0 eventsystem capi-system-info)
+pkg_check_modules(pkgs REQUIRED dlog vconf gio-2.0 gio-unix-2.0 eventsystem capi-system-info)
 
 FOREACH(flag ${pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
@@ -45,7 +45,8 @@ ADD_DEFINITIONS("-DVENDOR=\"${APP_VENDOR}\"")
 ADD_DEFINITIONS("-DAPPNAME=\"${APP_NAME}\"")
 ADD_DEFINITIONS("-DAPP_DIR=\"${APP_DIR}\"")
 ADD_DEFINITIONS("-DAPP_SYSCONFDIR=\"${APP_SYSCONFDIR}\"")
-ADD_DEFINITIONS("-DHPS_FEATURE")
+#ADD_DEFINITIONS("-DTIZEN_FEATURE_BT_HPS")
+ADD_DEFINITIONS("-DTIZEN_FEATURE_BT_OTP")
 
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
 
index 5a8fe67..247bfef 100644 (file)
 #define BT_CORE_IDLE_TERM_TIME 200 /* 200ms */
 #define BT_CORE_CHECK_ADAPTER_OBJECT_PATH_MAX 50
 
+#ifdef TIZEN_FEATURE_BT_OTP
+#define BT_OTP_OBJECT_PATH     "/org/projectx/otp"
+#define BT_OTP_INTERFACE_NAME  "org.projectx.otp_service"
+#define BLE_DISABLED           "LeDisabled"
+#endif
 
 static bt_status_t adapter_status = BT_DEACTIVATED;
 static bt_le_status_t adapter_le_status = BT_LE_DEACTIVATED;
@@ -298,13 +303,16 @@ int _bt_disable_adapter(void)
 
 int _bt_enable_adapter_le(void)
 {
-       BT_DBG("+");
+       BT_DBG("");
 
        int ret;
+       bt_status_t status;
        bt_le_status_t le_status;
-
        le_status = _bt_core_get_le_status();
-       if (le_status == BT_LE_DEACTIVATED) {
+       retv_if(le_status != BT_LE_DEACTIVATED, -1);
+
+       status = _bt_core_get_status();
+       if (status == BT_DEACTIVATED) {
                __bt_core_set_le_status(BT_LE_ACTIVATING);
                BT_DBG("Activate BT");
                if (TIZEN_FEATURE_BT_USB_DONGLE) {
@@ -321,41 +329,64 @@ int _bt_enable_adapter_le(void)
                        } else {
                                ret = __execute_command("/usr/etc/bluetooth/bt-dev-end.sh &", NULL);
                        }
+                       __bt_core_set_status(BT_DEACTIVATED);
                        __bt_core_set_le_status(BT_LE_DEACTIVATED);
                        return -1;
                }
        } else {
+               __bt_core_set_le_status(BT_LE_ACTIVATED);
                g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
        }
-#ifdef HPS_FEATURE
+#ifdef TIZEN_FEATURE_BT_HPS
        ret = _bt_core_start_httpproxy();
        if (ret < 0)
                BT_ERR("_bt_core_start_httpproxy() failed");
 #endif
-       __bt_core_set_le_status(BT_LE_ACTIVATED);
-       BT_DBG("-");
 
        return 0;
 }
 
+#ifdef TIZEN_FEATURE_BT_OTP
+static void _bt_core_stop_otp()
+{
+       GError *error = NULL;
+       GDBusMessage *msg = NULL;
+       GDBusConnection *conn = _bt_core_get_gdbus_connection();
+       msg = g_dbus_message_new_signal(BT_OTP_OBJECT_PATH, BT_OTP_INTERFACE_NAME, BLE_DISABLED);
+       if (!g_dbus_connection_send_message(conn, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, 0, NULL)) {
+               if (error != NULL) {
+                       BT_ERR("Failed to send BLE_DISABLED signal to OTP : errCode[%x], \
+                                       message[%s]",
+                                       error->code, error->message);
+                       g_clear_error(&error);
+               }
+       }
+}
+#endif
+
 int _bt_disable_adapter_le(void)
 {
        BT_DBG("+");
 
+       bt_status_t status;
        bt_le_status_t le_status;
 
        le_status = _bt_core_get_le_status();
        retv_if(le_status == BT_LE_DEACTIVATED, 0);
        retv_if(le_status == BT_LE_DEACTIVATING, -1);
 
-#ifdef HPS_FEATURE
+#ifdef TIZEN_FEATURE_BT_HPS
        _bt_core_stop_httpproxy();
 #endif
 
-       le_status = _bt_core_get_le_status();
-       BT_DBG("status : %d", le_status);
+#ifdef TIZEN_FEATURE_BT_OTP
+       _bt_core_stop_otp();
+#endif
 
-       if (le_status == BT_LE_ACTIVATED) {
+       status = _bt_core_get_status();
+       BT_DBG("status : %d", status);
+
+       if (status == BT_DEACTIVATED) {
                __bt_core_set_le_status(BT_LE_DEACTIVATING);
                int ret;
                if (TIZEN_FEATURE_BT_USB_DONGLE) {
@@ -401,13 +432,15 @@ int _bt_core_service_request_adapter(int service_function)
        return ret;
 }
 
-static gboolean __bt_core_check_the_adapter_path(GDBusConnection *conn)
+static gboolean __bt_core_check_the_adapter_path(void)
 {
        GError *err = NULL;
        GDBusProxy *manager_proxy = NULL;
        GVariant *result = NULL;
        char *adapter_path = NULL;
+       GDBusConnection *conn = NULL;
 
+       conn = _bt_core_get_gdbus_connection();
        if (conn == NULL)
                return FALSE;
 
@@ -429,7 +462,7 @@ static gboolean __bt_core_check_the_adapter_path(GDBusConnection *conn)
        }
 
        result = g_dbus_proxy_call_sync(manager_proxy, "DefaultAdapter", NULL,
-                       G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
+                       G_DBUS_CALL_FLAGS_NONE, 1000, NULL, &err);
        if (!result) {
                if (err != NULL) {
                        BT_ERR("Fail to get DefaultAdapter (Error: %s)", err->message);
@@ -474,7 +507,7 @@ void _bt_core_update_status(void)
        int bt_le_status = VCONFKEY_BT_LE_STATUS_OFF;
        gboolean ret = FALSE;
 
-       ret = __bt_core_check_the_adapter_path(_bt_core_get_gdbus_connection());
+       ret = __bt_core_check_the_adapter_path();
        BT_INFO("check the real status of bt_adapter");
 
        if (ret != TRUE) {
@@ -491,7 +524,7 @@ void _bt_core_update_status(void)
                if (bt_status & VCONFKEY_BT_STATUS_ON)
                        __bt_core_set_status(BT_ACTIVATED);
                if (bt_le_status & VCONFKEY_BT_LE_STATUS_ON)
-                       __bt_core_set_le_status(BT_LE_ACTIVATED);
+                       __bt_core_set_le_status(BT_ACTIVATED);
        }
 }
 
@@ -510,19 +543,37 @@ gboolean _bt_core_enable_adapter(void)
                return TRUE;
 }
 
+static gboolean __bt_core_terminate_cb(gpointer data)
+{
+       _bt_core_terminate();
+
+       return FALSE;
+}
+
 gboolean _bt_core_disable_adapter(void)
 {
        int ret;
+       gboolean adapter_state;
 
        _bt_set_flightmode_request(FALSE);
        if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
                BT_ERR("Set vconf failed");
 
+       adapter_state = __bt_core_check_the_adapter_path();
+       if (adapter_state == FALSE)
+               BT_INFO("Default adapter is NOT normal.");
+
        ret = _bt_disable_adapter();
-       if (ret < 0)
-               return FALSE;
-       else
+       if (adapter_state == FALSE) {
+               g_timeout_add(BT_CORE_IDLE_TERM_TIME,
+                             __bt_core_terminate_cb, NULL);
                return TRUE;
+       } else {
+               if (ret < 0)
+                       return FALSE;
+               else
+                       return TRUE;
+       }
 }
 
 gboolean _bt_core_recover_adapter(void)
@@ -681,7 +732,6 @@ gboolean _bt_core_factory_test_mode(const char *type, const char *arg)
                arg_list[0] = "bt-enable-rf-channel.sh";
                arg_list[1] = (char *)arg;
        } else {
-               _bt_core_terminate();
                return FALSE;
        }
 
@@ -689,7 +739,6 @@ gboolean _bt_core_factory_test_mode(const char *type, const char *arg)
        if (__execute_command(cmd, arg_list) < 0)
                BT_ERR("running script failed");
 
-       _bt_core_terminate();
        return TRUE;
 }
 
diff --git a/bt-core/bt-core-adapter.xml b/bt-core/bt-core-adapter.xml
deleted file mode 100644 (file)
index 82682cf..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-
-<node name="/">
-       <interface name="org.projectx.btcore">
-               <method name="EnableAdapter">
-                       <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
-               </method>
-               <method name="DisableAdapter">
-                       <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
-               </method>
-               <method name="RecoverAdapter">
-                       <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
-               </method>
-               <method name="ResetAdapter">
-                       <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
-               </method>
-               <method name="EnableAdapterLe">
-                       <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
-               </method>
-               <method name="DisableAdapterLe">
-                       <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
-               </method>
-               <method name="EnableCore">
-                       <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
-               </method>
-       </interface>
-</node>
index b6a0e77..5eb2894 100755 (executable)
@@ -29,7 +29,7 @@
 #define BT_SERVICE_NAME                "org.projectx.bt"
 #define BT_SERVICE_PATH                "/org/projectx/bt_service"
 
-#ifdef HPS_FEATURE
+#ifdef TIZEN_FEATURE_BT_HPS
 #define BT_HPS_SERVICE_NAME "org.projectx.httpproxy"
 #define BT_HPS_OBJECT_PATH "/org/projectx/httpproxy"
 #define BT_HPS_INTERFACE_NAME "org.projectx.httpproxy_service"
@@ -37,7 +37,7 @@
 
 static GDBusConnection *service_gconn;
 static GDBusProxy *service_gproxy;
-#ifdef HPS_FEATURE
+#ifdef TIZEN_FEATURE_BT_HPS
 static GDBusProxy *hps_gproxy;
 #endif
 
@@ -108,12 +108,12 @@ GDBusProxy *_bt_core_gdbus_get_service_proxy(void)
        return (service_gproxy) ? service_gproxy : __bt_core_gdbus_init_service_proxy();
 }
 
-#ifdef HPS_FEATURE
+#ifdef TIZEN_FEATURE_BT_HPS
 int _bt_core_start_httpproxy(void)
 {
        GVariant *variant = NULL;
        unsigned char enabled;
-
+       GError *err = NULL;
        BT_DBG(" ");
 
        hps_gproxy = _bt_core_gdbus_get_hps_proxy();
@@ -123,7 +123,11 @@ int _bt_core_start_httpproxy(void)
        }
 
        variant = g_dbus_proxy_call_sync(hps_gproxy, "enable",
-                               NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL);
+                               NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
+       if (err) {
+               BT_ERR("Error : %s" , err->message);
+               g_clear_error(&err);
+       }
        if (variant) {
                g_variant_get(variant, "(y)", &enabled);
                BT_ERR("HPS enabled status 0x%x", enabled);
@@ -135,7 +139,7 @@ int _bt_core_stop_httpproxy(void)
 {
        GVariant *variant = NULL;
        unsigned char enabled;
-
+       GError *err = NULL;
        BT_DBG(" ");
 
        hps_gproxy = _bt_core_gdbus_get_hps_proxy();
@@ -145,7 +149,11 @@ int _bt_core_stop_httpproxy(void)
        }
 
        variant = g_dbus_proxy_call_sync(hps_gproxy, "disable",
-                               NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL);
+                               NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
+       if (err) {
+               BT_ERR("Error : %s" , err->message);
+               g_clear_error(&err);
+       }
        if (variant) {
                g_variant_get(variant, "(y)", &enabled);
                BT_ERR("HPS disabled status 0x%x", enabled);
@@ -199,7 +207,7 @@ void _bt_core_gdbus_deinit_proxys(void)
                service_gproxy = NULL;
        }
 
-#ifdef HPS_FEATURE
+#ifdef TIZEN_FEATURE_BT_HPS
        if (hps_gproxy) {
                g_object_unref(hps_gproxy);
                hps_gproxy = NULL;
@@ -218,7 +226,7 @@ int _bt_core_service_request(int service_type, int service_function,
                        GArray **out_param1)
 {
        GDBusProxy  *proxy;
-       GVariant *ret;
+       GVariant *ret = NULL;
        GVariant *param1;
        GVariant *param2;
        GVariant *param3;
@@ -379,6 +387,7 @@ static void __bt_core_dbus_method(GDBusConnection *connection,
                ret = _bt_core_factory_test_mode(type, arg);
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", ret));
+               _bt_core_terminate();
                 return;
        } else {
                ret = FALSE;
@@ -534,6 +543,7 @@ gboolean _bt_core_register_dbus(void)
                                        node_info->interfaces[0],
                                        &method_table,
                                        NULL, NULL, &error);
+       g_dbus_node_info_unref(node_info);
        if (obj_id == 0) {
                BT_ERR("Failed to register: %s", error->message);
                g_error_free(error);
diff --git a/bt-core/bt-request-service.xml b/bt-core/bt-request-service.xml
deleted file mode 100644 (file)
index 9d34048..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<node name="/org/projectx/bt_service">
-  <interface name="org.projectx.bt">
-    <method name="service_request">
-      <annotation name="org.freedesktop.DBus.GLib.Async" value="bt_service_request"/>
-      <!-- INPUT PARAMS FOR SERVICE FUNCTION  -->
-      <arg type="i" name="service_type" direction="in" />
-      <arg type="i" name="service_function" direction="in" />
-      <arg type="i" name="request_type" direction="in" />
-      <arg type="ay" name="input_param1" direction="in" />
-      <arg type="ay" name="input_param2" direction="in" />
-      <arg type="ay" name="input_param3" direction="in" />
-      <arg type="ay" name="input_param4" direction="in" />
-      <arg type="ay" name="input_param5" direction="in" />
-      <!-- OUTPUT PARAMS FOR SERVICE FUNCTION  -->
-      <arg type="ay" name="output_param1" direction="out" />
-      <arg type="ay" name="output_param2" direction="out" />
-    </method>
-  </interface>
-</node>
-
index e868087..dfaef71 100755 (executable)
@@ -22,9 +22,6 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <dlog.h>
-#include <dbus/dbus.h>
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
 #include <glib.h>
 #include <gio/gio.h>
 
@@ -51,7 +48,7 @@ int _bt_core_service_request(int service_type, int service_function,
                        GArray **out_param1);
 void _bt_core_fill_garray_from_variant(GVariant *var, GArray *param);
 GDBusProxy *_bt_core_gdbus_get_service_proxy(void);
-#ifdef HPS_FEATURE
+#ifdef TIZEN_FEATURE_BT_HPS
 GDBusProxy *_bt_core_gdbus_get_hps_proxy(void);
 int _bt_core_start_httpproxy(void);
 int _bt_core_stop_httpproxy(void);