diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2009-01-05 17:34:02 +0100 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2009-01-05 17:34:02 +0100 |
commit | f48005d81c0983c77740c16abde90e02d9505304 (patch) | |
tree | 999f89cc3dd5bf8143e206e512d03bd92f52b0ae /src/connection.c | |
parent | fb0fb9058f300222717a025e6f8a0c7a030bf303 (diff) | |
download | connman-f48005d81c0983c77740c16abde90e02d9505304.tar.gz connman-f48005d81c0983c77740c16abde90e02d9505304.tar.bz2 connman-f48005d81c0983c77740c16abde90e02d9505304.zip |
Register connection interface
Diffstat (limited to 'src/connection.c')
-rw-r--r-- | src/connection.c | 97 |
1 files changed, 94 insertions, 3 deletions
diff --git a/src/connection.c b/src/connection.c index 78080a44..6c7e03b8 100644 --- a/src/connection.c +++ b/src/connection.c @@ -23,18 +23,111 @@ #include <config.h> #endif +#include <gdbus.h> + #include "connman.h" -static int connection_probe(struct connman_element *element) +static DBusMessage *get_properties(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + DBusMessage *reply; + DBusMessageIter array, dict; + + DBG("conn %p", conn); + + reply = dbus_message_new_method_return(msg); + if (reply == NULL) + return NULL; + + dbus_message_iter_init_append(reply, &array); + + dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY, + DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING + DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING + DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict); + + dbus_message_iter_close_container(&array, &dict); + + return reply; +} + +static DBusMessage *set_property(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + DBusMessageIter iter, value; + const char *name; + + DBG("conn %p", conn); + + if (dbus_message_iter_init(msg, &iter) == FALSE) + return __connman_error_invalid_arguments(msg); + + dbus_message_iter_get_basic(&iter, &name); + dbus_message_iter_next(&iter); + dbus_message_iter_recurse(&iter, &value); + + if (__connman_security_check_privileges(msg) < 0) + return __connman_error_permission_denied(msg); + + return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); +} + +static GDBusMethodTable connection_methods[] = { + { "GetProperties", "", "a{sv}", get_properties }, + { "SetProperty", "sv", "", set_property }, + { }, +}; + +static GDBusSignalTable connection_signals[] = { + { "PropertyChanged", "sv" }, + { }, +}; + +static DBusConnection *connection; + +static void emit_connections_signal(void) +{ +} + +static int register_interface(struct connman_element *element) { DBG("element %p name %s", element, element->name); + if (g_dbus_register_interface(connection, element->path, + CONNMAN_CONNECTION_INTERFACE, + connection_methods, connection_signals, + NULL, element, NULL) == FALSE) { + connman_error("Failed to register %s connection", element->path); + return -EIO; + } + + emit_connections_signal(); + return 0; } +static void unregister_interface(struct connman_element *element) +{ + DBG("element %p name %s", element, element->name); + + emit_connections_signal(); + + g_dbus_unregister_interface(connection, element->path, + CONNMAN_CONNECTION_INTERFACE); +} + +static int connection_probe(struct connman_element *element) +{ + DBG("element %p name %s", element, element->name); + + return register_interface(element); +} + static void connection_remove(struct connman_element *element) { DBG("element %p name %s", element, element->name); + + unregister_interface(element); } static struct connman_driver connection_driver = { @@ -45,8 +138,6 @@ static struct connman_driver connection_driver = { .remove = connection_remove, }; -static DBusConnection *connection; - int __connman_connection_init(void) { DBG(""); |