Exemplo n.º 1
0
        private void handleMethodReturn(MessageHeader header, Decoder decoder)
        {
            try
            {
                if (!expectedMessages.TryRemove(header.ReplySerial, out var tcs))
                {
                    decoder.Dispose();
                    throw new InvalidOperationException("Couldn't find the method call for the method return");
                }

                var receivedMessage = new ReceivedMessage(header, decoder);
                tcs.TrySetResult(receivedMessage);
            }
            catch (Exception e)
            {
                onUnobservedException(e);
            }
        }
Exemplo n.º 2
0
        public Task HandleMethodCallAsync(
            MethodCallOptions methodCallOptions,
            ReceivedMessage message,
            CancellationToken cancellationToken
            )
        {
            switch (methodCallOptions.Member)
            {
            case "GetManagedObjects":
                return(handleGetManagedObjectsAsync(methodCallOptions, message, cancellationToken));

            default:
                throw new DbusException(
                          DbusException.CreateErrorName("UnknownMethod"),
                          "Method not supported"
                          );
            }
        }
Exemplo n.º 3
0
        private async Task handleGetManagedObjectsAsync(
            MethodCallOptions methodCallOptions,
            ReceivedMessage message,
            CancellationToken cancellationToken
            )
        {
            message.AssertSignature("");
            var managedObjects = await target.GetManagedObjectsAsync(cancellationToken).ConfigureAwait(false);

            if (!methodCallOptions.ShouldSendReply)
            {
                return;
            }
            var sendBody = new Encoder();

            sendBody.AddArray(() =>
            {
                foreach (var managedObject in managedObjects)
                {
                    sendBody.StartCompoundValue();
                    sendBody.Add(managedObject.Key);
                    sendBody.AddArray(() =>
                    {
                        foreach (var proxy in managedObject.Value)
                        {
                            sendBody.StartCompoundValue();
                            sendBody.Add(proxy.InterfaceName);
                            proxy.EncodeProperties(sendBody);
                        }
                        sendBody.StartCompoundValue();
                        sendBody.Add("org.freedesktop.DBus.Properties");
                        sendBody.AddArray(() => { }, storesCompoundValues: true);  // empty properties for the properties interface
                    }, storesCompoundValues: true);
                }
            }, storesCompoundValues: true);
            await connection.SendMethodReturnAsync(
                methodCallOptions,
                sendBody,
                "a{oa{sa{sv}}}",
                cancellationToken
                ).ConfigureAwait(false);
        }