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); }
Hi, 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). best, Thomas
} This program just prints the same number over and over again -- the value of the bitrate when the program was first started. Meanwhile, I can open an nm-applet dialog simultaneously and watch the bitrate change merrily over time. What am I missing? Thank you!
Attachment:
signature.asc
Description: This is a digitally signed message part