TDE DBus Tutorial

From Trinity Desktop Project Wiki
Revision as of 15:13, 5 August 2018 by imported>Deloptes (TDE use of dbus-1-tqt and dbusxml2qt3)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Introduction

I want to put down a summary of my experience with auto-generated interfaces and their use in TDE.

I hope it will save many time for playing, copy/pasting "strange" code or just head ache.

There are few examples at the end to show the use of DBus proxy and DBus interface.

Additional information can be found in the documentation of package dbus-1-tqt.

Create DBus Interface

To create a DBus interface we need first a definition of the interface. More information on the interface type and signatures can be found in official dbus tutorial

The definition of the interface is a xml file. We take as example a file describing "org.freedesktop.DBus.ObjectManager".

     <!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
          "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
     <node name="/org/example/Service">
     	<interface name="org.freedesktop.DBus.ObjectManager">
     		<method name="GetManagedObjects">
     			<arg name="objects" type="a{oa{sa{sv}}}" direction="out" />
     		</method>
     		<signal name="InterfacesAdded">
     			<arg name="object" type="o" />
     			<arg name="interfaces" type="a{sa{sv}}" />
     		</signal>
     		<signal name="InterfacesRemoved">
     			<arg name="object" type="o" />
     			<arg name="interfaces" type="as" />
     		</signal>
     	</interface>
     	<node name="org" />
     </node>

To generate the TQt C++ classes use dbusxml2qt3 (Note: [1])

     $ /usr/bin/dbusxml2qt3 objectmanager.xml
     ClassGenerator: processing interface 'org.freedesktop.DBus.ObjectManager'
     Generating org.freedesktop.DBus.Introspectable on demand

in the second step generate the proxy with unique namespace to fit your application

     $/usr/bin/dbusxml2qt3 objectmanager.xml -p -N MyNameSpace::Proxy
     $ ls -1 | grep  -v xml
     introspectableinterface.cpp
     introspectableinterface.h
     objectmanagerinterface.cpp
     objectmanagerinterface.h
     objectmanagerproxy.cpp
     objectmanagerproxy.h
     org_example_servicenode.cpp
     org_example_servicenode.h


Now we can create our own object manager using the interface from step one, or create our own proxy from step two

[to be completed...]