Exemple #1
0
        internal protected async Task <IDisposable> WatchVoidSignalAsync(string iface, string member, Action <Exception> error, Action action)
        {
            var           synchronizationContext = _connection.CaptureSynchronizationContext();
            var           wrappedDisposable      = new WrappedDisposable(synchronizationContext);
            SignalHandler handler = (msg, ex) =>
            {
                if (ex != null)
                {
                    if (error == null)
                    {
                        return;
                    }
                    wrappedDisposable.Call(error, ex, disposes: true);
                    return;
                }

                if (!SenderMatches(msg))
                {
                    return;
                }
                wrappedDisposable.Call(action);
            };

            wrappedDisposable.Disposable = await _connection.WatchSignalAsync(ObjectPath, iface, member, handler);

            return(wrappedDisposable);
        }
Exemple #2
0
        internal protected async Task <IDisposable> WatchNonVoidSignalAsync <T>(string iface, string member, Action <Exception> error, Action <T> action, ReadMethodDelegate <T> readValue, bool isPropertiesChanged)
        {
            var           synchronizationContext = _connection.CaptureSynchronizationContext();
            var           wrappedDisposable      = new WrappedDisposable(synchronizationContext);
            SignalHandler handler = (msg, ex) =>
            {
                if (ex != null)
                {
                    if (error == null)
                    {
                        return;
                    }
                    wrappedDisposable.Call(error, ex, disposes: true);
                    return;
                }

                if (!SenderMatches(msg))
                {
                    return;
                }
                var reader = new MessageReader(msg, _factory);
                if (isPropertiesChanged)
                {
                    var eventIface = reader.ReadString();
                    if (eventIface != iface)
                    {
                        return;
                    }
                    reader.SetSkipNextStructPadding();
                }
                var value = readValue(reader);
                wrappedDisposable.Call(action, value);
            };

            if (isPropertiesChanged)
            {
                wrappedDisposable.Disposable = await _connection.WatchSignalAsync(ObjectPath, "org.freedesktop.DBus.Properties", "PropertiesChanged", handler);
            }
            else
            {
                wrappedDisposable.Disposable = await _connection.WatchSignalAsync(ObjectPath, iface, member, handler);
            }

            return(wrappedDisposable);
        }