hti/PC_Tools/HTIGateway/ServicePlugins/HtiKeyEvent/HtiKeyEvent.cpp
changeset 36 813b186005b6
parent 30 86a2e675b80a
child 41 838cdffd57ce
equal deleted inserted replaced
30:86a2e675b80a 36:813b186005b6
     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:
       
    15 */
       
    16 #include "HtiKeyEventH.h"
       
    17 #include "HtiPlugin.h"
       
    18 #include "HtiSoapHandlerInterface.h"
       
    19 
       
    20 const unsigned char CMD_SINGLE_KEY_PRESS   = 0x01;
       
    21 const unsigned char CMD_KEY_DOWN           = 0x02;
       
    22 const unsigned char CMD_KEY_UP             = 0x03;
       
    23 const unsigned char CMD_TYPE_TEXT          = 0x04;
       
    24 const unsigned char CMD_LONG_KEY_PRESS     = 0x05;
       
    25 const unsigned char CMD_TYPE_TEXT_PASSWORD = 0x06;
       
    26 const unsigned char CMD_KEY_PRESS_SEQUENCE = 0x07;
       
    27 const unsigned char CMD_TAP_SCREEN         = 0x10;
       
    28 const unsigned char CMD_TAP_AND_DRAG       = 0x11;
       
    29 const unsigned char CMD_TAP_AND_DRAG_MULTI = 0x12;
       
    30 const unsigned char CMD_POINTER_DOWN       = 0x13;
       
    31 const unsigned char CMD_POINTER_UP         = 0x14;
       
    32 
       
    33 const unsigned char KEY_EVENT_OK = 0xFF;
       
    34 
       
    35 //**********************************************************************************
       
    36 // SOAP FUNCTIONS
       
    37 //
       
    38 //**********************************************************************************
       
    39 //**********************************************************************************
       
    40 // ns1__pressKey()
       
    41 //**********************************************************************************
       
    42 int ns1__pressKey(struct soap* soap,
       
    43 				  short key,
       
    44                   struct ns1__pressKeyResponse *out)
       
    45 {
       
    46 	HtiMsgHelper msg( soap, HTI_KEYEVENT_UID, CMD_SINGLE_KEY_PRESS );
       
    47 	msg.AddWord( key );
       
    48 	return msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS );
       
    49 }
       
    50 
       
    51 //**********************************************************************************
       
    52 // ns1__holdKey()
       
    53 //**********************************************************************************
       
    54 int ns1__holdKey(struct soap* soap,
       
    55 				 short key,
       
    56                  struct ns1__holdKeyResponse *out )
       
    57 {
       
    58 	HtiMsgHelper msg( soap, HTI_KEYEVENT_UID, CMD_KEY_DOWN );
       
    59 	msg.AddWord( key );
       
    60 	return msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS );
       
    61 }
       
    62 
       
    63 //**********************************************************************************
       
    64 // ns1__releaseKey()
       
    65 //**********************************************************************************
       
    66 int ns1__releaseKey(struct soap* soap, 
       
    67 					short key,
       
    68                     struct ns1__releaseKeyResponse *out)
       
    69 {
       
    70 	HtiMsgHelper msg( soap, HTI_KEYEVENT_UID, CMD_KEY_UP );
       
    71 	msg.AddWord( key );
       
    72 	return msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS );
       
    73 }
       
    74 
       
    75 //**********************************************************************************
       
    76 // ns1__longKeyPress()
       
    77 //**********************************************************************************
       
    78 int ns1__longKeyPress(struct soap* soap,
       
    79 					  short key,
       
    80 					  short time,
       
    81                       struct ns1__longKeyPressResponse *out)
       
    82 {
       
    83 	HtiMsgHelper msg( soap, HTI_KEYEVENT_UID, CMD_LONG_KEY_PRESS );
       
    84 	msg.AddWord( key );
       
    85 	msg.AddWord( time );
       
    86 	return msg.SendReceiveMsg( time + HTIMSG_TIMEOUT_10_SECONDS );
       
    87 }
       
    88 
       
    89 //**********************************************************************************
       
    90 // ns1__typeText()
       
    91 //**********************************************************************************
       
    92 int ns1__typeText(struct soap* soap, 
       
    93 				  wchar_t *text, 
       
    94                   struct ns1__typeTextResponse *out)
       
    95 {
       
    96 	if(check_mandatory_wcstring_parameter(soap, text, "text"))
       
    97 		return SOAP_FAULT;
       
    98 
       
    99 	HtiMsgHelper msg( soap, HTI_KEYEVENT_UID, CMD_TYPE_TEXT );
       
   100 	msg.AddWCString( text );
       
   101 
       
   102 	// Set timeout for ok message
       
   103 	// Assume that writing 100 characters takes 10 seconds (should be more than enough)
       
   104 	// = 10s/100char = 0.1s/char = 100ms/char
       
   105 	int timeout = (int) wcslen(text)*100;
       
   106 	timeout+= HTIMSG_TIMEOUT_10_SECONDS; // add extra 10 seconds for lag
       
   107 	return msg.SendReceiveMsg( timeout );
       
   108 }
       
   109 
       
   110 //**********************************************************************************
       
   111 // ns1__typeTextPassword()
       
   112 //**********************************************************************************
       
   113 int ns1__typeTextPassword(struct soap* soap, 
       
   114 						  wchar_t *text, 
       
   115                           struct ns1__typeTextPasswordResponse *out)
       
   116 {
       
   117 	if(check_mandatory_wcstring_parameter(soap, text, "text"))
       
   118 		return SOAP_FAULT;
       
   119 
       
   120 	HtiMsgHelper msg( soap, HTI_KEYEVENT_UID, CMD_TYPE_TEXT_PASSWORD );
       
   121 	msg.AddWCString( text );
       
   122 
       
   123 	// Set timeout for ok message
       
   124 	// Assume that writing 100 characters takes 10 seconds (should be more than enough)
       
   125 	// = 10s/100char = 0.1s/char = 100ms/char
       
   126 	int timeout = (int) wcslen(text)*100;
       
   127 	timeout+= HTIMSG_TIMEOUT_10_SECONDS; // add extra 10 seconds for lag
       
   128 	return msg.SendReceiveMsg( timeout );
       
   129 }
       
   130 
       
   131 //**********************************************************************************
       
   132 // ns1__keyPressSequence()
       
   133 //**********************************************************************************
       
   134 int ns1__keyPressSequence(struct soap* soap,
       
   135                           short time,
       
   136                           short interval,
       
   137                           struct ns1__arrayOfKeyCodes keyCodes,
       
   138                        	  struct ns1__keyPressSequenceResponse *out)
       
   139 {
       
   140     HtiMsgHelper msg( soap, HTI_KEYEVENT_UID, CMD_KEY_PRESS_SEQUENCE );
       
   141     msg.AddWord( time );
       
   142     msg.AddWord( interval );
       
   143  	for ( int i = 0; i < keyCodes.__size; i++ )
       
   144 	{
       
   145 		msg.AddWord( keyCodes.__ptrKeyCode[i] );
       
   146     }
       
   147     int timeout = keyCodes.__size * ( time + interval );
       
   148     timeout += HTIMSG_TIMEOUT_10_SECONDS;
       
   149     return msg.SendReceiveMsg( timeout );
       
   150 }
       
   151 
       
   152 //**********************************************************************************
       
   153 // ns1__tapScreen()
       
   154 //**********************************************************************************
       
   155 int ns1__tapScreen(struct soap* soap,
       
   156 				   struct ns1__HtiPoint tapPoint,
       
   157 				   short timeToHold,
       
   158 				   short tapCount,
       
   159                    short pauseBetweenTaps,
       
   160                    struct ns1__tapScreenResponse *out)
       
   161 {
       
   162     HtiMsgHelper msg( soap, HTI_KEYEVENT_UID, CMD_TAP_SCREEN );
       
   163     msg.AddWord( tapPoint.xCoordinate );
       
   164 	msg.AddWord( tapPoint.yCoordinate );
       
   165     msg.AddWord( timeToHold );
       
   166     msg.AddWord( tapCount );
       
   167     msg.AddWord( pauseBetweenTaps );
       
   168     int timeout = tapCount * ( timeToHold + pauseBetweenTaps );
       
   169     timeout += HTIMSG_TIMEOUT_10_SECONDS;
       
   170 	return msg.SendReceiveMsg( timeout );
       
   171 }
       
   172 
       
   173 //**********************************************************************************
       
   174 // ns1__tapAndDrag()
       
   175 //**********************************************************************************
       
   176 int ns1__tapAndDrag(struct soap* soap,
       
   177                     struct ns1__HtiPoint pointDown,
       
   178                     struct ns1__HtiPoint pointUp,
       
   179                     short dragTime,
       
   180                     struct ns1__tapAndDragResponse *out)
       
   181 {
       
   182     HtiMsgHelper msg( soap, HTI_KEYEVENT_UID, CMD_TAP_AND_DRAG );
       
   183     msg.AddWord( pointDown.xCoordinate );
       
   184     msg.AddWord( pointDown.yCoordinate );
       
   185     msg.AddWord( pointUp.xCoordinate );
       
   186     msg.AddWord( pointUp.yCoordinate );
       
   187     msg.AddWord( dragTime );
       
   188     return msg.SendReceiveMsg( dragTime + HTIMSG_TIMEOUT_10_SECONDS );
       
   189 }
       
   190 
       
   191 //**********************************************************************************
       
   192 // ns1__tapAndDragMultipoint()
       
   193 //**********************************************************************************
       
   194 int ns1__tapAndDragMultipoint(struct soap* soap,
       
   195                               short timeBetweenPoints,
       
   196                               short timeBetweenLines,
       
   197                               struct ns1__arrayOfLines lines,
       
   198                               struct ns1__tapAndDragMultipointResponse *out)
       
   199 {
       
   200     HtiMsgHelper msg( soap, HTI_KEYEVENT_UID, CMD_TAP_AND_DRAG_MULTI );
       
   201     msg.AddWord( timeBetweenPoints );
       
   202     msg.AddWord( timeBetweenLines );
       
   203     int pointCount = 0;
       
   204     for ( int i = 0; i < lines.__size; i++ )
       
   205     {
       
   206         int pointsInLine = lines.__ptrLine[i].__size;
       
   207         pointCount += pointsInLine;
       
   208         msg.AddWord( pointsInLine );
       
   209         for ( int j = 0; j < pointsInLine; j++ )
       
   210         {
       
   211             msg.AddWord( lines.__ptrLine[i].__ptrPoint[j].xCoordinate );
       
   212             msg.AddWord( lines.__ptrLine[i].__ptrPoint[j].yCoordinate );
       
   213         }
       
   214     }
       
   215 
       
   216     int timeout = ( pointCount * timeBetweenPoints ) +
       
   217                   ( lines.__size * timeBetweenLines );
       
   218     timeout += HTIMSG_TIMEOUT_10_SECONDS;
       
   219     return msg.SendReceiveMsg( timeout );
       
   220 }
       
   221 
       
   222 //**********************************************************************************
       
   223 // ns1__pointerDown()
       
   224 //**********************************************************************************
       
   225 int ns1__pointerDown(struct soap* soap,
       
   226 				     struct ns1__HtiPoint pointDown,
       
   227                      struct ns1__pointerDownResponse *out )
       
   228 {
       
   229     HtiMsgHelper msg( soap, HTI_KEYEVENT_UID, CMD_POINTER_DOWN );
       
   230     msg.AddWord( pointDown.xCoordinate );
       
   231     msg.AddWord( pointDown.yCoordinate );
       
   232 	return msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS );
       
   233 }
       
   234 
       
   235 //**********************************************************************************
       
   236 // ns1__pointerUp()
       
   237 //**********************************************************************************
       
   238 int ns1__pointerUp(struct soap* soap,
       
   239 				   struct ns1__HtiPoint pointUp,
       
   240                    struct ns1__pointerUpResponse *out )
       
   241 {
       
   242     HtiMsgHelper msg( soap, HTI_KEYEVENT_UID, CMD_POINTER_UP );
       
   243     msg.AddWord( pointUp.xCoordinate );
       
   244     msg.AddWord( pointUp.yCoordinate );
       
   245 	return msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS );
       
   246 }