diff --git a/src/gatt-dbus.c b/src/gatt-dbus.c
index 28d7f78..d62e2cf 100644
--- a/src/gatt-dbus.c
+++ b/src/gatt-dbus.c
#include "log.h"
#include "error.h"
+#include "gatt.h"
#include "gatt-dbus.h"
#define GATT_MGR_IFACE "org.bluez.GattManager1"
eapp->proxies = g_slist_remove(eapp->proxies, proxy);
}
+static int register_external_service(const struct external_app *eapp,
+ GDBusProxy *proxy)
+{
+ DBusMessageIter iter;
+ const char *str, *path, *iface;
+ bt_uuid_t uuid;
+
+ path = g_dbus_proxy_get_path(proxy);
+ iface = g_dbus_proxy_get_interface(proxy);
+ if (g_strcmp0(eapp->path, path) != 0 ||
+ g_strcmp0(iface, GATT_SERVICE_IFACE) != 0)
+ return -EINVAL;
+
+ if (!g_dbus_proxy_get_property(proxy, "UUID", &iter))
+ return -EINVAL;
+
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+ return -EINVAL;
+
+ dbus_message_iter_get_basic(&iter, &str);
+
+ if (bt_string_to_uuid(&uuid, str) < 0)
+ return -EINVAL;
+
+ if (btd_gatt_add_service(&uuid) == NULL)
+ return -EINVAL;
+
+ return 0;
+}
+
+static void client_ready(GDBusClient *client, void *user_data)
+{
+ struct external_app *eapp = user_data;
+ GDBusProxy *proxy;
+
+ if (eapp->proxies == NULL)
+ goto fail;
+
+ proxy = eapp->proxies->data;
+ if (register_external_service(eapp, proxy) < 0)
+ goto fail;
+
+ DBG("Added GATT service %s", eapp->path);
+
+ return;
+
+fail:
+ error("Could not register external service: %s", eapp->path);
+}
+
static struct external_app *new_external_app(DBusConnection *conn,
const char *sender, const char *path)
{
g_dbus_client_set_proxy_handlers(client, proxy_added, proxy_removed,
NULL, eapp);
+ g_dbus_client_set_ready_watch(client, client_ready, eapp);
+
return eapp;
}