Reply
Thread Tools
No!No!No!Yes!'s Avatar
Posts: 700 | Thanked: 846 times | Joined on Nov 2009
#1
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.
__________________
Have a look at Queen BeeCon Widget (WIKI) Customizable and flexible widget-based multi-instance monitoring, alerting and interactive tool for the N900
Please provide comments and feedback for having QBW supported and enhanced further - (DONATE) - v1.3.3devel / v1.3.3testing / v1.3.3extras

Last edited by No!No!No!Yes!; 2010-05-13 at 12:16.
 
qwerty12's Avatar
Posts: 4,274 | Thanked: 5,358 times | Joined on Sep 2007 @ Looking at y'all and sighing
#2
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.
 

The Following User Says Thank You to qwerty12 For This Useful Post:
No!No!No!Yes!'s Avatar
Posts: 700 | Thanked: 846 times | Joined on Nov 2009
#3
Originally Posted by qwerty12 View Post
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.
__________________
Have a look at Queen BeeCon Widget (WIKI) Customizable and flexible widget-based multi-instance monitoring, alerting and interactive tool for the N900
Please provide comments and feedback for having QBW supported and enhanced further - (DONATE) - v1.3.3devel / v1.3.3testing / v1.3.3extras
 
qwerty12's Avatar
Posts: 4,274 | Thanked: 5,358 times | Joined on Sep 2007 @ Looking at y'all and sighing
#4
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
Attached Files
File Type: gz queen-beecon_0.1.4.diff.gz (3.2 KB, 84 views)

Last edited by qwerty12; 2010-05-13 at 20:29.
 

The Following User Says Thank You to qwerty12 For This Useful Post:
No!No!No!Yes!'s Avatar
Posts: 700 | Thanked: 846 times | Joined on Nov 2009
#5
Originally Posted by qwerty12 View Post
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!!!
__________________
Have a look at Queen BeeCon Widget (WIKI) Customizable and flexible widget-based multi-instance monitoring, alerting and interactive tool for the N900
Please provide comments and feedback for having QBW supported and enhanced further - (DONATE) - v1.3.3devel / v1.3.3testing / v1.3.3extras
 

The Following User Says Thank You to No!No!No!Yes! For This Useful Post:
Posts: 883 | Thanked: 980 times | Joined on Jul 2007 @ Bern, Switzerland
#6
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).
__________________
-Tom (N900, N810, N800)

"the idea of truly having a computer in your pocket just moved a big step closer."
 

The Following User Says Thank You to twaelti For This Useful Post:
No!No!No!Yes!'s Avatar
Posts: 700 | Thanked: 846 times | Joined on Nov 2009
#7
Originally Posted by twaelti View Post
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!!!!
__________________
Have a look at Queen BeeCon Widget (WIKI) Customizable and flexible widget-based multi-instance monitoring, alerting and interactive tool for the N900
Please provide comments and feedback for having QBW supported and enhanced further - (DONATE) - v1.3.3devel / v1.3.3testing / v1.3.3extras
 
No!No!No!Yes!'s Avatar
Posts: 700 | Thanked: 846 times | Joined on Nov 2009
#8
Originally Posted by qwerty12 View Post
...
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?

Originally Posted by qwerty12 View Post
...
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.
__________________
Have a look at Queen BeeCon Widget (WIKI) Customizable and flexible widget-based multi-instance monitoring, alerting and interactive tool for the N900
Please provide comments and feedback for having QBW supported and enhanced further - (DONATE) - v1.3.3devel / v1.3.3testing / v1.3.3extras
 
qwerty12's Avatar
Posts: 4,274 | Thanked: 5,358 times | Joined on Sep 2007 @ Looking at y'all and sighing
#9
Originally Posted by No!No!No!Yes! View Post
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.

Originally Posted by No!No!No!Yes! View Post
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.
 

The Following User Says Thank You to qwerty12 For This Useful Post:
Posts: 162 | Thanked: 351 times | Joined on Apr 2006 @ Cotswolds, UK
#10
Originally Posted by No!No!No!Yes! View Post
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 ").
 

The Following User Says Thank You to Graham Cobb For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 09:29.