Add basic methods and signals for manager interface
authorMarcel Holtmann <marcel@holtmann.org>
Wed, 26 Dec 2007 09:13:30 +0000 (10:13 +0100)
committerMarcel Holtmann <marcel@holtmann.org>
Wed, 26 Dec 2007 09:13:30 +0000 (10:13 +0100)
src/connman.h
src/iface.c
src/manager.c

index cff8f8f66413b3eedf1e2b03fd8d4eae3f6f4bdf..b5f0e48f089082054be8eea04f213b858edb7f41 100644 (file)
@@ -47,6 +47,8 @@ void __connman_plugin_cleanup(void);
 int __connman_iface_init(DBusConnection *conn);
 void __connman_iface_cleanup(void);
 
+void __connman_iface_list(DBusMessageIter *iter);
+
 #include <connman/rtnl.h>
 
 int __connman_rtnl_init(void);
index 9dc0c801eeddd3793198e30a38f350197b579ead..6825c51dce06f9f567c13a9b99d6232f3c740ad2 100644 (file)
@@ -53,8 +53,22 @@ void connman_iface_unregister(struct connman_iface_driver *driver)
 
 static GSList *interfaces = NULL;
 
+void __connman_iface_list(DBusMessageIter *iter)
+{
+       GSList *list;
+
+       DBG("");
+
+       for (list = interfaces; list; list = list->next) {
+               struct connman_iface *iface = list->data;
+
+               dbus_message_iter_append_basic(iter,
+                               DBUS_TYPE_OBJECT_PATH, &iface->path);
+       }
+}
+
 int connman_iface_update(struct connman_iface *iface,
-                                        enum connman_iface_state state)
+                                       enum connman_iface_state state)
 {
        switch (state) {
        case CONNMAN_IFACE_STATE_ACTIVE:
@@ -158,6 +172,12 @@ static int probe_device(LibHalContext *ctx,
                DBG("address %s", inet_ntoa(iface->ipv4.address));
        }
 
+       g_dbus_emit_signal(conn, CONNMAN_MANAGER_PATH,
+                                       CONNMAN_MANAGER_INTERFACE,
+                                       "InterfaceAdded",
+                                       DBUS_TYPE_OBJECT_PATH, &iface->path,
+                                       DBUS_TYPE_INVALID);
+
        if (driver->activate)
                driver->activate(iface);
 
@@ -197,6 +217,11 @@ static void device_removed(LibHalContext *ctx, const char *udi)
                struct connman_iface *iface = list->data;
 
                if (strcmp(udi, iface->udi) == 0) {
+                       g_dbus_emit_signal(conn, CONNMAN_MANAGER_PATH,
+                                       CONNMAN_MANAGER_INTERFACE,
+                                       "InterfaceRemoved",
+                                       DBUS_TYPE_OBJECT_PATH, &iface->path,
+                                       DBUS_TYPE_INVALID);
                        interfaces = g_slist_remove(interfaces, iface);
                        g_dbus_unregister_object(conn, iface->path);
                        break;
@@ -293,6 +318,12 @@ static void hal_cleanup(void *data)
 
                DBG("path %s", iface->path);
 
+               g_dbus_emit_signal(conn, CONNMAN_MANAGER_PATH,
+                                       CONNMAN_MANAGER_INTERFACE,
+                                       "InterfaceRemoved",
+                                       DBUS_TYPE_OBJECT_PATH, &iface->path,
+                                       DBUS_TYPE_INVALID);
+
                g_dbus_unregister_object(conn, iface->path);
        }
 
index 5fa60cc2b0a08871ba545412da1b0638703ebbad..1afecc886e1b02c1f2160019f6c3b631c5c554a0 100644 (file)
 
 #include "connman.h"
 
+static DBusMessage *list_interfaces(DBusConnection *conn,
+                                       DBusMessage *msg, void *data)
+{
+       DBusMessage *reply;
+       DBusMessageIter array, iter;
+
+       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_TYPE_OBJECT_PATH_AS_STRING, &iter);
+
+       __connman_iface_list(&iter);
+
+       dbus_message_iter_close_container(&array, &iter);
+
+       return reply;
+}
+
+static GDBusMethodTable manager_methods[] = {
+       { "ListInterfaces", "", "ao", list_interfaces },
+       { },
+};
+
+static GDBusSignalTable manager_signals[] = {
+       { "InterfaceAdded",   "o" },
+       { "InterfaceRemoved", "o" },
+       { },
+};
+
 static DBusConnection *connection = NULL;
 
 int __connman_manager_init(DBusConnection *conn)
@@ -39,6 +74,11 @@ int __connman_manager_init(DBusConnection *conn)
 
        g_dbus_register_object(connection, CONNMAN_MANAGER_PATH, NULL, NULL);
 
+       g_dbus_register_interface(connection, CONNMAN_MANAGER_PATH,
+                                               CONNMAN_MANAGER_INTERFACE,
+                                               manager_methods,
+                                               manager_signals, NULL);
+
        return 0;
 }
 
@@ -46,6 +86,9 @@ void __connman_manager_cleanup(void)
 {
        DBG("conn %p", connection);
 
+       g_dbus_unregister_interface(connection, CONNMAN_MANAGER_PATH,
+                                               CONNMAN_MANAGER_INTERFACE);
+
        g_dbus_unregister_object(connection, CONNMAN_MANAGER_PATH);
 
        dbus_connection_unref(connection);