Beispiel #1
0
        private static void OnHotPlug(KHOT_HANDLE hotHandle,
                                      KLST_DEVINFO_HANDLE deviceInfo,
                                      KLST_SYNC_FLAG plugType)
        {
            LinkDevice d;
            int        totalPluggedDeviceCount = (int)hotHandle.GetContext().ToInt64();

            if (totalPluggedDeviceCount == int.MaxValue)
            {
                // OnHotPlug is being called for the first time on handle: hotHandle.Pointer.
                totalPluggedDeviceCount = 0;
            }
            switch (plugType)
            {
            case KLST_SYNC_FLAG.ADDED:     // Arrival.
                totalPluggedDeviceCount++;
                lock (Manager.UsbConnectionLock) {
                    if (Settings.DebugLevel > 4)
                    {
                        Log.d(TAG, "OnHotPlug.Added: " + UsbLinkDevice.DeviceInfoToString(deviceInfo));
                    }
                    if (UsbPermissionValidator.CheckAllowed(deviceInfo.Common.Vid, deviceInfo.Common.Pid))
                    {
                        UsbLinkDevice.TryOpeningDevice(deviceInfo);
                    }
                    else
                    {
                        if (Settings.DebugLevel > 4)
                        {
                            Log.d(TAG, "OnHotPlug.Added: Not allowed: " + UsbLinkDevice.DeviceInfoToString(deviceInfo));
                        }
                    }
                }
                break;

            case KLST_SYNC_FLAG.REMOVED:     // Removal.
                totalPluggedDeviceCount--;
                lock (Manager.UsbConnectionLock) {
                    if (Settings.DebugLevel > 4)
                    {
                        Log.d(TAG, "OnHotPlug.Removed: " + UsbLinkDevice.DeviceInfoToString(deviceInfo));
                    }
                    d = LinkManager.Manager.FindDevice(UsbLinkDevice.GetDevIdFromHandle(deviceInfo));
                    UsbLinkDevice u = d as UsbLinkDevice;
                    if (u != null)
                    {
                        u.Disconnect(deviceInfo);                // Disconnect device but keep in Active list.
                    }
                }
                break;

            default:
                return;
            }
            hotHandle.SetContext(new IntPtr(totalPluggedDeviceCount));
        }
Beispiel #2
0
 // Scan the current usb devices to check all connected.
 private void CheckConnections()
 {
     lock (UsbConnectionLock) {
         KLST_DEVINFO_HANDLE deviceInfo;
         LstK lst         = new LstK(KLST_FLAG.NONE);
         int  deviceCount = 0;
         lst.Count(ref deviceCount);
         while (lst.MoveNext(out deviceInfo))
         {
             LinkDevice d = LinkManager.Manager.FindDevice(UsbLinkDevice.GetDevIdFromHandle(deviceInfo));
             // Check if d is a suspended Acc with same SN but different V/P.
             if (d == null || ((d.State != ComponentState.Working) /*&& !UsbLinkDevice.CompareVidPid(d, deviceInfo)*/))
             {
                 if (UsbPermissionValidator.CheckAllowed(deviceInfo.Common.Vid, deviceInfo.Common.Pid))
                 {
                     UsbLinkDevice.TryOpeningDevice(deviceInfo);
                 }
             }
         }
         lst.Free();
     }
 }