localconnectivityservice/dun/atext/src/DunAtNvramListen.cpp
branchRCL_3
changeset 39 4096754ee773
parent 38 3dcb815346df
child 40 52a167391590
equal deleted inserted replaced
38:3dcb815346df 39:4096754ee773
     1 /*
       
     2 * Copyright (c) 2008 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:  AT NVRAM status change listener and notifier
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "DunAtNvramListen.h"
       
    20 #include "DunDebug.h"
       
    21 
       
    22 // ---------------------------------------------------------------------------
       
    23 // Two-phased constructor.
       
    24 // ---------------------------------------------------------------------------
       
    25 //
       
    26 CDunAtNvramListen* CDunAtNvramListen::NewL( RATExt* aAtCmdExt,
       
    27                                             RATExtCommon* aAtCmdExtCommon )
       
    28     {
       
    29     CDunAtNvramListen* self = NewLC( aAtCmdExt, aAtCmdExtCommon );
       
    30     CleanupStack::Pop( self );
       
    31     return self;
       
    32     }
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // Two-phased constructor.
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 CDunAtNvramListen* CDunAtNvramListen::NewLC( RATExt* aAtCmdExt,
       
    39                                              RATExtCommon* aAtCmdExtCommon )
       
    40     {
       
    41     CDunAtNvramListen* self = new (ELeave) CDunAtNvramListen(
       
    42         aAtCmdExt,
       
    43         aAtCmdExtCommon );
       
    44     CleanupStack::PushL( self );
       
    45     self->ConstructL();
       
    46     return self;
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // Destructor.
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 CDunAtNvramListen::~CDunAtNvramListen()
       
    54     {
       
    55     FTRACE(FPrint( _L("CDunAtNvramListen::~CDunAtNvramListen()") ));
       
    56     ResetData();
       
    57     FTRACE(FPrint( _L("CDunAtNvramListen::~CDunAtNvramListen() complete") ));
       
    58     }
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // Resets data to initial values
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 void CDunAtNvramListen::ResetData()
       
    65     {
       
    66     FTRACE(FPrint( _L("CDunAtNvramListen::ResetData()") ));
       
    67     // APIs affecting this:
       
    68     // IssueRequest()
       
    69     Stop();
       
    70     // Internal
       
    71     Initialize();
       
    72     FTRACE(FPrint( _L("CDunAtNvramListen::ResetData() complete") ));
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // Starts waiting for NVRAM status changes
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 TInt CDunAtNvramListen::IssueRequest()
       
    80     {
       
    81     FTRACE(FPrint( _L("CDunAtNvramListen::IssueRequest()") ));
       
    82     if ( iNvramHandleState != EDunStateIdle )
       
    83         {
       
    84         FTRACE(FPrint( _L("CDunAtNvramListen::IssueRequest() (not ready) complete") ));
       
    85         return KErrNotReady;
       
    86         }
       
    87     if ( !iStarted )
       
    88         {
       
    89         iAtCmdExtCommon->GetNvramStatus( iNvramBuffer );
       
    90         iAtCmdExt->BroadcastNvramStatusChange( iNvramBuffer );
       
    91         iStarted = ETrue;
       
    92         }
       
    93     iStatus = KRequestPending;
       
    94     iAtCmdExtCommon->ReceiveNvramStatusChange( iStatus, iNvramBuffer );
       
    95     SetActive();
       
    96     iNvramHandleState = EDunStateNvramListening;
       
    97     FTRACE(FPrint( _L("CDunAtNvramListen::IssueRequest() complete") ));
       
    98     return KErrNone;
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // Stops waiting for NVRAM status changes
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 TInt CDunAtNvramListen::Stop()
       
   106     {
       
   107     FTRACE(FPrint( _L("CDunAtNvramListen::Stop()") ));
       
   108     if ( iNvramHandleState != EDunStateNvramListening )
       
   109         {
       
   110         FTRACE(FPrint( _L("CDunAtNvramListen::Stop() (not ready) complete" )));
       
   111         return KErrNotReady;
       
   112         }
       
   113     iAtCmdExtCommon->CancelReceiveNvramStatusChange();
       
   114     Cancel();
       
   115     iNvramHandleState = EDunStateIdle;
       
   116     FTRACE(FPrint( _L("CDunAtNvramListen::Stop() complete") ));
       
   117     // Note: Don't mark iStarted to EFalse here!
       
   118     return KErrNone;
       
   119     }
       
   120 
       
   121 // ---------------------------------------------------------------------------
       
   122 // CDunAtNvramListen::CDunAtNvramListen
       
   123 // ---------------------------------------------------------------------------
       
   124 //
       
   125 CDunAtNvramListen::CDunAtNvramListen( RATExt* aAtCmdExt,
       
   126                                       RATExtCommon* aAtCmdExtCommon ) :
       
   127     CActive( EPriorityHigh ),
       
   128     iAtCmdExt( aAtCmdExt ),
       
   129     iAtCmdExtCommon( aAtCmdExtCommon )
       
   130     {
       
   131     Initialize();
       
   132     }
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // CDunAtNvramListen::ConstructL
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 void CDunAtNvramListen::ConstructL()
       
   139     {
       
   140     FTRACE(FPrint( _L("CDunAtNvramListen::ConstructL()") ));
       
   141     if ( !iAtCmdExt || !iAtCmdExtCommon )
       
   142         {
       
   143         User::Leave( KErrGeneral );
       
   144         }
       
   145     CActiveScheduler::Add( this );
       
   146     FTRACE(FPrint( _L("CDunAtNvramListen::ConstructL() complete") ));
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // Initializes this class
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 void CDunAtNvramListen::Initialize()
       
   154     {
       
   155     // Don't initialize iAtCmdExt here (it is set through NewL)
       
   156     // Don't initialize iAtCmdExtCommon here (it is set through NewL)
       
   157     iNvramHandleState = EDunStateIdle;
       
   158     iStarted = EFalse;
       
   159     }
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 // From class CActive.
       
   163 // Gets called when NVRAM has changed
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 void CDunAtNvramListen::RunL()
       
   167     {
       
   168     FTRACE(FPrint( _L("CDunAtNvramListen::RunL()") ));
       
   169     iNvramHandleState = EDunStateIdle;
       
   170     TInt retTemp = iStatus.Int();
       
   171     if ( retTemp != KErrNone )
       
   172         {
       
   173         FTRACE(FPrint( _L("CDunAtNvramListen::RunL() (ERROR) complete (%d)"), retTemp ));
       
   174         return;
       
   175         }
       
   176     iAtCmdExt->BroadcastNvramStatusChange( iNvramBuffer );
       
   177     IssueRequest();
       
   178     FTRACE(FPrint( _L("CDunAtNvramListen::RunL() complete") ));
       
   179     }
       
   180 
       
   181 // ---------------------------------------------------------------------------
       
   182 // From class CActive.
       
   183 // Gets called on cancel
       
   184 // ---------------------------------------------------------------------------
       
   185 //
       
   186 void CDunAtNvramListen::DoCancel()
       
   187     {
       
   188     FTRACE(FPrint( _L("CDunAtNvramListen::DoCancel()") ));
       
   189     FTRACE(FPrint( _L("CDunAtNvramListen::DoCancel() complete") ));
       
   190     }