diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2007-01-19 16:03:11 +0000 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2007-01-19 16:03:11 +0000 |
commit | 209c6c831ac8371fa36828ac6f433d5380bc476c (patch) | |
tree | 96e1993a688a0938f27a326ce56cb185ea1ad927 /daemon/service.c | |
parent | f24e25355de0241f9a1c9117e0a3a3be35026611 (diff) |
Emulate service starting and stopping
Diffstat (limited to 'daemon/service.c')
-rw-r--r-- | daemon/service.c | 60 |
1 files changed, 44 insertions, 16 deletions
diff --git a/daemon/service.c b/daemon/service.c index a03a57f7..830ca7dc 100644 --- a/daemon/service.c +++ b/daemon/service.c @@ -25,6 +25,9 @@ #include <config.h> #endif +#include <stdlib.h> +#include <string.h> + #include <dbus/dbus.h> #include "dbus-helper.h" @@ -38,6 +41,8 @@ static DBusConnection *connection = NULL; +static char *test_conn_name = NULL; + DBusHandlerResult manager_list_services(DBusConnection *conn, DBusMessage *msg, void *data) { @@ -141,43 +146,66 @@ static DBusHandlerResult service_start(DBusConnection *conn, 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); + if (test_conn_name) { + reply = dbus_message_new_error(msg, ERROR_INTERFACE ".AlreadyRunning", + "Service is already running"); + if (!reply) + return DBUS_HANDLER_RESULT_NEED_MEMORY; + } else { + reply = dbus_message_new_method_return(msg); + if (!reply) + return DBUS_HANDLER_RESULT_NEED_MEMORY; + + test_conn_name = strdup("org.bluez.service"); + if (!test_conn_name) + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + + dbus_message_append_args(reply, DBUS_TYPE_INVALID); + } return dbus_connection_send_and_unref(conn, reply); } -static DBusHandlerResult service_is_running(DBusConnection *conn, +static DBusHandlerResult service_stop(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; + debug("Stopping service"); - dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &running, - DBUS_TYPE_INVALID); + if (test_conn_name) { + reply = dbus_message_new_method_return(msg); + if (!reply) + return DBUS_HANDLER_RESULT_NEED_MEMORY; + + free(test_conn_name); + test_conn_name = NULL; + + dbus_message_append_args(reply, DBUS_TYPE_INVALID); + } else { + reply = dbus_message_new_error(msg, ERROR_INTERFACE ".NotRunning", + "Service is not running"); + if (!reply) + return DBUS_HANDLER_RESULT_NEED_MEMORY; + } return dbus_connection_send_and_unref(conn, reply); } -static DBusHandlerResult service_stop(DBusConnection *conn, +static DBusHandlerResult service_is_running(DBusConnection *conn, DBusMessage *msg, void *data) { DBusMessage *reply; - - debug("Stopping service"); + dbus_bool_t running; reply = dbus_message_new_method_return(msg); if (!reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; - dbus_message_append_args(reply, DBUS_TYPE_INVALID); + running = test_conn_name ? TRUE : FALSE; + + dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &running, + DBUS_TYPE_INVALID); return dbus_connection_send_and_unref(conn, reply); } |