private async void HandleMethodCall(Message methodCall, IMessageStream peer) { switch (methodCall.Header.Interface) { case "org.freedesktop.DBus.Peer": switch (methodCall.Header.Member) { case "Ping": { SendMessage(MessageHelper.ConstructReply(methodCall), peer); return; } case "GetMachineId": { SendMessage(MessageHelper.ConstructReply(methodCall, Environment.MachineId), peer); return; } } break; } MethodHandler methodHandler; if (_methodHandlers.TryGetValue(methodCall.Header.Path.Value, out methodHandler)) { var reply = await methodHandler(methodCall); reply.Header.ReplySerial = methodCall.Header.Serial; reply.Header.Destination = methodCall.Header.Sender; SendMessage(reply, peer); } else { if (methodCall.Header.Interface == "org.freedesktop.DBus.Introspectable" && methodCall.Header.Member == "Introspect" && methodCall.Header.Path.HasValue) { var path = methodCall.Header.Path.Value; var childNames = GetChildNames(path); if (childNames.Length > 0) { var writer = new IntrospectionWriter(); writer.WriteDocType(); writer.WriteNodeStart(path.Value); foreach (var child in childNames) { writer.WriteChildNode(child); } writer.WriteNodeEnd(); var xml = writer.ToString(); SendMessage(MessageHelper.ConstructReply(methodCall, xml), peer); } } SendUnknownMethodError(methodCall, peer); } }
public Task <string> Introspect() { var path = CallContext.CurrentPath ?? ObjectPath.Root; var writer = new IntrospectionWriter(); writer.WriteDocType(); writer.WriteNodeStart(path.Value); var interfaces = Connection.BaseDBusConnection.RegisteredPathHandlers(path); foreach (var(InterfaceName, Handler) in interfaces) { writer.WriteInterfaceStart(InterfaceName); var def = Handler.GetInterfaceDefinitions(); foreach (var m in def.Methods) { writer.WriteMethodStart(m.Name); foreach (var arg in m.ArgTypes) { writer.WriteInArg(arg.Name, arg.Signature); } foreach (var arg in m.ReturnTypes) { writer.WriteOutArg(arg.Name, arg.Signature); } writer.WriteMethodEnd(); } foreach (var p in def.Properties) { writer.WriteProperty(p.Name, p.Type.Signature, p.Access); } foreach (var s in def.Signals) { writer.WriteSignalStart(s.Name); foreach (var arg in s.ArgDefs) { writer.WriteArg(arg.Name, arg.Signature); } writer.WriteSignalEnd(); } writer.WriteInterfaceEnd(); } var children = Connection.BaseDBusConnection.RegisteredPathChildren(path); foreach (var child in children) { writer.WriteChildNode(child); } writer.WriteNodeEnd(); return(Task.FromResult(writer.ToString())); }
private string GenerateIntrospectionXml(TypeDescription description) { var writer = new IntrospectionWriter(); bool hasProperties = false; foreach (var interf in description.Interfaces) { writer.WriteInterfaceStart(interf.Name); foreach (var method in interf.Methods) { writer.WriteMethodStart(method.Name); foreach (var arg in method.InArguments) { writer.WriteInArg(arg.Name, arg.Signature); } foreach (var arg in method.OutArguments) { writer.WriteOutArg(arg.Name, arg.Signature); } writer.WriteMethodEnd(); } foreach (var signal in interf.Signals) { writer.WriteSignalStart(signal.Name); foreach (var arg in signal.SignalArguments) { writer.WriteArg(arg.Name, arg.Signature); } writer.WriteSignalEnd(); } 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()); }
private Task <Message> HandleIntrospect(object o, Message methodCall, IProxyFactory factory) { IntrospectionWriter writer = new IntrospectionWriter(); writer.WriteDocType(); writer.WriteNodeStart(_objectPath.Value); writer.WriteLiteral(_typeIntrospection); foreach (var child in _connection.GetChildNames(_objectPath)) { writer.WriteChildNode(child); } writer.WriteNodeEnd(); var xml = writer.ToString(); var response = MessageHelper.ConstructReply(methodCall, xml); return(Task.FromResult(response)); }