satengine/SatServer/SatInternalClient/src/CSatCSelectItemHandler.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 *                Select Item proactive command.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include    <e32svr.h>
       
    21 #include    <basched.h>
       
    22 #include    "RSatUiSession.h"
       
    23 #include    "MSatUiObserver.h"
       
    24 #include    "SatSOpcodes.h"
       
    25 #include    "CSatCSelectItemHandler.h"
       
    26 #include    "SatLog.h"
       
    27 
       
    28 const TInt8 KMenuItemPop( 3 );
       
    29 
       
    30 // ======== MEMBER FUNCTIONS ========
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CSatCSelectItemHandler::CSatCSelectItemHandler
       
    34 // C++ default constructor can NOT contain any code, that
       
    35 // might leave.
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 CSatCSelectItemHandler::CSatCSelectItemHandler(
       
    39     TInt aPriority,
       
    40     RSatUiSession* aSession ) :
       
    41     CActive( aPriority ),
       
    42     iSession( aSession ),
       
    43     iSelectItemData(),
       
    44     iSelectItemPckg( iSelectItemData ),
       
    45     iSelectItemRsp(),
       
    46     iSelectItemRspPckg( iSelectItemRsp )
       
    47     {
       
    48     LOG( SIMPLE,
       
    49         "SATINTERNALCLIENT: CSatCSelectItemHandler::CSatCSelectItemHandler calling" )
       
    50 
       
    51     // Add to active scheduler.
       
    52     CActiveScheduler::Add( this );
       
    53 
       
    54     LOG( SIMPLE,
       
    55         "SATINTERNALCLIENT: CSatCSelectItemHandler::CSatCSelectItemHandler exiting" )
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CSatCSelectItemHandler::NewL
       
    60 // Two-phased constructor.
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 CSatCSelectItemHandler* CSatCSelectItemHandler::NewL(
       
    64     RSatUiSession* aSat )
       
    65     {
       
    66     LOG( SIMPLE, "SATINTERNALCLIENT: CSatCSelectItemHandler::NewL calling" )
       
    67 
       
    68     // Perform the construction.
       
    69     CSatCSelectItemHandler* self =
       
    70         new ( ELeave ) CSatCSelectItemHandler( EPriorityLow, aSat );
       
    71 
       
    72     LOG( SIMPLE, "SATINTERNALCLIENT: CSatCSelectItemHandler::NewL exiting" )
       
    73     return self;
       
    74     }
       
    75 
       
    76 // Destructor
       
    77 CSatCSelectItemHandler::~CSatCSelectItemHandler()
       
    78     {
       
    79     LOG( SIMPLE,
       
    80         "SATINTERNALCLIENT: CSatCSelectItemHandler::~CSatCSelectItemHandler calling" )
       
    81 
       
    82     // Cancel any outstanding requests.
       
    83     Cancel();
       
    84     iSession = NULL;
       
    85 
       
    86     LOG( SIMPLE,
       
    87         "SATINTERNALCLIENT: CSatCSelectItemHandler::~CSatCSelectItemHandler exiting" )
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CSatCSelectItemHandler::Start
       
    92 // Starts the handler.
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 void CSatCSelectItemHandler::Start()
       
    96     {
       
    97     LOG( SIMPLE, "SATINTERNALCLIENT: CSatCSelectItemHandler::Start calling" )
       
    98 
       
    99     // Empty the IPC data
       
   100     RSat::TSelectItemV2 temp;
       
   101     iSelectItemData = temp;
       
   102     RSat::TSelectItemRspV1 temp2;
       
   103     iSelectItemRsp = temp2;
       
   104 
       
   105     // Request Select Item notification.
       
   106     TIpcArgs arguments( &iSelectItemPckg );
       
   107 
       
   108     // Pass the Select Item IPC package.
       
   109     iSession->CreateRequest( ESatSProactiveSelectItem, arguments, iStatus );
       
   110 
       
   111     // Set this handler to active so that it can receive requests.
       
   112     SetActive();
       
   113 
       
   114     LOG( SIMPLE, "SATINTERNALCLIENT: CSatCSelectItemHandler::Start exiting" )
       
   115     }
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CSatCSelectItemHandler::RunL
       
   119 // Handles the command.
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 void CSatCSelectItemHandler::RunL()
       
   123     {
       
   124     LOG( SIMPLE, "SATINTERNALCLIENT: CSatCSelectItemHandler::RunL calling" )
       
   125 
       
   126     // Check the status of the asnychronous operation
       
   127     if ( KErrNone != iStatus.Int() )
       
   128         {
       
   129         LOG2(
       
   130             SIMPLE,
       
   131             "SATINTERNALCLIENT: CSatCSelectItemHandler::RunL error: %d",
       
   132             iStatus.Int() )
       
   133 
       
   134         // Renew the request
       
   135         Start();
       
   136         }
       
   137     else
       
   138         {
       
   139         // Create the menu item array.
       
   140         CDesC16ArrayFlat* menuItems = new( ELeave ) CDesC16ArrayFlat( 1 );
       
   141         CleanupStack::PushL( menuItems );
       
   142 
       
   143         // Create the next action indicator array.
       
   144         CArrayFixFlat<TSatAction>* menuActions =
       
   145             new( ELeave ) CArrayFixFlat<TSatAction>( 1 );
       
   146         CleanupStack::PushL( menuActions );
       
   147 
       
   148         // Create the menu item icon array.
       
   149         CArrayFixFlat<TInt>* menuIcons =
       
   150             new( ELeave ) CArrayFixFlat<TInt>( 1 );
       
   151         CleanupStack::PushL( menuIcons );
       
   152 
       
   153         // Fetch all the menu items.
       
   154         // Note that the indexing starts from 1 in SIM item lists.
       
   155         // This is the default menu item.
       
   156         TInt defaultItem( 0 );
       
   157         TBool defaultItemIdFound( EFalse );
       
   158 
       
   159         const TInt numberOfItems( static_cast<TInt>(
       
   160             iSelectItemData.NumberOfItems() ) );
       
   161             
       
   162         LOG2( SIMPLE,
       
   163         "SATINTERNALCLIENT: CSatCSelectItemHandler::RunL numberOfItems: %d",
       
   164         numberOfItems )
       
   165         for ( TInt currentItem = 1; currentItem <= numberOfItems; currentItem++ )
       
   166             {
       
   167             RSat::TItem item;
       
   168             TInt action;
       
   169             TInt icon( KErrNotFound );
       
   170 
       
   171             // Fetch all data for this index.
       
   172             iSelectItemData.GetItem( static_cast<TUint>( currentItem ),
       
   173                                      item, action, icon );
       
   174 
       
   175             if ( item.iItemId == iSelectItemData.iDefaultItemId )
       
   176                 {
       
   177                 LOG( SIMPLE, 
       
   178                 "SATINTERNALCLIENT: CSatCSelectItemHandler::RunL has defaultItemId" )
       
   179                 defaultItem = currentItem - 1;
       
   180                 defaultItemIdFound = ETrue;
       
   181                 }
       
   182 
       
   183             // Save the item name
       
   184             menuItems->AppendL( item.iItemString );
       
   185 
       
   186             // Save icon identifier.
       
   187             // icon will be KErrNotFound (-1) if it is not present in the
       
   188             // SAT menu.
       
   189             menuIcons->AppendL( icon );
       
   190             LOG2( SIMPLE,
       
   191             "SATINTERNALCLIENT: CSatCSelectItemHandler::RunL action: %d", action )
       
   192             if ( KErrNotFound != action )
       
   193                 {
       
   194                 // Save the next action indicator, if found.
       
   195                 menuActions->AppendL( STATIC_CAST( TSatAction, action ) );
       
   196                 }
       
   197             }
       
   198 
       
   199         // Do not return partial comprehension response when
       
   200         // default item is not set.
       
   201         if ( !iSelectItemData.iDefaultItemId )
       
   202             {
       
   203             LOG( SIMPLE, 
       
   204             "SATINTERNALCLIENT: CSatCSelectItemHandler::RunL \
       
   205             iSelectItemData.iDefaultItemId false" )
       
   206             defaultItemIdFound = ETrue;
       
   207             }
       
   208 
       
   209         // This will contain the user selection.
       
   210         TUint8 selection;
       
   211 
       
   212         // Indicates whether help is available
       
   213         TBool helpIsAvailable( EFalse );
       
   214         if ( iSelectItemData.iHelp == RSat::EHelpAvailable )
       
   215             {
       
   216             LOG( SIMPLE, 
       
   217             "SATINTERNALCLIENT: CSatCSelectItemHandler::RunL EHelpAvailable" )
       
   218             helpIsAvailable = ETrue;
       
   219             }
       
   220 
       
   221         // Has to be casted to TInt before casting to TSatIconQualifier,
       
   222         // because gcc warns about the direct cast.
       
   223         const struct TSatIconId iconId = { iSelectItemData.iIconId.iIdentifier,
       
   224             static_cast<TSatIconQualifier>(
       
   225                 static_cast<TInt>( iSelectItemData.iIconId.iQualifier ) ) };
       
   226 
       
   227         const enum TSatIconQualifier iconListQualifier(
       
   228             static_cast<TSatIconQualifier>(
       
   229                 static_cast<TInt>( iSelectItemData.iIconListQualifier ) ) );
       
   230 
       
   231         const enum TSatSelectionPreference selectionPreference(
       
   232             static_cast<TSatSelectionPreference>(
       
   233                 static_cast<TInt>( iSelectItemData.iPreference ) ) );
       
   234 
       
   235         // This will contain EFalse if requested icon is not displayed.
       
   236         TBool requestedIconDisplayed( ETrue );
       
   237 
       
   238         // About lint e64:
       
   239         // Error in lint was MDesC8Array = CDesC16ArrayFlat, which
       
   240         // is not the case.
       
   241         // Notify the registered client and save the response.
       
   242         //lint -e{64}
       
   243         TSatUiResponse response = iSession->SatUiObserver()->SelectItemL(
       
   244             iSelectItemData.iAlphaId.iAlphaId,
       
   245             *menuItems,
       
   246             menuActions,
       
   247             defaultItem,
       
   248             selection,
       
   249             helpIsAvailable,
       
   250             iconId,
       
   251             menuIcons,
       
   252             iconListQualifier,
       
   253             requestedIconDisplayed,
       
   254             selectionPreference );
       
   255 
       
   256         // By default, this command does not have additional information.
       
   257         iSelectItemRsp.iInfoType = RSat::KNoAdditionalInfo;
       
   258         iSelectItemRsp.iAdditionalInfo.Zero();
       
   259 
       
   260         // must use the same pcmd
       
   261         iSelectItemRsp.SetPCmdNumber( iSelectItemData.PCmdNumber() );
       
   262 
       
   263         // Examine the client response.
       
   264         ExamineClientResponse(
       
   265             response, selection, requestedIconDisplayed, defaultItemIdFound );
       
   266 
       
   267         // Pass the Select Item response package.
       
   268         TIpcArgs arguments( &iSelectItemRspPckg );
       
   269 
       
   270         // Perform the IPC data transfer.
       
   271         iSession->CreateRequest( ESatSProactiveSelectItemResponse, arguments );
       
   272 
       
   273         // Destroy the array objects: menuIcons, menuActions, menuItems.
       
   274         CleanupStack::PopAndDestroy( KMenuItemPop, menuItems );
       
   275 
       
   276         // Renew the service request.
       
   277         Start();
       
   278         }
       
   279 
       
   280     LOG( SIMPLE, "SATINTERNALCLIENT: CSatCSelectItemHandler::RunL exiting" )
       
   281     }
       
   282 
       
   283 // -----------------------------------------------------------------------------
       
   284 // CSatCSelectItemHandler::ExamineClientResponse
       
   285 // Examine the client response.
       
   286 // -----------------------------------------------------------------------------
       
   287 //
       
   288 void CSatCSelectItemHandler::ExamineClientResponse(
       
   289     TSatUiResponse aResponse,
       
   290     TUint8 aSelection,
       
   291     TBool aRequestedIconDisplayed,
       
   292     TBool aDefaultItemIdFound )
       
   293     {
       
   294     LOG2( SIMPLE,
       
   295     "SATINTERNALCLIENT: CSatCSelectItemHandler::ExamineClientResponse calling,\
       
   296     aResponse: %x", aResponse )
       
   297 
       
   298     // Examine the client response.
       
   299     switch ( aResponse )
       
   300         {
       
   301         case ESatSuccess:
       
   302             {
       
   303             // Convert terminal rsp if icon used
       
   304             RSat::TPCmdResult result( RSat::KSuccess );
       
   305             RSat::TIconQualifier iconQualifier(
       
   306                     iSelectItemData.iIconId.iQualifier );
       
   307 
       
   308             //lint -e{961} Else block meaningless
       
   309             if ( iSelectItemData.iDefaultItemId && !aDefaultItemIdFound )
       
   310                 {
       
   311                 LOG( SIMPLE,
       
   312                 "SATINTERNALCLIENT: CSatCSelectItemHandler::ExamineClientResponse \
       
   313                 KPartialComprehension" )
       
   314                 result = RSat::KPartialComprehension;
       
   315                 }
       
   316             else if ( !aRequestedIconDisplayed )
       
   317                 {
       
   318                 LOG( SIMPLE,
       
   319                 "SATINTERNALCLIENT: CSatCSelectItemHandler::ExamineClientResponse \
       
   320                 aRequestedIconDisplayed false" )
       
   321                 if ( iconQualifier == RSat::ESelfExplanatory ||
       
   322                      iconQualifier == RSat::ENotSelfExplanatory )
       
   323                     {
       
   324                     LOG( SIMPLE,
       
   325                     "SATINTERNALCLIENT: CSatCSelectItemHandler::ExamineClientResponse \
       
   326                     IconNotDisplayed" )
       
   327                     result = RSat::KSuccessRequestedIconNotDisplayed;
       
   328                     }
       
   329                 }
       
   330 
       
   331             iSelectItemRsp.iGeneralResult = result;
       
   332 
       
   333             // Change the additional information type.
       
   334             iSelectItemRsp.iInfoType = RSat::KItemIdentifier;
       
   335 
       
   336             // Search for the correct item ID.
       
   337             // Underflow not possible due to selection
       
   338             // being of type TUint8
       
   339             if ( aSelection > iSelectItemData.NumberOfItems() - 1 )
       
   340                 {
       
   341                 LOG( SIMPLE,
       
   342                 "SATINTERNALCLIENT: CSatCSelectItemHandler::ExamineClientResponse \
       
   343                 ESatSuccess ESelectedItemOutOfRange" )
       
   344                 iSession->Panic( ESelectedItemOutOfRange );
       
   345                 }
       
   346 
       
   347             // Get the item with the desired index.
       
   348             RSat::TItem item;
       
   349             iSelectItemData.GetItem( aSelection + 1, item );
       
   350 
       
   351             // Save the index of the item selected by the user.
       
   352             iSelectItemRsp.iAdditionalInfo.SetLength( 1 );
       
   353             iSelectItemRsp.iAdditionalInfo[0] = item.iItemId;
       
   354             break;
       
   355             }
       
   356         // Otherwise, just return the response.
       
   357         case ESatFailure:
       
   358             {
       
   359             iSelectItemRsp.iInfoType = RSat::KMeProblem;
       
   360             iSelectItemRsp.iGeneralResult = RSat::KMeUnableToProcessCmd;
       
   361             iSelectItemRsp.iAdditionalInfo.SetLength( 1 );
       
   362             iSelectItemRsp.iAdditionalInfo[0] = RSat::KNoSpecificMeProblem;
       
   363             break;
       
   364             }
       
   365         case ESatSessionTerminatedByUser:
       
   366             {
       
   367             iSelectItemRsp.iGeneralResult = RSat::KPSessionTerminatedByUser;
       
   368             break;
       
   369             }
       
   370         case ESatBackwardModeRequestedByUser:
       
   371             {
       
   372             iSelectItemRsp.iGeneralResult =
       
   373                 RSat::KBackwardModeRequestedByUser;
       
   374             break;
       
   375             }
       
   376         case ESatNoResponseFromUser:
       
   377             {
       
   378             iSelectItemRsp.iGeneralResult = RSat::KNoResponseFromUser;
       
   379             break;
       
   380             }
       
   381         case EHelpRequestedByUser:
       
   382             {
       
   383             iSelectItemRsp.iGeneralResult = RSat::KHelpRequestedByUser;
       
   384 
       
   385             // Change the additional information type.
       
   386             iSelectItemRsp.iInfoType = RSat::KItemIdentifier;
       
   387 
       
   388             // Search for the correct item ID.
       
   389             // Underflow not possible due to selection
       
   390             // being of type TUint8
       
   391             if ( aSelection > iSelectItemData.NumberOfItems() - 1 )
       
   392                 {
       
   393                 LOG( SIMPLE,
       
   394                 "SATINTERNALCLIENT: CSatCSelectItemHandler::ExamineClientResponse \
       
   395                 EHelpRequestedByUser ESelectedItemOutOfRange" )
       
   396                 iSession->Panic( ESelectedItemOutOfRange );
       
   397                 }
       
   398 
       
   399             // Get the item with the desired index.
       
   400             RSat::TItem item;
       
   401             iSelectItemData.GetItem( aSelection + 1, item );
       
   402 
       
   403             // Save the index of the item selected by the user.
       
   404             iSelectItemRsp.iAdditionalInfo.SetLength( 1 );
       
   405             iSelectItemRsp.iAdditionalInfo[0] = item.iItemId;
       
   406             break;
       
   407             }
       
   408         case EPCmdNotAcceptedByUser:
       
   409         case ESatCmdDataNotUnderstood:
       
   410         default:
       
   411             {
       
   412             iSession->Panic( ESatInvalidResponse );
       
   413             break;
       
   414             }
       
   415         }
       
   416 
       
   417     LOG( SIMPLE,
       
   418         "SATINTERNALCLIENT: CSatCSelectItemHandler::ExamineClientResponse exiting" )
       
   419     }
       
   420 
       
   421 // -----------------------------------------------------------------------------
       
   422 // CSatCSelectItemHandler::DoCancel
       
   423 // Cancels the pending request.
       
   424 // -----------------------------------------------------------------------------
       
   425 //
       
   426 void CSatCSelectItemHandler::DoCancel()
       
   427     {
       
   428     LOG( SIMPLE, "SATINTERNALCLIENT: CSatCSelectItemHandler::DoCancel calling" )
       
   429 
       
   430     // Complete the request with cancel code.
       
   431     TRequestStatus* requestStatus = &iStatus;
       
   432     User::RequestComplete( requestStatus, KErrCancel );
       
   433 
       
   434     LOG( SIMPLE, "SATINTERNALCLIENT: CSatCSelectItemHandler::DoCancel exiting" )
       
   435     }