htiui/HtiServicePlugins/HtiKeyEventServicePlugin/src/MultiTouchPointerEvent.cpp
branchRCL_3
changeset 18 48060abbbeaf
parent 17 d40e813b23c0
child 19 b3cee849fa46
equal deleted inserted replaced
17:d40e813b23c0 18:48060abbbeaf
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Functional implementation of one touch(pointer sequence) event service.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "HtiKeyEventServicePlugin.h"
       
    20 #include "MultiTouchPointerEvent.h"
       
    21 #include "MultiTouchPointerEventHandler.h"
       
    22 
       
    23 #include <HtiLogging.h>
       
    24 
       
    25 
       
    26 // CONSTANTS
       
    27 _LIT8( KErrorInternalFailure, "Internal pointer command failure" );
       
    28 _LIT (KPrintInfoString, "PrintInfo event id=%d time=%d type=%d X=%d Y=%d Z=%d");
       
    29 
       
    30 // ----------------------------------------------------------------------------
       
    31 // CMultiTouchPointerUnit::NewL()
       
    32 // ----------------------------------------------------------------------------
       
    33 CMultiTouchPointerEvent* CMultiTouchPointerEvent::NewL(TUint8 aTouchNumber,
       
    34         CMultiTouchPointerEventHandler* aEventHandler)
       
    35     {
       
    36     HTI_LOG_FUNC_IN( "CMultiTouchPointerEvent::NewL" );
       
    37     CMultiTouchPointerEvent* self = new (ELeave) CMultiTouchPointerEvent(aTouchNumber, aEventHandler);
       
    38     CleanupStack::PushL ( self );
       
    39     self->ConstructL();
       
    40     CleanupStack::Pop();
       
    41     HTI_LOG_FUNC_OUT( "CMultiTouchPointerEvent::NewL" );
       
    42     return self;
       
    43     }
       
    44 
       
    45 // ----------------------------------------------------------------------------
       
    46 // CMultiTouchPointerEvent::CMultiTouchPointerEvent()
       
    47 // ----------------------------------------------------------------------------
       
    48 CMultiTouchPointerEvent::CMultiTouchPointerEvent(TUint8 aTouchNumber,
       
    49         CMultiTouchPointerEventHandler *aEventHandler)
       
    50     : CActive(CActive::EPriorityStandard),
       
    51       iEventHandler(aEventHandler),
       
    52       iTouchNumber(aTouchNumber)
       
    53     {
       
    54     HTI_LOG_TEXT( "CMultiTouchPointerEvent constructor" );
       
    55     }
       
    56 
       
    57 // ----------------------------------------------------------------------------
       
    58 // CMultiTouchPointerEvent::~CMultiTouchPointerEvent()
       
    59 // ----------------------------------------------------------------------------
       
    60 CMultiTouchPointerEvent::~CMultiTouchPointerEvent()
       
    61     {
       
    62     HTI_LOG_TEXT( "CMultiTouchPointerEvent destructor" );
       
    63     Cancel();
       
    64     iTimer.Close();
       
    65 	
       
    66     iTimeArray.ResetAndDestroy(); 
       
    67 	iAdvPointerArray.ResetAndDestroy(); 
       
    68     }
       
    69 
       
    70 // ----------------------------------------------------------------------------
       
    71 // CMultiTouchPointerEvent::ConstructL()
       
    72 // ----------------------------------------------------------------------------
       
    73 void CMultiTouchPointerEvent::ConstructL()
       
    74     {
       
    75     HTI_LOG_TEXT( "CMultiTouchPointerEvent::ConstructL" );
       
    76     iTimeArray.Reset(); 
       
    77 
       
    78     User::LeaveIfError( iTimer.CreateLocal() );
       
    79     CActiveScheduler::Add( this );
       
    80     }
       
    81 
       
    82 
       
    83 // ----------------------------------------------------------------------------
       
    84 // CMultiTouchPointerEvent::StartTouch()
       
    85 // ----------------------------------------------------------------------------
       
    86 void CMultiTouchPointerEvent::StartTouch()
       
    87     {
       
    88     HTI_LOG_FUNC_IN( "CMultiTouchPointerEvent::StartTouch" );
       
    89     TBool bcontinue=ETrue;
       
    90     while (iTimeArray.Count()>0 && bcontinue)
       
    91         {
       
    92         TTimeIntervalMicroSeconds32* time=iTimeArray[0];
       
    93         iTimeArray.Remove(0);        
       
    94     	HTI_LOG_FORMAT( "Event time=%d ", time->Int() );    	
       
    95         if (time->Int()==0) 
       
    96             {
       
    97 			// execute immediately            
       
    98 			SimulatePointerEvent(); 
       
    99             }
       
   100         else
       
   101         	{
       
   102 			// wait for specified time
       
   103 			iTimer.After( iStatus, *time );
       
   104 			SetActive();        
       
   105 			bcontinue=EFalse;
       
   106         	}
       
   107         delete time;
       
   108         }
       
   109     
       
   110     if (iTimeArray.Count()==0)
       
   111     	{
       
   112 		HTI_LOG_FORMAT( "Notify touch %d complete", iTouchNumber );
       
   113 		iEventHandler->NotifyTouchComplete(iTouchNumber);  
       
   114     	}
       
   115     HTI_LOG_FUNC_OUT( "CMultiTouchPointerEvent::StartTouch" );
       
   116     }
       
   117 
       
   118 // ----------------------------------------------------------------------------
       
   119 // void CMultiTouchPointerEvent::InsertPointArrayL()
       
   120 // ----------------------------------------------------------------------------
       
   121 void CMultiTouchPointerEvent::InsertPointArrayL(TInt aX,TInt aY,TInt aZ,TRawEvent::TType aEventType)
       
   122     {
       
   123 
       
   124     TAdvancedPointer* point = new (ELeave) TAdvancedPointer;
       
   125     CleanupStack::PushL(point);
       
   126     iAdvPointerArray.AppendL(point);
       
   127     CleanupStack::Pop();
       
   128 
       
   129     point->X=aX;
       
   130     point->Y=aY;
       
   131     point->Z=aZ;
       
   132     point->EventType=aEventType;
       
   133 
       
   134     }
       
   135 
       
   136 // ----------------------------------------------------------------------------
       
   137 // void CMultiTouchPointerEvent::InsertTimeArrayL()
       
   138 // ----------------------------------------------------------------------------
       
   139 void CMultiTouchPointerEvent::InsertTimeArrayL(TTimeIntervalMicroSeconds32 aDelayTime)
       
   140     {
       
   141 
       
   142     TTimeIntervalMicroSeconds32* time=new (ELeave) TTimeIntervalMicroSeconds32(aDelayTime);
       
   143     iTimeArray.AppendL(time);
       
   144 
       
   145     }
       
   146 
       
   147 // ----------------------------------------------------------------------------
       
   148 // CMultiTouchPointerEvent::InterpolatePointL()
       
   149 // ----------------------------------------------------------------------------
       
   150 void CMultiTouchPointerEvent::InterpolatePointL(TInt aX1,TInt aY1, TInt aZ1, 
       
   151         TInt aX2,TInt aY2, TInt aZ2, TTimeIntervalMicroSeconds32 aDragTime, TInt aStepCount)
       
   152     {
       
   153     HTI_LOG_FUNC_IN( "CMultiTouchPointerEvent::InterpolatePointL" );
       
   154     TInt dx = (aX2-aX1)/aStepCount;
       
   155     TInt dy = (aY2-aY1)/aStepCount;  
       
   156     
       
   157     TTimeIntervalMicroSeconds32 dt = aDragTime.Int()/aStepCount;
       
   158     TInt X,Y,Z;
       
   159     for (TInt i=1;i<=aStepCount;i++)
       
   160         {         
       
   161         if (i<aStepCount)
       
   162             {
       
   163             X=aX1+i*dx;
       
   164             Y=aY1+i*dy;
       
   165             Z=aZ1;
       
   166             }
       
   167         else
       
   168             {
       
   169             X=aX2;
       
   170             Y=aY2;
       
   171             Z=aZ2;
       
   172             }             
       
   173         AddPointL(dt,X,Y,Z,TRawEvent::EPointerMove);        
       
   174         }
       
   175     
       
   176     HTI_LOG_FUNC_OUT( "CMultiTouchPointerEvent::InterpolatePointL" );
       
   177     }
       
   178 // ----------------------------------------------------------------------------
       
   179 // CMultiTouchPointerEvent::RunL()
       
   180 // ----------------------------------------------------------------------------
       
   181 void CMultiTouchPointerEvent::RunL()
       
   182     {
       
   183     HTI_LOG_FUNC_IN( "CMultiTouchPointerEvent::RunL" );
       
   184     SimulatePointerEvent();
       
   185     StartTouch();
       
   186     HTI_LOG_FUNC_OUT( "CMultiTouchPointerEvent::RunL" );
       
   187     }
       
   188 
       
   189 // ----------------------------------------------------------------------------
       
   190 // CMultiTouchPointerEvent::RunError()
       
   191 // ----------------------------------------------------------------------------
       
   192 TInt CMultiTouchPointerEvent::RunError( TInt aError )
       
   193     {
       
   194     HTI_LOG_FORMAT( "CMultiTouchPointerEvent::RunError %d", aError );
       
   195 
       
   196     return KErrNone;
       
   197     }
       
   198 
       
   199 // ----------------------------------------------------------------------------
       
   200 // CMultiTouchPointerEvent::DoCancel()
       
   201 // ----------------------------------------------------------------------------
       
   202 void CMultiTouchPointerEvent::DoCancel()
       
   203     {
       
   204     HTI_LOG_FUNC_IN( "CMultiTouchPointerEvent::DoCancel" );
       
   205     iTimer.Cancel();
       
   206     HTI_LOG_FUNC_OUT( "CMultiTouchPointerEvent::DoCancel" );
       
   207     }
       
   208 
       
   209 void CMultiTouchPointerEvent::PrintInfo()
       
   210 	{
       
   211 #ifdef __ENABLE_LOGGING__
       
   212 	HTI_LOG_FUNC_IN( "CMultiTouchPointerEvent::PrintInfo" );
       
   213 	
       
   214 	HTI_LOG_FORMAT( "PrintInfo touch number=%d ", iTouchNumber );
       
   215 	
       
   216 	TInt size=iTimeArray.Count(); 
       
   217 	HTI_LOG_FORMAT( "PrintInfo event array=%d ", size );	
       
   218 
       
   219 	TBuf<255> buf;
       
   220 
       
   221 	for (TInt i=0;i<size;i++)
       
   222 		{
       
   223         buf.Format(KPrintInfoString, 
       
   224                 i, iTimeArray[i]->Int(),iAdvPointerArray[i]->EventType ,
       
   225                 iAdvPointerArray[i]->X ,iAdvPointerArray[i]->Y, iAdvPointerArray[i]->Z );
       
   226         HTI_LOG_DES(buf);
       
   227 		}
       
   228 	HTI_LOG_FUNC_OUT( "CMultiTouchPointerEvent::PrintInfo" );
       
   229 #endif
       
   230 	}
       
   231 // ----------------------------------------------------------------------------
       
   232 // CMultiTouchPointerEvent::SimulatePointerEvent()
       
   233 // Sends the pointer event as a raw event.
       
   234 // ----------------------------------------------------------------------------
       
   235 void CMultiTouchPointerEvent::SimulatePointerEvent()
       
   236     {
       
   237     HTI_LOG_FUNC_IN( "CMultiTouchPointerEvent::SimulatePointerEvent" );    
       
   238        
       
   239 	if (iAdvPointerArray.Count()>0)
       
   240         {
       
   241         TAdvancedPointer* pointer = iAdvPointerArray[0];    
       
   242         iAdvPointerArray.Remove(0);
       
   243         
       
   244         iEventHandler->SimulateEvent(iTouchNumber, pointer->X, pointer->Y, pointer->Z,pointer->EventType);        
       
   245         delete pointer;
       
   246         }
       
   247 
       
   248     HTI_LOG_FUNC_OUT( "CMultiTouchPointerEvent::SimulatePointerEvent" );
       
   249 
       
   250     }
       
   251 void CMultiTouchPointerEvent::AddPointL(TTimeIntervalMicroSeconds32 aTime,
       
   252 		TInt aX, TInt aY, TInt aZ, TRawEvent::TType aEventType)
       
   253 	{
       
   254 	InsertPointArrayL( aX, aY, aZ,aEventType);
       
   255 	InsertTimeArrayL(aTime);
       
   256 	}
       
   257 // End of file