satengine/SatServer/Commands/PlayToneCmd/src/CPlayToneHandler.cpp
changeset 0 ff3b6d0fd310
child 22 71268bfa7aea
equal deleted inserted replaced
-1:000000000000 0:ff3b6d0fd310
       
     1 /*
       
     2 * Copyright (c) 2002-2007 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:  Handles PlayTone command
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include    "MSatApi.h"
       
    20 #include    "MSatUtils.h"
       
    21 #include    "MSatUiSession.h"
       
    22 #include    "MSatSystemState.h"
       
    23 #include    "SatSOpcodes.h"
       
    24 #include    "MSatSUiClientHandler.h"
       
    25 #include    "CPlayToneHandler.h"
       
    26 #include    "SatLog.h"
       
    27 
       
    28 // ======== MEMBER FUNCTIONS ========
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // Two-phased constructor.
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 CPlayToneHandler* CPlayToneHandler::NewL( MSatUtils* aUtils )
       
    35     {
       
    36     LOG( SIMPLE, "PLAYTONE: CPlayToneHandler::NewL calling" )
       
    37 
       
    38     CPlayToneHandler* self = new( ELeave ) CPlayToneHandler;
       
    39 
       
    40     CleanupStack::PushL( self );
       
    41     self->BaseConstructL( aUtils );
       
    42     self->ConstructL();
       
    43     CleanupStack::Pop( self );
       
    44 
       
    45     LOG( SIMPLE, "PLAYTONE: CPlayToneHandler::NewL exiting" )
       
    46     return self;
       
    47     }
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // Destructor.
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CPlayToneHandler::~CPlayToneHandler()
       
    54     {
       
    55     LOG( SIMPLE, "PLAYTONE: CPlayToneHandler::~CPlayToneHandler calling" )
       
    56 
       
    57     Cancel();
       
    58 
       
    59     LOG( SIMPLE, "PLAYTONE: CPlayToneHandler::~CPlayToneHandler exiting" )
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // From class MSatCommand.
       
    64 // Response from the client.
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 void CPlayToneHandler::ClientResponse()
       
    68     {
       
    69     LOG( SIMPLE, "PLAYTONE: CPlayToneHandler::ClientResponse calling" )
       
    70 
       
    71     iPlayToneRsp.SetPCmdNumber( iPlayToneData.PCmdNumber() );
       
    72     if ( RSat::KPSessionTerminatedByUser == iPlayToneRsp.iGeneralResult )
       
    73         {
       
    74         LOG( SIMPLE, "PLAYTONE: CPlayToneHandler::ClientResponse \
       
    75              KPSessionTerminatedByUser" )
       
    76         // Next SimSession end will close the ui session.
       
    77         iUtils->NotifyEvent( MSatUtils::ESessionTerminatedByUser );
       
    78         }
       
    79         
       
    80     // If command had icon data and was done succesfully, report that icon
       
    81     // was not shown
       
    82     // To be removed when icons are allowed in this command
       
    83     if ( ( RSat::KSuccess == iPlayToneRsp.iGeneralResult ) &&
       
    84         iIconCommand )
       
    85         {
       
    86         LOG( SIMPLE, "PLAYTONE: CPlayToneHandler::ClientResponse \
       
    87              requested icon not displayed" )
       
    88         iPlayToneRsp.iGeneralResult =
       
    89                     RSat::KSuccessRequestedIconNotDisplayed;
       
    90         }
       
    91 
       
    92     CSatCommandHandler::TerminalRsp( RSat::EPlayTone, iPlayToneRspPckg );
       
    93 
       
    94     LOG( SIMPLE, "PLAYTONE: CPlayToneHandler::ClientResponse exiting" )
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // From class CActive.
       
    99 // Cancels the sat request.
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 void CPlayToneHandler::DoCancel()
       
   103     {
       
   104     LOG( SIMPLE, "PLAYTONE: CPlayToneHandler::DoCancel calling" )
       
   105 
       
   106     iUtils->USatAPI().NotifyPlayToneCancel();
       
   107 
       
   108     LOG( SIMPLE, "PLAYTONE: CPlayToneHandler::DoCancel exiting" )
       
   109     }
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // From class CSatCommandHandler.
       
   113 // Requests the command notification.
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 void CPlayToneHandler::IssueUSATRequest( TRequestStatus& aStatus )
       
   117     {
       
   118     LOG( SIMPLE, "PLAYTONE: CPlayToneHandler::IssueUSATRequest calling" )
       
   119 
       
   120     // Clear the IPC package.
       
   121     new (&iPlayToneData) RSat::TPlayToneV2();
       
   122     iPlayToneRsp.iGeneralResult = RSat::KPSessionTerminatedByUser; // default
       
   123 
       
   124     iUtils->USatAPI().NotifyPlayTone( aStatus, iPlayTonePckg );
       
   125 
       
   126     LOG( SIMPLE, "PLAYTONE: CPlayToneHandler::IssueUSATRequest exiting" )
       
   127     }
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // From class CSatCommandHandler.
       
   131 // Precheck before executing the command.
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 TBool CPlayToneHandler::CommandAllowed()
       
   135     {
       
   136     LOG( SIMPLE, "PLAYTONE: CPlayToneHandler::CommandAllowed calling" )
       
   137     TBool allowed( ETrue );
       
   138 
       
   139     // This is used to determine zero length duration.
       
   140     const TBool zeroDuration( iPlayToneData.iDuration.iNumOfUnits == 0 );
       
   141     // Determines is it standard supervisory tone.
       
   142     const TBool standardSupervisoryTone(
       
   143         ( iPlayToneData.iTone >= RSat::KDialTone ) &&
       
   144         ( iPlayToneData.iTone <= RSat::KRingingTone ) );
       
   145     // Determines is it terminal proprietary tone
       
   146     const TBool terminalProprietaryTone(
       
   147         ( iPlayToneData.iTone >= RSat::KGeneralBeep ) &&
       
   148         ( iPlayToneData.iTone <= RSat::KUserSelectedToneIncomingSms ) );
       
   149     const TBool durationValid(
       
   150         ( RSat::ENoDurationAvailable != iPlayToneData.iDuration.iTimeUnit ) &&
       
   151         ( RSat::ETimeUnitNotSet != iPlayToneData.iDuration.iTimeUnit ) );
       
   152 
       
   153     // if icon data is received without alpha id,
       
   154     // command data is not understood.
       
   155     //lint -e{961} Else block not needed, allowed is then true.
       
   156     if ( ( RSat::EAlphaIdProvided != iPlayToneData.iAlphaId.iStatus ) &&
       
   157             ( RSat::ENotSelfExplanatory == iPlayToneData.iIconId.iQualifier ||
       
   158               RSat::ESelfExplanatory == iPlayToneData.iIconId.iQualifier ) )
       
   159         {
       
   160         allowed = EFalse;
       
   161         iPlayToneRsp.iGeneralResult = RSat::KCmdDataNotUnderstood;
       
   162         iPlayToneRsp.iInfoType = RSat::KNoAdditionalInfo;
       
   163         iPlayToneRsp.iAdditionalInfo.Zero();
       
   164         LOG( SIMPLE,
       
   165             "PLAYTONE: CPlayToneHandler::CommandAllowed \
       
   166             icon received without alpha id" )
       
   167         }
       
   168     // If the tone is not standard or terminal proprietary OR it is
       
   169     // standard without duration, command is not allowed.
       
   170     else if ( iPlayToneData.iTone != RSat::KToneNotSet &&
       
   171             ( !( standardSupervisoryTone ^ terminalProprietaryTone ) ||
       
   172                ( zeroDuration && durationValid ) ) )
       
   173         {
       
   174         allowed = EFalse;
       
   175         iPlayToneRsp.iGeneralResult = RSat::KCmdDataNotUnderstood;
       
   176         iPlayToneRsp.iInfoType = RSat::KNoAdditionalInfo;
       
   177         iPlayToneRsp.iAdditionalInfo.Zero();
       
   178         LOG( SIMPLE,
       
   179             "PLAYTONE: CPlayToneHandler::CommandAllowed \
       
   180             Not valid tone or duration" )
       
   181         }
       
   182     // If alpha id is not to be shown and 
       
   183     // tones are not ON command is not allowed.
       
   184     else if ( !iUtils->SystemState().IsWarningAndGameTonesOn() &&
       
   185              ( 0 == iPlayToneData.iAlphaId.iAlphaId.Length() ) )
       
   186         {
       
   187         allowed = EFalse;
       
   188         iPlayToneRsp.iGeneralResult = RSat::KMeUnableToProcessCmd;
       
   189         iPlayToneRsp.iInfoType = RSat::KNoAdditionalInfo;
       
   190         iPlayToneRsp.iAdditionalInfo.Zero();
       
   191         LOG( SIMPLE,
       
   192             "PLAYTONE: CPlayToneHandler::CommandAllowed \
       
   193             Tones are OFF" )
       
   194         }
       
   195     // Set icon command flag whether icon data was received and set qualifier
       
   196     // to no icon id
       
   197     // To be removed when icons are allowed in this command
       
   198     else if ( ( RSat::ESelfExplanatory ==
       
   199         iPlayToneData.iIconId.iQualifier ) ||
       
   200         ( RSat::ENotSelfExplanatory ==
       
   201         iPlayToneData.iIconId.iQualifier ) )
       
   202         {
       
   203         LOG( SIMPLE,
       
   204             "PLAYTONE: CPlayToneHandler::CommandAllowed ENoIconId" )
       
   205         iIconCommand = ETrue;
       
   206         iPlayToneData.iIconId.iQualifier = RSat::ENoIconId;
       
   207         }
       
   208     else
       
   209         {
       
   210         LOG( SIMPLE,
       
   211             "PLAYTONE: CPlayToneHandler::CommandAllowed others" )
       
   212         iIconCommand = EFalse;
       
   213         }
       
   214         
       
   215     // if not allowed, send terminal response immediatelly.
       
   216     if ( !allowed )
       
   217         {
       
   218         LOG( SIMPLE,
       
   219             "PLAYTONE: CPlayToneHandler::CommandAllowed allowed false" )
       
   220         iPlayToneRsp.SetPCmdNumber( iPlayToneData.PCmdNumber() );
       
   221         // Send terminal response.
       
   222         TerminalRsp( RSat::EPlayTone, iPlayToneRspPckg );
       
   223         }
       
   224 
       
   225     LOG2( SIMPLE, "PLAYTONE: CPlayToneHandler::CommandAllowed exiting,\
       
   226           allowed: %d", allowed )
       
   227     return allowed;
       
   228     }
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // From class CSatCommandHandler.
       
   232 // Answers for need of UI session.
       
   233 // -----------------------------------------------------------------------------
       
   234 //
       
   235 TBool CPlayToneHandler::NeedUiSession()
       
   236     {
       
   237     LOG( NORMAL, "PLAYTONE: CPlayToneHandler::NeedUiSession calling" )
       
   238 
       
   239     // Notify Cover UI if it's supported
       
   240     if ( iUtils->CoverUiSupported() )
       
   241         {
       
   242         LOG( NORMAL, "PLAYTONE: CPlayToneHandler::NeedUiSession \
       
   243              CoverUiSupported" )
       
   244         TSatCommandData medEventData;
       
   245         medEventData.iPCmdNumber = RSat::EPlayTone;
       
   246         medEventData.iAlphaId = iPlayToneData.iAlphaId;
       
   247         medEventData.iDuration = iPlayToneData.iDuration;
       
   248         medEventData.iIconID = iPlayToneData.iIconId;
       
   249         TSatCommandPckg tPckg( medEventData );
       
   250         iUtils->RaiseSatEvent( tPckg );
       
   251         }
       
   252 
       
   253     LOG( NORMAL, "PLAYTONE: CPlayToneHandler::NeedUiSession exiting" )
       
   254     return ETrue;
       
   255     }
       
   256 
       
   257 // -----------------------------------------------------------------------------
       
   258 // From class CSatCommandHandler.
       
   259 // Called when USAT API notifies that command.
       
   260 // -----------------------------------------------------------------------------
       
   261 //
       
   262 void CPlayToneHandler::HandleCommand()
       
   263     {
       
   264     LOG( SIMPLE, "PLAYTONE: CPlayToneHandler::HandleCommand calling" )
       
   265 
       
   266     iUtils->NotifyEvent( MSatUtils::EPlayToneExecuting );
       
   267 
       
   268     MSatUiSession* uiSession = iUtils->SatUiHandler().UiSession();
       
   269     uiSession->SendCommand(
       
   270         &iPlayTonePckg,
       
   271         &iPlayToneRspPckg,
       
   272         ESatSProactivePlayTone );
       
   273 
       
   274     LOG( SIMPLE, "PLAYTONE: CPlayToneHandler::HandleCommand exiting" )
       
   275     }
       
   276 
       
   277 // -----------------------------------------------------------------------------
       
   278 // From class CSatCommandHandler.
       
   279 // Indicates the failure of launching ui client.
       
   280 // -----------------------------------------------------------------------------
       
   281 //
       
   282 void CPlayToneHandler::UiLaunchFailed()
       
   283     {
       
   284     LOG( SIMPLE, "PLAYTONE: CPlayToneHandler::UiLaunchFailed calling" )
       
   285 
       
   286     iPlayToneRsp.iGeneralResult = RSat::KMeUnableToProcessCmd;
       
   287     iPlayToneRsp.iInfoType = RSat::KMeProblem;
       
   288     iPlayToneRsp.iAdditionalInfo.SetLength( 1 );
       
   289     iPlayToneRsp.iAdditionalInfo[0] = RSat::KNoSpecificMeProblem;
       
   290     iPlayToneRsp.SetPCmdNumber( iPlayToneData.PCmdNumber() );
       
   291     TerminalRsp( RSat::EPlayTone, iPlayToneRspPckg );
       
   292 
       
   293     LOG( SIMPLE, "PLAYTONE: CPlayToneHandler::UiLaunchFailed exiting" )
       
   294     }
       
   295 
       
   296 // -----------------------------------------------------------------------------
       
   297 // C++ default constructor can NOT contain any code, that
       
   298 // might leave.
       
   299 // -----------------------------------------------------------------------------
       
   300 //
       
   301 
       
   302 CPlayToneHandler::CPlayToneHandler() :
       
   303     CSatCommandHandler(),
       
   304     iPlayToneData(),
       
   305     iPlayTonePckg( iPlayToneData ),
       
   306     iPlayToneRsp(),
       
   307     iPlayToneRspPckg( iPlayToneRsp ),
       
   308     // To be removed when icons are allowed in this command
       
   309     iIconCommand( EFalse )
       
   310     {
       
   311     LOG( SIMPLE,
       
   312         "PLAYTONE: CPlayToneHandler::CPlayToneHandler calling - exiting" )
       
   313     }
       
   314 
       
   315 // -----------------------------------------------------------------------------
       
   316 // Symbian 2nd phase constructor can leave.
       
   317 // -----------------------------------------------------------------------------
       
   318 //
       
   319 void CPlayToneHandler::ConstructL()
       
   320     {
       
   321     LOG( SIMPLE, "PLAYTONE: CPlayToneHandler::ConstructL calling" )
       
   322 
       
   323     // Register service request handler for PlayTone command.
       
   324     iUtils->RegisterServiceRequestL(
       
   325         ESatSProactivePlayTone,
       
   326         ESatSProactivePlayToneResponse,
       
   327         this );
       
   328 
       
   329     LOG( SIMPLE, "PLAYTONE: CPlayToneHandler::ConstructL exiting" )
       
   330     }
       
   331