Ejemplo n.º 1
0
        private void handleConfigResponse(ref LEAP_CONNECTION_MESSAGE configMsg)
        {
            LEAP_CONFIG_RESPONSE_EVENT config_response_evt;

            StructMarshal <LEAP_CONFIG_RESPONSE_EVENT> .PtrToStruct(configMsg.eventStructPtr, out config_response_evt);

            string config_key = "";

            _configRequests.TryGetValue(config_response_evt.requestId, out config_key);
            if (config_key != null)
            {
                _configRequests.Remove(config_response_evt.requestId);
            }

            Config.ValueType dataType;
            object           value;
            uint             requestId = config_response_evt.requestId;

            if (config_response_evt.value.type != eLeapValueType.eLeapValueType_String)
            {
                switch (config_response_evt.value.type)
                {
                case eLeapValueType.eLeapValueType_Boolean:
                    dataType = Config.ValueType.TYPE_BOOLEAN;
                    value    = config_response_evt.value.boolValue;
                    break;

                case eLeapValueType.eLeapValueType_Int32:
                    dataType = Config.ValueType.TYPE_INT32;
                    value    = config_response_evt.value.intValue;
                    break;

                case eLeapValueType.eLeapValueType_Float:
                    dataType = Config.ValueType.TYPE_FLOAT;
                    value    = config_response_evt.value.floatValue;
                    break;

                default:
                    dataType = Config.ValueType.TYPE_UNKNOWN;
                    value    = new object();
                    break;
                }
            }
            else
            {
                LEAP_CONFIG_RESPONSE_EVENT_WITH_REF_TYPE config_ref_value;
                StructMarshal <LEAP_CONFIG_RESPONSE_EVENT_WITH_REF_TYPE> .PtrToStruct(configMsg.eventStructPtr, out config_ref_value);

                dataType = Config.ValueType.TYPE_STRING;
                value    = config_ref_value.value.stringValue;
            }
            SetConfigResponseEventArgs args = new SetConfigResponseEventArgs(config_key, dataType, value, requestId);

            if (LeapConfigResponse != null)
            {
                LeapConfigResponse.DispatchOnContext(this, EventContext, args);
            }
        }
Ejemplo n.º 2
0
        private void handleImageCompletion(ref LEAP_IMAGE_COMPLETE_EVENT imageMsg)
        {
            LEAP_IMAGE_PROPERTIES props;

            StructMarshal <LEAP_IMAGE_PROPERTIES> .PtrToStruct(imageMsg.properties, out props);

            ImageFuture pendingImage = _pendingImageRequestList.FindAndRemove(imageMsg.token);

            if (pendingImage == null)
            {
                return;
            }

            //Update distortion data, if changed
            if ((_currentDistortionData.Version != imageMsg.matrix_version) || !_currentDistortionData.IsValid)
            {
                _currentDistortionData         = new DistortionData();
                _currentDistortionData.Version = imageMsg.matrix_version;
                _currentDistortionData.Width   = LeapC.DistortionSize; //fixed value for now
                _currentDistortionData.Height  = LeapC.DistortionSize; //fixed value for now
                if (_currentDistortionData.Data == null || _currentDistortionData.Data.Length != (2 * _currentDistortionData.Width * _currentDistortionData.Height * 2))
                {
                    _currentDistortionData.Data = new float[(int)(2 * _currentDistortionData.Width * _currentDistortionData.Height * 2)]; //2 float values per map point
                }
                LEAP_DISTORTION_MATRIX matrix;
                StructMarshal <LEAP_DISTORTION_MATRIX> .PtrToStruct(imageMsg.distortionMatrix, out matrix);

                Array.Copy(matrix.matrix_data, _currentDistortionData.Data, matrix.matrix_data.Length);

                if (LeapDistortionChange != null)
                {
                    LeapDistortionChange.DispatchOnContext <DistortionEventArgs>(this, EventContext, new DistortionEventArgs(_currentDistortionData));
                }
            }

            pendingImage.imageData.CompleteImageData(props.type,
                                                     props.format,
                                                     props.bpp,
                                                     props.width,
                                                     props.height,
                                                     imageMsg.info.timestamp,
                                                     imageMsg.info.frame_id,
                                                     props.x_offset,
                                                     props.y_offset,
                                                     props.x_scale,
                                                     props.y_scale,
                                                     _currentDistortionData,
                                                     LeapC.DistortionSize,
                                                     imageMsg.matrix_version);

            Image completedImage = pendingImage.imageObject;

            if (LeapImageReady != null)
            {
                LeapImageReady.DispatchOnContext <ImageEventArgs>(this, EventContext, new ImageEventArgs(completedImage));
            }
        }
Ejemplo n.º 3
0
        public void GetPointMapping(ref LEAP_POINT_MAPPING pm)
        {
            UInt64 size   = 0;
            IntPtr buffer = IntPtr.Zero;

            while (true)
            {
                eLeapRS result = LeapC.GetPointMapping(_leapConnection, buffer, ref size);
                if (result == eLeapRS.eLeapRS_InsufficientBuffer)
                {
                    if (buffer != IntPtr.Zero)
                    {
                        Marshal.FreeHGlobal(buffer);
                    }
                    buffer = Marshal.AllocHGlobal((Int32)size);
                    continue;
                }
                reportAbnormalResults("LeapC get point mapping call was ", result);
                if (result != eLeapRS.eLeapRS_Success)
                {
                    pm.nPoints = 0;
                    pm.points  = null;
                    pm.ids     = null;
                    return;
                }
                break;
            }
            LEAP_POINT_MAPPING_INTERNAL pmi;

            StructMarshal <LEAP_POINT_MAPPING_INTERNAL> .PtrToStruct(buffer, out pmi);

            Int32 nPoints = (Int32)pmi.nPoints;

            pm.frame_id  = pmi.frame_id;
            pm.timestamp = pmi.timestamp;
            pm.nPoints   = pmi.nPoints;
            pm.points    = new LEAP_VECTOR[nPoints];
            pm.ids       = new UInt32[nPoints];

            float[] points = new float[3 * nPoints];
            Int32[] ids    = new Int32[nPoints];
            Marshal.Copy(pmi.points, points, 0, 3 * nPoints);
            Marshal.Copy(pmi.ids, ids, 0, nPoints);

            int j = 0;

            for (int i = 0; i < nPoints; i++)
            {
                pm.points[i].x = points[j++];
                pm.points[i].y = points[j++];
                pm.points[i].z = points[j++];
                pm.ids[i]      = unchecked ((UInt32)ids[i]);
            }
            Marshal.FreeHGlobal(buffer);
        }
 public void GetInterpolatedFrameFromTime(Frame toFill, Int64 time, Int64 sourceTime) {
   UInt64 size = GetInterpolatedFrameSize(time);
   IntPtr trackingBuffer = Marshal.AllocHGlobal((Int32)size);
   eLeapRS result = LeapC.InterpolateFrameFromTime(_leapConnection, time, sourceTime, trackingBuffer, size);
   reportAbnormalResults("LeapC get interpolated frame from time call was ", result);
   if (result == eLeapRS.eLeapRS_Success) {
     LEAP_TRACKING_EVENT tracking_evt;
     StructMarshal<LEAP_TRACKING_EVENT>.PtrToStruct(trackingBuffer, out tracking_evt);
     toFill.CopyFrom(ref tracking_evt);
   }
   Marshal.FreeHGlobal(trackingBuffer);
 }
Ejemplo n.º 5
0
        public void GetInterpolatedLeftRightTransform(Int64 time,
                                                      Int64 sourceTime,
                                                      Int64 leftId,
                                                      Int64 rightId,
                                                      out LeapTransform leftTransform,
                                                      out LeapTransform rightTransform)
        {
            leftTransform  = LeapTransform.Identity;
            rightTransform = LeapTransform.Identity;

            UInt64  size           = GetInterpolatedFrameSize(time);
            IntPtr  trackingBuffer = Marshal.AllocHGlobal((Int32)size);
            eLeapRS result         = LeapC.InterpolateFrameFromTime(_leapConnection, time, sourceTime, trackingBuffer, size);

            reportAbnormalResults("LeapC get interpolated frame from time call was ", result);

            if (result == eLeapRS.eLeapRS_Success)
            {
                LEAP_TRACKING_EVENT tracking_evt;
                StructMarshal <LEAP_TRACKING_EVENT> .PtrToStruct(trackingBuffer, out tracking_evt);

                int             id;
                LEAP_VECTOR     position;
                LEAP_QUATERNION orientation;

                long handPtr = tracking_evt.pHands.ToInt64();
                long idPtr   = handPtr + _handIdOffset;
                long posPtr  = handPtr + _handPositionOffset;
                long rotPtr  = handPtr + _handOrientationOffset;
                int  stride  = StructMarshal <LEAP_HAND> .Size;

                for (uint i = tracking_evt.nHands; i-- != 0; idPtr += stride, posPtr += stride, rotPtr += stride)
                {
                    id = Marshal.ReadInt32(new IntPtr(idPtr));
                    StructMarshal <LEAP_VECTOR> .PtrToStruct(new IntPtr(posPtr), out position);

                    StructMarshal <LEAP_QUATERNION> .PtrToStruct(new IntPtr(rotPtr), out orientation);

                    LeapTransform transform = new LeapTransform(position.ToLeapVector(), orientation.ToLeapQuaternion());
                    if (id == leftId)
                    {
                        leftTransform = transform;
                    }
                    else if (id == rightId)
                    {
                        rightTransform = transform;
                    }
                }
            }

            Marshal.FreeHGlobal(trackingBuffer);
        }
Ejemplo n.º 6
0
        public Hand makeHand(ref LEAP_HAND hand, Frame owningFrame)
        {
            LEAP_BONE arm = StructMarshal <LEAP_BONE> .PtrToStruct(hand.arm);

            Arm       newArm = makeArm(ref arm);
            LEAP_PALM palm   = StructMarshal <LEAP_PALM> .PtrToStruct(hand.palm);

            Hand newHand = new Hand(
                (int)owningFrame.Id,
                (int)hand.id,
                hand.confidence,
                hand.grab_strength,
                hand.grab_angle,
                hand.pinch_strength,
                hand.pinch_distance,
                palm.width,
                hand.type == eLeapHandType.eLeapHandType_Left,
                hand.visible_time,
                newArm,
                new List <Finger>(5),
                new Vector(palm.position.x, palm.position.y, palm.position.z),
                new Vector(palm.stabilized_position.x, palm.stabilized_position.y, palm.stabilized_position.z),
                new Vector(palm.velocity.x, palm.velocity.y, palm.velocity.z),
                new Vector(palm.normal.x, palm.normal.y, palm.normal.z),
                new Vector(palm.direction.x, palm.direction.y, palm.direction.z),
                newArm.NextJoint //wrist position
                );
            LEAP_DIGIT thumbDigit = StructMarshal <LEAP_DIGIT> .PtrToStruct(hand.thumb);

            newHand.Fingers.Insert(0, makeFinger(owningFrame, ref hand, ref thumbDigit, Finger.FingerType.TYPE_THUMB));

            LEAP_DIGIT indexDigit = StructMarshal <LEAP_DIGIT> .PtrToStruct(hand.index);

            newHand.Fingers.Insert(1, makeFinger(owningFrame, ref hand, ref indexDigit, Finger.FingerType.TYPE_INDEX));

            LEAP_DIGIT middleDigit = StructMarshal <LEAP_DIGIT> .PtrToStruct(hand.middle);

            newHand.Fingers.Insert(2, makeFinger(owningFrame, ref hand, ref middleDigit, Finger.FingerType.TYPE_MIDDLE));

            LEAP_DIGIT ringDigit = StructMarshal <LEAP_DIGIT> .PtrToStruct(hand.ring);

            newHand.Fingers.Insert(3, makeFinger(owningFrame, ref hand, ref ringDigit, Finger.FingerType.TYPE_RING));

            LEAP_DIGIT pinkyDigit = StructMarshal <LEAP_DIGIT> .PtrToStruct(hand.pinky);

            newHand.Fingers.Insert(4, makeFinger(owningFrame, ref hand, ref pinkyDigit, Finger.FingerType.TYPE_PINKY));

            return(newHand);
        }
Ejemplo n.º 7
0
        public void GetInterpolatedFrameFromTime(Frame toFill, long time, long sourceTime)
        {
            ulong   interpolatedFrameSize = this.GetInterpolatedFrameSize(time);
            IntPtr  pEvent = Marshal.AllocHGlobal((int)interpolatedFrameSize);
            eLeapRS result = LeapC.InterpolateFrameFromTime(this._leapConnection, time, sourceTime, pEvent, interpolatedFrameSize);

            this.reportAbnormalResults("LeapC get interpolated frame from time call was ", result);
            if (result == eLeapRS.eLeapRS_Success)
            {
                LEAP_TRACKING_EVENT leap_tracking_event;
                StructMarshal <LEAP_TRACKING_EVENT> .PtrToStruct(pEvent, out leap_tracking_event);

                toFill.CopyFrom(ref leap_tracking_event);
            }
            Marshal.FreeHGlobal(pEvent);
        }
Ejemplo n.º 8
0
        public void GetInterpolatedLeftRightTransform(long time, long sourceTime, long leftId, long rightId, out LeapTransform leftTransform, out LeapTransform rightTransform)
        {
            leftTransform  = LeapTransform.Identity;
            rightTransform = LeapTransform.Identity;
            ulong   interpolatedFrameSize = this.GetInterpolatedFrameSize(time);
            IntPtr  pEvent = Marshal.AllocHGlobal((int)interpolatedFrameSize);
            eLeapRS result = LeapC.InterpolateFrameFromTime(this._leapConnection, time, sourceTime, pEvent, interpolatedFrameSize);

            this.reportAbnormalResults("LeapC get interpolated frame from time call was ", result);
            if (result == eLeapRS.eLeapRS_Success)
            {
                LEAP_TRACKING_EVENT leap_tracking_event;
                StructMarshal <LEAP_TRACKING_EVENT> .PtrToStruct(pEvent, out leap_tracking_event);

                int  num3   = leap_tracking_event.pHands.ToInt32();
                int  num4   = num3 + _handIdOffset;
                int  num5   = num3 + _handPositionOffset;
                int  num6   = num3 + _handOrientationOffset;
                int  size   = StructMarshal <LEAP_HAND> .Size;
                uint nHands = leap_tracking_event.nHands;
                while (nHands-- != 0)
                {
                    LEAP_VECTOR     leap_vector;
                    LEAP_QUATERNION leap_quaternion;
                    int             num2 = Marshal.ReadInt32(new IntPtr(num4));
                    StructMarshal <LEAP_VECTOR> .PtrToStruct(new IntPtr(num5), out leap_vector);

                    StructMarshal <LEAP_QUATERNION> .PtrToStruct(new IntPtr(num6), out leap_quaternion);

                    LeapTransform transform = new LeapTransform(leap_vector.ToLeapVector(), leap_quaternion.ToLeapQuaternion());
                    if (num2 == leftId)
                    {
                        leftTransform = transform;
                    }
                    else if (num2 == rightId)
                    {
                        rightTransform = transform;
                    }
                    num4 += size;
                    num5 += size;
                    num6 += size;
                }
            }
            Marshal.FreeHGlobal(pEvent);
        }
Ejemplo n.º 9
0
        public Frame GetInterpolatedFrame(Int64 time)
        {
            UInt64  size           = GetInterpolatedFrameSize(time);
            IntPtr  trackingBuffer = Marshal.AllocHGlobal((Int32)size);
            eLeapRS result         = LeapC.InterpolateFrame(_leapConnection, time, trackingBuffer, size);

            reportAbnormalResults("LeapC get interpolated frame call was ", result);
            Frame frame = null;

            if (result == eLeapRS.eLeapRS_Success)
            {
                LEAP_TRACKING_EVENT tracking_evt = StructMarshal <LEAP_TRACKING_EVENT> .PtrToStruct(trackingBuffer);

                frame = frameFactory.makeFrame(ref tracking_evt);
            }
            Marshal.FreeHGlobal(trackingBuffer);
            return(frame);
        }
Ejemplo n.º 10
0
        private DistortionData createDistortionData(LEAP_IMAGE image, Image.CameraType camera)
        {
            DistortionData distortionData = new DistortionData();

            distortionData.Version = image.matrix_version;
            distortionData.Width   = LeapC.DistortionSize;                                               //fixed value for now
            distortionData.Height  = LeapC.DistortionSize;                                               //fixed value for now
            distortionData.Data    = new float[(int)(distortionData.Width * distortionData.Height * 2)]; //2 float values per map point
            LEAP_DISTORTION_MATRIX matrix;

            StructMarshal <LEAP_DISTORTION_MATRIX> .PtrToStruct(image.distortionMatrix, out matrix);

            Array.Copy(matrix.matrix_data, distortionData.Data, matrix.matrix_data.Length);

            if (LeapDistortionChange != null)
            {
                LeapDistortionChange.DispatchOnContext <DistortionEventArgs>(this, EventContext, new DistortionEventArgs(distortionData, camera));
            }
            return(distortionData);
        }
Ejemplo n.º 11
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.º 12
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();
            }
        }