Re: How to get the D-bus path of the settings of a connection ?



On Thu, 2014-04-10 at 14:44 +0200, Manuel Yguel wrote:
I have successfully created and deleted adhoc networks from the glib API 
thanks to Dan help. However my test program suffers from one problem: 
the network connection configurations get stored in the network manager 
memory and pollute the user interface. Thus I try to call 
org.freedesktop.NetworkManager.Settings.Connection.Delete for a certain 
NMConnection object without any success so far.
I can see in the D-bus (with qdbusviewer) the configuration for a single 
network connection and I am able to call the Delete method on it 
(because I can see it appears when the setting configuration is recorded).
However I do not know how to get the number (x) in the path that appears at
org/freedesktop/NetworkManager/Settings/x
in order to create a proxy for that "Settings.Connection object" and 
call the Delete method on it later.
First I would like to know if there is a way to get the path of the 
object storing the org.freedesktop.NetworkManager.Settings.Connection 
from the glib API ?

When you add the connection to NetworkManager originally, NM will return
to you the object path that you can use to work with the Connection
object later.  With the libnm-glib API, when you call:

gboolean nm_remote_settings_add_connection (NMRemoteSettings *settings,
                                            NMConnection *connection,
                                            NMRemoteSettingsAddConnectionFunc callback,
                                            gpointer user_data);

"callback" is called when the add is completed, and your callback has
the prototype of:

typedef void (*NMRemoteSettingsAddConnectionFunc) (NMRemoteSettings *settings,
                                                   NMRemoteConnection *connection,
                                                   GError *error,
                                                   gpointer user_data);

The NMRemoteConnection object (a subclass of NMConnection) represents
the actual connection known by NM.  You can throw away the NMConnection
that you handed to nm_remote_settings_add_connection(), it is unchanged
by the call.  The NMRemoteConnection is the "live" object, which you can
keep around and use later with functions like:

void nm_remote_connection_delete (NMRemoteConnection *connection,
                                  NMRemoteConnectionResultFunc callback,
                                  gpointer user_data);

I was first thinking that it may be a NMSettingConnection object. I was 
able to access it but I was only able to get the uuid or the human name 
of the connection.
I also tried the nm_connection_get_path on the NMConnection object but I 
get a NULL string.
I am quite stuck now and any help would be much appreciated.

I think the issue is that you might still be using the NMConnection that
you built up to send to NM with the add_connection() call.  That object
isn't consumed by add_connection(), but serves as a template and can be
disposed after calling add_connection().  The NMRemoteConnection is what
you want to use.

I've committed some more documentation to libnm-glib's NMRemoteSettings
object which describes this and hopefully helps you out.

http://cgit.freedesktop.org/NetworkManager/NetworkManager/commit/?id=2200687b0f92d553dc79e54b672069b2b704203d

There are also some examples here, the ones you're interested in have
"libnm-glib" in the name:

http://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/examples/C/glib

Let us know if you have further questions!

Dan



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