コード例 #1
0
 public int RegisterDeviceEvent(EventCallbackFunction eventFunc, object obj)
 {
     unsafe
     {
         if (eventList.Count == 0)
         {
             var eventFunctionDelegate = new EventFunctionDelegate(eventFunction);
             if (obj != null)
             {
                 eventContextHandle        = GCHandle.Alloc(obj);
                 registeredEventFunctionId = ((!_isWin)
                     ? LinuxInterop.tdRegisterDeviceEvent(eventFunctionDelegate, (void *)GCHandle.ToIntPtr(eventContextHandle))
                     : WinInterop.tdRegisterDeviceEvent(eventFunctionDelegate, (void *)GCHandle.ToIntPtr(eventContextHandle)));
             }
             else
             {
                 registeredEventFunctionId = ((!_isWin)
                     ? LinuxInterop.tdRegisterDeviceEvent(eventFunctionDelegate, null)
                     : WinInterop.tdRegisterDeviceEvent(eventFunctionDelegate, null));
             }
             if (callbackFunctionReferenceList.ContainsKey(registeredEventFunctionId))
             {
                 callbackFunctionReferenceList.Remove(registeredEventFunctionId);
             }
             callbackFunctionReferenceList.Add(registeredEventFunctionId, eventFunctionDelegate);
         }
         this.lastEventID++;
         int lastEventID = this.lastEventID;
         eventList.Add(lastEventID, eventFunc);
         return(lastEventID);
     }
 }
コード例 #2
0
		public int RegisterDeviceEvent(EventCallbackFunction eventFunc, object obj)
		{
			unsafe
			{
				if (eventList.Count == 0)
				{
					var eventFunctionDelegate = new EventFunctionDelegate(eventFunction);
					if (obj != null)
					{
						eventContextHandle = GCHandle.Alloc(obj);
						registeredEventFunctionId = ((!_isWin)
							? LinuxInterop.tdRegisterDeviceEvent(eventFunctionDelegate, (void*) GCHandle.ToIntPtr(eventContextHandle))
							: WinInterop.tdRegisterDeviceEvent(eventFunctionDelegate, (void*) GCHandle.ToIntPtr(eventContextHandle)));
					}
					else
					{
						registeredEventFunctionId = ((!_isWin)
							? LinuxInterop.tdRegisterDeviceEvent(eventFunctionDelegate, null)
							: WinInterop.tdRegisterDeviceEvent(eventFunctionDelegate, null));
					}
					if (callbackFunctionReferenceList.ContainsKey(registeredEventFunctionId))
					{
						callbackFunctionReferenceList.Remove(registeredEventFunctionId);
					}
					callbackFunctionReferenceList.Add(registeredEventFunctionId, eventFunctionDelegate);
				}
				this.lastEventID++;
				int lastEventID = this.lastEventID;
				eventList.Add(lastEventID, eventFunc);
				return lastEventID;
			}
		}