Re: Questions on NetworkManager-0.7.0



On Tue, 2008-03-25 at 03:11 +0000, Jue Yang wrote:
> Hi,
> 
>  
> 
> I’m a fresh to develop Network Manager based on version 0.7.0. I have
> digged it few days and feel so confused. Could anybody give me the
> answers to following questions. 
> 
> 1.       Why does NM separate to two layers, libnm and src?

libnm-glib is only used by _client_ of NetworkManager, and wraps the
D-Bus objects that NetworkManager exports in a glib friendly API.

libnm-util is common code and structures used both by clients of
NetworkManager and NetworkManager itself.

> 2.       How to do initialization of all objects? I mean who calls
> those “class_init” functions. 

This is handled by glib.  When you call g_object_new(<type>, ...) glib
looks up the type that you have given it (which is registered indirectly
by those lines in the header files like #define NM_TYPE_FOO
(nm_foo_get_type ())).

Once it's got the class structure identified by the type you have given
it with g_object_new(), glib will call the class_init and constructor
functions of the class and it's subclasses as necessary.

For more information on glib objects, see:

http://library.gnome.org/devel/gobject/unstable/chapter-gobject.html

> 3.       Can Applet just call functions in libnm? During Applet
> setting an active network, which way used to keep synchronizing
> between libnm and src?

Yes, the applet can call libnm-glib functions, provided it has created
the right objects.  You must first create the libnm-glib NMClient
object, which effectively wraps the D-Bus interface exported by the
NMManager object in src/.  Once the applet has the NMClient object, it
can attach to the signals of NMClient, ask NMClient for the list of
devices, the list of currently active connections, etc.

Most of the synchronization between a client an NetworkManager (aided by
libnm-glib for glib-based applications) is through signals.  The
NMClient object proxies the PropertiesChanged signal that NetowrkManager
emits when the NMManager state changes, and it decodes the signal and
re-emits the signal as a GObject signal on the NMClient object.  There's
actually some magic underneath to extract the properties that have
actually changed (there can be more than one at a time) from the
PropertiesChanged signal over D-Bus, and then set the internal cached
variables inside the NMClient object, and when those internal cached
variables change, emit GObject notify signals to alert users of
libnm-glib that something has changed.

It's sort of complicated; but as a client of NetworkManager you just
need to pick one of (1) the D-Bus interface, or (2) the libnm-glib
interface, or (3) the KDE Solid interface when it's done.  (2) and (3)
just wrap the D-Bus interface (1) in a more friendly manner and do
things like convert D-Bus types to glib/qt types (a{sv} -> GHashTable
for example).

Dan




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