Exemple #1
0
 public NameOwnerWatcherRegistration(DBusConnection dbusConnection, string key, OwnerChangedMatchRule rule, Action <ServiceOwnerChangedEventArgs, Exception> handler)
 {
     _connection = dbusConnection;
     _rule       = rule;
     _handler    = handler;
     _key        = key;
 }
        public override bool Equals(object o)
        {
            OwnerChangedMatchRule r = o as OwnerChangedMatchRule;

            if (o == null)
            {
                return(false);
            }

            return(Interface == r.Interface &&
                   Member == r.Member &&
                   Path == r.Path &&
                   ServiceName == r.ServiceName);
        }
Exemple #3
0
 private void RemoveNameOwnerWatcher(string key, OwnerChangedMatchRule rule, Action <ServiceOwnerChangedEventArgs, Exception> dlg)
 {
     lock (_gate)
     {
         if (_nameOwnerWatchers?.ContainsKey(key) == true)
         {
             _nameOwnerWatchers[key] = (Action <ServiceOwnerChangedEventArgs, Exception>)Delegate.Remove(_nameOwnerWatchers[key], dlg);
             if (_nameOwnerWatchers[key] == null)
             {
                 _nameOwnerWatchers.Remove(key);
                 CallRemoveMatchRule(rule.ToString());
             }
         }
     }
 }
Exemple #4
0
        public async Task <IDisposable> WatchNameOwnerChangedAsync(string serviceName, Action <ServiceOwnerChangedEventArgs, Exception> handler)
        {
            var    rule = new OwnerChangedMatchRule(serviceName);
            string key  = serviceName;

            Task task = null;

            lock (_gate)
            {
                ThrowIfNotConnected();
                ThrowIfRemoteIsNotBus();

                if (_nameOwnerWatchers.ContainsKey(key))
                {
                    _nameOwnerWatchers[key] = (Action <ServiceOwnerChangedEventArgs, Exception>)Delegate.Combine(_nameOwnerWatchers[key], handler);
                    task = Task.CompletedTask;
                }
                else
                {
                    _nameOwnerWatchers[key] = handler;
                    task = CallAddMatchRuleAsync(rule.ToString());
                }
            }
            NameOwnerWatcherRegistration registration = new NameOwnerWatcherRegistration(this, key, rule, handler);

            try
            {
                await task;
            }
            catch
            {
                registration.Dispose();
                throw;
            }
            return(registration);
        }