summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2008-05-08 18:37:09 +0000
committerMarcel Holtmann <marcel@holtmann.org>2008-05-08 18:37:09 +0000
commitb5514e6c7f0258da455bbde02482fbcdb29d4442 (patch)
tree5e3fceee9da373a47ecc9d3c13f60c2fddee2d3f
parent5442ba4d63b8f9548e140a47f63046c11819a972 (diff)
Register service and UUIDs in one step
-rw-r--r--audio/main.c6
-rw-r--r--hcid/dbus-service.c184
-rw-r--r--hcid/dbus-service.h5
-rw-r--r--input/main.c6
-rw-r--r--network/main.c6
-rw-r--r--serial/main.c2
6 files changed, 99 insertions, 110 deletions
diff --git a/audio/main.c b/audio/main.c
index f54f74de..5b4e395b 100644
--- a/audio/main.c
+++ b/audio/main.c
@@ -96,17 +96,13 @@ static int audio_init(void)
g_key_file_free(config);
- register_service("audio");
-
- register_uuids("audio", uuids);
+ register_service("audio", uuids);
return 0;
}
static void audio_exit(void)
{
- unregister_uuids("audio");
-
unregister_service("audio");
audio_manager_exit();
diff --git a/hcid/dbus-service.c b/hcid/dbus-service.c
index 5282ffd1..192ff738 100644
--- a/hcid/dbus-service.c
+++ b/hcid/dbus-service.c
@@ -481,94 +481,6 @@ int service_unregister(DBusConnection *conn, struct service *service)
return unregister_service_for_connection(conn, service);
}
-static struct service *create_external_service(const char *ident)
-{
- struct service *service;
- const char *name;
-
- service = g_try_new0(struct service, 1);
- if (!service) {
- error("OOM while allocating new external service");
- return NULL;
- }
-
- if (!strcmp(ident, "input"))
- name = "Input service";
- else if (!strcmp(ident, "audio"))
- name = "Audio service";
- else if (!strcmp(ident, "network"))
- name = "Network service";
- else if (!strcmp(ident, "serial"))
- name = "Serial service";
- else
- name = "";
-
- service->ident = g_strdup(ident);
- service->name = g_strdup(name);
-
- return service;
-}
-
-int register_service(const char *ident)
-{
- DBusConnection *conn = get_dbus_connection();
- struct service *service;
- char obj_path[PATH_MAX];
- int i;
-
- if (g_slist_find_custom(services, ident,
- (GCompareFunc) service_cmp_ident))
- return -EADDRINUSE;
-
- snprintf(obj_path, sizeof(obj_path) - 1,
- "/org/bluez/service_%s", ident);
-
- /* Make the path valid for D-Bus */
- for (i = strlen("/org/bluez/"); obj_path[i]; i++) {
- if (!isalnum(obj_path[i]))
- obj_path[i] = '_';
- }
-
- if (g_slist_find_custom(services, obj_path,
- (GCompareFunc) service_cmp_path))
- return -EADDRINUSE;
-
- service = create_external_service(ident);
-
- debug("Registering service object: %s (%s)",
- service->ident, obj_path);
-
- if (!dbus_connection_create_object_path(conn, obj_path,
- service, NULL)) {
- error("D-Bus failed to register %s object", obj_path);
- return -1;
- }
-
- if (!service_init(conn, obj_path)) {
- error("Service init failed");
- return -1;
- }
-
- service->object_path = g_strdup(obj_path);
-
- services = g_slist_append(services, service);
-
- dbus_connection_emit_signal(conn, BASE_PATH, MANAGER_INTERFACE,
- "ServiceAdded",
- DBUS_TYPE_STRING, &service->object_path,
- DBUS_TYPE_INVALID);
-
- dbus_connection_emit_signal(conn, service->object_path,
- SERVICE_INTERFACE,
- "Started", DBUS_TYPE_INVALID);
-
- return 0;
-}
-
-void unregister_service(const char *ident)
-{
-}
-
static gint name_cmp(struct service_uuids *su, const char *name)
{
return strcmp(su->name, name);
@@ -607,7 +519,7 @@ struct service *search_service_by_uuid(const char *uuid)
return service;
}
-void register_uuids(const char *ident, const char **uuids)
+static void register_uuids(const char *ident, const char **uuids)
{
struct service_uuids *su;
int i;
@@ -643,7 +555,7 @@ static void service_uuids_free(struct service_uuids *su)
g_free(su);
}
-void unregister_uuids(const char *ident)
+static void unregister_uuids(const char *ident)
{
struct service_uuids *su;
GSList *l;
@@ -661,6 +573,98 @@ void unregister_uuids(const char *ident)
service_uuids_free(su);
}
+static struct service *create_external_service(const char *ident)
+{
+ struct service *service;
+ const char *name;
+
+ service = g_try_new0(struct service, 1);
+ if (!service) {
+ error("OOM while allocating new external service");
+ return NULL;
+ }
+
+ if (!strcmp(ident, "input"))
+ name = "Input service";
+ else if (!strcmp(ident, "audio"))
+ name = "Audio service";
+ else if (!strcmp(ident, "network"))
+ name = "Network service";
+ else if (!strcmp(ident, "serial"))
+ name = "Serial service";
+ else
+ name = "";
+
+ service->ident = g_strdup(ident);
+ service->name = g_strdup(name);
+
+ return service;
+}
+
+int register_service(const char *ident, const char **uuids)
+{
+ DBusConnection *conn = get_dbus_connection();
+ struct service *service;
+ char obj_path[PATH_MAX];
+ int i;
+
+ if (g_slist_find_custom(services, ident,
+ (GCompareFunc) service_cmp_ident))
+ return -EADDRINUSE;
+
+ snprintf(obj_path, sizeof(obj_path) - 1,
+ "/org/bluez/service_%s", ident);
+
+ /* Make the path valid for D-Bus */
+ for (i = strlen("/org/bluez/"); obj_path[i]; i++) {
+ if (!isalnum(obj_path[i]))
+ obj_path[i] = '_';
+ }
+
+ if (g_slist_find_custom(services, obj_path,
+ (GCompareFunc) service_cmp_path))
+ return -EADDRINUSE;
+
+ service = create_external_service(ident);
+
+ debug("Registering service object: %s (%s)",
+ service->ident, obj_path);
+
+ if (!dbus_connection_create_object_path(conn, obj_path,
+ service, NULL)) {
+ error("D-Bus failed to register %s object", obj_path);
+ return -1;
+ }
+
+ if (!service_init(conn, obj_path)) {
+ error("Service init failed");
+ return -1;
+ }
+
+ service->object_path = g_strdup(obj_path);
+
+ services = g_slist_append(services, service);
+
+ if (uuids)
+ register_uuids(ident, uuids);
+
+ dbus_connection_emit_signal(conn, BASE_PATH, MANAGER_INTERFACE,
+ "ServiceAdded",
+ DBUS_TYPE_STRING, &service->object_path,
+ DBUS_TYPE_INVALID);
+
+ dbus_connection_emit_signal(conn, service->object_path,
+ SERVICE_INTERFACE,
+ "Started", DBUS_TYPE_INVALID);
+
+ return 0;
+}
+
+void unregister_service(const char *ident)
+{
+ unregister_uuids(ident);
+}
+
static struct adapter *ba2adapter(bdaddr_t *src)
{
DBusConnection *conn = get_dbus_connection();
diff --git a/hcid/dbus-service.h b/hcid/dbus-service.h
index c96179ea..8923907a 100644
--- a/hcid/dbus-service.h
+++ b/hcid/dbus-service.h
@@ -38,12 +38,9 @@ struct service *search_service_by_uuid(const char *uuid);
int service_unregister(DBusConnection *conn, struct service *service);
-int register_service(const char *ident);
+int register_service(const char *ident, const char **uuids);
void unregister_service(const char *ident);
-void register_uuids(const char *ident, const char **uuids);
-void unregister_uuids(const char *ident);
-
typedef void (*service_auth_cb) (DBusError *derr, void *user_data);
int service_req_auth(bdaddr_t *src, bdaddr_t *dst,
const char *uuid, service_auth_cb cb, void *user_data);
diff --git a/input/main.c b/input/main.c
index a98bc72f..c9432c21 100644
--- a/input/main.c
+++ b/input/main.c
@@ -55,17 +55,13 @@ static int input_init(void)
return -EIO;
}
- register_service("input");
-
- register_uuids("input", uuids);
+ register_service("input", uuids);
return 0;
}
static void input_exit(void)
{
- unregister_uuids("input");
-
unregister_service("input");
input_manager_exit();
diff --git a/network/main.c b/network/main.c
index 54bdf3d6..c84ba59b 100644
--- a/network/main.c
+++ b/network/main.c
@@ -180,17 +180,13 @@ static int network_init(void)
return -EIO;
}
- register_service("network");
-
- register_uuids("network", uuids);
+ register_service("network", uuids);
return 0;
}
static void network_exit(void)
{
- unregister_uuids("network");
-
unregister_service("network");
network_manager_exit();
diff --git a/serial/main.c b/serial/main.c
index 0916f760..57a65f88 100644
--- a/serial/main.c
+++ b/serial/main.c
@@ -50,7 +50,7 @@ static int serial_init(void)
return -EIO;
}
- register_service("serial");
+ register_service("serial", NULL);
return 0;
}