Ejemplo n.º 1
0
 public int RegisterSensorEvent(SensorCallbackFunction listeningFunc, object obj)
 {
     unsafe
     {
         if (sensorListenerList.Count == 0)
         {
             var sensorListeningDelegate = new SensorListeningDelegate(sensorListeningFunction);
             if (obj != null)
             {
                 sensorListenerContextHandle        = GCHandle.Alloc(obj);
                 registeredSensorListenerFunctionId = ((!_isWin)
                     ? LinuxInterop.tdRegisterSensorEvent(sensorListeningDelegate,
                                                          (void *)GCHandle.ToIntPtr(sensorListenerContextHandle))
                     : WinInterop.tdRegisterSensorEvent(sensorListeningDelegate,
                                                        (void *)GCHandle.ToIntPtr(sensorListenerContextHandle)));
             }
             else
             {
                 registeredSensorListenerFunctionId = ((!_isWin)
                     ? LinuxInterop.tdRegisterSensorEvent(sensorListeningDelegate, null)
                     : WinInterop.tdRegisterSensorEvent(sensorListeningDelegate, null));
             }
             if (!callbackFunctionReferenceList.ContainsKey(registeredSensorListenerFunctionId))
             {
                 callbackFunctionReferenceList.Remove(registeredSensorListenerFunctionId);
             }
             callbackFunctionReferenceList.Add(registeredSensorListenerFunctionId, sensorListeningDelegate);
         }
         this.lastEventID++;
         int lastEventID = this.lastEventID;
         sensorListenerList.Add(lastEventID, listeningFunc);
         return(lastEventID);
     }
 }
Ejemplo n.º 2
0
		public int RegisterSensorEvent(SensorCallbackFunction listeningFunc, object obj)
		{
			unsafe
			{
				if (sensorListenerList.Count == 0)
				{
					var sensorListeningDelegate = new SensorListeningDelegate(sensorListeningFunction);
					if (obj != null)
					{
						sensorListenerContextHandle = GCHandle.Alloc(obj);
						registeredSensorListenerFunctionId = ((!_isWin)
							? LinuxInterop.tdRegisterSensorEvent(sensorListeningDelegate,
								(void*) GCHandle.ToIntPtr(sensorListenerContextHandle))
							: WinInterop.tdRegisterSensorEvent(sensorListeningDelegate,
								(void*) GCHandle.ToIntPtr(sensorListenerContextHandle)));
					}
					else
					{
						registeredSensorListenerFunctionId = ((!_isWin)
							? LinuxInterop.tdRegisterSensorEvent(sensorListeningDelegate, null)
							: WinInterop.tdRegisterSensorEvent(sensorListeningDelegate, null));
					}
					if (!callbackFunctionReferenceList.ContainsKey(registeredSensorListenerFunctionId))
					{
						callbackFunctionReferenceList.Remove(registeredSensorListenerFunctionId);
					}
					callbackFunctionReferenceList.Add(registeredSensorListenerFunctionId, sensorListeningDelegate);
				}
				this.lastEventID++;
				int lastEventID = this.lastEventID;
				sensorListenerList.Add(lastEventID, listeningFunc);
				return lastEventID;
			}
		}