Skip to content

Commit

Permalink
Generate introspection xml for properties, peer and introspectable. (#51
Browse files Browse the repository at this point in the history
)
  • Loading branch information
tmds authored Jul 19, 2018
1 parent 5f9c774 commit c173ac5
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Tmds.DBus/CodeGen/DBusAdapterTypeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 2 additions & 0 deletions src/Tmds.DBus/DBusConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
55 changes: 55 additions & 0 deletions src/Tmds.DBus/Protocol/IntrospectionWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(" <interface name=\"{0}\">\n", name);
Expand Down
69 changes: 69 additions & 0 deletions test/Tmds.DBus.Tests/IntrospectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ private static string FormatUnixLineEndings(string value)
<arg direction=""out"" name=""value"" type=""s""/>
</method>
</interface>
<interface name=""org.freedesktop.DBus.Introspectable"">
<method name=""Introspect"">
<arg direction=""out"" name=""data"" type=""s""/>
</method>
</interface>
<interface name=""org.freedesktop.DBus.Peer"">
<method name=""Ping"">
</method>
<method name=""GetMachineId"">
<arg direction=""out"" name=""machineId"" type=""s""/>
</method>
</interface>
</node>
");

Expand All @@ -110,6 +122,18 @@ private static string FormatUnixLineEndings(string value)
<arg direction=""out"" name=""value"" type=""s""/>
</method>
</interface>
<interface name=""org.freedesktop.DBus.Introspectable"">
<method name=""Introspect"">
<arg direction=""out"" name=""data"" type=""s""/>
</method>
</interface>
<interface name=""org.freedesktop.DBus.Peer"">
<method name=""Ping"">
</method>
<method name=""GetMachineId"">
<arg direction=""out"" name=""machineId"" type=""s""/>
</method>
</interface>
<node name=""child1""/>
<node name=""child2""/>
</node>
Expand All @@ -119,6 +143,18 @@ private static string FormatUnixLineEndings(string value)
@"<!DOCTYPE node PUBLIC ""-//freedesktop//DTD D-BUS Object Introspection 1.0//EN""
""http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"">
<node name=""/tmds/dbus/tests"">
<interface name=""org.freedesktop.DBus.Introspectable"">
<method name=""Introspect"">
<arg direction=""out"" name=""data"" type=""s""/>
</method>
</interface>
<interface name=""org.freedesktop.DBus.Peer"">
<method name=""Ping"">
</method>
<method name=""GetMachineId"">
<arg direction=""out"" name=""machineId"" type=""s""/>
</method>
</interface>
<node name=""stringoperations""/>
<node name=""otherstringoperations""/>
</node>
Expand All @@ -144,6 +180,39 @@ private static string FormatUnixLineEndings(string value)
<property name=""IsMarried"" type=""b"" access=""readwrite""/>
<property name=""Tuple"" type=""(iiiiiiii)"" access=""readwrite""/>
</interface>
<interface name=""org.freedesktop.DBus.Properties"">
<method name=""Get"">
<arg direction=""in"" name=""interfaceName"" type=""s""/>
<arg direction=""in"" name=""propertyName"" type=""s""/>
<arg direction=""out"" name=""value"" type=""v""/>
</method>
<method name=""Set"">
<arg direction=""in"" name=""interfaceName"" type=""s""/>
<arg direction=""in"" name=""propertyName"" type=""s""/>
<arg direction=""in"" name=""value"" type=""v""/>
</method>
<method name=""GetAll"">
<arg direction=""in"" name=""interfaceName"" type=""s""/>
<arg direction=""out"" name=""properties"" type=""a{sv}""/>
</method>
<signal name=""PropertiesChanged"">
<arg name=""interfaceName"" type=""s""/>
<arg name=""changed"" type=""a{sv}""/>
<arg name=""invalidated"" type=""as""/>
</signal>
</interface>
<interface name=""org.freedesktop.DBus.Introspectable"">
<method name=""Introspect"">
<arg direction=""out"" name=""data"" type=""s""/>
</method>
</interface>
<interface name=""org.freedesktop.DBus.Peer"">
<method name=""Ping"">
</method>
<method name=""GetMachineId"">
<arg direction=""out"" name=""machineId"" type=""s""/>
</method>
</interface>
</node>
");

Expand Down

0 comments on commit c173ac5

Please sign in to comment.