Re: difference between "g_signal_emit and g_object_notify" and how to listen to these signals



On Wed, October 27, 2010 7:19 am, hong sheng wrote:
> I am reading the NetworkManager code as well as ModemManager code.
> I noticed that NetworkManager is
> using "g_object_notify" to send out the event signals,
> while ModemManager is using "g_signal_emit" to emit signals.
>
> Anyone knows what's the difference between these two function call?

Hi Hong Sheng,

Most of these are pure GTK+ questions.

g_signal_emit_by_name() and g_signal_emit() are the typical ways to emit
GTK+ signals.

g_object_notify() is usually used when implementing a GObject (as opposed
to using a ready-made GObject.)

g_object_notify() emits a "notify" signal for the property property_name
on object.

> In the Applet,
> if I want to listen to the signal sent from g_object_notify,
> what should I listen?

g_signal_connect( G_OBJECT(the_gobject_with_relevant_property),
    "notify::DetailNameHere",
    G_CALLBACK(my_notify_detailname_property_change_callback),
    userdata_or_window_if_desired);

The "notify" signal callback functions have this function prototype:

void my_notify_detailname_property_change_callback(
    GObject *the_gobject_with_relevant_property,
    GParamSpec *arg1,
    gpointer userdata_or_window_if_desired);


> If I want to listen to the signal sent from
> g_signal_emit, how can I implement it?

This is just the same as how you program a GTK+ application normally:
g_signal_connect( G_OBJECT(the_relevant_gobject),
    "signal_name",
    G_CALLBACK(my_callback_func),
    NULL );

The GTK+ mailing list is at:
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


The callback function prototype depends on the signal.
You can, usually, find that out by
looking at (NetworkManager) documentation
  (easy for newbies, but I don't know if it is there),
looking for a sample handler (callback) function (easy too),
searching through the (NetworkManager) source code
  to find out its default handler and
  append an extra userdata argument
  (more involved and confusing for newbies.)

The callback function prototype used is not generic to GTK+, but specific
to NetworkManager.

Regards,

-- 
Daniel Yek


>
> thanks
>
> Xiaohong





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