Ejemplo n.º 1
0
 public int RegisterDeviceChangeEvent(DeviceChangeEventCallbackFunction deviceEventFunc, object obj)
 {
     unsafe
     {
         if (deviceChangeEventList.Count == 0)
         {
             var deviceChangeEventFunctionDelegate = new DeviceChangeEventFunctionDelegate(deviceEventFunction);
             if (obj != null)
             {
                 deviceChangeEventContextHandle        = GCHandle.Alloc(obj);
                 registeredDeviceChangeEventFunctionId = ((!_isWin)
                     ? LinuxInterop.tdRegisterDeviceChangeEvent(deviceChangeEventFunctionDelegate,
                                                                (void *)GCHandle.ToIntPtr(deviceChangeEventContextHandle))
                     : WinInterop.tdRegisterDeviceChangeEvent(deviceChangeEventFunctionDelegate,
                                                              (void *)GCHandle.ToIntPtr(deviceChangeEventContextHandle)));
             }
             else
             {
                 registeredDeviceChangeEventFunctionId = ((!_isWin)
                     ? LinuxInterop.tdRegisterDeviceChangeEvent(deviceChangeEventFunctionDelegate, null)
                     : WinInterop.tdRegisterDeviceChangeEvent(deviceChangeEventFunctionDelegate, null));
             }
             if (!callbackFunctionReferenceList.ContainsKey(registeredDeviceChangeEventFunctionId))
             {
                 callbackFunctionReferenceList.Remove(registeredDeviceChangeEventFunctionId);
             }
             callbackFunctionReferenceList.Add(registeredDeviceChangeEventFunctionId,
                                               deviceChangeEventFunctionDelegate);
         }
         this.lastEventID++;
         int lastEventID = this.lastEventID;
         deviceChangeEventList.Add(lastEventID, deviceEventFunc);
         return(lastEventID);
     }
 }