Re: Call AddConnection DBus



Dear,
       Thanks Dan reply. But it has a little problem.
I use add-system-setting.py. It works & create /etc/NetworkManager/system-connections/*
( But dbus-monitor can't see any message about AddConnection or GetSettings [ d-feet send & dbus-send same ] )
Is it normally?
My Networkmanager 0.8 version.

BTW, i try to combine test-keyfile.c & AddConnection DBUS. 
But it also can't work. I modify this source simplification.

Thanks everyone
blue

2010/9/29 Dan Williams <dcbw redhat com>
On Mon, 2010-09-27 at 16:48 +0800, rain blue wrote:
> Dear,
>          I found this type. But it will occur error.
> i will check it. Thanks everyone.

There's various code inside nm-applet that does this, but the easiest
way to do it is probably to (assuming an Ethernet connection):

#define DBUS_TYPE_G_MAP_OF_VARIANT          (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE))
#define DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT   (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, DBUS_TYPE_G_MAP_OF_VARIANT))

NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
char *uuid;
GHashTable *hash;

DBusGConnection *p_source_bus;
        DBusGProxy *p_source_object;
        GError *p_source_error = NULL;

        g_type_init ();

        p_source_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &p_source_error);
        if (!p_source_bus)
                printf ("Couldn't connect to session bus");

        p_source_object = dbus_g_proxy_new_for_name (p_source_bus,
                                              NM_DBUS_SERVICE,  // or  NM_DBUS_SYSTEM_SETTINGS
                                              NM_DBUS_PATH_SETTINGS,
                                              NM_DBUS_IFACE_SETTINGS);
        if (!p_source_object)
                printf ("Failed to get name owner");
 
/* Create a new connection object */
connection = nm_connection_new ();

/* Build up the 'connection' Setting */
s_con = (NMSettingConnection *) nm_setting_connection_new ();
uuid = nm_utils_uuid_generate ();
g_object_set (G_OBJECT (s_con),
             NM_SETTING_CONNECTION_UUID, uuid,
             NM_SETTING_CONNECTION_ID, "Test connection",
             NULL);
g_free (uuid);
nm_connection_add_setting (connection, NM_SETTING (s_con));

/* Build up the 'wired' Setting */
s_wired = (NMSettingWired *) nm_setting_wired_new ();
nm_connection_add_setting (connection, NM_SETTING (s_wired));

hash = nm_connection_to_hash (connection);

       dbus_g_proxy_call (p_source_object , "AddConnection", &p_source_error,
                                      DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, hash,
                                      G_TYPE_INVALID);

g_hash_table_destroy (hash);
g_object_unref (connection);

> _______________________________________________
> networkmanager-list mailing list
> networkmanager-list gnome org
> http://mail.gnome.org/mailman/listinfo/networkmanager-list





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]