#include<stdlib.h>
#include<unistd.h>
#include<stdint.h>
+#include<stdbool.h>
#include "bt-common.h"
#include "bt-internal-types.h"
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[] =
{
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;
}
{
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;
}