diff options
| author | Marcel Holtmann <marcel@holtmann.org> | 2008-05-08 18:37:09 +0000 | 
|---|---|---|
| committer | Marcel Holtmann <marcel@holtmann.org> | 2008-05-08 18:37:09 +0000 | 
| commit | b5514e6c7f0258da455bbde02482fbcdb29d4442 (patch) | |
| tree | 5e3fceee9da373a47ecc9d3c13f60c2fddee2d3f /hcid/dbus-service.c | |
| parent | 5442ba4d63b8f9548e140a47f63046c11819a972 (diff) | |
Register service and UUIDs in one step
Diffstat (limited to 'hcid/dbus-service.c')
| -rw-r--r-- | hcid/dbus-service.c | 184 | 
1 files changed, 94 insertions, 90 deletions
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();  | 
