summaryrefslogtreecommitdiffstats
path: root/hcid/dbus-service.c
diff options
context:
space:
mode:
authorClaudio Takahasi <claudio.takahasi@openbossa.org>2006-10-27 12:58:54 +0000
committerClaudio Takahasi <claudio.takahasi@openbossa.org>2006-10-27 12:58:54 +0000
commit6d3c7f4586facea63a29d56ce15dab12fee8acd5 (patch)
treed915801b6d72bb3ce9f8ccde706666d0dd0112f5 /hcid/dbus-service.c
parent5e38061721d1119e128574c4363e45c4902b8367 (diff)
Added service agent start method
Diffstat (limited to 'hcid/dbus-service.c')
-rw-r--r--hcid/dbus-service.c75
1 files changed, 69 insertions, 6 deletions
diff --git a/hcid/dbus-service.c b/hcid/dbus-service.c
index 57cc8cb8..319e9144 100644
--- a/hcid/dbus-service.c
+++ b/hcid/dbus-service.c
@@ -30,24 +30,31 @@
#include <unistd.h>
#include <stdlib.h>
-
#include <dbus/dbus.h>
#include "hcid.h"
#include "dbus.h"
#include "list.h"
-struct service_call {
- DBusConnection *conn;
- DBusMessage *msg;
-};
+#define START_REPLY_TIMEOUT 5000
+
+#define SERVICE_RUNNING 1
+#define SERVICE_NOT_RUNNING 0
struct service_agent {
char *id; /* Connection id */
char *name;
char *description;
+ int running;
+};
+
+struct service_call {
+ DBusConnection *conn;
+ DBusMessage *msg;
+ struct service_agent *agent;
};
+
static struct slist *services = NULL;
static void service_call_free(void *data)
@@ -295,10 +302,66 @@ static DBusHandlerResult get_description(DBusConnection *conn,
return send_message_and_unref(conn, reply);
}
+static void start_reply(DBusPendingCall *call, void *udata)
+{
+ struct service_call *call_data = udata;
+ DBusMessage *agent_reply = dbus_pending_call_steal_reply(call);
+ DBusMessage *source_reply;
+ DBusError err;
+
+ dbus_error_init(&err);
+ if (dbus_set_error_from_message(&err, agent_reply)) {
+ call_data->agent->running = SERVICE_NOT_RUNNING;
+ dbus_error_free(&err);
+ } else {
+ DBusMessage *message;
+ call_data->agent->running = SERVICE_RUNNING;
+
+ /* Send a signal to indicate that the service started properly */
+ message = dbus_message_new_signal(dbus_message_get_path(call_data->msg),
+ dbus_message_get_interface(call_data->msg),
+ "Started");
+
+ send_message_and_unref(call_data->conn, message);
+ }
+
+ source_reply = dbus_message_copy(agent_reply);
+ dbus_message_set_destination(source_reply, dbus_message_get_sender(call_data->msg));
+ dbus_message_set_no_reply(source_reply, TRUE);
+ dbus_message_set_reply_serial(source_reply, dbus_message_get_serial(call_data->msg));
+
+ send_message_and_unref(call_data->conn, source_reply);
+
+ dbus_message_unref(agent_reply);
+ dbus_pending_call_unref (call);
+}
+
static DBusHandlerResult start(DBusConnection *conn,
DBusMessage *msg, void *data)
{
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ DBusPendingCall *pending;
+ struct service_call *call_data;
+ struct service_agent *agent = data;
+ DBusMessage *forward = dbus_message_copy(msg);
+
+ dbus_message_set_destination(forward, agent->id);
+ dbus_message_set_interface(forward, "org.bluez.ServiceAgent");
+ dbus_message_set_path(forward, dbus_message_get_path(msg));
+
+ call_data = malloc(sizeof(struct service_call));
+ call_data->conn = dbus_connection_ref(conn);
+ call_data->msg = dbus_message_ref(msg);
+ call_data->agent = data;
+
+ if (dbus_connection_send_with_reply(conn, forward, &pending, START_REPLY_TIMEOUT) == FALSE) {
+ dbus_message_unref(forward);
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+
+ dbus_pending_call_set_notify(pending, start_reply, call_data, service_call_free);
+ dbus_message_unref(forward);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
}
static DBusHandlerResult stop(DBusConnection *conn,