maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Help needed: DBUS signals not received by hildon-desktop widget (I need widget2widget & system2widget IPC) (https://talk.maemo.org/showthread.php?t=52578)

No!No!No!Yes! 2010-05-13 12:06

Help needed: DBUS signals not received by hildon-desktop widget (I need widget2widget & system2widget IPC)
 
Hi, developers...
I'd like to enhance Queen Beecon Widget with the ability to perform QBW to QBW instance and System to QBW instance IPC (Inter Process Communication).

I just need a very basic and simple IPC mechanism which responds to commands like these:

Code:

run-standalone.sh dbus-send --session --type=signal /com/nokia/qbw/Object com.nokia.qbw.Interface.update string:"id0" string:"layout"
Code:

run-standalone.sh dbus-send --session --type=signal /com/nokia/qbw/Object com.nokia.qbw.Interface.update string:"id<xx>" string:"content"
and let QBW instance (id0 ... id<xx>) perform relevant actions (update QBW layout or update QBW content or ...)

I already coded some snippets into QBW:

DBUS, Signal & Marshalling includes:
PHP Code:

...
#include <dbus/dbus-glib.h>
...
#include <signal.h>
...
#include <marshal.h> 

Signal Callback declaration:
PHP Code:

static void queen_beecon_handle_dbus_signal_update (const DBusGProxy *object G_GNUC_UNUSED, const gchar *id, const gchar *status G_GNUC_UNUSED, const QueenBeecon *self); 

Constants declarations:
PHP Code:

/* libcsnet D-Bus definitions */
#define QBW_DBUS_SERVICE  "com.nokia.qbw.Service"
#define QBW_DBUS_PATH  "/com/nokia/qbw/Object"
#define QBW_DBUS_IFACE "com.nokia.qbw.Interface"

#define QBW_UPDATE_SIGNAL            "update"
#define QBW_UPDATE_SIGNAL_LAYOUT    "layout"
#define QBW_UPDATE_SIGNAL_CONTENT    "content" 

Global DBUS Connection and Proxy definitions:
PHP Code:

static DBusGConnection    *dbus_conn=NULL;
static 
DBusGProxy        *qbw_proxy=NULL

Private class instance ID definition for signals:
PHP Code:

struct _QueenBeeconPrivate
{
        ...

        
// DBUS Signal
        
gchar             *qbwSigId;
}; 

Signal callback function definition:
PHP Code:

static void queen_beecon_handle_dbus_signal_update (const DBusGProxy *object G_GNUC_UNUSED, const gchar *id, const gchar *action, const QueenBeecon *self)
{
    
g_warning ("(%p) queen_beecon_handle_dbus_signal (id=%s, action=%s)",selfidaction);

    if (
g_strcmp0(id,self->priv->qbwSigId)) return; //if signal is not for current instance .... return

    
if (!g_strcmp0(actionQBW_UPDATE_SIGNAL_LAYOUT))
        
queen_beecon_update_content_layout ((QueenBeecon *)self); // No... only update layout
    
else
        
queen_beecon_update_content ((QueenBeecon *)self);


Signal connection at instance initialization:
PHP Code:

static void queen_beecon_realize (GtkWidget *widget)
{
g_warning ("(%p) queen_beecon_realize",widget);
    
QueenBeecon *self QUEEN_BEECON (widget);
    ...
    
self->priv->qbwSigId NULL;
    
self->priv->qbwSigId g_strdup_printf("id%s",&last_dot[1]);
    
dbus_g_proxy_connect_signal (qbw_proxyQBW_UPDATE_SIGNALG_CALLBACK (queen_beecon_handle_dbus_signal_update), selfNULL);


Signal disconnection at instance termination:
PHP Code:

static void queen_beecon_finalize (GObject *object)
{
g_warning ("(%p) queen_beecon_finalize",object);
    
QueenBeecon *self QUEEN_BEECON (object);

    ...
    
dbus_g_proxy_disconnect_signal (qbw_proxyQBW_UPDATE_SIGNALG_CALLBACK (queen_beecon_handle_dbus_signal_update), self); 

DBUS connection and Proxy creation at QBW main class instantiation:
PHP Code:

static void queen_beecon_class_init (QueenBeeconClass *klass)
{
g_warning ("(%p) queen_beecon_class_init",klass);
    ...
    
GErrorerror NULL;
    
DBusGProxy *remote_object;

    
dbus_conn dbus_g_bus_get(DBUS_BUS_SESSION, &error);
    if (
error != NULL) {
        ...
      }

    
qbw_proxy dbus_g_proxy_new_for_name (dbus_connQBW_DBUS_SERVICEQBW_DBUS_PATHQBW_DBUS_IFACE);

    if (
G_LIKELY (qbw_proxy))    {
        
dbus_g_object_register_marshaller (marshal_VOID__STRING_STRINGG_TYPE_NONEG_TYPE_STRINGG_TYPE_STRINGG_TYPE_INVALID);
        
dbus_g_proxy_add_signal (qbw_proxyQBW_UPDATE_SIGNALG_TYPE_STRINGG_TYPE_STRINGG_TYPE_INVALID);
    }
    
dbus_g_connection_flush (dbus_conn);
    ...


Signal disconnection and DBUS unreferencing when last QBW instance closed and class dismissed:
PHP Code:

static void queen_beecon_class_finalize (QueenBeeconClass *klass G_GNUC_UNUSED)
{
    ...
    if (
qbw_proxy) {
        
g_object_unref (qbw_proxy);
    }

    if (
dbus_conndbus_g_connection_unref (dbus_conn);


To test my code, I issue dbus-send commands:
Code:

[sbox-FREMANTLE_X86: ~] > run-standalone.sh dbus-send --session --type=signal /com/nokia/qbw/Object com.nokia.qbw.Interface.update string:"id0" string:"layout"
[sbox-FREMANTLE_X86: ~] > run-standalone.sh dbus-send --session --type=signal /com/nokia/qbw/Object com.nokia.qbw.Interface.update string:"id0" string:"xxx"
[sbox-FREMANTLE_X86: ~] >

dbus-monitor reports signals on the bus:
Code:

[sbox-FREMANTLE_X86: ~] >  run-standalone.sh dbus-monitor "type='signal',interface='com.nokia.qbw.Interface'"
signal sender=org.freedesktop.DBus -> dest=:1.35 serial=2 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameAcquired
  string ":1.35"
signal sender=:1.36 -> dest=(null destination) serial=2 path=/com/nokia/qbw/Object; interface=com.nokia.qbw.Interface; member=update
  string "id0"
  string "layout"
signal sender=:1.37 -> dest=(null destination) serial=2 path=/com/nokia/qbw/Object; interface=com.nokia.qbw.Interface; member=update
  string "id0"
  string "xxx"

but QBW is unable to receive any signal at all, thus not triggering callback functions to perform requested actions.

Any help will be greately appreciated.

I already googled here and there for hints but without success.
Also I already had a look at Help with creating daemon for n900 thread here
Ciao.

qwerty12 2010-05-13 12:45

Re: Help needed: DBUS signals not received by hildon-desktop widget (I need widget2widget & system2widget IPC)
 
Hello,

I'm no D-Bus expert, but I don't think signals are what you want. Signals, generally, are emitted when your application does something and you want listeners to be notified of a change. A method call would be better suited to this application.

Anyway, what you appear to be doing would be listening for a signal emission. I guess you'd specify that it is your program providing the method call.

The DBus-GLib way would be http://dbus.freedesktop.org/doc/dbus...ml#glib-server

Examples of programs doing this are, off the top of my head: Evince (look for its XML files), Diablo's hildon-desktop (look in the background-manager folder), my FMTX Faker (I would not recommend looking at it, however) and N900 FMRX Enabler among others.

No!No!No!Yes! 2010-05-13 13:10

Re: Help needed: DBUS signals not received by hildon-desktop widget (I need widget2widget & system2widget IPC)
 
Quote:

Originally Posted by qwerty12 (Post 656759)
Hello,

I'm no D-Bus expert, but I don't think signals are what you want. Signals, generally, are emitted when your application does something and you want listeners to be notified of a change. A method call would be better suited to this application.

Anyway, what you appear to be doing would be listening for a signal emission. I guess you'd specify that it is your program providing the method call.

The DBus-GLib way would be http://dbus.freedesktop.org/doc/dbus...ml#glib-server

Examples of programs doing this are, off the top of my head: Evince (look for its XML files), Diablo's hildon-desktop (look in the background-manager folder), my FMTX Faker (I would not recommend looking at it, however) and N900 FMRX Enabler among others.

Xx for really quick response ...

I know signals is not the most orthodox way to do that and methods are the way to go ... I just needed a quick, cheap and dirty solution to provide very basic IPC.

For use case and very simple POC: imagine 1 QBW (button) which gives "roll" impulse to 2 instances of QBW Naive Dice Roller, or drives "shuffle" of - say - 5 cards-looking QBWs or (long requested) have many QBW buttons for changing CPU overclocking frequencies and impulse to a gauge QBW for displaying results and other stats.

I'll inspect much further but it's still a mistery why QBW doesn't receive signals (I tried also with a basic signal with no parameters and no marshalling)

Second mistery is how I can debug issues like this one...

Ciao.

qwerty12 2010-05-13 18:57

Re: Help needed: DBUS signals not received by hildon-desktop widget (I need widget2widget & system2widget IPC)
 
1 Attachment(s)
My attempt is attached. It's pretty bad and I'm not sure all instances recieve the signal...

Test with "dbus-send --session --type=method_call --dest=com.nokia.qbw /com/nokia/qbw com.nokia.qbw.update string:"id0" string:"layout""

Crap, I forgot to apply the org.freedesktop.DBus.GLib.NoReply attribute

OK, it does only work for one instance. What you probably should do is when dbus-g-connection-register-g-object is called, is to append the path "/com/nokia/qbw" so that it looks like "/com/nokia/qbw/$ID" so that each instance of the object has their own path - this way you also don't need to pass the id as a parameter too

No!No!No!Yes! 2010-05-13 19:45

Re: Help needed: DBUS signals not received by hildon-desktop widget (I need widget2widget & system2widget IPC)
 
Quote:

Originally Posted by qwerty12 (Post 657284)
My attempt is attached. It's pretty bad and I'm not sure all instances recieve the signal...

Test with "dbus-send --session --type=method_call --dest=com.nokia.qbw /com/nokia/qbw com.nokia.qbw.update string:"id0" string:"layout""

Can't see the "SUPER-MEGA-HYPER-THANKS" button!!!
R E S P E C T... my friend!

I'll give it a shot tomorrow!!! :D

twaelti 2010-05-13 20:01

Re: Help needed: DBUS signals not received by hildon-desktop widget (I need widget2widget & system2widget IPC)
 
Also remember that you're trying to use D-Bus not in an app, but in a hildon-desktop widget. Therefore, you need a special way to get hold of the DBusConnection.
An alternate hackish python way can be found in my recaller sourcecode (I'm using it for the autorecording, listening to systemdbus).

No!No!No!Yes! 2010-05-13 21:01

Re: Help needed: DBUS signals not received by hildon-desktop widget (I need widget2widget & system2widget IPC)
 
Quote:

Originally Posted by twaelti (Post 657402)
Also remember that you're trying to use D-Bus not in an app, but in a hildon-desktop widget. Therefore, you need a special way to get hold of the DBusConnection.
An alternate hackish python way can be found in my recaller sourcecode (I'm using it for the autorecording, listening to systemdbus).

Yes, you are right ... I was aware of those special functions/stubs for hd_home_plugin_item* DBUS acquisition:

PHP Code:

/**
* hd_home_plugin_item_get_dbus_connection:
* @item: A #HDHomePluginItem
* @type: The #DBusBusType %DBUS_BUS_SESSION or %DBUS_BUS_SYSTEM
* @error: A #DBusError to return error messages
*
* Creates a new private #DBusConnection to the D-Bus session or system bus.
*
* It is similar to the dbus_bus_get_private() function but in contrast to the
* dbus_bus_get_private() function the application will not exit if the connection
* closes. Additionally this function is used to map the unique D-Bus name to the
* plugin.
*
* So this function should be used by plugins to create D-Bus connections.
*
* Returns: A new private connection to bus %type. The connection must be unrefed with
* dbus_connection_unref() when it is not longer needed.
**/
DBusConnection *
hd_home_plugin_item_get_dbus_connection (HDHomePluginItem *item,
DBusBusType type,
DBusError *error)
{
HDHomePluginItemPrivate *priv;
DBusConnection *connection;

g_return_val_if_fail (HD_IS_HOME_PLUGIN_ITEM (item), NULL);

priv item->priv;

/* Create a private connection */
connection dbus_bus_get_private (typeerror);

if (!
connection || (error != NULL && dbus_error_is_set (error)))
return 
NULL;

/* Do not exit on disconnect */
dbus_connection_set_exit_on_disconnect (connectionFALSE);

/* Log the connection name for debug purposes */
g_debug ("Plugin '%s' opened D-Bus connection '%s'.",
hd_home_plugin_item_get_dl_filename (item),
dbus_bus_get_unique_name (connection));

return 
connection;
}

/**
* hd_home_plugin_item_get_dbus_g_connection:
* @item: A #HDHomePluginItem
* @type: The #DBusBusType %DBUS_BUS_SESSION or %DBUS_BUS_SYSTEM
* @error: A #GError to return error messages
*
* Creates a new #DBusGConnection to the D-Bus session or system bus.
*
* Internally, calls dbus_g_bus_get(). See there for further informations.
*
* Returns: A shared connection.
**/
DBusGConnection *
hd_home_plugin_item_get_dbus_g_connection (HDHomePluginItem *item,
DBusBusType type,
GError **error)
{
HDHomePluginItemPrivate *priv;
DBusGConnection *g_connection;
DBusConnection *connection;
GError *tmp_error NULL;

g_return_val_if_fail (HD_IS_HOME_PLUGIN_ITEM (item), NULL);

priv item->priv;

/* Create a DBusGConnection (not private yet) */
g_connection dbus_g_bus_get (type, &tmp_error);

if (
tmp_error != NULL)
{
g_propagate_error (errortmp_error);
return 
NULL;
}

connection dbus_g_connection_get_connection (g_connection);

/* Log the connection name for debug purposes */
g_debug ("Plugin '%s' opened D-Bus connection '%s'.",
hd_home_plugin_item_get_dl_filename (item),
dbus_bus_get_unique_name (connection));

return 
g_connection;


but first time i tried I got and "assertion failed" notification stating that caller was not a hd_home_plugin_item.
However that could have been my mistake in calling the function back in my "try-this-and-see-what-happens" hours!!!

GOD SAVE THE MAEMO COMMUNITY!!!!
:cool:

No!No!No!Yes! 2010-05-13 21:17

Re: Help needed: DBUS signals not received by hildon-desktop widget (I need widget2widget & system2widget IPC)
 
Quote:

Originally Posted by qwerty12 (Post 657284)
...
Crap, I forgot to apply the org.freedesktop.DBus.GLib.NoReply attribute

Sorry ... not sure what to change for this ... could you please elaborate 2/3 lines more?

Quote:

Originally Posted by qwerty12 (Post 657284)
...
OK, it does only work for one instance. What you probably should do is when dbus-g-connection-register-g-object is called, is to append the path "/com/nokia/qbw" so that it looks like "/com/nokia/qbw/$ID" so that each instance of the object has their own path - this way you also don't need to pass the id as a parameter too

Yeah... that was one of my first concerns which ended up that way (string:id<xx>) because of the signal issues. But I agree "/com/nokia/qbw/$ID" is the way to go for multi-instance awareness.

Secondly got your warning here:
PHP Code:

#You are discouraged from using "com.nokia"!
QBW_DBUS_SERVICE="com.nokia.qbw"
AC_DEFINE_UNQUOTED(QBW_DBUS_SERVICE"$QBW_DBUS_SERVICE", [Name of D-Bus service])
AC_SUBST([QBW_DBUS_SERVICE]) 

Could you suggest any other "safe" "not-well-known" name to use here?

Ciao.

qwerty12 2010-05-13 21:35

Re: Help needed: DBUS signals not received by hildon-desktop widget (I need widget2widget & system2widget IPC)
 
Quote:

Originally Posted by No!No!No!Yes! (Post 657532)
Sorry ... not sure what to change for this ... could you please elaborate 2/3 lines more?

Sorry, please ignore me - that attribute is only for the client-side bindings.

Quote:

Originally Posted by No!No!No!Yes! (Post 657532)
Could you suggest any other "safe" "not-well-known" name to use here?

Well, anything within reason I guess :)

"it.nononoyes.qbw"? :P

Best regards.

Graham Cobb 2010-05-14 19:36

Re: Help needed: DBUS signals not received by hildon-desktop widget (I need widget2widget & system2widget IPC)
 
Quote:

Originally Posted by No!No!No!Yes! (Post 657509)
Yes, you are right ... I was aware of those special functions/stubs for

but first time i tried I got and "assertion failed" notification stating that caller was not a hd_home_plugin_item.
However that could have been my mistake in calling the function back in my "try-this-and-see-what-happens" hours!!!

You could take a look at the code in gpesummary. Look at gpe_summary_plugin_init for the way I use hd_home_plugin_item_get_dbus_connection.

As for debugging these sorts of issues, it can be pretty horrible. I recommend using scratchbox, in an X86 session. Start up the hildon environment, then kill hildon-desktop and re-run it under gdb (see http://wiki.maemo.org/Using_Valgrind..._in_Scratchbox,
particularly the section on "Starting Maemo-Launched Application with Maemo-Summoner ").


All times are GMT. The time now is 12:12.

vBulletin® Version 3.8.8