|
2010-05-13
, 12:45
|
|
Posts: 4,274 |
Thanked: 5,358 times |
Joined on Sep 2007
@ Looking at y'all and sighing
|
#2
|
The Following User Says Thank You to qwerty12 For This Useful Post: | ||
|
2010-05-13
, 13:10
|
|
Posts: 700 |
Thanked: 846 times |
Joined on Nov 2009
|
#3
|
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.
|
2010-05-13
, 18:57
|
|
Posts: 4,274 |
Thanked: 5,358 times |
Joined on Sep 2007
@ Looking at y'all and sighing
|
#4
|
The Following User Says Thank You to qwerty12 For This Useful Post: | ||
|
2010-05-13
, 19:45
|
|
Posts: 700 |
Thanked: 846 times |
Joined on Nov 2009
|
#5
|
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""
The Following User Says Thank You to No!No!No!Yes! For This Useful Post: | ||
|
2010-05-13
, 20:01
|
Posts: 883 |
Thanked: 980 times |
Joined on Jul 2007
@ Bern, Switzerland
|
#6
|
The Following User Says Thank You to twaelti For This Useful Post: | ||
|
2010-05-13
, 21:01
|
|
Posts: 700 |
Thanked: 846 times |
Joined on Nov 2009
|
#7
|
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).
/**
* 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 (type, error);
if (!connection || (error != NULL && dbus_error_is_set (error)))
return NULL;
/* Do not exit on disconnect */
dbus_connection_set_exit_on_disconnect (connection, FALSE);
/* 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 (error, tmp_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;
}
|
2010-05-13
, 21:17
|
|
Posts: 700 |
Thanked: 846 times |
Joined on Nov 2009
|
#8
|
...
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
#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])
|
2010-05-13
, 21:35
|
|
Posts: 4,274 |
Thanked: 5,358 times |
Joined on Sep 2007
@ Looking at y'all and sighing
|
#9
|
Sorry ... not sure what to change for this ... could you please elaborate 2/3 lines more?
Could you suggest any other "safe" "not-well-known" name to use here?
The Following User Says Thank You to qwerty12 For This Useful Post: | ||
|
2010-05-14
, 19:36
|
Posts: 162 |
Thanked: 351 times |
Joined on Apr 2006
@ Cotswolds, UK
|
#10
|
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!!!
The Following User Says Thank You to Graham Cobb For This Useful Post: | ||
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:
I already coded some snippets into QBW:
DBUS, Signal & Marshalling includes:
...
#include <dbus/dbus-glib.h>
...
#include <signal.h>
...
#include <marshal.h>
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);
/* 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"
static DBusGConnection *dbus_conn=NULL;
static DBusGProxy *qbw_proxy=NULL;
struct _QueenBeeconPrivate
{
...
// DBUS Signal
gchar *qbwSigId;
};
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)",self, id, action);
if (g_strcmp0(id,self->priv->qbwSigId)) return; //if signal is not for current instance .... return
if (!g_strcmp0(action, QBW_UPDATE_SIGNAL_LAYOUT))
queen_beecon_update_content_layout ((QueenBeecon *)self); // No... only update layout
else
queen_beecon_update_content ((QueenBeecon *)self);
}
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_proxy, QBW_UPDATE_SIGNAL, G_CALLBACK (queen_beecon_handle_dbus_signal_update), self, NULL);
}
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_proxy, QBW_UPDATE_SIGNAL, G_CALLBACK (queen_beecon_handle_dbus_signal_update), self);
static void queen_beecon_class_init (QueenBeeconClass *klass)
{
g_warning ("(%p) queen_beecon_class_init",klass);
...
GError* error = 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_conn, QBW_DBUS_SERVICE, QBW_DBUS_PATH, QBW_DBUS_IFACE);
if (G_LIKELY (qbw_proxy)) {
dbus_g_object_register_marshaller (marshal_VOID__STRING_STRING, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
dbus_g_proxy_add_signal (qbw_proxy, QBW_UPDATE_SIGNAL, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
}
dbus_g_connection_flush (dbus_conn);
...
}
static void queen_beecon_class_finalize (QueenBeeconClass *klass G_GNUC_UNUSED)
{
...
if (qbw_proxy) {
g_object_unref (qbw_proxy);
}
if (dbus_conn) dbus_g_connection_unref (dbus_conn);
}
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.