1

I'm using the Qt D-Bus library to interact with the BlueZ service. The platform is Linux OS.

I've exported the DTD D-BUS Object Introspection of the /org/bluez/hci0 object and I've added the needed annotations (see: qdbusxml2cpp unknown type)

Consider the following XML snippet:

  <method name="SetDiscoveryFilter">
     <arg name="properties" type="a{sv}" direction="in" />
     <annotation name="org.qtproject.QtDBus.QtTypeName.In0"  value="ProperyList"/>
  </method>

  <signal name="PropertiesChanged">
     <arg name="interface" type="s" direction="in" />
     <arg name="changed_properties" type="a{sv}" direction="in" />
     <arg name="invalidated_properties" type="as" direction="in" />
     <annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="InvalidatedProperties"/>
  </signal>

The "properties" arg in the method "SetDiscoveryFilter" has the same type of the "changed_properties" arg in the signal "PropertiesChanged" (a{sv}).

Suppose I want to annotate the "properties" and "changed_properties" args with two different values.

"properties" in "PropertyList", "changed_properties" in "ChangedProperties"

According to the answer qdbusxml2cpp unknown type the proxy class needs to have a typedef which defines the "ProperyList" and "ChangedProperties" types in the Qt context.

typedef QVariantMap PropertyList;
typedef QVariantMap ChangedProperties;

Q_DECLARE_METATYPE(PropertyList) 
Q_DECLARE_METATYPE(ChangedProperties)

When compiling I've got a "redefinition" error related to the Q_DECLARE_METATYPE. Indeed there is a problem in the registration of two types both of type "QVariantMap".

Which is the correct way to handle this situation? Have I to annotate all the "a{sv}" types in the DTD D-BUS Object Introspection with the same value?

Consider that the code above is just an example. My Qt code needs to handle several interfaces in which arguments of types "a{sv}" are used in several different contexts.

Can be the abstraction of the "a{sv}" type a solution?

Consider the following annotation:

<annotation name="org.qtproject.QtDBus.QtTypeName.In0"  value="DbusQVariantMap"/>

Is the annotation accettable or is it possible to adopt a different solution?

Community
  • 1
  • 1
Grynium
  • 163
  • 2
  • 11

1 Answers1

1

The solution I've found is to use a single QVariantMap typedef and define two additional struct to wrap this object.

typedef QVariantMap DBusQVariantMap;
Q_DECLARE_METATYPE(DBusQVariantMap)

struct PropertyList
{
    DBusQVariantMap propertyListMap;
};
Q_DECLARE_METATYPE(PropertyList)

struct ChangedProperties
{
    DBusQVariantMap changedPropertiesMap;
};
Q_DECLARE_METATYPE(ChangedProperties)

The struct are used as container of the QVariantMap (QMap). The info regarding the contents of the DBusQVariantMap is detailed into the name of the structures.

Grynium
  • 163
  • 2
  • 11