Provide connection element and its interface
authorMarcel Holtmann <marcel@holtmann.org>
Sun, 23 Nov 2008 13:50:56 +0000 (14:50 +0100)
committerMarcel Holtmann <marcel@holtmann.org>
Sun, 23 Nov 2008 13:50:56 +0000 (14:50 +0100)
include/element.h
plugins/resolvconf.c
plugins/resolvfile.c
src/element.c
src/manager.c

index 96031db2a497ddf129b9654972db8120dbfe23fc..55f959377aefe31587cb2ad348c4680c9d71165b 100644 (file)
@@ -57,7 +57,7 @@ enum connman_element_type {
        CONNMAN_ELEMENT_TYPE_ZEROCONF   = 9,
        CONNMAN_ELEMENT_TYPE_RESOLVER   = 10,
 
-       CONNMAN_ELEMENT_TYPE_INTERNET   = 42,
+       CONNMAN_ELEMENT_TYPE_CONNECTION = 42,
 };
 
 enum connman_element_subtype {
index 814bbeb75522d27e3e0b11550647a229449a843e..f81d1062078608ebbf92f2074798cdfed5837699 100644 (file)
@@ -68,7 +68,7 @@ static int resolvconf_probe(struct connman_element *element)
 
        internet = connman_element_create(NULL);
 
-       internet->type = CONNMAN_ELEMENT_TYPE_INTERNET;
+       internet->type = CONNMAN_ELEMENT_TYPE_CONNECTION;
 
        connman_element_register(internet, element);
 
index 0920441c5cbd488fc2b86a80e14dd68e15a635b2..54ad41b3d64094a69e5377174f69987cec6876c7 100644 (file)
@@ -65,7 +65,7 @@ static int resolvfile_probe(struct connman_element *element)
 
        internet = connman_element_create(NULL);
 
-       internet->type = CONNMAN_ELEMENT_TYPE_INTERNET;
+       internet->type = CONNMAN_ELEMENT_TYPE_CONNECTION;
 
        connman_element_register(internet, element);
 
index 005626d5b965453dcbdc20dd3c011a45d92c431e..d3040ccefaab2a1ed42c12978b19242a8e3d22c0 100644 (file)
@@ -119,8 +119,8 @@ static const char *type2string(enum connman_element_type type)
                return "zeroconf";
        case CONNMAN_ELEMENT_TYPE_RESOLVER:
                return "resolver";
-       case CONNMAN_ELEMENT_TYPE_INTERNET:
-               return "internet";
+       case CONNMAN_ELEMENT_TYPE_CONNECTION:
+               return "connection";
        }
 
        return NULL;
@@ -319,6 +319,33 @@ static DBusMessage *get_network_properties(DBusConnection *conn,
        return reply;
 }
 
+static DBusMessage *get_connection_properties(DBusConnection *conn,
+                                       DBusMessage *msg, void *data)
+{
+       struct connman_element *element = 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);
+
+       add_common_properties(element, &dict);
+
+       dbus_message_iter_close_container(&array, &dict);
+
+       return reply;
+}
+
 static DBusMessage *set_property(DBusConnection *conn,
                                        DBusMessage *msg, void *data)
 {
@@ -505,6 +532,11 @@ static GDBusMethodTable network_methods[] = {
        { },
 };
 
+static GDBusMethodTable connection_methods[] = {
+       { "GetProperties", "",   "a{sv}", get_connection_properties },
+       { },
+};
+
 struct append_filter {
        enum connman_element_type type;
        DBusMessageIter *iter;
@@ -1369,6 +1401,15 @@ static void register_element(gpointer data, gpointer user_data)
                                                                element->path);
        }
 
+       if (element->type == CONNMAN_ELEMENT_TYPE_CONNECTION) {
+               if (g_dbus_register_interface(connection, element->path,
+                                       CONNMAN_CONNECTION_INTERFACE,
+                                       connection_methods, element_signals,
+                                       NULL, element, NULL) == FALSE)
+                       connman_error("Failed to register %s connection",
+                                                               element->path);
+       }
+
        g_dbus_emit_signal(connection, CONNMAN_MANAGER_PATH,
                                CONNMAN_MANAGER_INTERFACE, "ElementAdded",
                                DBUS_TYPE_OBJECT_PATH, &element->path,
@@ -1428,6 +1469,10 @@ static gboolean remove_element(GNode *node, gpointer user_data)
                                DBUS_TYPE_OBJECT_PATH, &element->path,
                                                        DBUS_TYPE_INVALID);
 
+       if (element->type == CONNMAN_ELEMENT_TYPE_CONNECTION)
+               g_dbus_unregister_interface(connection, element->path,
+                                               CONNMAN_CONNECTION_INTERFACE);
+
        if (element->type == CONNMAN_ELEMENT_TYPE_NETWORK)
                g_dbus_unregister_interface(connection, element->path,
                                                CONNMAN_NETWORK_INTERFACE);
index 9de73e0b5776d105b1ea893abcde21e7f2bb7c06..58f2982920ded076c95b8c27827bf2cf4a91ee07 100644 (file)
@@ -96,7 +96,7 @@ static void append_connections(DBusMessageIter *dict)
        dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
                                DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter);
 
-       __connman_element_list(CONNMAN_ELEMENT_TYPE_INTERNET, &iter);
+       __connman_element_list(CONNMAN_ELEMENT_TYPE_CONNECTION, &iter);
 
        dbus_message_iter_close_container(&value, &iter);