From c173ac56daf611a103050c0e465e89bfa15eef7b Mon Sep 17 00:00:00 2001 From: Tom Deseyn Date: Thu, 19 Jul 2018 21:44:21 +0200 Subject: [PATCH] Generate introspection xml for properties, peer and introspectable. (#51) --- .../CodeGen/DBusAdapterTypeBuilder.cs | 8 +++ src/Tmds.DBus/DBusConnection.cs | 2 + src/Tmds.DBus/Protocol/IntrospectionWriter.cs | 55 +++++++++++++++ test/Tmds.DBus.Tests/IntrospectionTests.cs | 69 +++++++++++++++++++ 4 files changed, 134 insertions(+) diff --git a/src/Tmds.DBus/CodeGen/DBusAdapterTypeBuilder.cs b/src/Tmds.DBus/CodeGen/DBusAdapterTypeBuilder.cs index 0c5076e0..1422c5ff 100644 --- a/src/Tmds.DBus/CodeGen/DBusAdapterTypeBuilder.cs +++ b/src/Tmds.DBus/CodeGen/DBusAdapterTypeBuilder.cs @@ -368,6 +368,7 @@ private MethodInfo GenMethodHandler(string key, MethodDescription dbusMethod, bo private string GenerateIntrospectionXml(TypeDescription description) { var writer = new IntrospectionWriter(); + bool hasProperties = false; foreach (var interf in description.Interfaces) { @@ -398,10 +399,17 @@ private string GenerateIntrospectionXml(TypeDescription description) foreach (var prop in interf.Properties) { + hasProperties = true; writer.WriteProperty(prop.Name, prop.Signature, prop.Access); } writer.WriteInterfaceEnd(); } + if (hasProperties) + { + writer.WritePropertiesInterface(); + } + writer.WriteIntrospectableInterface(); + writer.WritePeerInterface(); return writer.ToString(); } diff --git a/src/Tmds.DBus/DBusConnection.cs b/src/Tmds.DBus/DBusConnection.cs index 58380aa8..03c39611 100644 --- a/src/Tmds.DBus/DBusConnection.cs +++ b/src/Tmds.DBus/DBusConnection.cs @@ -729,6 +729,8 @@ private async void HandleMethodCall(Message methodCall, IMessageStream peer) writer.WriteDocType(); writer.WriteNodeStart(path.Value); + writer.WriteIntrospectableInterface(); + writer.WritePeerInterface(); foreach (var child in childNames) { writer.WriteChildNode(child); diff --git a/src/Tmds.DBus/Protocol/IntrospectionWriter.cs b/src/Tmds.DBus/Protocol/IntrospectionWriter.cs index b0e3fed4..d65c452d 100644 --- a/src/Tmds.DBus/Protocol/IntrospectionWriter.cs +++ b/src/Tmds.DBus/Protocol/IntrospectionWriter.cs @@ -16,6 +16,61 @@ public void WriteDocType() _sb.Append("\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"); } + public void WriteIntrospectableInterface() + { + WriteInterfaceStart("org.freedesktop.DBus.Introspectable"); + + WriteMethodStart("Introspect"); + WriteOutArg("data", Signature.StringSig); + WriteMethodEnd(); + + WriteInterfaceEnd(); + } + + public void WritePropertiesInterface() + { + WriteInterfaceStart("org.freedesktop.DBus.Properties"); + + WriteMethodStart("Get"); + WriteInArg("interfaceName", Signature.StringSig); + WriteInArg("propertyName", Signature.StringSig); + WriteOutArg("value", Signature.VariantSig); + WriteMethodEnd(); + + WriteMethodStart("Set"); + WriteInArg("interfaceName", Signature.StringSig); + WriteInArg("propertyName", Signature.StringSig); + WriteInArg("value", Signature.VariantSig); + WriteMethodEnd(); + + WriteMethodStart("GetAll"); + WriteInArg("interfaceName", Signature.StringSig); + WriteOutArg("properties", new Signature("a{sv}")); + WriteMethodEnd(); + + WriteSignalStart("PropertiesChanged"); + WriteArg("interfaceName", Signature.StringSig); + WriteArg("changed", new Signature("a{sv}")); + WriteArg("invalidated", new Signature("as")); + WriteSignalEnd(); + + WriteInterfaceEnd(); + } + + public void WritePeerInterface() + { + WriteInterfaceStart("org.freedesktop.DBus.Peer"); + + WriteMethodStart("Ping"); + WriteMethodEnd(); + + WriteMethodStart("GetMachineId"); + WriteOutArg("machineId", Signature.StringSig); + WriteMethodEnd(); + + WriteInterfaceEnd(); + } + public void WriteInterfaceStart(string name) { _sb.AppendFormat(" \n", name); diff --git a/test/Tmds.DBus.Tests/IntrospectionTests.cs b/test/Tmds.DBus.Tests/IntrospectionTests.cs index 81a98b2f..103fe7a5 100644 --- a/test/Tmds.DBus.Tests/IntrospectionTests.cs +++ b/test/Tmds.DBus.Tests/IntrospectionTests.cs @@ -96,6 +96,18 @@ private static string FormatUnixLineEndings(string value) + + + + + + + + + + + + "); @@ -110,6 +122,18 @@ private static string FormatUnixLineEndings(string value) + + + + + + + + + + + + @@ -119,6 +143,18 @@ private static string FormatUnixLineEndings(string value) @" + + + + + + + + + + + + @@ -144,6 +180,39 @@ private static string FormatUnixLineEndings(string value) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ");