phoneclientserver/phoneserver/Inc/Ussd/CPhSrvUssdManager.h
changeset 46 2fa1fa551b0b
parent 42 35488577e233
child 48 78df25012fda
equal deleted inserted replaced
42:35488577e233 46:2fa1fa551b0b
     1 /*
       
     2 * Copyright (c) 2002-2010 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 all the Ussd sessions.
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef CPHSRVUSSDMANAGER_H
       
    19 #define CPHSRVUSSDMANAGER_H
       
    20 
       
    21 
       
    22 // INCLUDES
       
    23 #include <etelmm.h>            // ETel
       
    24 #include "phcltclientserver.h" 
       
    25 #include "mphsrvussdnetworkobserver.h" 
       
    26 #include "mphsrvussdreplytimerobserver.h" 
       
    27 #include <badesca.h>
       
    28 #include <hbdevicemessageboxsymbian.h>
       
    29 
       
    30 // FORWARD DECLARATIONS
       
    31 class RFs;
       
    32 class CPhSrvResourceManager;
       
    33 class CPhSrvUssdSendHandler;
       
    34 class CPhSrvUssdReceiveHandler;
       
    35 class CPhSrvUssdReplyTimer;
       
    36 class MPhSrvPhoneInterface;
       
    37 class MPhSrvUssdMessageSentObserver;
       
    38 class CPhSrvUssdSessionCancelWaiter;
       
    39 class CPhSrvUssdNotifyNWRelease;
       
    40 
       
    41 // CLASS DECLARATION
       
    42 
       
    43 /**
       
    44 *  Handles all the Ussd sessions.
       
    45 *
       
    46 *  @since 1.0
       
    47 */
       
    48 class CPhSrvUssdManager : 
       
    49     public CActive, 
       
    50     public MPhSrvUssdNetworkObserver, 
       
    51     public MPhSrvUssdReplyTimerObserver,
       
    52     public MHbDeviceMessageBoxObserver
       
    53     {
       
    54     public:  // Constructors and destructor
       
    55 
       
    56         /**
       
    57         * C++ constructor.
       
    58         *
       
    59         * @param aFsSession The file session.
       
    60         * @param aResourceManager The resource manager.
       
    61         */
       
    62         CPhSrvUssdManager( 
       
    63             RFs& aFsSession, 
       
    64             CPhSrvResourceManager& aResourceManager
       
    65          );
       
    66 
       
    67         /**
       
    68         * C++ destructor.
       
    69         */
       
    70         ~CPhSrvUssdManager();
       
    71         
       
    72         /**
       
    73         * Symbian OS second phase constructor
       
    74         *
       
    75         * @param aPhoneInterface The phone interfaces.
       
    76         */
       
    77         void ConstructL( MPhSrvPhoneInterface& aPhoneInterface );
       
    78         
       
    79 
       
    80     public: // New functions
       
    81         
       
    82         /**
       
    83         * Send the USSD message.
       
    84         * 
       
    85         * @param aMsgData The USSD message to be sent.
       
    86         * @param aMsgAttribute The USSD message attributes.
       
    87         * @param aObserver Observer for sent event.
       
    88         */
       
    89         void SendUssdL( 
       
    90             const TDesC8& aMsgData, 
       
    91             RMobileUssdMessaging::TMobileUssdAttributesV1& aMsgAttribute, 
       
    92             MPhSrvUssdMessageSentObserver& aObserver );
       
    93 
       
    94         /**
       
    95         * Cancel sending the USSD.
       
    96         */
       
    97         void SendUssdCancel();
       
    98 
       
    99         
       
   100         /**
       
   101         * These are called when status of Ussd application changes.
       
   102         * 
       
   103         * @return 0 if editor should not be cleared.
       
   104         */
       
   105         void InformUssdApplicationStarting();
       
   106         void InformUssdApplicationTerminatingL( const RMessage2& aMessage );
       
   107         TInt InformUssdApplicationToForeground();      
       
   108         void InformUssdApplicationToBackground();
       
   109         
       
   110         /**
       
   111         * Starts the editor.
       
   112         */
       
   113         void RequestStartEditingL();
       
   114 
       
   115         /**
       
   116         * SAT starts.
       
   117         *
       
   118         * @param aSatMessage Message to be comleted when session ends.
       
   119         */
       
   120         void InformStartSAT( const RMessage2& aSatMessage );
       
   121 
       
   122         /**
       
   123         * SAT ends.
       
   124         */
       
   125         void InformStopSAT();
       
   126         
       
   127         /**
       
   128         * Completes SAT request if it's ongoing.
       
   129         *
       
   130         * @param aReceiveString If session end with a string it is passed
       
   131         *        as a paramter.
       
   132         * @param aError Completion code.
       
   133         * @return The error code of the SAT request.
       
   134         */
       
   135          void CompleteSatL( 
       
   136             TDesC* aReceiveString, 
       
   137             TInt aError );
       
   138         
       
   139     protected: // From base classes
       
   140         
       
   141         /**
       
   142         * @see MPhSrvUssdNetworkObserver
       
   143         */
       
   144         void UssdNetworkObserverHandleSendEventL( TInt aError );
       
   145         
       
   146         /**
       
   147         * @see MPhSrvUssdNetworkObserver
       
   148         */
       
   149         void UssdNetworkObserverHandleReceivedEventL(
       
   150             const TDes8& aMsgData, 
       
   151             const RMobileUssdMessaging::TMobileUssdAttributesV1& 
       
   152                   aMsgAttributes,
       
   153             TInt aError );
       
   154 
       
   155         void UssdNetworkObserverHandleNotifyNWReleaseL( 
       
   156         const RMobilePhone::TMobilePhoneSendSSRequestV3 & aReturnResult, 
       
   157         TInt aError );
       
   158         
       
   159         /**
       
   160         * @see MPhSrvUssdReplyTimerObserver
       
   161         */
       
   162         void UssdReplyTimerObserverHandleExpiredL( TInt aError );
       
   163         
       
   164         /**
       
   165         * @see MHbDeviceMessageBoxObserver
       
   166         */        
       
   167         void MessageBoxClosed(const CHbDeviceMessageBoxSymbian* aMessageBox,
       
   168             CHbDeviceMessageBoxSymbian::TButtonId aButton);
       
   169         
       
   170         /*
       
   171         * @see CActive
       
   172         */
       
   173         void RunL();
       
   174         
       
   175         /*
       
   176         * @see CActive
       
   177         */
       
   178         void DoCancel();
       
   179         
       
   180         /*
       
   181         * @see CActive
       
   182         */
       
   183         TInt RunError( TInt aError );
       
   184 
       
   185     private: // New functions
       
   186         
       
   187         CPhSrvUssdSendHandler& SendHandlerL();
       
   188 
       
   189         void ShowErrorNoteL( TInt aError );
       
   190 
       
   191         void DecodeL( 
       
   192             const TDesC8& aSrc, 
       
   193             TDes& aDes, 
       
   194             TUint8 aDcs );
       
   195        
       
   196         void FindFirstCarriageReturnL( 
       
   197             const TDesC8& aBuffer ,
       
   198             TUint& aSkipChars , 
       
   199             TUint& aStartBit );
       
   200         
       
   201         /** Display the "Done" note */
       
   202         void ShowDoneNoteL();
       
   203         
       
   204         /** Check is the ussd app running 
       
   205          * @return app running or not
       
   206          */
       
   207         TBool UssdAppTaskExistsL();
       
   208         
       
   209         // If the notification array is empty, close the session.
       
   210         void TryCloseSession();
       
   211         
       
   212         // Close the session; clear state etc.
       
   213         void CloseSession();
       
   214         
       
   215         /** Second stage handler for received messages 
       
   216          */
       
   217         void UssdHandleReceivedEventL(
       
   218             const TDes8& aMsgData, 
       
   219             const RMobileUssdMessaging::TMobileUssdAttributesV1& 
       
   220                   aMsgAttributes);
       
   221         // Restart the reply timer
       
   222         void RestartReplyTimerL();
       
   223         
       
   224         /** Is the reply timer up and running? */
       
   225         TBool NetworkWaitingForAnAnswer();
       
   226         
       
   227         // Set timer and activate it if there are notifications available
       
   228         void SetActiveIfPendingNotificationsExist();
       
   229         
       
   230         // Launch the global message query (used from RunL)
       
   231         void LaunchGlobalMessageQueryL();
       
   232         
       
   233         // Send an MO ACK message if any such are pending
       
   234         void ProcessMoAcksL();
       
   235         
       
   236         // Trigger an asynchronous call to call ProcessMoAcksL later
       
   237         void AsyncProcessMoAcks();
       
   238         
       
   239         // The static callback function for AsyncProcessMoAcks
       
   240         static TInt MoAckCallback(TAny *);
       
   241         
       
   242         /**
       
   243         * Return boolean value that states whether or not 
       
   244         * indicated feature is supported or not.
       
   245         * 
       
   246         * @since 2.1
       
   247         * @param aFeatureId The feature that is inspected 
       
   248         *        (see values from Telephony_Variant.hrh)
       
   249         * @return ETrue if the feature is supported, EFalse otherwise.
       
   250         */
       
   251         TBool IsTelephonyFeatureSupported( const TInt aFeatureId );
       
   252 
       
   253         /**
       
   254         * Play USSD tone.
       
   255         * 
       
   256         * @since 2.1
       
   257         * @return KErrNone if successful, otherwise Symbian error code.
       
   258         */
       
   259         TInt PlayUssdTone();
       
   260 
       
   261         /**
       
   262         * Returns telephony variant read-only data.
       
   263         * 
       
   264         * @since 2.1
       
   265         * @return Error code.
       
   266         */
       
   267         TInt GetTelephonyVariantData();
       
   268 
       
   269         /**
       
   270         * Send the MO acknowledgement.
       
   271         * 
       
   272         * @since 2.6
       
   273         */
       
   274         void SendMoAcknowledgementL();
       
   275         
       
   276         /**
       
   277         * Return boolean value that states whether notes are shown or not
       
   278         * 
       
   279         * @since 3.0
       
   280         */
       
   281         TBool ShowNotesL();
       
   282         
       
   283         /**
       
   284         * Check notify message array
       
   285         * 
       
   286         * @since 3.1
       
   287         */
       
   288         void CheckArray( );
       
   289         
       
   290         /**
       
   291         * Clears notify message array
       
   292         * 
       
   293         * @since 3.1
       
   294         */
       
   295         void ClearArrayL();
       
   296         
       
   297         /**
       
   298         * Returns notify message count
       
   299         * 
       
   300         * @since 3.1
       
   301         */
       
   302         TInt NotifyCount();
       
   303         
       
   304         
       
   305         /**
       
   306         * Updates Notify Message
       
   307         * 
       
   308         * @since 3.1
       
   309         */
       
   310         void UpdateNotifyMessageL();
       
   311         
       
   312         /**
       
   313         * Turn lights on
       
   314         * 
       
   315         * @since 3.1
       
   316         */
       
   317         void TurnLightsOn();
       
   318         
       
   319         /**
       
   320         * Load default string by QT style localization
       
   321         * @param aText default string id defined by _LIT
       
   322         */        
       
   323         const TPtrC LoadDefaultString( const TDesC& aText );
       
   324 
       
   325     private:     // Data
       
   326         
       
   327         // The file session reference.
       
   328         RFs& iFsSession;
       
   329         
       
   330         // The resource manager reference.
       
   331         CPhSrvResourceManager& iResourceManager;
       
   332 
       
   333         // The USSD functionality in lower level (TSY).
       
   334         RMobileUssdMessaging iMobileUssdMessaging;
       
   335         
       
   336         // The observer waiting message sent notification.
       
   337         MPhSrvUssdMessageSentObserver* iObserver;
       
   338 
       
   339         // The send operation handler.
       
   340         CPhSrvUssdSendHandler* iUssdSendHandler;
       
   341 
       
   342         // The receive operation handler.
       
   343         CPhSrvUssdReceiveHandler* iUssdReceiveHandler;
       
   344         
       
   345         // The network release notifier.
       
   346          CPhSrvUssdNotifyNWRelease* iUssdNotifyNWRelease;
       
   347         
       
   348         // The reply timer.
       
   349         CPhSrvUssdReplyTimer* iUssdReplyTimer;
       
   350         
       
   351         // The buffer for received message.
       
   352         TBuf< KPhCltUssdMax8BitCharacters > iReceivedMessage;
       
   353         
       
   354         // The message query for showing USSD operation queries.
       
   355         CHbDeviceMessageBoxSymbian* iDeviceDialog;
       
   356        
       
   357         // Is editor emptied.
       
   358         TBool iEmptyEditor;
       
   359         
       
   360         // Will the editor be started.
       
   361         TBool iStartEditor;
       
   362         
       
   363         // The timer.
       
   364         RTimer iTimer;
       
   365 
       
   366         // Is there pending SAT message.
       
   367         TBool iHavePendingSatMessagePointer;
       
   368 
       
   369         // The pending SAT message.
       
   370         RMessage2 iPendingSatMessagePointer;
       
   371 
       
   372         // Reference to phone interfaces.
       
   373         MPhSrvPhoneInterface* iPhoneInterface;
       
   374 
       
   375         // The used DCS in the SAT message
       
   376         TUint iDCS;
       
   377 
       
   378         // Softkeys in Global MessageQuery.
       
   379         TInt iSoftkeys;
       
   380 
       
   381         // Global MessageQuery launching indicator.
       
   382         TBool iLaunchGMQ;
       
   383 
       
   384         // Local Telephony variant read-only data.
       
   385         TInt iVariantReadOnlyValues;
       
   386 
       
   387         // The buffer for received decoded message.
       
   388         TBuf< KPhCltUssdMax8BitCharacters > iDecodedMessage;
       
   389 
       
   390         // If ETrue, then the last received USSD message was EUssdMtNotify.
       
   391         TBool iNotifyMessage;
       
   392         
       
   393         //NotifyNetWorkRelease return result
       
   394         RMobilePhone::TMobilePhoneSendSSRequestV3 iReturnResult;
       
   395         
       
   396         //NotifyNetWorkRelease return result
       
   397         RMobilePhone::TMobilePhoneSendSSRequestV3Pckg iReturnResultPckg;
       
   398         
       
   399         // Array for notify messages
       
   400         CDesCArray* iNotifyArray;
       
   401         
       
   402         //Sending Release status
       
   403         TBool iSendRelease;
       
   404 
       
   405         // Notify array reset status
       
   406         TBool iClearArray;
       
   407 
       
   408         // Sat cancel status
       
   409         TBool iSatCanceled;
       
   410         
       
   411         // Show Done note
       
   412         TBool iShowDone;
       
   413 
       
   414         // Checks if received message type is Reply
       
   415         TBool iMsgTypeReply;
       
   416         
       
   417         // Has the transaction been closed or not
       
   418         TBool iNetworkReleased;
       
   419         
       
   420         // Is the current send operation an MO ACK message or not 
       
   421         TBool iSendingAck;
       
   422         
       
   423         // Number of MO ACK messages pending to be sent. Normally max 2.
       
   424         TInt iAcksToBeSent;
       
   425         
       
   426         // An asynchronous callback for sending MO ACK messages
       
   427         CAsyncCallBack* iMoAckCallback;
       
   428         
       
   429         TBool iTextResolver;
       
   430         
       
   431         HBufC* iTextBuffer;
       
   432 
       
   433     };
       
   434     
       
   435 #endif // CPHSRVUSSDMANAGER_H
       
   436 
       
   437 
       
   438 // End of File