Add the gatt server check flag 25/77525/2 accepted/tizen/common/20160703.130620 accepted/tizen/ivi/20160701.033635 accepted/tizen/mobile/20160701.033725 accepted/tizen/tv/20160701.033559 accepted/tizen/wearable/20160701.033640 submit/tizen/20160630.090533 submit/tizen_common/20160701.180000
authorHyuk Lee <hyuk0512.lee@samsung.com>
Thu, 30 Jun 2016 06:38:28 +0000 (15:38 +0900)
committerHyuk Lee <hyuk0512.lee@samsung.com>
Thu, 30 Jun 2016 06:40:56 +0000 (15:40 +0900)
Change-Id: Id5e278baa4246bb3b7ebcff2e6545cbc9034e1ca
Signed-off-by: Hyuk Lee <hyuk0512.lee@samsung.com>
bt-api/bt-gatt-service.c

index bfef525..8278ca9 100644 (file)
@@ -21,6 +21,7 @@
 #include<stdlib.h>
 #include<unistd.h>
 #include<stdint.h>
+#include<stdbool.h>
 
 #include "bt-common.h"
 #include "bt-internal-types.h"
@@ -34,6 +35,7 @@ static gboolean new_service = FALSE;
 static gboolean new_char = FALSE;
 static int serv_id = 1;
 static int register_pending_cnt = 0;
+static bool is_server_started = false;
 
 /* Introspection data for the service we are exporting */
 static const gchar service_introspection_xml[] =
@@ -1397,24 +1399,30 @@ BT_EXPORT_API int bluetooth_gatt_unregister_application(void)
 {
        GDBusProxy *proxy = NULL;
 
-       proxy = __bt_gatt_gdbus_get_manager_proxy("org.bluez",
-                                       "/org/bluez/hci0", GATT_MNGR_INTERFACE);
+       if (is_server_started) {
+               proxy = __bt_gatt_gdbus_get_manager_proxy("org.bluez",
+                               "/org/bluez/hci0", GATT_MNGR_INTERFACE);
 
-       if (proxy == NULL || app_path == NULL)
-               return BLUETOOTH_ERROR_INTERNAL;
+               if (proxy == NULL || app_path == NULL)
+                       return BLUETOOTH_ERROR_INTERNAL;
 
-       BT_INFO("UnregisterApplication");
+               BT_INFO("UnregisterApplication");
 
-       /* Async Call to Unregister Service */
-       g_dbus_proxy_call(proxy,
+               /* Async Call to Unregister Service */
+               g_dbus_proxy_call(proxy,
                                "UnregisterApplication",
                                g_variant_new("(o)",
-                               app_path),
+                                       app_path),
                                G_DBUS_CALL_FLAGS_NONE, -1,
                                NULL,
                                (GAsyncReadyCallback) unregister_application_cb,
                                NULL);
 
+               is_server_started = false;
+               return BLUETOOTH_ERROR_NONE;
+       }
+
+       BT_INFO("GATT server not started");
        return BLUETOOTH_ERROR_NONE;
 }
 
@@ -2043,27 +2051,36 @@ BT_EXPORT_API int bluetooth_gatt_register_application(void)
 {
        GDBusProxy *proxy = NULL;
 
-       if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_GATT_REGISTER_APPLICATION)
-                       == BLUETOOTH_ERROR_PERMISSION_DEINED) {
-               BT_ERR("Don't have aprivilege to use this API");
-               return BLUETOOTH_ERROR_PERMISSION_DEINED;
-       }
+       if (!is_server_started) {
 
-       proxy = __bt_gatt_gdbus_get_manager_proxy("org.bluez",
-                                       "/org/bluez/hci0", GATT_MNGR_INTERFACE);
-       if (proxy == NULL || app_path == NULL)
-               return BLUETOOTH_ERROR_INTERNAL;
+               if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_GATT_REGISTER_APPLICATION)
+                               == BLUETOOTH_ERROR_PERMISSION_DEINED) {
+                       BT_ERR("Don't have aprivilege to use this API");
+                       return BLUETOOTH_ERROR_PERMISSION_DEINED;
+               }
 
-       BT_INFO("RegisterApplication");
+               proxy = __bt_gatt_gdbus_get_manager_proxy("org.bluez",
+                               "/org/bluez/hci0", GATT_MNGR_INTERFACE);
+               if (proxy == NULL || app_path == NULL)
+                       return BLUETOOTH_ERROR_INTERNAL;
 
-       g_dbus_proxy_call(proxy,
-                       "RegisterApplication",
-                       g_variant_new("(oa{sv})",
-                       app_path, NULL),
-                       G_DBUS_CALL_FLAGS_NONE, -1,
-                       NULL,
-                       (GAsyncReadyCallback) register_application_cb,
-                       NULL);
+               BT_INFO("RegisterApplication");
+
+               g_dbus_proxy_call(proxy,
+                               "RegisterApplication",
+                               g_variant_new("(oa{sv})",
+                                       app_path, NULL),
+                               G_DBUS_CALL_FLAGS_NONE, -1,
+                               NULL,
+                               (GAsyncReadyCallback) register_application_cb,
+                               NULL);
+
+               is_server_started = true;
+
+               return BLUETOOTH_ERROR_NONE;
+       }
+
+       BT_INFO("Already RegisterApplication");
 
        return BLUETOOTH_ERROR_NONE;
 }