Re: [Vala] Question about DBusConnection.add_filter()



On Fri, 2010-10-29 at 22:46 -0200, Daniel Alonso wrote:
Hi everybody,

as an absolute beginner to vala I'm having a hard time to understand how
I should use the add_filter() method in DBusConnection class.

Excuse me if they are a lot of questions ...

1) The valadoc gives the following description for
DBusConnection.add_filter():

public uint add_filter (DBusMessageFilterFunction filter_function,
DestroyNotify user_data_free_func)

Thanks for pointing that out! It should actually be:

public uint add_filter (owned GLib.DBusMessageFilterFunction
filter_function);

I've pushed a fix to git.

but this doesn't seem to match the corresponding method in gio:

guint g_dbus_connection_add_filter (GDBusConnection *connection,
GDBusMessageFilterFunction filter_function, gpointer user_data,
GDestroyNotify user_data_free_func);

where is the user_data pointer in the vala's equivalent method?

valac uses the user_data pointer internally. For instance, if you are
passing an instance method valac will use it for the 'this' pointer.

If you want to pass something other than the instance, you should
probably use a closure. There is some information in the tutorial:

http://live.gnome.org/Vala/Tutorial#Anonymous_Methods_.2BAC8_Closures

2) About the FilterFunction to be passed to add_event(), valadoc gives
the following description:

public bool DBusMessageFilterFunction (DBusConnection connection,
DBusMessage message, bool incoming)

but again this doesn't seem to match the corresponding method in gio:

GDBusMessage *(*GDBusMessageFilterFunction) (GDBusConnection
*connection, GDBusMessage *message, gboolean incoming, gpointer
user_data);

again due to the user_data parameter being missing in the vala's method.
And when should it return true or false?

The user_data thing is the same as above. As for the return value, it
looks like valadoc.org needs to be updated. The vapi currently (since
19c951c1e06283e48cbf39f1e07fe3c11c8304fc) has:

public delegate unowned GLib.DBusMessage DBusMessageFilterFunction
(GLib.DBusConnection connection, GLib.DBusMessage message, bool
incoming);

The old version was probably accurate for a pre-release GIO.

3) Moreover, how should I define the filter_function? I've tried the
following:

  private bool MyFilterMsg (DBusConnection connection, 
                             DBusMessage message,
                             bool incoming)
  {
      return true;    
  }                  
  ...
  uint filter_uid = connection.add_filter (MyFilterMsg, ...)

but then the compiler complains that it cannot convert from MyFilterMsg
to GLib.DBusMessageFilter.

You're probably running into problems because the documentation is
outdated. You should be returning a GLib.DBusMessage, not a bool... you
can always check your vapi to be sure.




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