示例#1
0
 /// <summary>
 /// Resolves the local address for a service.
 /// </summary>
 /// <param name="serviceName">Name of the service.</param>
 /// <returns>
 /// Local address of service. <c>null</c> is returned when the service name is not available.
 /// </returns>
 /// <exception cref="ConnectException">There was an error establishing the connection.</exception>
 /// <exception cref="ObjectDisposedException">The connection has been disposed.</exception>
 /// <exception cref="InvalidOperationException">The operation is invalid in the current state.</exception>
 /// <exception cref="DisconnectedException">The connection is closed.</exception>
 public async Task <string> ResolveServiceOwnerAsync(string serviceName)
 {
     try
     {
         return(await DBus.GetNameOwnerAsync(serviceName));
     }
     catch (DBusException e) when(e.ErrorName == "org.freedesktop.DBus.Error.NameHasNoOwner")
     {
         return(null);
     }
     catch
     {
         throw;
     }
 }
示例#2
0
        public async Task <IDisposable> WatchSignalAsync(SignalHandler handler, string @interface, string signalName, string sender, ObjectPath?path = null)
        {
            ThrowIfNotConnected();
            if (RemoteIsBus.HasValue && RemoteIsBus.Value && sender.Trim()[0] != ':')
            {
                sender = await DBus.GetNameOwner(sender);
            }

            var rule = new SignalMatchRule(
                @interface: @interface ?? throw new ArgumentNullException(nameof(@interface)),
                member: signalName ?? throw new ArgumentNullException(nameof(signalName)),
                path: path,
                sender: sender);

            Task task = null;

            lock (_gate)
            {
                if (_signalHandlers.TryGetValue(rule, out SignalHandler prevHandler))
                {
                    _signalHandlers[rule] = (SignalHandler)Delegate.Combine(prevHandler, handler);
                }
                else
                {
                    _signalHandlers[rule] = handler;
                    if (RemoteIsBus == true)
                    {
                        task = DBus.AddMatch(rule.ToString());
                    }
                }
            }
            var 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);
 }
示例#4
0
 public QStatus RequestName(string requestedName, DBus.NameFlags flags)
 {
     return alljoyn_busattachment_requestname(_busAttachment, requestedName, (uint)flags);
 }
示例#5
0
 /// <summary>
 /// List services that are available.
 /// </summary>
 /// <returns>
 /// List of available services.
 /// </returns>
 /// <exception cref="ConnectException">There was an error establishing the connection.</exception>
 /// <exception cref="ObjectDisposedException">The connection has been disposed.</exception>
 /// <exception cref="InvalidOperationException">The operation is invalid in the current state.</exception>
 /// <exception cref="DisconnectedException">The connection is closed.</exception>
 public Task <string[]> ListServicesAsync()
 => DBus.ListNamesAsync();
示例#6
0
 /// <summary>
 /// Checks if a service is available.
 /// </summary>
 /// <param name="serviceName">Name of the service.</param>
 /// <returns>
 /// <c>true</c> when the service is available, <c>false</c> otherwise.
 /// </returns>
 /// <exception cref="ConnectException">There was an error establishing the connection.</exception>
 /// <exception cref="ObjectDisposedException">The connection has been disposed.</exception>
 /// <exception cref="InvalidOperationException">The operation is invalid in the current state.</exception>
 /// <exception cref="DisconnectedException">The connection is closed.</exception>
 public Task <bool> IsServiceActiveAsync(string serviceName)
 => DBus.NameHasOwnerAsync(serviceName);
示例#7
0
 /// <summary>
 /// Activates a service.
 /// </summary>
 /// <param name="serviceName">Name of the service.</param>
 /// <returns>
 /// The result of the activation.
 /// </returns>
 /// <exception cref="ConnectException">There was an error establishing the connection.</exception>
 /// <exception cref="ObjectDisposedException">The connection has been disposed.</exception>
 /// <exception cref="InvalidOperationException">The operation is invalid in the current state.</exception>
 /// <exception cref="DisconnectedException">The connection is closed.</exception>
 public Task <ServiceStartResult> ActivateServiceAsync(string serviceName)
 => DBus.StartServiceByNameAsync(serviceName, 0);
示例#8
0
 /// <summary>
 /// List services that can be activated.
 /// </summary>
 /// <returns>
 /// List of activatable services.
 /// </returns>
 /// <exception cref="ConnectException">There was an error establishing the connection.</exception>
 /// <exception cref="ObjectDisposedException">The connection has been disposed.</exception>
 /// <exception cref="InvalidOperationException">The operation is invalid in the current state.</exception>
 /// <exception cref="DisconnectedException">The connection is closed.</exception>
 public Task <string[]> ListActivatableServicesAsync()
 => DBus.ListActivatableNamesAsync();
示例#9
0
 private void OnDownloaderStateChanged(DBus.ObjectPath path, TorrentState from, TorrentState to)
 {
     if (downloader.GetState () == TorrentState.Seeding) {
         SetProgress (100);
         SetStatus (TaskStatus.Succeeded);
         OnTaskCompleted (null, false);
     }
 }
示例#10
0
        public static Type DefineHandler(ModuleBuilder modB, DBus.Introspection.Signal declSignal)
        {
            string dlgName = declSignal.Name + "Handler";
            TypeBuilder handlerB = modB.DefineType (dlgName, TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.Sealed | TypeAttributes.AnsiClass | TypeAttributes.AutoClass, typeof (System.MulticastDelegate));
            const MethodAttributes mattr = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.Virtual | MethodAttributes.NewSlot;

            ConstructorBuilder constructorBuilder = handlerB.DefineConstructor (MethodAttributes.RTSpecialName | MethodAttributes.HideBySig | MethodAttributes.Public, CallingConventions.Standard, new Type[] { typeof (object), typeof (System.IntPtr) });
            constructorBuilder.SetImplementationFlags (MethodImplAttributes.Runtime | MethodImplAttributes.Managed);

            //MethodBuilder invokeB = handlerB.DefineMethod ("Invoke", mattr, typeof (void), Type.EmptyTypes);
            MethodBuilder invokeB = DefineSignal (handlerB, "Invoke", mattr, declSignal.Arguments, true);

            invokeB.SetImplementationFlags (MethodImplAttributes.Runtime | MethodImplAttributes.Managed);
            return handlerB.CreateType ();
        }