diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2006-10-25 12:39:05 +0000 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2006-10-25 12:39:05 +0000 |
commit | 8f1ce2e4d88269025427fcc84328b03497005664 (patch) | |
tree | 46e5d297a49489c8ffa8c6f1e4e0aa01b80228e7 /hcid | |
parent | e212b5b11b674b717a547310bb8407885d0e20c0 (diff) |
Add missing methods to the service agent example
Diffstat (limited to 'hcid')
-rw-r--r-- | hcid/service-agent.c | 102 |
1 files changed, 101 insertions, 1 deletions
diff --git a/hcid/service-agent.c b/hcid/service-agent.c index be8f06db..5a511073 100644 --- a/hcid/service-agent.c +++ b/hcid/service-agent.c @@ -68,6 +68,43 @@ static DBusHandlerResult agent_filter(DBusConnection *conn, return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } +static DBusHandlerResult interfaces_message(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + DBusMessage *reply; + DBusMessageIter iter, array_iter; + const char *intf = "org.bluez.Example"; + + if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_INVALID)) { + fprintf(stderr, "Invalid arguments for service Interfaces method"); + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + + reply = dbus_message_new_method_return(msg); + if (!reply) { + fprintf(stderr, "Can't create reply message\n"); + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + + dbus_message_iter_init_append(reply, &iter); + + dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, + DBUS_TYPE_STRING_AS_STRING, &array_iter); + + dbus_message_iter_append_basic(&array_iter, + DBUS_TYPE_STRING, &intf); + + dbus_message_iter_close_container(&iter, &array_iter); + + dbus_connection_send(conn, reply, NULL); + + dbus_connection_flush(conn); + + dbus_message_unref(reply); + + return DBUS_HANDLER_RESULT_HANDLED; +} + static DBusHandlerResult name_message(DBusConnection *conn, DBusMessage *msg, void *data) { @@ -97,6 +134,57 @@ static DBusHandlerResult name_message(DBusConnection *conn, return DBUS_HANDLER_RESULT_HANDLED; } +static DBusHandlerResult description_message(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + DBusMessage *reply; + const char *text = "This is an example service"; + + if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_INVALID)) { + fprintf(stderr, "Invalid arguments for service Description method"); + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + + reply = dbus_message_new_method_return(msg); + if (!reply) { + fprintf(stderr, "Can't create reply message\n"); + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + + dbus_message_append_args(reply, DBUS_TYPE_STRING, &text, + DBUS_TYPE_INVALID); + + dbus_connection_send(conn, reply, NULL); + + dbus_connection_flush(conn); + + dbus_message_unref(reply); + + return DBUS_HANDLER_RESULT_HANDLED; +} + +static DBusHandlerResult start_message(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_INVALID)) { + fprintf(stderr, "Invalid arguments for service Start method"); + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + + return DBUS_HANDLER_RESULT_HANDLED; +} + +static DBusHandlerResult stop_message(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_INVALID)) { + fprintf(stderr, "Invalid arguments for service Stop method"); + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + + return DBUS_HANDLER_RESULT_HANDLED; +} + static DBusHandlerResult release_message(DBusConnection *conn, DBusMessage *msg, void *data) { @@ -116,9 +204,21 @@ static DBusHandlerResult release_message(DBusConnection *conn, static DBusHandlerResult service_message(DBusConnection *conn, DBusMessage *msg, void *data) { - if (dbus_message_is_method_call(msg, "org.bluez.PasskeyAgent", "Name")) + if (dbus_message_is_method_call(msg, "org.bluez.ServiceAgent", "Interfaces")) + return interfaces_message(conn, msg, data); + + if (dbus_message_is_method_call(msg, "org.bluez.ServiceAgent", "Name")) return name_message(conn, msg, data); + if (dbus_message_is_method_call(msg, "org.bluez.ServiceAgent", "Description")) + return description_message(conn, msg, data); + + if (dbus_message_is_method_call(msg, "org.bluez.ServiceAgent", "Start")) + return start_message(conn, msg, data); + + if (dbus_message_is_method_call(msg, "org.bluez.ServiceAgent", "Stop")) + return stop_message(conn, msg, data); + if (dbus_message_is_method_call(msg, "org.bluez.ServiceAgent", "Release")) return release_message(conn, msg, data); |