Exemple #1
0
 public int RegisterRawDeviceEvent(RawListeningCallbackFunction listeningFunc, object obj)
 {
     unsafe
     {
         if (rawListenerList.Count == 0)
         {
             var rawListeningDelegate = new RawListeningDelegate(rawListeningFunction);
             if (obj != null)
             {
                 rawListenerContextHandle        = GCHandle.Alloc(obj);
                 registeredRawListenerFunctionId = ((!_isWin)
                     ? LinuxInterop.tdRegisterRawDeviceEvent(rawListeningDelegate,
                                                             (void *)GCHandle.ToIntPtr(rawListenerContextHandle))
                     : WinInterop.tdRegisterRawDeviceEvent(rawListeningDelegate,
                                                           (void *)GCHandle.ToIntPtr(rawListenerContextHandle)));
             }
             else
             {
                 registeredRawListenerFunctionId = ((!_isWin)
                     ? LinuxInterop.tdRegisterRawDeviceEvent(rawListeningDelegate, null)
                     : WinInterop.tdRegisterRawDeviceEvent(rawListeningDelegate, null));
             }
             if (!callbackFunctionReferenceList.ContainsKey(registeredRawListenerFunctionId))
             {
                 callbackFunctionReferenceList.Remove(registeredRawListenerFunctionId);
             }
             callbackFunctionReferenceList.Add(registeredRawListenerFunctionId, rawListeningDelegate);
         }
         this.lastEventID++;
         int lastEventID = this.lastEventID;
         rawListenerList.Add(lastEventID, listeningFunc);
         return(lastEventID);
     }
 }
		public int RegisterRawDeviceEvent(RawListeningCallbackFunction listeningFunc, object obj)
		{
			unsafe
			{
				if (rawListenerList.Count == 0)
				{
					var rawListeningDelegate = new RawListeningDelegate(rawListeningFunction);
					if (obj != null)
					{
						rawListenerContextHandle = GCHandle.Alloc(obj);
						registeredRawListenerFunctionId = ((!_isWin)
							? LinuxInterop.tdRegisterRawDeviceEvent(rawListeningDelegate,
								(void*) GCHandle.ToIntPtr(rawListenerContextHandle))
							: WinInterop.tdRegisterRawDeviceEvent(rawListeningDelegate,
								(void*) GCHandle.ToIntPtr(rawListenerContextHandle)));
					}
					else
					{
						registeredRawListenerFunctionId = ((!_isWin)
							? LinuxInterop.tdRegisterRawDeviceEvent(rawListeningDelegate, null)
							: WinInterop.tdRegisterRawDeviceEvent(rawListeningDelegate, null));
					}
					if (!callbackFunctionReferenceList.ContainsKey(registeredRawListenerFunctionId))
					{
						callbackFunctionReferenceList.Remove(registeredRawListenerFunctionId);
					}
					callbackFunctionReferenceList.Add(registeredRawListenerFunctionId, rawListeningDelegate);
				}
				this.lastEventID++;
				int lastEventID = this.lastEventID;
				rawListenerList.Add(lastEventID, listeningFunc);
				return lastEventID;
			}
		}