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



On Thursday 28 of October 2010 01:30:40 hong sheng wrote:
> Hi Daniel,
> 
> Thank you very much. I have some more questions.
> 
> If I used g_signal_connect at the same program for g_signal_emit, for
> example, in modemmanager, I can receive that signal because I know the
> right object for the signal to connect.
> 
> However, in a different program, how can I get the right GObject to connect
> the signal?
> 
You can't use pure Glib signals as inter-process communication (IPC). They are 
limited for one process only. For communication between two processes you need 
some IPC means, like D-Bus.
Nevertheless, D-Bus signals can be used to "extend" glib signals. Thus 
g_signal_emit() will in turn issue "SignalQuality" signal on D-Bus. And this 
signal is received by the other process and converted to "local" glib signal.

> 
> For example, in the open source modemmanager, there is a function called "
> g_signal_emit (self, signals[SIGNAL_QUALITY], 0, quality)", where object:
> self is a modemclass.  If I write my own applet, how can I set
> "g_signal_connect" with right Object of Modem? I mean how can I get the
> right object pointer of Modem for the signal to be connected?
> 
> In addition, I found in the openSource applet, there is a function to
> connect signal"SignalQuality" as follows:
> 
>         dbus_g_proxy_add_signal (info->cdma_proxy, "SignalQuality",
> G_TYPE_UINT, G_TYPE_INVALID);
>         dbus_g_proxy_connect_signal (info->cdma_proxy, "SignalQuality",
>                                      G_CALLBACK
> (signal_quality_changed_cb), info, NULL);
> 
> But I didn't find a place to emit this signal("SignalQuality") either in
> modemmanager or in the networkmanager. Something missed in modemmanager or
> networkmanager?
> 
This is the client part of the whole picture.  dbus_g_proxy_add_signal() 
specify the signal we are interested in and dbus_g_proxy_connect_signal() 
install the handlers that will be called upon signal reception. So, when 
ModemManager emits SIGNAL_QUALITY, "SignalQuality" D-Bus signal is emitted (in 
addition to local glib signal). The D-Bus signal is received by the applet and 
via dbus-glib converted to local glib signal. This causes 
signal_quality_changed_cb() handler to be called.

http://dbus.freedesktop.org/doc/dbus-glib/dbus-glib-DBusGProxy.html#dbus-g-
proxy-add-signal

Jirka


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