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 )); }
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" ); } }
public void EncodeProperty(Encoder encoder, string requestedProperty) => throw new DbusException( DbusException.CreateErrorName("InvalidCall"), "ObjectManager has no Properties" );