2016-06-18 14 views
0

Ich möchte ein Python-Objekt auf einem Session-Bus veröffentlichen, mit pydbus und Python 2.7. Ich bin neu in pydbus, also bleibe ich beim Beispiel und habe das Tutorial gemacht. Es ist mir jedoch nicht gelungen, einen einfachen Testserver mit pydbus zu starten.pydbus: Wie publiziere ich ein Objekt?

Ich schrieb eine einfache Klasse, mit nur einer Methode, die eine Zeichenfolge zurückgibt. Ich habe eine Schnittstelle angegeben und eine Ereignisschleife erstellt.

Code:

from pydbus import SessionBus 
from gi.repository import GObject 

loop = GObject.MainLoop() 

class Testclass(object): 
    """ 
    <node> 
     <interface name='org.philipp.DBUSTutorial'> 
      <method name='helloworld'> 
       <arg type='s' name='reply' direction='out'/> 
      </method> 
     </interface> 
    </node> 
    """ 

    def helloworld(): 
     return "Hello World" 

bus = SessionBus() 
bus.publish("org.philipp.DBUSTutorial", Testclass()) 
loop.run() 

Nach der Ausführung des Skripts ein Fehler wirft.

Fehlermeldung:

Traceback (most recent call last): 
    File "test.py", line 24, in <module> 
    bus.publish("org.philipp.DBUSTutorial", Testclass()) 
    File "/usr/local/lib/python2.7/dist-packages/pydbus/publication.py", line 33, in publish 
    return Publication(self, bus_name, *objects) 
    File "/usr/local/lib/python2.7/dist-packages/pydbus/publication.py", line 26, in __init__ 
    self._at_exit(bus.register_object(path, object, node_info).__exit__) 
    File "/usr/local/lib/python2.7/dist-packages/pydbus/registration.py", line 123, in register_object 
    return ObjectRegistration(self.con, path, interfaces, wrapper, own_wrapper=True) 
    File "/usr/local/lib/python2.7/dist-packages/pydbus/registration.py", line 103, in __init__ 
    ids = [con.register_object(path, interface, wrapper.call_method, wrapper.get_property, wrapper.set_property) for interface in interfaces] 
TypeError: argument vtable: Expected Gio.DBusInterfaceVTable, but got pydbus.registration.instancemethod 

Was mache ich falsch? Es wäre toll, wenn jemand mir helfen könnte, meinen Fehler zu finden.

Antwort

3

Wie in Readme beschrieben: "Seit 0,5, es Publishing-Objekten auf dem Bus unterstützt - dies erfordert jedoch Glib 2.46 oder höher."

Leider gibt es keine Möglichkeit, Objekte mit älteren GLib zu veröffentlichen.

0

ein dbus Objekt registrieren:

import dbus 
bus = dbus.SessionBus() 

class Foo(dbus.service.Object): 
""" 
""" 
    def __init__(self, path): 
     super(Foo, self).__init__(bus, path) 

    # A method 
    @dbus.service.method(<dbus_interface_name>, 
         in_signature="", out_signature="") 
    def foo(self): 
     pass