satengine/SatServer/SatInternalClient/src/CSatCGetInkeyHandler.cpp
changeset 46 2fa1fa551b0b
parent 42 35488577e233
child 48 78df25012fda
equal deleted inserted replaced
42:35488577e233 46:2fa1fa551b0b
     1 /*
       
     2 * Copyright (c) 2002-2008 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:  This is the handler for the SIM Application Toolkit
       
    15 *                Get Inkey proactive command.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include    <e32svr.h>
       
    21 #include    "RSatUiSession.h"
       
    22 #include    "MSatUiObserver.h"
       
    23 #include    "CSatCGetInkeyHandler.h"
       
    24 #include    "SatSOpcodes.h"
       
    25 #include    "SatLog.h"
       
    26 
       
    27 const TInt KTenthOfSecondsInMinute( 600 );
       
    28 const TInt8 KSecond( 10 );
       
    29 const TUint8 KHalfSecond( 5 );
       
    30 const TInt KHalfMinute( 300 );
       
    31 const TUint8 KByteMax( 255 );
       
    32 
       
    33 // ======== MEMBER FUNCTIONS ========
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CSatCGetInkeyHandler::CSatCGetInkeyHandler
       
    37 // C++ default constructor can NOT contain any code, that
       
    38 // might leave.
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CSatCGetInkeyHandler::CSatCGetInkeyHandler(
       
    42     TInt aPriority,
       
    43     RSatUiSession* aSession ) :
       
    44     CActive( aPriority ),
       
    45     iSession( aSession ),
       
    46     iGetInkeyData(),
       
    47     iGetInkeyPckg( iGetInkeyData ),
       
    48     iGetInkeyRsp(),
       
    49     iGetInkeyRspPckg( iGetInkeyRsp )
       
    50     {
       
    51     LOG( SIMPLE,
       
    52         "SATINTERNALCLIENT: CSatCGetInkeyHandler::CSatCGetInkeyHandler calling" )
       
    53 
       
    54     // Add to active scheduler.
       
    55     CActiveScheduler::Add( this );
       
    56 
       
    57     LOG( SIMPLE,
       
    58         "SATINTERNALCLIENT: CSatCGetInkeyHandler::CSatCGetInkeyHandler exiting" )
       
    59     }
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CSatCGetInkeyHandler::NewL
       
    63 // Two-phased constructor.
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 CSatCGetInkeyHandler* CSatCGetInkeyHandler::NewL(
       
    67     RSatUiSession* aSat )
       
    68     {
       
    69     LOG( SIMPLE, "SATINTERNALCLIENT: CSatCGetInkeyHandler::NewL calling" )
       
    70 
       
    71     // Perform construction.
       
    72     CSatCGetInkeyHandler* self =
       
    73         new ( ELeave ) CSatCGetInkeyHandler( EPriorityLow, aSat );
       
    74 
       
    75     LOG( SIMPLE, "SATINTERNALCLIENT: CSatCGetInkeyHandler::NewL exiting" )
       
    76     return self;
       
    77     }
       
    78 
       
    79 // Destructor
       
    80 CSatCGetInkeyHandler::~CSatCGetInkeyHandler()
       
    81     {
       
    82     LOG( SIMPLE,
       
    83         "SATINTERNALCLIENT: CSatCGetInkeyHandler::~CSatCGetInkeyHandler calling" )
       
    84 
       
    85     // Cancel any outstanding requests.
       
    86     Cancel();
       
    87     iSession = NULL;
       
    88 
       
    89     LOG( SIMPLE,
       
    90         "SATINTERNALCLIENT: CSatCGetInkeyHandler::~CSatCGetInkeyHandler exiting" )
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CSatCGetInkeyHandler::Start
       
    95 // Starts the handler.
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 void CSatCGetInkeyHandler::Start()
       
    99     {
       
   100     LOG( SIMPLE, "SATINTERNALCLIENT: CSatCGetInkeyHandler::Start calling" )
       
   101 
       
   102     // Empty the IPC data
       
   103     RSat::TGetInkeyV2 temp;
       
   104     iGetInkeyData = temp;
       
   105     RSat::TGetInkeyRspV2 temp2;
       
   106     iGetInkeyRsp = temp2;
       
   107 
       
   108     // Request Get Inkey notifications.
       
   109     TIpcArgs arguments( &iGetInkeyPckg );
       
   110 
       
   111     // Pass the Get Inkey IPC package.
       
   112     iSession->CreateRequest( ESatSProactiveGetInkey, arguments, iStatus );
       
   113 
       
   114     // Set this handler to active so that it can receive requests.
       
   115     SetActive();
       
   116 
       
   117     LOG( SIMPLE, "SATINTERNALCLIENT: CSatCGetInkeyHandler::Start exiting" )
       
   118     }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CSatCGetInkeyHandler::RunL
       
   122 // Handles the command.
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 void CSatCGetInkeyHandler::RunL()
       
   126     {
       
   127     LOG( SIMPLE, "SATINTERNALCLIENT: CSatCGetInkeyHandler::RunL calling" )
       
   128 
       
   129     // Check the status of the asnychronous operation
       
   130     if ( KErrNone != iStatus.Int() )
       
   131         {
       
   132         LOG2(
       
   133             SIMPLE,
       
   134             "SATINTERNALCLIENT: CSatCGetInkeyHandler::RunL exiting, error: %d",
       
   135             iStatus.Int() )
       
   136 
       
   137         // Renew the request
       
   138         Start();
       
   139 
       
   140         return;
       
   141         }
       
   142     
       
   143     LOG2( SIMPLE,
       
   144     "SATINTERNALCLIENT: CSatCGetInkeyHandler::RunL iGetInkeyData.iRspFormat: %d",
       
   145     iGetInkeyData.iRspFormat )
       
   146     // Set the character set parameter.
       
   147     TSatCharacterSet characterSet = ESatCharSmsDefaultAlphabet;
       
   148     if ( RSat::EDigitOnly == iGetInkeyData.iRspFormat )
       
   149         {        
       
   150         characterSet = ESatDigitOnly;
       
   151         }
       
   152     else if ( RSat::ECharSmsDefaultAlphabet == iGetInkeyData.iRspFormat )
       
   153         {        
       
   154         characterSet = ESatCharSmsDefaultAlphabet;
       
   155         }
       
   156     else if ( RSat::ECharUcs2Alphabet == iGetInkeyData.iRspFormat )
       
   157         {        
       
   158         characterSet = ESatCharUcs2Alphabet;
       
   159         }
       
   160     else if ( RSat::EYesNo == iGetInkeyData.iRspFormat )
       
   161         {        
       
   162         characterSet = ESatYesNo;
       
   163         }
       
   164     else
       
   165         {        
       
   166         characterSet = ESatCharSmsDefaultAlphabet;
       
   167         }
       
   168 
       
   169     // This will contain user input.
       
   170     TChar character;
       
   171 
       
   172     // Indicates whether help is available
       
   173     TBool helpIsAvailable( EFalse );
       
   174     if ( RSat::EHelpAvailable == iGetInkeyData.iHelp )
       
   175         {
       
   176         LOG( SIMPLE, 
       
   177         "SATINTERNALCLIENT: CSatCGetInkeyHandler::RunL HelpAvailable" )
       
   178         helpIsAvailable = ETrue;
       
   179         }
       
   180 
       
   181     // Has to be casted to TInt before casting to TSatIconQualifier, because
       
   182     // GCC warns about the direct cast.
       
   183     const struct TSatIconId iconId = { iGetInkeyData.iIconId.iIdentifier,
       
   184         static_cast<TSatIconQualifier>(
       
   185             static_cast<TInt>( iGetInkeyData.iIconId.iQualifier ) ) };
       
   186 
       
   187     // This will contain EFalse if requested icon is not displayed.
       
   188     // And if icon is displayed, it contains ETrue.
       
   189     TBool requestedIconDisplayed( EFalse );
       
   190 
       
   191     TUint duration( 0 );
       
   192     TUint8 timeUnit( iGetInkeyData.iDuration.iTimeUnit );
       
   193 
       
   194     // check if duration data is available.
       
   195     if ( ( RSat::ENoDurationAvailable != timeUnit ) &&
       
   196         ( RSat::ETimeUnitNotSet != timeUnit ) &&
       
   197         iGetInkeyData.iDuration.iNumOfUnits )
       
   198         {
       
   199         // The resolution of a timer is tenth of second.
       
   200         duration = DurationInTenthOfSeconds();
       
   201         LOG2( SIMPLE, "SATINTERNALCLIENT: CSatCGetInkeyHandler duration %i",
       
   202             duration )
       
   203         }
       
   204 
       
   205     TBool immediateDigitResponse( EFalse );
       
   206     if ( RSat::EImmediateDigitRsp == iGetInkeyData.iMode )
       
   207         {
       
   208         LOG( SIMPLE, 
       
   209         "SATINTERNALCLIENT: CSatCGetInkeyHandler::RunL EImmediateDigitRsp" )
       
   210         immediateDigitResponse = ETrue;
       
   211         }
       
   212 
       
   213     // Notify the registered client and save the response.
       
   214     TSatUiResponse response = iSession->SatUiObserver()->GetInkeyL(
       
   215         iGetInkeyData.iText,
       
   216         characterSet, character, helpIsAvailable,
       
   217         iconId, requestedIconDisplayed,
       
   218         duration, immediateDigitResponse
       
   219         );
       
   220 
       
   221     // If duration exists set duration value in response
       
   222     if ( duration &&
       
   223         ( ESatSuccess == response || ESatNoResponseFromUser == response ) )
       
   224         {
       
   225         TenthOfSecondsToDuration( duration );
       
   226         LOG2( SIMPLE,
       
   227             "SATINTERNALCLIENT: CSatCGetInkeyHandler duration in response %i",
       
   228             iGetInkeyRsp.iDuration.iNumOfUnits )
       
   229         }
       
   230 
       
   231     // Use the same format in the response as it is in the input.
       
   232     iGetInkeyRsp.iRspFormat = iGetInkeyData.iRspFormat;
       
   233 
       
   234     // By default, this command does not have additional information.
       
   235     iGetInkeyRsp.iInfoType = RSat::KNoAdditionalInfo;
       
   236     iGetInkeyRsp.iAdditionalInfo.Zero();
       
   237 
       
   238     iGetInkeyRsp.SetPCmdNumber( iGetInkeyData.PCmdNumber() );
       
   239 
       
   240     // Examine the client response.
       
   241     ExamineClientResponse(
       
   242         response, character, requestedIconDisplayed );
       
   243 
       
   244     // Pass the Get Inkey response package.
       
   245     TIpcArgs arguments( &iGetInkeyRspPckg );
       
   246 
       
   247     // Perform the IPC data transfer.
       
   248     iSession->CreateRequest( ESatSProactiveGetInkeyResponse, arguments );
       
   249 
       
   250     // Renew the service request.
       
   251     Start();
       
   252 
       
   253     LOG( SIMPLE, "SATINTERNALCLIENT: CSatCGetInkeyHandler::RunL exiting" )
       
   254     }
       
   255 
       
   256 // -----------------------------------------------------------------------------
       
   257 // CSatCGetInkeyHandler::ExamineClientResponse
       
   258 // Examine the client response.
       
   259 // -----------------------------------------------------------------------------
       
   260 //
       
   261 void CSatCGetInkeyHandler::ExamineClientResponse(
       
   262     TSatUiResponse aResponse,
       
   263     const TChar& aCharacter,
       
   264     TBool aRequestedIconDisplayed )
       
   265     {
       
   266     LOG2( SIMPLE,
       
   267     "SATINTERNALCLIENT: CSatCGetInkeyHandler::ExamineClientResponse calling,\
       
   268     aResponse: %x", aResponse )
       
   269 
       
   270     // Examine the client response.
       
   271     switch ( aResponse )
       
   272         {
       
   273         case ESatSuccess:
       
   274             {
       
   275              // Convert terminal rsp if icon used
       
   276             RSat::TPCmdResult result( RSat::KSuccess );
       
   277             RSat::TIconQualifier iconQualifier(
       
   278                 iGetInkeyData.iIconId.iQualifier );
       
   279 
       
   280             if ( !aRequestedIconDisplayed )
       
   281                 {
       
   282                 LOG( SIMPLE,
       
   283                 "SATINTERNALCLIENT: CSatCGetInkeyHandler::ExamineClientResponse \
       
   284                 aRequestedIconDisplayed false" )
       
   285                 if ( iconQualifier == RSat::ESelfExplanatory ||
       
   286                     iconQualifier == RSat::ENotSelfExplanatory )
       
   287                     {
       
   288                     LOG( SIMPLE,
       
   289                     "SATINTERNALCLIENT: CSatCGetInkeyHandler::ExamineClientResponse \
       
   290                     IconNotDisplayed" )
       
   291                     result = RSat::KSuccessRequestedIconNotDisplayed;
       
   292                     }
       
   293                 }
       
   294 
       
   295             iGetInkeyRsp.iGeneralResult = result;
       
   296 
       
   297             // If GetInkey is type of YesNo, aCharacter is 0 if user selects NO
       
   298             if ( aCharacter || ( RSat::EYesNo == iGetInkeyData.iRspFormat ) )
       
   299                 {
       
   300                 LOG( SIMPLE,
       
   301                 "SATINTERNALCLIENT: CSatCGetInkeyHandler::ExamineClientResponse \
       
   302                 set AdditionalInfo" )
       
   303                 // Change the additional information type
       
   304                 iGetInkeyRsp.iInfoType = RSat::KTextString;
       
   305 
       
   306                 // Save the character input by the user
       
   307                 iGetInkeyRsp.iAdditionalInfo.Append( aCharacter );
       
   308                 }
       
   309             else
       
   310                 {
       
   311                 LOG( SIMPLE,
       
   312                 "SATINTERNALCLIENT: CSatCGetInkeyHandler::ExamineClientResponse \
       
   313                 no AdditionalInfo" )
       
   314                 // Otherwise, just return the response.
       
   315                 iGetInkeyRsp.iInfoType = RSat::KNoAdditionalInfo;
       
   316                 }
       
   317             break;
       
   318             }
       
   319         case ESatFailure:
       
   320             {
       
   321             iGetInkeyRsp.iInfoType = RSat::KMeProblem;
       
   322             iGetInkeyRsp.iGeneralResult = RSat::KMeUnableToProcessCmd;
       
   323             iGetInkeyRsp.iAdditionalInfo.SetLength( 1 );
       
   324             iGetInkeyRsp.iAdditionalInfo[0] = RSat::KNoSpecificMeProblem;
       
   325             break;
       
   326             }
       
   327         case ESatSessionTerminatedByUser:
       
   328             {
       
   329             iGetInkeyRsp.iGeneralResult = RSat::KPSessionTerminatedByUser;
       
   330             break;
       
   331             }
       
   332         case ESatBackwardModeRequestedByUser:
       
   333             {
       
   334             iGetInkeyRsp.iGeneralResult =
       
   335                 RSat::KBackwardModeRequestedByUser;
       
   336             break;
       
   337             }
       
   338         case ESatNoResponseFromUser:
       
   339             {
       
   340             iGetInkeyRsp.iGeneralResult = RSat::KNoResponseFromUser;
       
   341             break;
       
   342             }
       
   343         case EHelpRequestedByUser:
       
   344             {
       
   345             iGetInkeyRsp.iGeneralResult = RSat::KHelpRequestedByUser;
       
   346             break;
       
   347             }
       
   348         case EPCmdNotAcceptedByUser:
       
   349         case ESatCmdDataNotUnderstood:
       
   350         default:
       
   351             {
       
   352             iSession->Panic( ESatInvalidResponse );
       
   353             break;
       
   354             }
       
   355         }
       
   356 
       
   357     LOG( SIMPLE,
       
   358         "SATINTERNALCLIENT: CSatCGetInkeyHandler::ExamineClientResponse exiting" )
       
   359     }
       
   360 
       
   361 // -----------------------------------------------------------------------------
       
   362 // CSatCGetInkeyHandler::DoCancel
       
   363 // Cancels the pending request.
       
   364 // -----------------------------------------------------------------------------
       
   365 //
       
   366 void CSatCGetInkeyHandler::DoCancel()
       
   367     {
       
   368     LOG( SIMPLE, "SATINTERNALCLIENT: CSatCGetInkeyHandler::DoCancel calling" )
       
   369 
       
   370     // Complete the request with cancel code.
       
   371     TRequestStatus* requestStatus = &iStatus;
       
   372     User::RequestComplete( requestStatus, KErrCancel );
       
   373 
       
   374     LOG( SIMPLE, "SATINTERNALCLIENT: CSatCGetInkeyHandler::DoCancel exiting" )
       
   375     }
       
   376 
       
   377 // -----------------------------------------------------------------------------
       
   378 // CSatCGetInkeyHandler::DurationInTenthOfSeconds
       
   379 // Return duration in seconds.
       
   380 // -----------------------------------------------------------------------------
       
   381 //
       
   382 TUint CSatCGetInkeyHandler::DurationInTenthOfSeconds() const
       
   383     {
       
   384     LOG2( SIMPLE, 
       
   385     "SATINTERNALCLIENT: CSatCGetInkeyHandler::DurationInTenthOfSeconds calling,\
       
   386     iGetInkeyData.iDuration.iTimeUnit: %d",iGetInkeyData.iDuration.iTimeUnit )
       
   387     TUint duration( 0 );
       
   388 
       
   389     switch ( iGetInkeyData.iDuration.iTimeUnit )
       
   390         {
       
   391         case RSat::EMinutes:
       
   392             {
       
   393             duration =
       
   394                 iGetInkeyData.iDuration.iNumOfUnits * KTenthOfSecondsInMinute;
       
   395             break;
       
   396             }
       
   397         case RSat::ESeconds:
       
   398             {
       
   399             duration = iGetInkeyData.iDuration.iNumOfUnits * KSecond;
       
   400             break;
       
   401             }
       
   402         case RSat::ETenthsOfSeconds:
       
   403             {
       
   404             duration = iGetInkeyData.iDuration.iNumOfUnits;
       
   405             break;
       
   406             }
       
   407         default:
       
   408             {
       
   409             //duration is 0
       
   410             break;
       
   411             }
       
   412         }
       
   413     LOG2( SIMPLE, 
       
   414     "SATINTERNALCLIENT: CSatCGetInkeyHandler::DurationInTenthOfSeconds exiting,\
       
   415     duration: %d", duration )
       
   416     return duration;
       
   417     }
       
   418 
       
   419 // -----------------------------------------------------------------------------
       
   420 // CSatCGetInkeyHandler::TenthOfSecondsToDuration
       
   421 // Convert second to duration.
       
   422 // -----------------------------------------------------------------------------
       
   423 //
       
   424 void CSatCGetInkeyHandler::TenthOfSecondsToDuration(
       
   425     TUint aDuration )
       
   426     {
       
   427     LOG2( SIMPLE, 
       
   428     "SATINTERNALCLIENT: CSatCGetInkeyHandler::TenthOfSecondsToDuration calling,\
       
   429     iGetInkeyData.iDuration.iTimeUnit: %d",iGetInkeyData.iDuration.iTimeUnit )
       
   430     switch ( iGetInkeyData.iDuration.iTimeUnit )
       
   431         {
       
   432         case RSat::EMinutes:
       
   433             {
       
   434             iGetInkeyRsp.iDuration.iTimeUnit = RSat::EMinutes;
       
   435 
       
   436             // Make Roundup
       
   437             TUint numOfUnits(
       
   438                 ( aDuration + KHalfMinute ) / KTenthOfSecondsInMinute );
       
   439 
       
   440             if ( KByteMax >= numOfUnits )
       
   441                 {
       
   442                 LOG( SIMPLE, 
       
   443                 "SATINTERNALCLIENT: CSatCGetInkeyHandler::TenthOfSecondsToDuration \
       
   444                 EMinutes KByteMax >= numOfUnits" )
       
   445                 iGetInkeyRsp.iDuration.iNumOfUnits =
       
   446                     static_cast<TUint8>( numOfUnits );
       
   447                 }
       
   448             else
       
   449                 {
       
   450                 iGetInkeyRsp.iDuration.iNumOfUnits = KByteMax;
       
   451                 }
       
   452 
       
   453             break;
       
   454             }
       
   455         case RSat::ESeconds:
       
   456             {
       
   457             iGetInkeyRsp.iDuration.iTimeUnit = RSat::ESeconds;
       
   458 
       
   459             // Make Roundup
       
   460             TUint numOfUnits(
       
   461                 ( aDuration + KHalfSecond ) / KSecond );
       
   462 
       
   463             if ( KByteMax >= numOfUnits )
       
   464                 {
       
   465                 LOG( SIMPLE, 
       
   466                 "SATINTERNALCLIENT: CSatCGetInkeyHandler::TenthOfSecondsToDuration \
       
   467                 ESeconds KByteMax >= numOfUnits" )
       
   468                 iGetInkeyRsp.iDuration.iNumOfUnits =
       
   469                     static_cast<TUint8>( numOfUnits );
       
   470                 }
       
   471             else
       
   472                 {
       
   473                 iGetInkeyRsp.iDuration.iNumOfUnits = KByteMax;
       
   474                 }
       
   475 
       
   476             break;
       
   477             }
       
   478         case RSat::ETenthsOfSeconds:
       
   479             {
       
   480             iGetInkeyRsp.iDuration.iTimeUnit = RSat::ETenthsOfSeconds;
       
   481             if ( KByteMax >= aDuration )
       
   482                 {
       
   483                 LOG( SIMPLE, 
       
   484                 "SATINTERNALCLIENT: CSatCGetInkeyHandler::TenthOfSecondsToDuration \
       
   485                 ETenthsOfSeconds KByteMax >= aDuration" )
       
   486                 iGetInkeyRsp.iDuration.iNumOfUnits =
       
   487                     static_cast<TUint8>( aDuration );
       
   488                 }
       
   489             else
       
   490                 {
       
   491                 iGetInkeyRsp.iDuration.iNumOfUnits = KByteMax;
       
   492                 }
       
   493 
       
   494             break;
       
   495             }
       
   496         default:
       
   497             {
       
   498             break;
       
   499             }
       
   500         }
       
   501     LOG( SIMPLE, 
       
   502     "SATINTERNALCLIENT: CSatCGetInkeyHandler::TenthOfSecondsToDuration exiting" )
       
   503     }