phoneclientserver/phoneserver/Src/Ussd/CPhSrvUssdReceiveHandler.cpp
changeset 0 ff3b6d0fd310
child 19 7d48bed6ce0c
equal deleted inserted replaced
-1:000000000000 0:ff3b6d0fd310
       
     1 /*
       
     2 * Copyright (c) 2002 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:  Ussd Handler Receive.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CPhSrvUssdReceiveHandler.h"
       
    22 #include "MPhSrvUssdNetworkObserver.h"
       
    23 
       
    24 
       
    25 // CONSTANTS
       
    26 const TInt KPhSrvUssdReceiverPriority = CActive::EPriorityLow + 2;
       
    27 
       
    28 
       
    29 
       
    30 // ============================ MEMBER FUNCTIONS ===============================
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CPhSrvUssdReceiveHandler::CPhSrvUssdReceiveHandler
       
    34 // 
       
    35 // C++ constructor
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 /*****************************************************
       
    39 *   Series 60 Customer / ETel
       
    40 *   Series 60  ETel API
       
    41 *****************************************************/
       
    42 CPhSrvUssdReceiveHandler::CPhSrvUssdReceiveHandler(
       
    43     MPhSrvUssdNetworkObserver& aObserver,
       
    44     RMobileUssdMessaging& aUssdMessaging)
       
    45     :    CActive(KPhSrvUssdReceiverPriority), 
       
    46          iAutoReceive( ETrue ), // the value is hardcoded here.
       
    47          iObserver( aObserver ),
       
    48          iUssdMessaging( aUssdMessaging ),
       
    49          iMsgAttributesPckg( iMsgAttributes )
       
    50     {
       
    51     CActiveScheduler::Add( this );
       
    52     iMsgData.Zero();
       
    53     }
       
    54 
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CPhSrvUssdReceiveHandler::~CPhSrvUssdReceiveHandler
       
    58 // 
       
    59 // C++ Destructor
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CPhSrvUssdReceiveHandler::~CPhSrvUssdReceiveHandler()
       
    63     {
       
    64     Cancel();
       
    65     }
       
    66 
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CPhSrvUssdReceiveHandler::ConstructL
       
    70 // 
       
    71 // Symbian OS 2nd phase constructor
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 void CPhSrvUssdReceiveHandler::ConstructL()
       
    75     {
       
    76     // Start receiving automatically if wanted.
       
    77     if ( iAutoReceive )
       
    78         {
       
    79         User::LeaveIfError( StartReceiving() );
       
    80         }
       
    81     }
       
    82 
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CPhSrvUssdReceiveHandler::StartReceiving
       
    86 // 
       
    87 // Start receiving a message
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 /*****************************************************
       
    91 *   Series 60 Customer / ETel
       
    92 *   Series 60  ETel API
       
    93 *****************************************************/
       
    94 TInt CPhSrvUssdReceiveHandler::StartReceiving()
       
    95     {
       
    96     if ( IsActive() )
       
    97         {
       
    98         return KErrInUse;
       
    99         } 
       
   100 
       
   101     iUssdMessaging.ReceiveMessage( iStatus, iMsgData , iMsgAttributesPckg );
       
   102     SetActive();
       
   103     return KErrNone;
       
   104     }
       
   105 
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CPhSrvUssdReceiveHandler::RunL
       
   109 // 
       
   110 // Called when a message is received
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 void CPhSrvUssdReceiveHandler::RunL()
       
   114     {
       
   115     TInt error = iStatus.Int();
       
   116     if ( error == KErrCancel )
       
   117         {
       
   118         return;
       
   119         }
       
   120     iObserver.UssdNetworkObserverHandleReceivedEventL( 
       
   121         iMsgData, 
       
   122         iMsgAttributes, 
       
   123         error );
       
   124     
       
   125     if ( iAutoReceive && error != KErrCancel && error != KErrNotSupported )
       
   126         {
       
   127         StartReceiving();
       
   128         }
       
   129     }
       
   130 
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CPhSrvUssdReceiveHandler::DoCancel
       
   134 // 
       
   135 // Cancel a pending request
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 /*****************************************************
       
   139 *   Series 60 Customer / ETel
       
   140 *   Series 60  ETel API
       
   141 *****************************************************/
       
   142 void CPhSrvUssdReceiveHandler::DoCancel()
       
   143     {
       
   144     iUssdMessaging.CancelAsyncRequest( EMobileUssdMessagingReceiveMessage );
       
   145     }
       
   146 
       
   147 
       
   148 // -----------------------------------------------------------------------------
       
   149 // CPhSrvUssdReceiveHandler::RunError
       
   150 // 
       
   151 // Called when RunL leaves
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 TInt CPhSrvUssdReceiveHandler::RunError( TInt aError )
       
   155     {
       
   156     // Shows an error note.
       
   157     TRAP_IGNORE(  iObserver.UssdNetworkObserverHandleReceivedEventL( 
       
   158         iMsgData, iMsgAttributes , aError ) );
       
   159     
       
   160     if ( iAutoReceive )
       
   161         {
       
   162         StartReceiving();
       
   163         }
       
   164     
       
   165     return KErrNone;
       
   166     }
       
   167 
       
   168 
       
   169 //  End of File