summaryrefslogtreecommitdiffstats
path: root/daemon/service.c
diff options
context:
space:
mode:
Diffstat (limited to 'daemon/service.c')
-rw-r--r--daemon/service.c138
1 files changed, 131 insertions, 7 deletions
diff --git a/daemon/service.c b/daemon/service.c
index b56087c4..4d024b3a 100644
--- a/daemon/service.c
+++ b/daemon/service.c
@@ -38,26 +38,31 @@
static DBusConnection *connection = NULL;
-DBusMessage *service_list(DBusMessage *msg)
+DBusHandlerResult manager_list_services(DBusConnection *conn,
+ DBusMessage *msg, void *data)
{
DBusMessage *reply;
DBusMessageIter iter, array;
+ const char path[] = "/org/bluez/service", *ptr = path;
reply = dbus_message_new_method_return(msg);
if (!reply)
- return NULL;
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
dbus_message_iter_init_append(reply, &iter);
dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
DBUS_TYPE_STRING_AS_STRING, &array);
+ dbus_message_iter_append_basic(&array, DBUS_TYPE_STRING, &ptr);
+
dbus_message_iter_close_container(&iter, &array);
- return reply;
+ return dbus_connection_send_and_unref(conn, reply);
}
-DBusMessage *service_find(DBusMessage *msg)
+DBusHandlerResult manager_find_service(DBusConnection *conn,
+ DBusMessage *msg, void *data)
{
DBusMessage *reply;
const char *pattern;
@@ -69,11 +74,14 @@ DBusMessage *service_find(DBusMessage *msg)
reply = dbus_message_new_error(msg, ERROR_INTERFACE ".NotFound",
"Service does not exists");
+ if (!reply)
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
- return reply;
+ return dbus_connection_send_and_unref(conn, reply);
}
-DBusMessage *service_activate(DBusMessage *msg)
+DBusHandlerResult manager_activate_service(DBusConnection *conn,
+ DBusMessage *msg, void *data)
{
DBusMessage *reply;
const char *pattern;
@@ -85,10 +93,106 @@ DBusMessage *service_activate(DBusMessage *msg)
reply = dbus_message_new_error(msg, ERROR_INTERFACE ".NotFound",
"Service does not exists");
+ if (!reply)
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
- return reply;
+ return dbus_connection_send_and_unref(conn, reply);
}
+static DBusHandlerResult service_get_name(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ DBusMessage *reply;
+ const char name[] = "Demo service", *ptr = name;
+
+ reply = dbus_message_new_method_return(msg);
+ if (!reply)
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+
+ dbus_message_append_args(reply, DBUS_TYPE_STRING, &ptr,
+ DBUS_TYPE_INVALID);
+
+ return dbus_connection_send_and_unref(conn, reply);
+}
+
+static DBusHandlerResult service_get_description(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ DBusMessage *reply;
+ const char text[] = "Demo service for testing", *ptr = text;
+
+ reply = dbus_message_new_method_return(msg);
+ if (!reply)
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+
+ dbus_message_append_args(reply, DBUS_TYPE_STRING, &ptr,
+ DBUS_TYPE_INVALID);
+
+ return dbus_connection_send_and_unref(conn, reply);
+}
+
+static DBusHandlerResult service_start(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ DBusMessage *reply;
+
+ debug("Starting service");
+
+ reply = dbus_message_new_method_return(msg);
+ if (!reply)
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+
+ dbus_message_append_args(reply, DBUS_TYPE_INVALID);
+
+ return dbus_connection_send_and_unref(conn, reply);
+}
+
+static DBusHandlerResult service_is_running(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ DBusMessage *reply;
+ dbus_bool_t running = FALSE;
+
+ reply = dbus_message_new_method_return(msg);
+ if (!reply)
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+
+ dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &running,
+ DBUS_TYPE_INVALID);
+
+ return dbus_connection_send_and_unref(conn, reply);
+}
+
+static DBusHandlerResult service_stop(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ DBusMessage *reply;
+
+ debug("Stopping service");
+
+ reply = dbus_message_new_method_return(msg);
+ if (!reply)
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+
+ dbus_message_append_args(reply, DBUS_TYPE_INVALID);
+
+ return dbus_connection_send_and_unref(conn, reply);
+}
+
+static DBusMethodVTable service_table[] = {
+ { "GetName", service_get_name,
+ DBUS_TYPE_INVALID_AS_STRING, DBUS_TYPE_STRING_AS_STRING },
+ { "GetDescription", service_get_description,
+ DBUS_TYPE_INVALID_AS_STRING, DBUS_TYPE_STRING_AS_STRING },
+ { "Start", service_start,
+ DBUS_TYPE_INVALID_AS_STRING, DBUS_TYPE_INVALID_AS_STRING },
+ { "Stop", service_stop,
+ DBUS_TYPE_INVALID_AS_STRING, DBUS_TYPE_INVALID_AS_STRING },
+ { "IsRunning", service_is_running,
+ DBUS_TYPE_INVALID_AS_STRING, DBUS_TYPE_BOOLEAN_AS_STRING },
+ { }
+};
+
static void config_notify(int action, const char *name, void *data)
{
switch (action) {
@@ -114,6 +218,21 @@ int service_init(DBusConnection *conn)
notify_add(CONFIGDIR, config_notify, NULL);
+ if (dbus_connection_create_object_path(connection,
+ "/org/bluez/service", NULL, NULL) == FALSE) {
+ error("Service path registration failed");
+ dbus_connection_unref(connection);
+ return -1;
+ }
+
+ if (dbus_connection_register_interface(connection, "/org/bluez/service",
+ SERVICE_INTERFACE, service_table, NULL) == FALSE) {
+ error("Service interface registration failed");
+ dbus_connection_destroy_object_path(connection, "/org/bluez/service");
+ dbus_connection_unref(connection);
+ return -1;
+ }
+
return 0;
}
@@ -123,6 +242,11 @@ void service_exit(void)
notify_remove(CONFIGDIR);
+ dbus_connection_unregister_interface(connection,
+ "/org/bluez/service", SERVICE_INTERFACE);
+
+ dbus_connection_destroy_object_path(connection, "/org/bluez/service");
+
dbus_connection_unref(connection);
connection = NULL;