Re: Change IP address with libnm



On Wed, 2020-02-26 at 16:02 +0000, António Mendes wrote:
Hello again Thomas.

After read more documentation and follow your guidelines, I achieved
my objective but if you can, I would appreciate a second opinion in
the developed code, if you don't mind...

Hi,


You call nm_remote_connection_commit_changes_async(). That will
basically send the D-Bus request via D-Bus (to Update).

Usually, you would have your application to wait for the response from
commit_changes_async(). 

NMClient is build around GDBusConnection and thus GMainContext. That
means, when you start an async operation, you need to run/iterate the
maincontext for the response callback to be invoked. I think [1] is a
very good introduction to understand how this works.

From the provided code it's not clear whether you are iterating the
main context (as you have to). However your networkManager() function
doesn't give the caller a way to know when the callback was invoked
(and whether it can stop waiting).


On a minor note, nm_remote_connection_commit_changes_finish() returns a
GVariant on success. You must free that. Also, you don't pass a
user_data argument to nm_remote_connection_commit_changes_async(),
so the g_object_unref(op) is wrong.


[1] https://developer.gnome.org/programming-guidelines/stable/main-contexts.html.en


best,
Thomas

Attachment: signature.asc
Description: This is a digitally signed message part



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