D-Bus Introspection: pure data structure representation

Felipe Gasper felipe at felipegasper.com
Fri May 17 16:03:26 UTC 2019


Hi all,

	Sometime back I came up with a schema for representing a D-Bus interface as a pure data structure rather than as an XML document. This would allow applications to interface with D-Bus without needing to load XML libraries, which seem to be in progressively less use nowadays as formats such as JSON have become predominant.

	Here is an example interface description, using JSON:

-----
{
   "name" : "MyInterface",
   "annotations" : {
      "if_foo" : "bar"
   },
   "methods" : {
      "MyMethod" : {
         "annotations" : {
            "meth_baz" : "bar",
            "meth_foo" : "bar"
         },
         "inputs" : [
            {
               "annotations" : {
                  "input_baz" : "bar",
                  "input_foo" : "bar"
               },
               "name" : "haha",
               "type" : "s"
            },
            {
               "annotations" : {},
               "name" : "hoho",
               "type" : "s"
            },
            {
               "name" : "hehe",
               "type" : "s"
            }
         ],
         "outputs" : [
            {
               "annotations" : {
                  "output_foo" : "bar"
               },
               "name" : "haha",
               "type" : "s"
            },
            {
               "annotations" : {},
               "name" : "hoho",
               "type" : "s"
            },
            {
               "name" : "hehe",
               "type" : "s"
            }
         ]
      }
   },
   "properties" : {
      "propOne" : {
         "access" : "read",
         "annotations" : {
            "prop_baz" : "bar",
            "prop_foo" : "bar"
         },
         "type" : "as"
      },
      "propThree" : {
         "access" : "read",
         "annotations" : {},
         "type" : "as"
      },
      "propTwo" : {
         "access" : "read",
         "type" : "as"
      }
   },
   "signals" : {
      "MySignal" : {
         "annotations" : {
            "sig_foo" : "bar"
         },
         "parameters" : [
            {
               "annotations" : {
                  "parm_foo" : "bar"
               },
               "name" : "haha",
               "type" : "s"
            }
         ]
      }
   }
}
-----

	Note that I’ve separated method inputs/outputs into separate lists rather than keeping them together as a single list. I’m not opposed to combining them as the standard XML representation does, but I just think it’s much easier to understand when they’re in separate lists.

	This would seem simple enough to implement by adding a new method, e.g., “IntrospectAsStruct”, in the Introspectable interface, with a single parameter that gives the serialization format (e.g., JSON, YAML, CBOR, MessagePack, Sereal, …) to use. It would likely also be good to add a property, Serializations, that gives supported serializations, either as strings or as numerical constants.

	So, e.g.,:

dbus-send --dest my.service /my/service org.freedesktop.DBus.Introspectable.IntrospectAsStruct format:json

… would return a JSON string.

	What are folks’ thoughts here? I feel like XML is an increasingly obscure and unnecessary stumbling block to use of D-Bus’s introspection.

	Thank you for your time!

-Felipe Gasper


More information about the dbus mailing list