phoneclientserver/phoneclient/Src/UssdWrapper/CPhCltUssdSatClient.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 Sat Client.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "CPhCltUssdImp.h"
       
    22 #include    "PhCltClientServer.h"
       
    23 #include    <CPhCltUssdSatClient.h>
       
    24 #include    <CPhCltUssd.h>
       
    25 
       
    26 
       
    27 // ============================= LOCAL FUNCTIONS ===============================
       
    28 
       
    29 #ifndef CPHCLTUSSDSATACTIVE_H
       
    30 #define CPHCLTUSSDSATACTIVE_H
       
    31 
       
    32 /**
       
    33 * The waiter class for SAT sessions.
       
    34 */
       
    35 NONSHARABLE_CLASS( CPhCltUssdSatActive ) : public CActive
       
    36     {
       
    37     public:
       
    38 
       
    39         /**
       
    40         * Constructor.
       
    41         */
       
    42         CPhCltUssdSatActive();
       
    43 
       
    44         /**
       
    45         * Destructor.
       
    46         */
       
    47         ~CPhCltUssdSatActive();
       
    48 
       
    49         /**
       
    50         * Set this active object active.
       
    51         * Hides the function derived from CActive.
       
    52         */
       
    53         void SetActive();
       
    54 
       
    55         /**
       
    56         * Wait until the Sat Session is ended.
       
    57         * @return The error code of the session.
       
    58         */
       
    59         TInt WaitSatSessionToEnd();
       
    60 
       
    61 
       
    62     protected:  // From base classes
       
    63 
       
    64         /**
       
    65         * @see CActive::RunL
       
    66         */
       
    67         void RunL();
       
    68 
       
    69         /**
       
    70         * @see CActive::DoCancel
       
    71         */
       
    72         void DoCancel();
       
    73 
       
    74 
       
    75     private:
       
    76 
       
    77         // The Active scheduler waiter.
       
    78         CActiveSchedulerWait iSatWaiter;
       
    79 
       
    80         // The error code storage place.
       
    81         TInt* iError;
       
    82     };
       
    83 
       
    84 #endif // CPHCLTUSSDSATACTIVE_H
       
    85 
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CPhCltUssdSatActive::CPhCltUssdSatActive
       
    89 //
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 CPhCltUssdSatActive::CPhCltUssdSatActive() : CActive( EPriorityStandard )
       
    93     {
       
    94     CActiveScheduler::Add( this );
       
    95     }
       
    96 
       
    97 
       
    98 // Destructor
       
    99 CPhCltUssdSatActive::~CPhCltUssdSatActive()
       
   100     {
       
   101     Cancel();
       
   102     if ( iSatWaiter.IsStarted() )
       
   103         {
       
   104         iSatWaiter.AsyncStop();
       
   105         }
       
   106 
       
   107     }
       
   108 
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CPhCltUssdSatActive::SetActive
       
   112 //
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 void CPhCltUssdSatActive::SetActive()
       
   116     {
       
   117     CActive::SetActive();
       
   118     iError = NULL;
       
   119     }
       
   120 
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CPhCltUssdSatActive::WaitSatSessionToEnd
       
   124 //
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 TInt CPhCltUssdSatActive::WaitSatSessionToEnd()
       
   128     {
       
   129     if ( !IsActive() )
       
   130         {
       
   131         if ( iError )
       
   132             {
       
   133             return *iError;
       
   134             }
       
   135         else
       
   136             {
       
   137             return KErrNone;
       
   138             }
       
   139         }
       
   140 
       
   141     TInt error = KErrNone;
       
   142     iError = &error;
       
   143     iSatWaiter.Start();
       
   144     return error;
       
   145     }
       
   146 
       
   147 
       
   148 // -----------------------------------------------------------------------------
       
   149 // CPhCltUssdSatActive::RunL
       
   150 //
       
   151 // -----------------------------------------------------------------------------
       
   152 //
       
   153 void CPhCltUssdSatActive::RunL()
       
   154     {
       
   155     if ( iError )
       
   156         {
       
   157         *iError = iStatus.Int();
       
   158         }
       
   159     if ( iSatWaiter.IsStarted() )
       
   160         {
       
   161         iSatWaiter.AsyncStop();
       
   162         }
       
   163     }
       
   164 
       
   165 
       
   166 // -----------------------------------------------------------------------------
       
   167 // CPhCltUssdSatActive::DoCancel
       
   168 //
       
   169 // -----------------------------------------------------------------------------
       
   170 //
       
   171 void CPhCltUssdSatActive::DoCancel()
       
   172     {
       
   173     if ( iError )
       
   174         {
       
   175         *iError = KErrCancel;
       
   176         }
       
   177     }
       
   178 
       
   179 
       
   180 
       
   181 // ============================ MEMBER FUNCTIONS ===============================
       
   182 
       
   183 // -----------------------------------------------------------------------------
       
   184 // CPhCltUssdSatClient::CPhCltUssdSatClient
       
   185 // C++ default constructor can NOT contain any code, that
       
   186 // might leave.
       
   187 // -----------------------------------------------------------------------------
       
   188 //
       
   189 CPhCltUssdSatClient::CPhCltUssdSatClient()
       
   190     {
       
   191     }
       
   192 
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // CPhCltUssdSatClient::ConstructL
       
   196 // Symbian 2nd phase constructor can leave.
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 void CPhCltUssdSatClient::ConstructL( TBool aShowNotes )
       
   200     {
       
   201     iUssdWrapper = CPhCltUssdImp::NewL( aShowNotes );
       
   202 
       
   203     iShowNotes = aShowNotes;
       
   204 
       
   205     iSatActive = new( ELeave ) CPhCltUssdSatActive();
       
   206     }
       
   207 
       
   208 
       
   209 // -----------------------------------------------------------------------------
       
   210 // CPhCltUssdSatClient::NewL
       
   211 // Two-phased constructor.
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 EXPORT_C CPhCltUssdSatClient* CPhCltUssdSatClient::NewL( TBool aShowNotes )
       
   215     {
       
   216     CPhCltUssdSatClient* self = new ( ELeave ) CPhCltUssdSatClient;
       
   217     
       
   218     CleanupStack::PushL( self );
       
   219     self->ConstructL( aShowNotes );
       
   220     CleanupStack::Pop();
       
   221     
       
   222     return self;
       
   223     }
       
   224 
       
   225 
       
   226 // Destructor
       
   227 EXPORT_C CPhCltUssdSatClient::~CPhCltUssdSatClient()
       
   228     {
       
   229     if ( iSatActive )
       
   230         {
       
   231         if ( iSatActive->IsActive() )
       
   232             {
       
   233             iUssdWrapper->StopSAT();
       
   234             }
       
   235         delete iSatActive;
       
   236         iSatActive = NULL;
       
   237         }
       
   238 
       
   239     delete iUssdWrapper;
       
   240     iUssdWrapper = NULL;
       
   241     }
       
   242 
       
   243 
       
   244 // -----------------------------------------------------------------------------
       
   245 // CPhCltUssdSatClient::SendSatMessage
       
   246 // Send SAT message and receive the last message.
       
   247 // 
       
   248 // -----------------------------------------------------------------------------
       
   249 //
       
   250 EXPORT_C TInt CPhCltUssdSatClient::SendSatMessage( 
       
   251     const TDesC& aSendMessage, 
       
   252     const TUint8 iSendDcs,
       
   253     TDes& aReceiveMessage,
       
   254     TBool& aSendCompletedFirst,
       
   255     TUint8& aReceivedDcs) 
       
   256     {
       
   257     // Do not process request if earlier request is ongoing.
       
   258     if ( iSatActive->IsActive() )
       
   259         {
       
   260         // Stop (complete) the earlier request so that we can send new
       
   261         // SATmessage during next function call.
       
   262         iUssdWrapper->StopSAT();
       
   263         return KErrInUse;
       
   264         }
       
   265     iUssdWrapper->SetDCS( iSendDcs );
       
   266     iSatError = KErrNone;
       
   267     iSendCompletedFirst = &aSendCompletedFirst;
       
   268     *iSendCompletedFirst = ETrue;
       
   269     iReceiveMessage.Set( aReceiveMessage );
       
   270     aReceiveMessage.Zero();
       
   271     aReceivedDcs = EPhCltDcsUnknown;
       
   272     
       
   273     iShowNotesAndDcs = 0; // reset the variable
       
   274     if ( iShowNotes )
       
   275         {
       
   276         iShowNotesAndDcs = KPhCltShowNotes;
       
   277         }
       
   278 
       
   279     TPckg< TUint > showNotesAndDcs( iShowNotesAndDcs );
       
   280 
       
   281     // Send receive message to the server. status is completed when Ussd session
       
   282     // ends.
       
   283     iUssdWrapper->StartSAT( 
       
   284         iSatActive->iStatus, 
       
   285         aReceiveMessage , 
       
   286         showNotesAndDcs );
       
   287 
       
   288     iSatActive->SetActive();
       
   289 
       
   290     
       
   291     // Now send the string according to the parameter.
       
   292     TPtrC pMessage( aSendMessage );
       
   293     iSatError = iUssdWrapper->SendUssd( pMessage );
       
   294 
       
   295     if ( iSatError != KErrNone )
       
   296         {
       
   297         iSendCompletedFirst = NULL;
       
   298         iUssdWrapper->StopSAT();
       
   299 
       
   300         iSatActive->WaitSatSessionToEnd();
       
   301         return iSatError; // Message send error
       
   302         }
       
   303     
       
   304     // Wait until the Ussd conversation is over:
       
   305     TInt satWaiterError = iSatActive->WaitSatSessionToEnd();
       
   306     if ( satWaiterError > KErrNone )
       
   307         {
       
   308         *iSendCompletedFirst = EFalse;
       
   309         }
       
   310     
       
   311     // Get the error code:
       
   312     iSatError = Min ( iSatError, satWaiterError );
       
   313     
       
   314     iSendCompletedFirst = NULL;
       
   315 
       
   316     // Return the DCS to the caller.
       
   317     DecodeDcs( aReceivedDcs );
       
   318     aReceivedDcs = iShowNotesAndDcs;
       
   319     return iSatError; // Receive error code
       
   320     }
       
   321 
       
   322 
       
   323 // -----------------------------------------------------------------------------
       
   324 // CPhCltUssdSatClient::SendSatMessageCancel
       
   325 // 
       
   326 // Cancels the out-standing request.
       
   327 // -----------------------------------------------------------------------------
       
   328 //
       
   329 EXPORT_C void CPhCltUssdSatClient::SendSatMessageCancel()
       
   330     {
       
   331     iUssdWrapper->SendUssdCancel();
       
   332     iSendCompletedFirst = NULL;
       
   333     iUssdWrapper->StopSAT();
       
   334     iSatActive->Cancel();
       
   335     }
       
   336 
       
   337 // -----------------------------------------------------------------------------
       
   338 // CPhCltUssdSatClient::DecodeDcs
       
   339 // 
       
   340 // In this function the DCS received from PhoneServer is decoded.
       
   341 // -----------------------------------------------------------------------------
       
   342 //
       
   343 void CPhCltUssdSatClient::DecodeDcs( TUint8& aReceivedDcs ) 
       
   344     {
       
   345     // Check what DCS was used, and update aReceivedDcs
       
   346     if ( iShowNotesAndDcs == KPhCltDcs7Bit )
       
   347         {
       
   348         aReceivedDcs = EPhCltDcs7Bit;
       
   349         }
       
   350     else if ( iShowNotesAndDcs == KPhCltDcs8Bit )
       
   351         {
       
   352         aReceivedDcs = EPhCltDcs8Bit;
       
   353         }
       
   354     else if ( iShowNotesAndDcs == KPhCltDcsUcs2 )
       
   355         {
       
   356         aReceivedDcs = EPhCltDcsUCS2;
       
   357         }
       
   358     else
       
   359         {
       
   360         aReceivedDcs = EPhCltDcsUnknown;
       
   361         }
       
   362     }
       
   363 
       
   364 
       
   365 //  End of File