Hello. I’m trying to implement a simple D-Bus server mock using the dasbus library. I need to implement a D-Bus signal with a specific signature for testing purposes.
I tried to adjust one of the dasbus examples (05_chat). However, when I check my adjusted service with d-feet, the signal does not show up. See code below.
Could somebody please help me and give some hints what could be wrong with my code. Thanks in advance.
"""
This is how it should look like:
<node>
<interface name="org.example.ExampleService">
<signal name="calculationDone">
<arg name="requestId" type="i" direction="out"/>
<arg name="frameNo" type="u" direction="out"/>
<arg name="probabilities" type="ad" direction="out"/>
</signal>
</interface>
</node>
"""
from dasbus.connection import SessionMessageBus
from dasbus.identifier import DBusServiceIdentifier
from dasbus.loop import EventLoop
from dasbus.server.interface import dbus_interface, dbus_signal
from dasbus.server.publishable import Publishable
from dasbus.server.template import InterfaceTemplate
from dasbus.signal import Signal
from dasbus.xml import XMLGenerator
SESSION_BUS = SessionMessageBus()
EXAMPLE_SERVICE_NAMESPACE = ("org", "example", "ExampleService")
EXAMPLE_SERVICE = DBusServiceIdentifier(
namespace=EXAMPLE_SERVICE_NAMESPACE, message_bus=SESSION_BUS
)
@dbus_interface(EXAMPLE_SERVICE.interface_name)
class ExampleServiceInterface(InterfaceTemplate):
def connect_signals(self):
self.implementation.calculation_done.connect(self.calculationDone)
@dbus_signal
def calculationDone(self):
#return (1, 2, [0.1, 0.2, 0.3])
print("calculationDone")
class ExampleService(Publishable):
def __init__(self):
self._calculation_done = Signal()
def for_publication(self):
return ExampleServiceInterface(self)
@property
def calculation_done(self):
return self._calculation_done
if __name__ == "__main__":
print(XMLGenerator.prettify_xml(ExampleServiceInterface.__dbus_xml__))
try:
example_service = ExampleService()
SESSION_BUS.publish_object(
EXAMPLE_SERVICE.object_path, example_service.for_publication()
)
SESSION_BUS.register_service(EXAMPLE_SERVICE.service_name)
loop = EventLoop()
loop.run()
finally:
SESSION_BUS.disconnect()
Output is as follows:
<node>
<!--Specifies ExampleServiceInterface-->
<interface name="org.example.ExampleService"></interface>
</node>
The signal is missing.