Ejemplo n.º 1
0
        //Run in Polster thread, fills in object queues
        private void processMessages()
        {
            //Only profiling block currently is the Handle Event block
            const string HANDLE_EVENT_PROFILER_BLOCK = "Handle Event";
            bool         hasBegunProfilingForThread  = false;

            try
            {
                eLeapRS result;
                _leapInit.DispatchOnContext(this, EventContext, new LeapEventArgs(LeapEvent.EVENT_INIT));
                while (_isRunning)
                {
                    if (LeapBeginProfilingForThread != null && !hasBegunProfilingForThread)
                    {
                        LeapBeginProfilingForThread(new BeginProfilingForThreadArgs("Worker Thread",
                                                                                    HANDLE_EVENT_PROFILER_BLOCK));
                        hasBegunProfilingForThread = true;
                    }

                    LEAP_CONNECTION_MESSAGE _msg = new LEAP_CONNECTION_MESSAGE();
                    uint timeout = 150;
                    result = LeapC.PollConnection(_leapConnection, timeout, ref _msg);

                    if (result != eLeapRS.eLeapRS_Success)
                    {
                        reportAbnormalResults("LeapC PollConnection call was ", result);
                        continue;
                    }

                    if (LeapBeginProfilingBlock != null && hasBegunProfilingForThread)
                    {
                        LeapBeginProfilingBlock(new BeginProfilingBlockArgs(HANDLE_EVENT_PROFILER_BLOCK));
                    }

                    switch (_msg.type)
                    {
                    case eLeapEventType.eLeapEventType_None:
                        break;

                    case eLeapEventType.eLeapEventType_Connection:
                        LEAP_CONNECTION_EVENT connection_evt;
                        StructMarshal <LEAP_CONNECTION_EVENT> .PtrToStruct(_msg.eventStructPtr, out connection_evt);

                        handleConnection(ref connection_evt);
                        break;

                    case eLeapEventType.eLeapEventType_ConnectionLost:
                        LEAP_CONNECTION_LOST_EVENT connection_lost_evt;
                        StructMarshal <LEAP_CONNECTION_LOST_EVENT> .PtrToStruct(_msg.eventStructPtr, out connection_lost_evt);

                        handleConnectionLost(ref connection_lost_evt);
                        break;

                    case eLeapEventType.eLeapEventType_Device:
                        LEAP_DEVICE_EVENT device_evt;
                        StructMarshal <LEAP_DEVICE_EVENT> .PtrToStruct(_msg.eventStructPtr, out device_evt);

                        handleDevice(ref device_evt);
                        break;

                    // Note that unplugging a device generates an eLeapEventType_DeviceLost event
                    // message, not a failure message. DeviceLost is further down.
                    case eLeapEventType.eLeapEventType_DeviceFailure:
                        LEAP_DEVICE_FAILURE_EVENT device_failure_evt;
                        StructMarshal <LEAP_DEVICE_FAILURE_EVENT> .PtrToStruct(_msg.eventStructPtr, out device_failure_evt);

                        handleFailedDevice(ref device_failure_evt);
                        break;

                    case eLeapEventType.eLeapEventType_Policy:
                        LEAP_POLICY_EVENT policy_evt;
                        StructMarshal <LEAP_POLICY_EVENT> .PtrToStruct(_msg.eventStructPtr, out policy_evt);

                        handlePolicyChange(ref policy_evt);
                        break;

                    case eLeapEventType.eLeapEventType_Tracking:
                        LEAP_TRACKING_EVENT tracking_evt;
                        StructMarshal <LEAP_TRACKING_EVENT> .PtrToStruct(_msg.eventStructPtr, out tracking_evt);

                        handleTrackingMessage(ref tracking_evt);
                        break;

                    case eLeapEventType.eLeapEventType_LogEvent:
                        LEAP_LOG_EVENT log_evt;
                        StructMarshal <LEAP_LOG_EVENT> .PtrToStruct(_msg.eventStructPtr, out log_evt);

                        reportLogMessage(ref log_evt);
                        break;

                    case eLeapEventType.eLeapEventType_DeviceLost:
                        LEAP_DEVICE_EVENT device_lost_evt;
                        StructMarshal <LEAP_DEVICE_EVENT> .PtrToStruct(_msg.eventStructPtr, out device_lost_evt);

                        handleLostDevice(ref device_lost_evt);
                        break;

                    case eLeapEventType.eLeapEventType_ConfigChange:
                        LEAP_CONFIG_CHANGE_EVENT config_change_evt;
                        StructMarshal <LEAP_CONFIG_CHANGE_EVENT> .PtrToStruct(_msg.eventStructPtr, out config_change_evt);

                        handleConfigChange(ref config_change_evt);
                        break;

                    case eLeapEventType.eLeapEventType_ConfigResponse:
                        handleConfigResponse(ref _msg);
                        break;

                    case eLeapEventType.eLeapEventType_DroppedFrame:
                        LEAP_DROPPED_FRAME_EVENT dropped_frame_evt;
                        StructMarshal <LEAP_DROPPED_FRAME_EVENT> .PtrToStruct(_msg.eventStructPtr, out dropped_frame_evt);

                        handleDroppedFrame(ref dropped_frame_evt);
                        break;

                    case eLeapEventType.eLeapEventType_Image:
                        LEAP_IMAGE_EVENT image_evt;
                        StructMarshal <LEAP_IMAGE_EVENT> .PtrToStruct(_msg.eventStructPtr, out image_evt);

                        handleImage(ref image_evt);
                        break;

                    case eLeapEventType.eLeapEventType_PointMappingChange:
                        LEAP_POINT_MAPPING_CHANGE_EVENT point_mapping_change_evt;
                        StructMarshal <LEAP_POINT_MAPPING_CHANGE_EVENT> .PtrToStruct(_msg.eventStructPtr, out point_mapping_change_evt);

                        handlePointMappingChange(ref point_mapping_change_evt);
                        break;

                    case eLeapEventType.eLeapEventType_HeadPose:
                        LEAP_HEAD_POSE_EVENT head_pose_event;
                        StructMarshal <LEAP_HEAD_POSE_EVENT> .PtrToStruct(_msg.eventStructPtr, out head_pose_event);

                        handleHeadPoseChange(ref head_pose_event);
                        break;

                    case eLeapEventType.eLeapEventType_DeviceStatusChange:
                        LEAP_DEVICE_STATUS_CHANGE_EVENT status_evt;
                        StructMarshal <LEAP_DEVICE_STATUS_CHANGE_EVENT> .PtrToStruct(_msg.eventStructPtr, out status_evt);

                        handleDeviceStatusEvent(ref status_evt);
                        break;
                    } //switch on _msg.type

                    if (LeapEndProfilingBlock != null && hasBegunProfilingForThread)
                    {
                        LeapEndProfilingBlock(new EndProfilingBlockArgs(HANDLE_EVENT_PROFILER_BLOCK));
                    }
                } //while running
            }
            catch (Exception e)
            {
                Logger.Log("Exception: " + e);
                _isRunning = false;
            }
            finally
            {
                if (LeapEndProfilingForThread != null && hasBegunProfilingForThread)
                {
                    LeapEndProfilingForThread(new EndProfilingForThreadArgs());
                }
            }
        }
Ejemplo n.º 2
0
        //Run in Polster thread, fills in object queues
        private void processMessages()
        {
            try
            {
                eLeapRS result;
                _leapInit.Dispatch <LeapEventArgs>(this, new LeapEventArgs(LeapEvent.EVENT_INIT));
                while (true)
                {
                    LEAP_CONNECTION_MESSAGE _msg = new LEAP_CONNECTION_MESSAGE();
                    lock (_connLocker) {
                        if (_leapConnection == IntPtr.Zero)
                        {
                            break;
                        }
                        uint timeout = 1000;
                        result = LeapC.PollConnection(_leapConnection, timeout, ref _msg);
                    }

                    if (result != eLeapRS.eLeapRS_Success)
                    {
                        reportAbnormalResults("LeapC PollConnection call was ", result);
                        continue;
                    }

                    switch (_msg.type)
                    {
                    case eLeapEventType.eLeapEventType_Connection:
                        LEAP_CONNECTION_EVENT connection_evt = StructMarshal <LEAP_CONNECTION_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        handleConnection(ref connection_evt);
                        break;

                    case eLeapEventType.eLeapEventType_ConnectionLost:
                        LEAP_CONNECTION_LOST_EVENT connection_lost_evt = StructMarshal <LEAP_CONNECTION_LOST_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        handleConnectionLost(ref connection_lost_evt);
                        break;

                    case eLeapEventType.eLeapEventType_Device:
                        LEAP_DEVICE_EVENT device_evt = StructMarshal <LEAP_DEVICE_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        handleDevice(ref device_evt);
                        break;

                    case eLeapEventType.eLeapEventType_DeviceLost:
                        LEAP_DEVICE_EVENT device_lost_evt = StructMarshal <LEAP_DEVICE_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        handleLostDevice(ref device_lost_evt);
                        break;

                    case eLeapEventType.eLeapEventType_DeviceFailure:
                        LEAP_DEVICE_FAILURE_EVENT device_failure_evt = StructMarshal <LEAP_DEVICE_FAILURE_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        handleFailedDevice(ref device_failure_evt);
                        break;

                    case eLeapEventType.eLeapEventType_Tracking:
                        LEAP_TRACKING_EVENT tracking_evt = StructMarshal <LEAP_TRACKING_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        handleTrackingMessage(ref tracking_evt);
                        break;

                    case eLeapEventType.eLeapEventType_ImageComplete:
                        completeCount++;
                        LEAP_IMAGE_COMPLETE_EVENT image_complete_evt = StructMarshal <LEAP_IMAGE_COMPLETE_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        handleImageCompletion(ref image_complete_evt);
                        break;

                    case eLeapEventType.eLeapEventType_ImageRequestError:
                        failedCount++;
                        LEAP_IMAGE_FRAME_REQUEST_ERROR_EVENT failed_image_evt = StructMarshal <LEAP_IMAGE_FRAME_REQUEST_ERROR_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        handleFailedImageRequest(ref failed_image_evt);
                        break;

                    case eLeapEventType.eLeapEventType_LogEvent:
                        LEAP_LOG_EVENT log_evt = StructMarshal <LEAP_LOG_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        reportLogMessage(ref log_evt);
                        break;

                    case eLeapEventType.eLeapEventType_PolicyChange:
                        LEAP_POLICY_EVENT policy_evt = StructMarshal <LEAP_POLICY_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        handlePolicyChange(ref policy_evt);
                        break;

                    case eLeapEventType.eLeapEventType_ConfigChange:
                        LEAP_CONFIG_CHANGE_EVENT config_change_evt = StructMarshal <LEAP_CONFIG_CHANGE_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        handleConfigChange(ref config_change_evt);
                        break;

                    case eLeapEventType.eLeapEventType_ConfigResponse:
                        handleConfigResponse(ref _msg);
                        break;

                    default:
                        //discard unknown message types
                        Logger.Log("Unhandled message type " + Enum.GetName(typeof(eLeapEventType), _msg.type));
                        break;
                    } //switch on _msg.type
                }     //while running
            }
            catch (Exception e)
            {
                Logger.Log("Exception: " + e);
                this.Cleanup();
            }
        }