diff options
author | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2006-10-30 13:29:04 +0000 |
---|---|---|
committer | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2006-10-30 13:29:04 +0000 |
commit | 856bcd33e00299605e833b6c1f756212b9f005b1 (patch) | |
tree | 66ee3838123096eda8469d97d1ef8691ad5797e6 /hcid | |
parent | 836ecd862504864bf88e77789b4542527a98b108 (diff) |
Cleanup: added function to create service_call
Diffstat (limited to 'hcid')
-rw-r--r-- | hcid/dbus-service.c | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/hcid/dbus-service.c b/hcid/dbus-service.c index 7acd7d4b..10d811a6 100644 --- a/hcid/dbus-service.c +++ b/hcid/dbus-service.c @@ -49,6 +49,20 @@ struct service_call { static struct slist *services = NULL; +static struct service_call *service_call_new(DBusConnection *conn, DBusMessage *msg, struct service_agent *agent) +{ + struct service_call *call; + call = malloc(sizeof(struct service_call)); + if (!call) + return NULL; + memset(call, 0, sizeof(struct service_call)); + call->conn = dbus_connection_ref(conn); + call->msg = dbus_message_ref(msg); + call->agent = agent; + + return call; +} + static void service_call_free(void *data) { struct service_call *call = data; @@ -323,12 +337,14 @@ static DBusHandlerResult start(DBusConnection *conn, 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; + call_data = service_call_new(conn, msg, agent); + if (!call_data) { + dbus_message_unref(forward); + return DBUS_HANDLER_RESULT_NEED_MEMORY; + } if (dbus_connection_send_with_reply(conn, forward, &pending, START_REPLY_TIMEOUT) == FALSE) { + service_call_free(call_data); dbus_message_unref(forward); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } @@ -392,12 +408,14 @@ static DBusHandlerResult stop(DBusConnection *conn, 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; + call_data = service_call_new(conn, msg, agent); + if (!call_data) { + dbus_message_unref(forward); + return DBUS_HANDLER_RESULT_NEED_MEMORY; + } if (dbus_connection_send_with_reply(conn, forward, &pending, START_REPLY_TIMEOUT) == FALSE) { + service_call_free(call_data); dbus_message_unref(forward); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } @@ -575,15 +593,12 @@ static DBusHandlerResult msg_func_services(DBusConnection *conn, dbus_message_set_destination(forward, agent->id); dbus_message_set_path(forward, dbus_message_get_path(msg)); - call_data = malloc(sizeof(struct service_call)); + call_data = service_call_new(conn, msg, agent); if (!call_data) { dbus_message_unref(forward); return DBUS_HANDLER_RESULT_NEED_MEMORY; } - call_data->conn = dbus_connection_ref(conn); - call_data->msg = dbus_message_ref(msg); - if (dbus_connection_send_with_reply(conn, forward, &pending, -1) == FALSE) { service_call_free(call_data); dbus_message_unref(forward); |