vpnengine/kmdserver/src/iachangeobserver.cpp
changeset 0 33413c0669b9
equal deleted inserted replaced
-1:000000000000 0:33413c0669b9
       
     1 /*
       
     2 * Copyright (c) 2009 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:  active object, that monitors internal address change
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "ikedebug.h"
       
    20 #include "ikepluginsessionif.h"
       
    21 #include "internaladdress.h"
       
    22 #include "eventmediatorapi.h"
       
    23 
       
    24 // CLASS HEADER
       
    25 #include "iachangeobserver.h"
       
    26 
       
    27 // ======== MEMBER FUNCTIONS ========
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 // Two-phased constructor.
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 CIaChangeObserver* CIaChangeObserver::NewL( TUint32 aVpnIapId,
       
    34                                             const TInetAddr& aDnsServerAddr,
       
    35                                             MIkePluginSessionIf& aIkePluginSession,
       
    36                                             MIkeDebug& aDebug )
       
    37     {
       
    38     CIaChangeObserver* self = new (ELeave) CIaChangeObserver( aVpnIapId,
       
    39                                                               aDnsServerAddr,
       
    40                                                               aIkePluginSession,
       
    41                                                               aDebug );
       
    42     CleanupStack::PushL( self );
       
    43     self->ConstructL();    
       
    44     CleanupStack::Pop( self );
       
    45     return self;
       
    46     
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // Destructor.
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 CIaChangeObserver::~CIaChangeObserver()
       
    54     {
       
    55     Cancel();            
       
    56     iEventMediator.Close();
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // Constructor.
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 CIaChangeObserver::CIaChangeObserver( TUint32 aVpnIapId,
       
    64                                       const TInetAddr& aDnsServerAddr,
       
    65                                       MIkePluginSessionIf& aIkePluginSession,
       
    66                                       MIkeDebug& aDebug )
       
    67  : CActive( EPriorityStandard ),
       
    68    iVpnIapId( aVpnIapId ),
       
    69    iDnsServerAddr( aDnsServerAddr ),
       
    70    iIkePluginSession( aIkePluginSession ),
       
    71    iDebug( aDebug )
       
    72     {
       
    73     CActiveScheduler::Add( this );
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // Constructor.
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 void CIaChangeObserver::ConstructL()
       
    81     {
       
    82     User::LeaveIfError( iEventMediator.Connect() );    
       
    83     }
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // Requests asynchronous internal address change notification.
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 void CIaChangeObserver::StartObserving()
       
    90     {
       
    91     iIkePluginSession.NotifyInternalAddressChanged( iInternalAddress,
       
    92                                                     iStatus );
       
    93     SetActive();
       
    94     }
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // From class CActive
       
    98 // Handles completion of asynchronous notification request. 
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 void CIaChangeObserver::RunL()
       
   102     {
       
   103     __ASSERT_DEBUG( iStatus.Int() == KErrNone ||
       
   104                     iStatus.Int() == KErrCancel,
       
   105                     User::Invariant() );
       
   106 
       
   107     if ( iStatus.Int() == KErrNone )
       
   108         {
       
   109         // VPN NET id is not needed in reporting internal address change.
       
   110         TConnectionInfo connectionInfo( iVpnIapId, 0 );
       
   111         TConnectionInfoBuf pckgConnectionInfo( connectionInfo );
       
   112         
       
   113         TVPNAddressPckg pckgVpnAddress( iInternalAddress );        
       
   114         TInt err = iEventMediator.ReportEvent( EKmdAddressChangeEvent,
       
   115                                                pckgConnectionInfo,
       
   116                                                pckgVpnAddress );
       
   117         err = err;
       
   118     
       
   119 #ifdef _DEBUG                            
       
   120         TBuf<80> txt_addr;        
       
   121         iInternalAddress.iVPNIfAddr.OutputWithScope(txt_addr);
       
   122         DEBUG_LOG3(_L("Internal address changed to %S, VPN IAP id=%d, err=%d"),
       
   123                 &txt_addr, iVpnIapId, err );
       
   124 #endif            
       
   125         
       
   126         StartObserving();    
       
   127         }
       
   128     }
       
   129 
       
   130 // ---------------------------------------------------------------------------
       
   131 // From class CActive
       
   132 // Handles cancellation of asynchronous notification request. 
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 void CIaChangeObserver::DoCancel()
       
   136     {
       
   137     iIkePluginSession.CancelNotifyInternalAddressChanged();
       
   138     }
       
   139