mmsengine/mmshttptransport/src/mmsbearerstatus.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2002-2006 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:  
       
    15 *     This class implements notifications from bearers which is needed when
       
    16 *     transferring data to/from WAP GW.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include    <es_sock.h>
       
    24 
       
    25 #include    "mmsbearerstatus.h"
       
    26 #include    "mmssession.h"
       
    27 #include    "mmstransportobserver.h"
       
    28 #include    "mmsservercommon.h"
       
    29 #include    "MmsServerDebugLogging.h"
       
    30 
       
    31 // ================= MEMBER FUNCTIONS =======================
       
    32 
       
    33 // ---------------------------------------------------------
       
    34 // C++ constructor
       
    35 // ---------------------------------------------------------
       
    36 //
       
    37 CMmsBearerStatus::CMmsBearerStatus()
       
    38     :CActive ( EPriorityStandard),
       
    39     iRequester ( NULL ),
       
    40     iConnected( EFalse ),
       
    41     iSuspended( EFalse )
       
    42     {
       
    43     iBearerType = EMmsBearerGprs; // default
       
    44     }
       
    45 
       
    46 // ---------------------------------------------------------
       
    47 // CMmsBearerStatus::ConstructL
       
    48 // ---------------------------------------------------------
       
    49 //
       
    50 void CMmsBearerStatus::ConstructL( RConnection& aRConnection )
       
    51     {
       
    52     LOG( _L("CMmsBearerStatus::ConstructL") );
       
    53     iRConnection = &aRConnection;
       
    54     CActiveScheduler::Add( this );
       
    55     }
       
    56 
       
    57 // ---------------------------------------------------------
       
    58 // Symbian two-phased constructor
       
    59 // ---------------------------------------------------------
       
    60 //
       
    61 CMmsBearerStatus* CMmsBearerStatus::NewL( RConnection& aRConnection )
       
    62     {
       
    63     CMmsBearerStatus* self = new ( ELeave ) CMmsBearerStatus();
       
    64     CleanupStack::PushL( self );
       
    65     self->ConstructL( aRConnection );
       
    66     CleanupStack::Pop( self );
       
    67     return self;
       
    68     }
       
    69     
       
    70 // ---------------------------------------------------------
       
    71 // Destructor
       
    72 // ---------------------------------------------------------
       
    73 //
       
    74 CMmsBearerStatus::~CMmsBearerStatus()
       
    75     {
       
    76     Cancel();
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------
       
    80 // CMmsBearerStatus::IsGprs
       
    81 // ---------------------------------------------------------
       
    82 //
       
    83 TBool CMmsBearerStatus::IsGprs() const
       
    84     {
       
    85     if( iBearerType == EMmsBearerGprs )
       
    86         {
       
    87         return ETrue;
       
    88         }
       
    89     else
       
    90         {
       
    91         return EFalse;
       
    92         }
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------
       
    96 // CMmsBearerStatus::IsSuspendedL
       
    97 // ---------------------------------------------------------
       
    98 //
       
    99 TBool CMmsBearerStatus::IsSuspended()
       
   100     {
       
   101     if( iBearerType != EMmsBearerGprs )
       
   102         {
       
   103         LOG( _L("CMmsBearerStatus::IsSuspended: Something wrong, no GPRS!") );
       
   104         return EFalse;
       
   105         }
       
   106     TNifProgress nifProgress;
       
   107     TInt err = iRConnection->Progress( nifProgress );
       
   108     if( err == KErrNone )
       
   109         {
       
   110         if( nifProgress.iStage == KDataTransferTemporarilyBlocked )
       
   111             {
       
   112             iSuspended = ETrue;
       
   113             return ETrue;
       
   114             }
       
   115         }
       
   116     return EFalse;
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------
       
   120 // CMmsBearerStatus::SubscribeNotification
       
   121 // ---------------------------------------------------------
       
   122 //
       
   123 void CMmsBearerStatus::SubscribeNotification( MMmsTransportObserver* aRequester )
       
   124     {
       
   125     LOG( _L("CMmsBearerStatus::SubscribeNotification") );
       
   126     
       
   127     iRequester = ( MMmsTransportObserver* ) aRequester;
       
   128     // set status to pending to make sure that it is RNif
       
   129     // that sets it to complete
       
   130     iStatus = KRequestPending;
       
   131     iRConnection->ProgressNotification( iProgressBuffer, iStatus );
       
   132 
       
   133 #ifndef _NO_MMSS_LOGGING_
       
   134     if( IsActive() )
       
   135         {
       
   136         LOG( _L(" - already active") );
       
   137         }
       
   138 #endif  //_NO_MMSS_LOGGING_
       
   139     SetActive();
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------
       
   143 // CMmsBearerStatus::RunL
       
   144 // ---------------------------------------------------------
       
   145 //
       
   146 void CMmsBearerStatus::RunL()
       
   147     {
       
   148 #ifndef _NO_MMSS_LOGGING_
       
   149     if( iStatus.Int() != KErrNone )
       
   150         {
       
   151         LOG2( _L("ERROR in CMmsBearerStatus::RunL status %d)"), iStatus.Int() );
       
   152         }
       
   153     LOG2( _L("CMmsBearerStatus::RunL(): progress stage %d"), iProgressBuffer().iStage );
       
   154 #endif  //_NO_MMSS_LOGGING_
       
   155 
       
   156 
       
   157     if( iProgressBuffer().iStage == KLinkLayerClosed && iConnected )
       
   158         {
       
   159         iConnected = EFalse;
       
   160         iRequester->TransferCancelled();
       
   161         }
       
   162     else if( iProgressBuffer().iStage == KLinkLayerOpen ) 
       
   163         {
       
   164         iConnected = ETrue;
       
   165         if( iSuspended )
       
   166             {
       
   167             iSuspended = EFalse;
       
   168             iRequester->GprsResumed();
       
   169             // GprsResumed() puts the observer (this) active if necessary
       
   170             }
       
   171         else
       
   172             {
       
   173             SubscribeNotification( iRequester );
       
   174             }
       
   175         }
       
   176     else if( iProgressBuffer().iStage == KDataTransferTemporarilyBlocked )
       
   177         {
       
   178         iSuspended = ETrue;
       
   179         iRequester->GprsSuspended();
       
   180         SubscribeNotification( iRequester );
       
   181         }
       
   182     else
       
   183         {
       
   184         // Some other state, not really interested about those...
       
   185         SubscribeNotification( iRequester );        
       
   186         }    
       
   187     }
       
   188 
       
   189 // ---------------------------------------------------------
       
   190 // CMmsBearerStatus::DoCancel
       
   191 // ---------------------------------------------------------
       
   192 //
       
   193 void CMmsBearerStatus::DoCancel()
       
   194     {
       
   195     LOG( _L("CMmsBearerStatus::DoCancel") );
       
   196     iRConnection->CancelProgressNotification();
       
   197     }
       
   198 
       
   199 // ================= OTHER EXPORTED FUNCTIONS ==============
       
   200 
       
   201 //  End of File  
       
   202