7f81e1593a
It is no longer necessary to duplicate the list of function parameters when declaring a D-Bus methods. Instead methods are added to a DBusObjectHelper instance with the minimum amount of information: - optional this pointer for methods - the address of the method, global or static function - the name of the D-Bus method The DBusHelper::add() call determines the signature based on the function pointer. It would have been nice to pass a boost::bind() result and that way get rid of the special case of method pointers, but it seems to be impossible to determine the type of all parameters in the functor returned by boost::bind(). The maximum number of parameters of methods, including the "this" pointer, is now 9, the maximum supported by boost::bind(). Internally DBusHelper maintains a DBusMethodTable with one pointer to a boost::function instance for each method. This depends on the new libgdbus per-method callback data. Signals are also added with add() and likewise maintained inside the DBusObjectHelper. This avoids duplicating the signal name. All strings passed to DBusObjectHelper are copied and freed when no longer needed. The old handling of asynchronous method implementations via dedicated method callbacks was replaced with code that detects when a method ask for a Result* parameter. This is done via dbus_traits for those parameter types, similar to the way how Watches were handled. The compiler can detect this situation at compile time, which should remove the useless post-method handling of the return values from the generated code. The main advantage is that the exponential duplication of code for the various combinations of n arguments and m asynchronous result values could be removed. It is nicer for users, too, because the _ASYNC flag no longer has to be specified manually when registering the method.
50 lines
1.2 KiB
Python
Executable file
50 lines
1.2 KiB
Python
Executable file
#!/usr/bin/python
|
|
|
|
import dbus
|
|
from dbus.mainloop.glib import DBusGMainLoop
|
|
import gobject
|
|
|
|
DBusGMainLoop(set_as_default=True)
|
|
|
|
bus = dbus.SessionBus()
|
|
|
|
dummy = dbus.Interface(bus.get_object('org.example', '/test'),
|
|
'org.freedesktop.DBus.Introspectable')
|
|
|
|
print dummy.Introspect()
|
|
|
|
|
|
object = dbus.Interface(bus.get_object('org.example', '/test'),
|
|
'org.example.Secondary')
|
|
object.Hello()
|
|
|
|
object = dbus.Interface(bus.get_object('org.example', '/test'),
|
|
'org.example.Test')
|
|
|
|
print object.Test()
|
|
print object.Method2(1)
|
|
print object.Method3(1)
|
|
print object.Hash({1: 1, 2: 2, 3: 3})
|
|
print object.Array([1, 2, 3, 4])
|
|
print object.ArgTest((1, 'hello', {'foo': 'bar'}))
|
|
|
|
loop = gobject.MainLoop()
|
|
|
|
def AsyncFinished(x=None):
|
|
print "TestAsync:", x
|
|
loop.quit()
|
|
|
|
print object.TestAsync(2,
|
|
reply_handler=AsyncFinished,
|
|
error_handler=AsyncFinished)
|
|
|
|
# This will trigger the "caller has disconnect"
|
|
# because our client-side time out will get us
|
|
# out of the loop and then we quit.
|
|
object.TestAsync(600,
|
|
reply_handler=AsyncFinished,
|
|
error_handler=AsyncFinished,
|
|
timeout=5)
|
|
loop.run()
|
|
|
|
object.Error()
|