示例#1
0
 private void RemoveSignalHandler(SignalMatchRule rule, SignalHandler dlg)
 {
     lock (_gate)
     {
         if (_signalHandlers?.ContainsKey(rule) == true)
         {
             _signalHandlers[rule] = (SignalHandler)Delegate.Remove(_signalHandlers[rule], dlg);
             if (_signalHandlers[rule] == null)
             {
                 _signalHandlers.Remove(rule);
                 if (ConnectionInfo.RemoteIsBus)
                 {
                     CallRemoveMatchRule(rule.ToString());
                 }
             }
         }
     }
 }
示例#2
0
        public async Task <IDisposable> WatchSignalAsync(ObjectPath path, string @interface, string signalName, SignalHandler handler)
        {
            SignalMatchRule rule = new SignalMatchRule()
            {
                Interface = @interface,
                Member    = signalName,
                Path      = path
            };

            Task task = null;

            lock (_gate)
            {
                ThrowIfNotConnected();
                if (_signalHandlers.ContainsKey(rule))
                {
                    _signalHandlers[rule] = (SignalHandler)Delegate.Combine(_signalHandlers[rule], handler);
                    task = Task.CompletedTask;
                }
                else
                {
                    _signalHandlers[rule] = handler;
                    if (ConnectionInfo.RemoteIsBus)
                    {
                        task = CallAddMatchRuleAsync(rule.ToString());
                    }
                }
            }
            SignalHandlerRegistration registration = new SignalHandlerRegistration(this, rule, handler);

            try
            {
                if (task != null)
                {
                    await task;
                }
            }
            catch
            {
                registration.Dispose();
                throw;
            }
            return(registration);
        }
示例#3
0
 Task RemoveSignalHandler(SignalMatchRule rule, SignalHandler dlg)
 {
     lock (_gate)
     {
         if (_signalHandlers.ContainsKey(rule))
         {
             var sh = _signalHandlers[rule];
             _signalHandlers[rule] = (SignalHandler)Delegate.Remove(sh, dlg);
             if (_signalHandlers[rule] == null)
             {
                 _signalHandlers.Remove(rule);
                 if (RemoteIsBus == true)
                 {
                     return(DBus.RemoveMatch(rule.ToString()));
                 }
             }
         }
     }
     return(Task.CompletedTask);
 }