satengine/SatServer/SatInternalClient/src/CSatCPlayToneHandler.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 *                Play Tone proactive command.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include    <e32svr.h>
       
    21 #include    "RSatUiSession.h"
       
    22 #include    "MSatUiObserver.h"
       
    23 #include    "SatSOpcodes.h"
       
    24 #include    "CSatCPlayToneHandler.h"
       
    25 #include    "SatLog.h"
       
    26 
       
    27 // Used when Play tone doesn't contain duration.
       
    28 const TInt KSatPtDefaultDuration = 5;
       
    29 
       
    30 // ======== MEMBER FUNCTIONS ========
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CSatCPlayToneHandler::CSatCPlayToneHandler
       
    34 // C++ default constructor can NOT contain any code, that
       
    35 // might leave.
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 CSatCPlayToneHandler::CSatCPlayToneHandler(
       
    39     TInt aPriority,
       
    40     RSatUiSession* aSession ) :
       
    41     CActive( aPriority ),
       
    42     iSession( aSession ),
       
    43     iPlayToneData(),
       
    44     iPlayTonePckg( iPlayToneData ),
       
    45     iPlayToneRsp(),
       
    46     iPlayToneRspPckg( iPlayToneRsp )
       
    47     {
       
    48     LOG( SIMPLE,
       
    49         "SATINTERNALCLIENT: CSatCPlayToneHandler::CSatCPlayToneHandler calling" )
       
    50 
       
    51     // Add to active scheduler.
       
    52     CActiveScheduler::Add( this );
       
    53 
       
    54     LOG( SIMPLE,
       
    55         "SATINTERNALCLIENT: CSatCPlayToneHandler::CSatCPlayToneHandler exiting" )
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CSatCPlayToneHandler::NewL
       
    60 // Two-phased constructor.
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 CSatCPlayToneHandler* CSatCPlayToneHandler::NewL(
       
    64     RSatUiSession* aSat )
       
    65     {
       
    66     LOG( SIMPLE, "SATINTERNALCLIENT: CSatCPlayToneHandler::NewL calling" )
       
    67 
       
    68     // Perform the construction.
       
    69     CSatCPlayToneHandler* self =
       
    70         new ( ELeave ) CSatCPlayToneHandler( EPriorityLow, aSat );
       
    71 
       
    72     LOG( SIMPLE, "SATINTERNALCLIENT: CSatCPlayToneHandler::NewL exiting" )
       
    73     return self;
       
    74     }
       
    75 
       
    76 // Destructor
       
    77 CSatCPlayToneHandler::~CSatCPlayToneHandler()
       
    78     {
       
    79     LOG( SIMPLE,
       
    80         "SATINTERNALCLIENT: CSatCPlayToneHandler::~CSatCPlayToneHandler calling" )
       
    81     // Cancel any outstanding requests.
       
    82 
       
    83     Cancel();
       
    84     iSession = NULL;
       
    85 
       
    86     LOG( SIMPLE,
       
    87         "SATINTERNALCLIENT: CSatCPlayToneHandler::~CSatCPlayToneHandler exiting" )
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CSatCPlayToneHandler::Start
       
    92 // Starts the handler.
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 void CSatCPlayToneHandler::Start()
       
    96     {
       
    97     LOG( SIMPLE, "SATINTERNALCLIENT: CSatCPlayToneHandler::Start calling" )
       
    98 
       
    99     // Empty the IPC data
       
   100     RSat::TPlayToneV2 temp;
       
   101     iPlayToneData = temp;
       
   102     RSat::TPlayToneRspV1 temp2;
       
   103     iPlayToneRsp = temp2;
       
   104 
       
   105     // Request Play Tone notification.
       
   106     TIpcArgs arguments( &iPlayTonePckg );
       
   107 
       
   108     // Pass the Play Tone IPC package.
       
   109     iSession->CreateRequest( ESatSProactivePlayTone, arguments, iStatus );
       
   110 
       
   111     // Set this handler to active so that it can receive requests.
       
   112     SetActive();
       
   113 
       
   114     LOG( SIMPLE, "SATINTERNALCLIENT: CSatCPlayToneHandler::Start exiting" )
       
   115     }
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CSatCPlayToneHandler::RunL
       
   119 // Handles the command.
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 void CSatCPlayToneHandler::RunL()
       
   123     {
       
   124     LOG( SIMPLE, "SATINTERNALCLIENT: CSatCPlayToneHandler::RunL calling" )
       
   125 
       
   126     // Check the status of the asnychronous operation
       
   127     if ( KErrNone != iStatus.Int() )
       
   128         {
       
   129         LOG2(
       
   130             SIMPLE,
       
   131             "SATINTERNALCLIENT: CSatCPlayToneHandler::RunL exiting, error: %d",
       
   132             iStatus.Int() )
       
   133 
       
   134         // Renew the request
       
   135         Start();
       
   136 
       
   137         return;
       
   138         }
       
   139 
       
   140     // Determine the play duration.
       
   141     TTimeIntervalMicroSeconds interval( static_cast<TInt64>( 0 ) );
       
   142     LOG2( SIMPLE,
       
   143     "SATINTERNALCLIENT: CSatCPlayToneHandler::RunL \
       
   144     iPlayToneData.iDuration.iTimeUnit: %d",iPlayToneData.iDuration.iTimeUnit )
       
   145     switch ( iPlayToneData.iDuration.iTimeUnit )
       
   146         {
       
   147         case RSat::EMinutes:
       
   148             {
       
   149             TInt64 temp1(
       
   150             static_cast<TInt>( iPlayToneData.iDuration.iNumOfUnits ) );
       
   151             TInt64 temp2( KSatCMicroSecondsInMinute );
       
   152             interval = temp1 * temp2;
       
   153             break;
       
   154             }
       
   155         case RSat::ESeconds:
       
   156             {
       
   157             interval = iPlayToneData.iDuration.iNumOfUnits *
       
   158                 KSatCMicroSecondsInSecond;
       
   159             break;
       
   160             }
       
   161         case RSat::ETenthsOfSeconds:
       
   162             {
       
   163             interval = iPlayToneData.iDuration.iNumOfUnits *
       
   164                 KSatCMicroSecondsInOneTenthSecond;
       
   165             break;
       
   166             }
       
   167         case RSat::ETimeUnitNotSet:
       
   168         case RSat::ENoDurationAvailable:
       
   169             {
       
   170             // We are defaulting to 5 seconds in S60
       
   171             interval = KSatPtDefaultDuration *
       
   172                 KSatCMicroSecondsInSecond;
       
   173             break;
       
   174             }
       
   175         default:
       
   176             {
       
   177             LOG( SIMPLE, "SATINTERNALCLIENT: Unexpected time unit" )
       
   178             }
       
   179         }
       
   180     // Set the type of tone to be played.
       
   181     // Cannot use static_cast directly because of GCC
       
   182     TSatTone dialTone( static_cast<TSatTone>(
       
   183         static_cast<TInt>( iPlayToneData.iTone ) ) );
       
   184 
       
   185     // Has to be casted to TInt before casting to TSatIconQualifier, because
       
   186     // GCC warns about the direct cast.
       
   187     const struct TSatIconId iconId = { iPlayToneData.iIconId.iIdentifier,
       
   188         static_cast<TSatIconQualifier>(
       
   189             static_cast<TInt>( iPlayToneData.iIconId.iQualifier ) ) };
       
   190 
       
   191     // This will contain EFalse if requested icon is not displayed.
       
   192     // And if icon is displayed, it contains ETrue.
       
   193     TBool requestedIconDisplayed( EFalse );
       
   194 
       
   195     // Notify the registered client and save the response.
       
   196     TSatUiResponse response = iSession->SatUiObserver()->PlayTone(
       
   197         iPlayToneData.iAlphaId.iAlphaId, dialTone, interval,
       
   198         iconId, requestedIconDisplayed );
       
   199 
       
   200     // This command never has any additional information.
       
   201     iPlayToneRsp.iInfoType = RSat::KNoAdditionalInfo;
       
   202     iPlayToneRsp.iAdditionalInfo.Zero();
       
   203 
       
   204     iPlayToneRsp.SetPCmdNumber( iPlayToneData.PCmdNumber() );
       
   205 
       
   206     // Examine the client response.
       
   207     ExamineClientResponse(
       
   208         response, requestedIconDisplayed );
       
   209 
       
   210     // Pass the Play Tone response IPC package.
       
   211     TIpcArgs arguments( &iPlayToneRspPckg );
       
   212 
       
   213     // Perform the IPC data transfer.
       
   214     iSession->CreateRequest( ESatSProactivePlayToneResponse, arguments );
       
   215 
       
   216     // Renew the request
       
   217     Start();
       
   218 
       
   219     LOG( SIMPLE, "SATINTERNALCLIENT: CSatCPlayToneHandler::RunL exiting" )
       
   220     }
       
   221 
       
   222 // -----------------------------------------------------------------------------
       
   223 // CSatCPlayToneHandler::ExamineClientResponse
       
   224 // Examine the client response.
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 void CSatCPlayToneHandler::ExamineClientResponse(
       
   228     TSatUiResponse aResponse,
       
   229     TBool aRequestedIconDisplayed )
       
   230     {
       
   231     LOG2( SIMPLE,
       
   232     "SATINTERNALCLIENT: CSatCPlayToneHandler::ExamineClientResponse calling,\
       
   233     aResponse: %x", aResponse )
       
   234 
       
   235     // Examine the client response.
       
   236     switch ( aResponse )
       
   237         {
       
   238         case ESatSuccess:
       
   239         case ESatSuccessToneNotPlayed: // for future use,
       
   240         // specified in ETSI spec but not currently implemented in etelsat.
       
   241             {
       
   242             // Convert terminal rsp if icon used
       
   243             RSat::TPCmdResult result( RSat::KSuccess );
       
   244             RSat::TIconQualifier iconQualifier(
       
   245                 iPlayToneData.iIconId.iQualifier );
       
   246 
       
   247             if ( !aRequestedIconDisplayed )
       
   248                 {
       
   249                 LOG( SIMPLE,
       
   250                 "SATINTERNALCLIENT: CSatCPlayToneHandler::ExamineClientResponse \
       
   251                 aRequestedIconDisplayed false" )
       
   252                 if ( iconQualifier == RSat::ESelfExplanatory ||
       
   253                      iconQualifier == RSat::ENotSelfExplanatory )
       
   254                     {
       
   255                     LOG( SIMPLE,
       
   256                     "SATINTERNALCLIENT: CSatCPlayToneHandler::ExamineClientResponse \
       
   257                     IconNotDisplayed" )
       
   258                     result = RSat::KSuccessRequestedIconNotDisplayed;
       
   259                     }
       
   260                 }
       
   261 
       
   262             iPlayToneRsp.iGeneralResult = result;
       
   263             break;
       
   264             }
       
   265         case ESatFailure:
       
   266             {
       
   267             iPlayToneRsp.iInfoType = RSat::KMeProblem;
       
   268             iPlayToneRsp.iGeneralResult = RSat::KMeUnableToProcessCmd;
       
   269             iPlayToneRsp.iAdditionalInfo.SetLength( 1 );
       
   270             iPlayToneRsp.iAdditionalInfo[0] = RSat::KNoSpecificMeProblem;
       
   271             break;
       
   272             }
       
   273         case ESatSessionTerminatedByUser:
       
   274             {
       
   275             iPlayToneRsp.iGeneralResult = RSat::KPSessionTerminatedByUser;
       
   276             break;
       
   277             }
       
   278         case ESatBackwardModeRequestedByUser:
       
   279             {
       
   280             iPlayToneRsp.iGeneralResult =
       
   281                 RSat::KBackwardModeRequestedByUser;
       
   282             break;
       
   283             }
       
   284         case ESatNoResponseFromUser:
       
   285             {
       
   286             iPlayToneRsp.iGeneralResult = RSat::KNoResponseFromUser;
       
   287             break;
       
   288             }
       
   289         case ESatCmdDataNotUnderstood:
       
   290             {
       
   291             iPlayToneRsp.iGeneralResult = RSat::KCmdDataNotUnderstood;
       
   292             iPlayToneRsp.iInfoType = RSat::KNoAdditionalInfo;
       
   293             iPlayToneRsp.iAdditionalInfo.Zero();
       
   294             break;
       
   295             }
       
   296         // No help is ever available with this command.
       
   297         case EHelpRequestedByUser:
       
   298         case EPCmdNotAcceptedByUser:
       
   299         default:
       
   300             {
       
   301             iSession->Panic( ESatInvalidResponse );
       
   302             break;
       
   303             }
       
   304         }
       
   305 
       
   306     LOG( SIMPLE,
       
   307         "SATINTERNALCLIENT: CSatCPlayToneHandler::ExamineClientResponse exiting" )
       
   308     }
       
   309 
       
   310 // -----------------------------------------------------------------------------
       
   311 // CSatCPlayToneHandler::DoCancel
       
   312 // Cancels the pending request.
       
   313 // -----------------------------------------------------------------------------
       
   314 //
       
   315 void CSatCPlayToneHandler::DoCancel()
       
   316     {
       
   317     LOG( SIMPLE, "SATINTERNALCLIENT: CSatCPlayToneHandler::DoCancel calling" )
       
   318 
       
   319     // Complete the request with cancel code.
       
   320     TRequestStatus* requestStatus = &iStatus;
       
   321     User::RequestComplete( requestStatus, KErrCancel );
       
   322 
       
   323     LOG( SIMPLE, "SATINTERNALCLIENT: CSatCPlayToneHandler::DoCancel exiting" )
       
   324     }