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

2014-04-15 Thread Manuel Yguel

Thanks a lot Dan, your explanations were very clear.
Thank to you I got a running example doing creation, connection, 
disconnection and deletion of the settings. I attached the code I wrote. 
It is not completely mature yet since it mixes c++ and C. But I intend 
to put some orthodoxy in it later.
I have an other question, I have seen that the connection called "Test 
of my" is still visible in the list of scanned networks displayed by the 
network-manager-applet. I thought first that it was because the list was 
not updated but it seems not to be the case. Worse: I am able to click 
on it and it looks like it tries to activate it, however I think it does 
not work.
Is this a problem related to the applet or did I miss to remove 
something when managing the adhoc connection ?



Manuel


On 04/10/2014 05:52 PM, Dan Williams wrote:

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



#This CMakeLists.txt was automatically generated.
#You can add things but not change existing things.
#For instance don't change the variable names !
#One exception: you can change the name of the the target library.

cmake_minimum_required(VERSION 2.4)

if(COMMAND cmake_policy)
if( POLICY CMP0003 )
   cmake_policy(SET CMP0003 NEW)
endif( POLICY CMP0003 )
if( POLICY CMP0015 )
cmake_policy(SET CMP0015 NEW)
  endif( POLICY CMP0015 )
endif(COMMAND cmake_policy)

project( manage_

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

2014-04-10 Thread Manuel Yguel
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 ?


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.

- all the best,

Manuel

--

Manuel Yguel

___
networkmanager-list mailing list
networkmanager-list@gnome.org
https://mail.gnome.org/mailman/listinfo/networkmanager-list


Re: nm_device_disconnect

2014-04-02 Thread Manuel Yguel

Thanks a lot Dan,
It worked as you explained.
I will document a minimal example corresponding to my use case and 
submit it through the mailing list for the record.



On 04/02/2014 03:18 PM, Dan Winship wrote:

On 04/01/2014 07:08 PM, Manuel Yguel wrote:

Thanks for the answer,
Is there an other way ? Because I want the adhoc network to stop as soon
as possible.

It *will* stop as soon as possible


Plus I do not do anything in the disconnect callback, so I
fear that it is just my callback that is called when the adhoc network
is disconnected (by somebody else or by the fact that the network is not
available anymore) and then that this not the function for my purpose.

No, the callback is only called for the action that you initiated.


Well, well, what I am looking for is the function that is called when in
a GUI the user hit the disconnect button...

Which is nm_device_disconnect().


I took a look at the sources of NetworkManager and I noted that there
are several files called nm-device.h that offer different interfaces.

One of them is the object inside the NetworkManager daemon itself, the
other is the client-side representation of that object.

-- Dan



-- Manuel

___
networkmanager-list mailing list
networkmanager-list@gnome.org
https://mail.gnome.org/mailman/listinfo/networkmanager-list


Re: nm_device_disconnect

2014-04-02 Thread Manuel Yguel

I took a look at the sources of NetworkManager and I noted that there are 
several files called nm-device.h that offer different interfaces. The one 
exported in libnm-glib does not expose as much functionality as I need. In 
particular the following function is not provided:

gboolean nm_device_disconnect (NMDevice *device, GError **error)
{
NMDevicePrivate *priv;

g_return_val_if_fail (device != NULL, FALSE);
g_return_val_if_fail (NM_IS_DEVICE (device), FALSE);

priv = NM_DEVICE_GET_PRIVATE (device);
if (priv->state <= NM_DEVICE_STATE_DISCONNECTED) {
g_set_error_literal (error, NM_DEVICE_ERROR, 
NM_DEVICE_ERROR_NOT_ACTIVE,
 "Cannot disconnect an inactive device.");
return FALSE;
}

priv->autoconnect_inhibit = TRUE;
nm_device_state_changed (device,
 NM_DEVICE_STATE_DISCONNECTED,
 NM_DEVICE_STATE_REASON_USER_REQUESTED);
return TRUE;
}

why is that so ?  I wonder if this function is not exposed due to a 
synchronization problem with the GUI.

 


-- Manuel


On 04/01/2014 08:16 PM, Dan Winship wrote:

On 04/01/2014 01:18 PM, Manuel Yguel wrote:

however in the include directory of libnm-glib the file nm-device.h
contains only the following function:
void nm_device_disconnect (NMDevice *device,
NMDeviceDeactivateFn callback, gpointer user_data);

I tried to use the last one with a dummy callback function and with a
pointer to a NMClient object but it did not disconnect the network.

Thanks for any hint or pointer.

A libnm-glib method that takes a callback is most likely asynchronous.
So you need to call nm_device_disconnect() and then run the main loop
until the callback gets called.

-- Dan



___
networkmanager-list mailing list
networkmanager-list@gnome.org
https://mail.gnome.org/mailman/listinfo/networkmanager-list


Re: nm_device_disconnect

2014-04-01 Thread Manuel Yguel

Thanks for the answer,
Is there an other way ? Because I want the adhoc network to stop as soon 
as possible. Plus I do not do anything in the disconnect callback, so I 
fear that it is just my callback that is called when the adhoc network 
is disconnected (by somebody else or by the fact that the network is not 
available anymore) and then that this not the function for my purpose.


Well, well, what I am looking for is the function that is called when in 
a GUI the user hit the disconnect button... So it exists somewhere, but 
maybe it is not in a public API ?


-- Manuel



On 04/01/2014 08:16 PM, Dan Winship wrote:

On 04/01/2014 01:18 PM, Manuel Yguel wrote:

however in the include directory of libnm-glib the file nm-device.h
contains only the following function:
void nm_device_disconnect (NMDevice *device,
NMDeviceDeactivateFn callback, gpointer user_data);

I tried to use the last one with a dummy callback function and with a
pointer to a NMClient object but it did not disconnect the network.

Thanks for any hint or pointer.

A libnm-glib method that takes a callback is most likely asynchronous.
So you need to call nm_device_disconnect() and then run the main loop
until the callback gets called.

-- Dan



___
networkmanager-list mailing list
networkmanager-list@gnome.org
https://mail.gnome.org/mailman/listinfo/networkmanager-list


nm_device_disconnect

2014-04-01 Thread Manuel Yguel

Hi,
I am using libnm-glib version 0.9.4.0-0ubuntu4.3 on ubuntu 12.04 precise 
pangolin.
I would like to time the delay of activation of an adhoc network and I 
would like to do statistics:
creating an adhoc network with a pc, scan and connect with an other, log 
the different times and repeat.
So far I am able to create the adhoc network, scan and connect. I am 
stuck at the repeat part since I would like to disconnect the network 
but I do not find how to proceed.
It seems that there exists a nm_device_disconnect function with the 
following prototype:
   gboolean nm_device_disconnect (NMDevice *device, 
GError **error);

in the source of the NetworkManager
however in the include directory of libnm-glib the file nm-device.h 
contains only the following function:
   void nm_device_disconnect (NMDevice *device, 
NMDeviceDeactivateFn callback, gpointer user_data);


I tried to use the last one with a dummy callback function and with a 
pointer to a NMClient object but it did not disconnect the network.


Thanks for any hint or pointer.

--

Manuel

___
networkmanager-list mailing list
networkmanager-list@gnome.org
https://mail.gnome.org/mailman/listinfo/networkmanager-list