List of devices available on the current subnet
Runs callbacks when a device is detected on or removed from a network. Clients can't iterate the list's contents so must take note of the device in their 'added' callback and remove the device in their 'removed' callback. Since CpDevice instances are reference counted, a reference must be claimed inside the 'added' callback and removed inside the 'removed' callback. This class can't be directly instantiated. Clients should instead use subclasses which will define policy on how to detect devices etc. Dispose() must be called before Core.Library.Close().
Inheritance: ICpDeviceList, IDisposable
Exemple #1
0
        protected static void Removed(IntPtr aPtr, IntPtr aHandle)
        {
            CpDevice     device = new CpDevice(aHandle);
            GCHandle     gch    = GCHandle.FromIntPtr(aPtr);
            CpDeviceList list   = (CpDeviceList)gch.Target;

            if (list.iRemoved != null)
            {
                CallListChangedDelegate(list.iRemoved, list, device);
            }
        }
Exemple #2
0
 private static void CallListChangedDelegate(ChangeHandler aDelegate, CpDeviceList aList, CpDevice aDevice)
 {
     try
     {
         aDelegate(aList, aDevice);
     }
     catch (ProxyError e)
     {
         Console.WriteLine("WARNING: ProxyError ({0}:{1}) thrown from {2} in device list change delegate", e.Code, (e.Description != null ? e.Description : "<none>"), e.TargetSite.Name);
     }
 }
Exemple #3
0
 private static void CallListChangedDelegate(ChangeHandler aDelegate, CpDeviceList aList, CpDevice aDevice)
 {
     try
     {
         aDelegate(aList, aDevice);
     }
     catch (ProxyError e)
     {
         System.Diagnostics.Debug.WriteLine("WARNING: ProxyError thrown in device list change delegate: {0}", new object[] { e });
     }
 }
 private void DeviceAdded(CpDeviceList aList, CpDevice aDevice)
 {
     lock (this)
     {
         if (iDeviceList.Count == 0 && aDevice.Udn() == DeviceBasic.gDeviceName)
         {
             aDevice.AddRef();
             iDeviceList.Add(aDevice);
         }
     }
 }
Exemple #5
0
 private static void CallListChangedDelegate(ChangeHandler aDelegate, CpDeviceList aList, CpDevice aDevice)
 {
     try
     {
         aDelegate(aList, aDevice);
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(String.Format("WARNING: Unhandled exception in device list change delegate.\n\tDevice is {0}\n\tException is {1}", aDevice.Udn(), new object[] { e }));
     }
 }
 private void DeviceRemoved(CpDeviceList aList, CpDevice aDevice)
 {
     /* The device stack sends byebyes then alives for each newly enabled device.
        These can be interleaved with responses to a msearch and can cause tests to misbehave,
        thinking a device has been removed.  The simplest way to work around this is to say
        our test guarantees that a device remains available as long as its needed then take
        advantage of this by ignoring device removed callbacks. */
     /*lock (this)
     {
         string udn = aDevice.Udn();
         int count = iDeviceList.Count;
         for (int i = 0; i < count; i++)
         {
             if (iDeviceList[i].Udn() == udn)
             {
                 iDeviceList.RemoveAt(i);
                 iDeviceList[i].RemoveRef();
             }
         }
     }*/
 }
Exemple #7
0
 private void DeviceRemoved(ControlPoint.CpDeviceList aList, ControlPoint.CpDevice aDevice)
 {
     lock (this)
     {
         if (!iListFrozen)
         {
             PrintDeviceInfo("Removed", aDevice);
             string udn   = aDevice.Udn();
             int    count = iDeviceList.Count;
             for (int i = 0; i < count; i++)
             {
                 if (iDeviceList[i].Udn() == udn)
                 {
                     iDeviceList[i].RemoveRef();
                     iDeviceList.RemoveAt(i);
                     break;
                 }
             }
         }
     }
 }
Exemple #8
0
 private static void CallListChangedDelegate(ChangeHandler aDelegate, CpDeviceList aList, CpDevice aDevice)
 {
     try
     {
         aDelegate(aList, aDevice);
     }
     catch (ProxyError e)
     {
         Console.WriteLine("WARNING: ProxyError ({0}:{1}) thrown from {2} in device list change delegate", e.Code, (e.Description != null ? e.Description : "<none>"), e.TargetSite.Name);
     }
 }
 /// <summary>
 /// Create a device list that detects UPnP devices bearing a specific type of service.
 /// </summary>
 /// <param name="aDomain">Vendor domain for the target service (e.g. upnp.org).</param>
 /// <param name="aServiceType">Name of the target service.</param>
 /// <param name="aVersion">Version number for the target service.</param>
 /// <param name="aAdded">Delegate which will be run when a new device is detected.
 /// Clients who are interested this new device should call AddRef() on it and add it to some local collection.
 /// This callback will never be run for a device that is already in the list.</param>
 /// <param name="aRemoved">Delegatewhich will be run when a device is removed from the network.
 /// Clients who had previously stored a reference to the device in their aAdded callback should call RemoveRef()
 /// and remove the device from their local collection.
 /// Clients who had not previously claimed a reference to a device must not call ReleaseRef().</param>
 public ICpDeviceList CreateListServiceType(
     string aDomain,
     string aServiceType,
     uint aVersion,
     CpDeviceList.ChangeHandler aAdded,
     CpDeviceList.ChangeHandler aRemoved)
 {
     return new CpDeviceListUpnpServiceType(aDomain, aServiceType, aVersion, aAdded, aRemoved);
 }
 /// <summary>
 /// Create a device list that detects a UPnP devices with a specific Udn.
 /// </summary>
 /// <param name="aUuid">Unique identifier for the target device.</param>
 /// <param name="aAdded">Delegate which will be run when a new device is detected.
 /// Clients who are interested this new device should call AddRef() on it and add it to some local collection.
 /// This callback will never be run for a device that is already in the list.</param>
 /// <param name="aRemoved">Delegatewhich will be run when a device is removed from the network.
 /// Clients who had previously stored a reference to the device in their aAdded callback should call RemoveRef()
 /// and remove the device from their local collection.
 /// Clients who had not previously claimed a reference to a device must not call ReleaseRef().</param>
 public ICpDeviceList CreateListUuid(
     string aUuid,
     CpDeviceList.ChangeHandler aAdded,
     CpDeviceList.ChangeHandler aRemoved)
 {
     return new CpDeviceListUpnpUuid(aUuid, aAdded, aRemoved);
 }
 /// <summary>
 /// Create a device list that detects all UPnP root devices.
 /// </summary>
 /// <param name="aAdded">Delegate which will be run when a new device is detected.
 /// Clients who are interested this new device should call AddRef() on it and add it to some local collection.
 /// This callback will never be run for a device that is already in the list.</param>
 /// <param name="aRemoved">Delegatewhich will be run when a device is removed from the network.
 /// Clients who had previously stored a reference to the device in their aAdded callback should call RemoveRef()
 /// and remove the device from their local collection.
 /// Clients who had not previously claimed a reference to a device must not call ReleaseRef().</param>
 public ICpDeviceList CreateListRoot(
     CpDeviceList.ChangeHandler aAdded,
     CpDeviceList.ChangeHandler aRemoved)
 {
     return new CpDeviceListUpnpRoot(aAdded, aRemoved);
 }
Exemple #12
0
 private void DeviceRemoved(CpDeviceList aList, CpDevice aDevice)
 {
     lock (this)
     {
         string udn = aDevice.Udn();
         int count = iDeviceList.Count;
         for (int i = 0; i < count; i++)
         {
             if (iDeviceList[i].Udn() == udn)
             {
                 iDeviceList.RemoveAt(i);
                 iDeviceList[i].RemoveRef();
             }
         }
     }
 }
Exemple #13
0
 private static void CallListChangedDelegate(ChangeHandler aDelegate, CpDeviceList aList, CpDevice aDevice)
 {
     try
     {
         aDelegate(aList, aDevice);
     }
     catch (Exception e)
     {
         Console.WriteLine("WARNING: unexpected exception {0}(\"{1}\") thrown by {2}", e.GetType(), e.Message, e.TargetSite.Name);
         Console.WriteLine("         No exceptions should be thrown by device list change delegates");
     }
 }
Exemple #14
0
 private static void CallListChangedDelegate(ChangeHandler aDelegate, CpDeviceList aList, CpDevice aDevice)
 {
     try
     {
         aDelegate(aList, aDevice);
     }
     catch (ProxyError e)
     {
         System.Diagnostics.Debug.WriteLine("WARNING: ProxyError thrown in device list change delegate: {0}", new object[] { e });
     }
 }
Exemple #15
0
 void DeviceRemoved(CpDeviceList aAlist, CpDevice aAdevice)
 {
     iCallbackTracker.PreventClose(() => iListener.DeviceRemoved(aAdevice));
 }