Beispiel #1
0
        private void handleError(MessageHeader header, Decoder decoder)
        {
            try
            {
                using (decoder)
                {
                    if (header.ReplySerial == 0)
                    {
                        throw new InvalidOperationException("Only errors for method calls are supported");
                    }

                    DbusException exception;
                    if (header.BodySignature is null || header.ErrorName is null)
                    {
                        exception = new DbusException("Invalid message");
                    }
                    else if (header.BodySignature.ToString().StartsWith("s"))
                    {
                        var message = decoder.GetString();
                        exception = new DbusException(header.ErrorName, message);
                    }
                    else
                    {
                        exception = new DbusException(header.ErrorName);
                    }

                    if (!expectedMessages.TryRemove(header.ReplySerial, out var tcs))
                    {
                        throw new InvalidOperationException("Couldn't find the method call for the error", exception);
                    }

                    tcs.TrySetException(exception);
                }
        private void handleMethodCall(
            MethodCallOptions methodCallOptions,
            ReceivedMessage receivedMessage,
            CancellationToken cancellationToken
            )
        {
            async Task withExceptionHandling(Func <MethodCallOptions, ReceivedMessage, CancellationToken, Task> work, CancellationToken localCancellationToken)
            {
                try
                {
                    using (receivedMessage)
                        await work(methodCallOptions, receivedMessage, localCancellationToken);
                }
                catch (DbusException dbusException)
                {
                    await sendMethodCallErrorAsync(
                        methodCallOptions,
                        dbusException.ErrorName,
                        dbusException.ErrorMessage,
                        localCancellationToken
                        );
                }
                catch (Exception e)
                {
                    await sendMethodCallErrorAsync(
                        methodCallOptions,
                        DbusException.CreateErrorName("General"),
                        e.Message,
                        localCancellationToken
                        );
                }
            }

            if (methodCallOptions.InterfaceName == "org.freedesktop.DBus.Properties")
            {
                Task.Run(() => withExceptionHandling(handlePropertyRequestAsync, cancellationToken));
                return;
            }

            var dictionaryEntry = methodCallOptions.Path + "\0" + methodCallOptions.InterfaceName;

            if (objectProxies.TryGetValue(dictionaryEntry, out var proxy))
            {
                Task.Run(() => withExceptionHandling(proxy.HandleMethodCallAsync, cancellationToken));
                return;
            }

            receivedMessage.Dispose();
            Task.Run(() => sendMethodCallErrorAsync(
                         methodCallOptions,
                         DbusException.CreateErrorName("MethodCallTargetNotFound"),
                         "The requested method call isn't mapped to an actual object",
                         cancellationToken
                         ));
        }
Beispiel #3
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"
                          );
            }
        }
Beispiel #4
0
 public void EncodeProperty(Encoder encoder, string requestedProperty)
 => throw new DbusException(
           DbusException.CreateErrorName("InvalidCall"),
           "ObjectManager has no Properties"
           );