summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2007-01-16 10:09:05 +0000
committerMarcel Holtmann <marcel@holtmann.org>2007-01-16 10:09:05 +0000
commit424e98b0d14ffe676fb478ed48d083fced91e111 (patch)
tree4dedd1fa42410bf75e120f10a5dacae0f2e0a5a5
parentd25a07673af6e6320baa7380eca777533b67c1ef (diff)
Implement FindService method
-rw-r--r--hcid/dbus-error.c7
-rw-r--r--hcid/dbus-error.h1
-rw-r--r--hcid/dbus-manager.c21
-rw-r--r--hcid/dbus-service.c24
-rw-r--r--hcid/dbus-service.h2
5 files changed, 54 insertions, 1 deletions
diff --git a/hcid/dbus-error.c b/hcid/dbus-error.c
index 6897417c..becbda67 100644
--- a/hcid/dbus-error.c
+++ b/hcid/dbus-error.c
@@ -99,6 +99,13 @@ DBusHandlerResult error_no_such_adapter(DBusConnection *conn, DBusMessage *msg)
"No such adapter"));
}
+DBusHandlerResult error_no_such_service(DBusConnection *conn, DBusMessage *msg)
+{
+ return send_message_and_unref(conn,
+ dbus_message_new_error(msg, ERROR_INTERFACE ".NoSuchService",
+ "No such service"));
+}
+
DBusHandlerResult error_not_available(DBusConnection *conn, DBusMessage *msg)
{
return send_message_and_unref(conn,
diff --git a/hcid/dbus-error.h b/hcid/dbus-error.h
index 819182e3..9db9e117 100644
--- a/hcid/dbus-error.h
+++ b/hcid/dbus-error.h
@@ -34,6 +34,7 @@ DBusHandlerResult error_not_authorized(DBusConnection *conn, DBusMessage *msg);
DBusHandlerResult error_rejected(DBusConnection *conn, DBusMessage *msg);
DBusHandlerResult error_out_of_memory(DBusConnection *conn, DBusMessage *msg);
DBusHandlerResult error_no_such_adapter(DBusConnection *conn, DBusMessage *msg);
+DBusHandlerResult error_no_such_service(DBusConnection *conn, DBusMessage *msg);
DBusHandlerResult error_not_available(DBusConnection *conn, DBusMessage *msg);
DBusHandlerResult error_not_supported(DBusConnection *conn, DBusMessage *msg);
DBusHandlerResult error_request_deferred(DBusConnection *conn, DBusMessage *msg);
diff --git a/hcid/dbus-manager.c b/hcid/dbus-manager.c
index 83363c73..ae180cc6 100644
--- a/hcid/dbus-manager.c
+++ b/hcid/dbus-manager.c
@@ -198,7 +198,26 @@ static DBusHandlerResult list_adapters(DBusConnection *conn,
static DBusHandlerResult find_service(DBusConnection *conn,
DBusMessage *msg, void *data)
{
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ DBusMessage *reply;
+ const char *pattern, *path;
+
+ if (!dbus_message_get_args(msg, NULL,
+ DBUS_TYPE_STRING, &pattern,
+ DBUS_TYPE_INVALID))
+ return error_invalid_arguments(conn, msg);
+
+ path = search_service(conn, pattern);
+ if (!path)
+ return error_no_such_service(conn, msg);
+
+ reply = dbus_message_new_method_return(msg);
+ if (!reply)
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+
+ dbus_message_append_args(reply, DBUS_TYPE_STRING, &path,
+ DBUS_TYPE_INVALID);
+
+ return send_message_and_unref(conn, reply);
}
static DBusHandlerResult list_services(DBusConnection *conn,
diff --git a/hcid/dbus-service.c b/hcid/dbus-service.c
index 5a6d8199..4f935ff5 100644
--- a/hcid/dbus-service.c
+++ b/hcid/dbus-service.c
@@ -877,6 +877,30 @@ void release_services(DBusConnection *conn)
services = NULL;
}
+const char *search_service(DBusConnection *conn, const char *pattern)
+{
+ GSList *l = services;
+ struct service *service;
+ const char *path;
+
+ while (l) {
+ path = l->data;
+
+ l = l->next;
+
+ if (!dbus_connection_get_object_path_data(conn, path, (void *) &service))
+ continue;
+
+ if (!service)
+ continue;
+
+ if (service->ident && !strcmp(service->ident, pattern))
+ return path;
+ }
+
+ return NULL;
+}
+
void append_available_services(DBusMessageIter *array_iter)
{
GSList *l;
diff --git a/hcid/dbus-service.h b/hcid/dbus-service.h
index 8d513235..94fd580a 100644
--- a/hcid/dbus-service.h
+++ b/hcid/dbus-service.h
@@ -69,6 +69,8 @@ void release_services(DBusConnection *conn);
void append_available_services(DBusMessageIter *iter);
+const char *search_service(DBusConnection *conn, const char *pattern);
+
int register_service_records(GSList *lrecords);
struct service_call *service_call_new(DBusConnection *conn, DBusMessage *msg,