#define GATT_CHR_IFACE "org.bluez.GattCharacteristic1"
#define GATT_DESCRIPTOR_IFACE "org.bluez.GattDescriptor1"
-struct external_app {
+struct external_service {
char *owner;
char *path;
DBusMessage *reg;
*/
static GHashTable *proxy_hash;
-static GSList *external_apps;
+static GSList *external_services;
-static int external_app_path_cmp(gconstpointer a, gconstpointer b)
+static int external_service_path_cmp(gconstpointer a, gconstpointer b)
{
- const struct external_app *eapp = a;
+ const struct external_service *esvc = a;
const char *path = b;
- return g_strcmp0(eapp->path, path);
+ return g_strcmp0(esvc->path, path);
}
-static void external_app_watch_destroy(gpointer user_data)
+static void external_service_watch_destroy(gpointer user_data)
{
- struct external_app *eapp = user_data;
+ struct external_service *esvc = user_data;
/* TODO: Remove from the database */
- external_apps = g_slist_remove(external_apps, eapp);
+ external_services = g_slist_remove(external_services, esvc);
- g_dbus_client_unref(eapp->client);
- if (eapp->reg)
- dbus_message_unref(eapp->reg);
+ g_dbus_client_unref(esvc->client);
+ if (esvc->reg)
+ dbus_message_unref(esvc->reg);
- g_free(eapp->owner);
- g_free(eapp->path);
- g_free(eapp);
+ g_free(esvc->owner);
+ g_free(esvc->path);
+ g_free(esvc);
}
static int proxy_path_cmp(gconstpointer a, gconstpointer b)
static void proxy_added(GDBusProxy *proxy, void *user_data)
{
- struct external_app *eapp = user_data;
+ struct external_service *esvc = user_data;
const char *interface, *path;
interface = g_dbus_proxy_get_interface(proxy);
path = g_dbus_proxy_get_path(proxy);
- if (!g_str_has_prefix(path, eapp->path))
+ if (!g_str_has_prefix(path, esvc->path))
return;
if (g_strcmp0(interface, GATT_CHR_IFACE) != 0 &&
* proxies sorted by path helps the logic to register the
* object path later.
*/
- eapp->proxies = g_slist_insert_sorted(eapp->proxies, proxy,
+ esvc->proxies = g_slist_insert_sorted(esvc->proxies, proxy,
proxy_path_cmp);
}
static void proxy_removed(GDBusProxy *proxy, void *user_data)
{
- struct external_app *eapp = user_data;
+ struct external_service *esvc = user_data;
const char *interface, *path;
interface = g_dbus_proxy_get_interface(proxy);
DBG("path %s iface %s", path, interface);
- eapp->proxies = g_slist_remove(eapp->proxies, proxy);
+ esvc->proxies = g_slist_remove(esvc->proxies, proxy);
}
static void proxy_read_cb(struct btd_attribute *attr,
}
-static int register_external_service(const struct external_app *eapp,
+static int register_external_service(const struct external_service *esvc,
GDBusProxy *proxy)
{
DBusMessageIter iter;
path = g_dbus_proxy_get_path(proxy);
iface = g_dbus_proxy_get_interface(proxy);
- if (g_strcmp0(eapp->path, path) != 0 ||
+ if (g_strcmp0(esvc->path, path) != 0 ||
g_strcmp0(iface, GATT_SERVICE_IFACE) != 0)
return -EINVAL;
static void client_ready(GDBusClient *client, void *user_data)
{
- struct external_app *eapp = user_data;
+ struct external_service *esvc = user_data;
GDBusProxy *proxy;
DBusConnection *conn = btd_get_dbus_connection();
DBusMessage *reply;
- if (!eapp->proxies)
+ if (!esvc->proxies)
goto fail;
- proxy = eapp->proxies->data;
- if (register_external_service(eapp, proxy) < 0)
+ proxy = esvc->proxies->data;
+ if (register_external_service(esvc, proxy) < 0)
goto fail;
- if (register_external_characteristics(g_slist_next(eapp->proxies)) < 0)
+ if (register_external_characteristics(g_slist_next(esvc->proxies)) < 0)
goto fail;
- DBG("Added GATT service %s", eapp->path);
+ DBG("Added GATT service %s", esvc->path);
- reply = dbus_message_new_method_return(eapp->reg);
+ reply = dbus_message_new_method_return(esvc->reg);
goto reply;
fail:
- error("Could not register external service: %s", eapp->path);
+ error("Could not register external service: %s", esvc->path);
- reply = btd_error_invalid_args(eapp->reg);
- /* TODO: missing eapp/database cleanup */
+ reply = btd_error_invalid_args(esvc->reg);
+ /* TODO: missing esvc/database cleanup */
reply:
- dbus_message_unref(eapp->reg);
- eapp->reg = NULL;
+ dbus_message_unref(esvc->reg);
+ esvc->reg = NULL;
g_dbus_send_message(conn, reply);
}
-static struct external_app *new_external_app(DBusConnection *conn,
+static struct external_service *new_external_service(DBusConnection *conn,
DBusMessage *msg, const char *path)
{
- struct external_app *eapp;
+ struct external_service *esvc;
GDBusClient *client;
const char *sender = dbus_message_get_sender(msg);
if (!client)
return NULL;
- eapp = g_new0(struct external_app, 1);
+ esvc = g_new0(struct external_service, 1);
- eapp->watch = g_dbus_add_disconnect_watch(btd_get_dbus_connection(),
- sender, NULL, eapp, external_app_watch_destroy);
- if (eapp->watch == 0) {
+ esvc->watch = g_dbus_add_disconnect_watch(btd_get_dbus_connection(),
+ sender, NULL, esvc, external_service_watch_destroy);
+ if (esvc->watch == 0) {
g_dbus_client_unref(client);
- g_free(eapp);
+ g_free(esvc);
return NULL;
}
- eapp->owner = g_strdup(sender);
- eapp->reg = dbus_message_ref(msg);
- eapp->client = client;
- eapp->path = g_strdup(path);
+ esvc->owner = g_strdup(sender);
+ esvc->reg = dbus_message_ref(msg);
+ esvc->client = client;
+ esvc->path = g_strdup(path);
g_dbus_client_set_proxy_handlers(client, proxy_added, proxy_removed,
- NULL, eapp);
+ NULL, esvc);
- g_dbus_client_set_ready_watch(client, client_ready, eapp);
+ g_dbus_client_set_ready_watch(client, client_ready, esvc);
- return eapp;
+ return esvc;
}
static DBusMessage *register_service(DBusConnection *conn,
DBusMessage *msg, void *user_data)
{
- struct external_app *eapp;
+ struct external_service *esvc;
DBusMessageIter iter;
const char *path;
dbus_message_iter_get_basic(&iter, &path);
- if (g_slist_find_custom(external_apps, path, external_app_path_cmp))
+ if (g_slist_find_custom(external_services, path,
+ external_service_path_cmp))
return btd_error_already_exists(msg);
- eapp = new_external_app(conn, msg, path);
- if (!eapp)
+ esvc = new_external_service(conn, msg, path);
+ if (!esvc)
return btd_error_failed(msg, "Not enough resources");
- external_apps = g_slist_prepend(external_apps, eapp);
+ external_services = g_slist_prepend(external_services, esvc);
- DBG("New app %p: %s", eapp, path);
+ DBG("New service %p: %s", esvc, path);
return NULL;
}