Re: libnm and updating wifi bitrate



On Thu, Apr 12, 2018 at 2:55 AM, Thomas Haller <thaller redhat com> wrote:
On Wed, 2018-04-11 at 23:17 -0400, Doug Torrance wrote:
> Hello,
>
> I'm coding a small utility using libnm.  I'd like the bitrate of wifi
> devices to update over time, just like in the "Connection
> Information" dialog of nm-applet.  However, the bitrate never seems
> to change.
>
> The code below illustrates my problem:
>
> #include <NetworkManager.h>
> #include <unistd.h>
> #include <stdio.h>
>
> int main(int argc, char *argv[])
> {
>       NMClient *client;
>       const GPtrArray *devices;
>       NMDevice *device;
>
>       client = nm_client_new(NULL, NULL);
>       devices = nm_client_get_devices(client);
>       device = g_ptr_array_index(devices, 0);
>
>       while (1) {
>               printf("%d\n",
>
>  nm_device_wifi_get_bitrate(NM_DEVICE_WIFI(device)));
>               sleep(5);
>       }

you never iterate the mainloop, hence, no D-Bus signals from
NetworkManager are processed, and the value never changes.

You need to run the mainloop, like g_main_loop_run() or
g_main_context_iterate().

Also, note that unless you keep references to the instances, they might
be destroyed while the mainloop processes events. So, you could take a
reference, but better is probably to re-fetch it every time (or watch
whether the device gets deleted in the meantime, by listening to
signals).

That worked perfectly -- thank you!

Doug 


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