vpnengine/vpnconnagt/src/vpnsipobserver.cpp
branchRCL_3
changeset 8 032d3a818f49
child 26 74294b43d401
equal deleted inserted replaced
4:29b591713d44 8:032d3a818f49
       
     1 /*
       
     2 * Copyright (c) 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 : P&S key monitor for communication between VPN client
       
    15 *               and SIP Profile server
       
    16 * Name        : vpnsipobserver.cpp
       
    17 * Part of     : VPN client / VPN Connection Agent
       
    18 * Version     : 1.0
       
    19 *
       
    20 */
       
    21 
       
    22 // SYSTEM INCLUDES
       
    23 #include <e32property.h>                  // For P&S key
       
    24 #include <vpnsipobserverpskeys.h>         // For P&S key definition
       
    25 
       
    26 // USER INCLUDES
       
    27 #include "vpnsipobserver.h"
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 // two phased constructor
       
    31 // ---------------------------------------------------------------------------
       
    32 //             
       
    33 CVpnSipObserver* CVpnSipObserver::NewL( CVPNConnAgt& aAgent )
       
    34     {// dkangchecked
       
    35     CVpnSipObserver* self = new( ELeave ) CVpnSipObserver( aAgent );
       
    36 
       
    37     CleanupStack::PushL( self );
       
    38     self->ConstructL();
       
    39     CleanupStack::Pop( self );
       
    40 
       
    41     return self;
       
    42     }
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // second phased constructor
       
    46 // ---------------------------------------------------------------------------
       
    47 //        
       
    48 void CVpnSipObserver::ConstructL()
       
    49     {
       
    50     // KVpnSipState P&S key is used for communication between VPN client
       
    51     // and SIP Profile Server regarding SIP de/re-registration.
       
    52     // KPSVpnSipUid is defined in a SIP System State Monitor plugin
       
    53     // (CSipVpnMonitorAo).
       
    54     User::LeaveIfError( iSIPProperty.Attach( KPSVpnSipUid, KVpnSipState ) );
       
    55 
       
    56     // Start monitoring the P&S key.
       
    57     Subscribe();
       
    58     }
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // C++ constructor
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 CVpnSipObserver::CVpnSipObserver( CVPNConnAgt& aAgent )
       
    65     : CActive( EPriorityStandard ),
       
    66       iAgent( aAgent )
       
    67     {
       
    68     CActiveScheduler::Add( this );
       
    69     }
       
    70                  
       
    71 // ---------------------------------------------------------------------------
       
    72 // C++ destructor
       
    73 // ---------------------------------------------------------------------------
       
    74 //             
       
    75 CVpnSipObserver::~CVpnSipObserver()
       
    76     {
       
    77     Cancel();
       
    78     iSIPProperty.Close();
       
    79     }
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // CVpnSipObserver::RequestDeregister
       
    83 // ---------------------------------------------------------------------------
       
    84 //             
       
    85 TInt CVpnSipObserver::RequestDeregister()
       
    86     {
       
    87     // Tells SIP Profile Server that a VPN session is about to be started.
       
    88     // This will trigger SIP deregistration process by SIP Profile Server.
       
    89     // Should not leave if failed. This will be handled by VPN Conn Agt.
       
    90     return iSIPProperty.Set( KPSVpnSipUid, KVpnSipState, EVpnInitiating );
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // CVpnSipObserver::RequestRegister
       
    95 // ---------------------------------------------------------------------------
       
    96 //             
       
    97 TInt CVpnSipObserver::RequestRegister()
       
    98     {
       
    99     // Tells SIP Profile Server that a VPN session ended.
       
   100     // This will trigger SIP re-registration process by SIP Profile Server.	
       
   101     // Should not leave if failed. This will be handled by VPN Conn Agt.
       
   102     return iSIPProperty.Set( KPSVpnSipUid, KVpnSipState, EVpnTerminated );
       
   103     }
       
   104              
       
   105 // ---------------------------------------------------------------------------
       
   106 // CVpnSipObserver::RunL
       
   107 // ---------------------------------------------------------------------------
       
   108 //             
       
   109 void CVpnSipObserver::RunL()
       
   110     {
       
   111     if ( iStatus == KErrNone ) 
       
   112         {
       
   113         TInt val = 0;
       
   114         // SIP Profile Server notified completion of SIP deregistration.
       
   115         TInt err = iSIPProperty.Get( KPSVpnSipUid, KVpnSipState, val );
       
   116         
       
   117         if ( err == KErrNone )
       
   118             {
       
   119             // If SIP is deregistered, let the VPN Connection Agent to 
       
   120             // proceed VPN session start.
       
   121             if ( val == ESipDeregisterCompleted )
       
   122                 {
       
   123                 iAgent.ProceedServiceStart();
       
   124                 }
       
   125             }
       
   126         // Keep monitoring.
       
   127         Subscribe();
       
   128         }
       
   129     // Check if observer can be restarted.
       
   130     else if ( iStatus != KErrCancel 
       
   131            && iStatus != KErrServerTerminated
       
   132            && iStatus != KErrNotSupported )
       
   133         {
       
   134         // Keep monitoring.
       
   135         Subscribe();
       
   136         }
       
   137     else
       
   138         {
       
   139         // Error.
       
   140         LOG_1( "CVpnSipObserver::RunL Unknown error situation, iStatus = %d", iStatus.Int() );
       
   141         }
       
   142     }
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // CVpnSipObserver::DoCancel
       
   146 // ---------------------------------------------------------------------------
       
   147 //                
       
   148 void CVpnSipObserver::DoCancel()
       
   149     {
       
   150     iSIPProperty.Cancel();
       
   151     }
       
   152 
       
   153 // ---------------------------------------------------------------------------
       
   154 // CVpnSipObserver::Subscribe
       
   155 // ---------------------------------------------------------------------------
       
   156 //        
       
   157 void CVpnSipObserver::Subscribe()
       
   158     {
       
   159     iSIPProperty.Subscribe( iStatus );
       
   160     SetActive();
       
   161     }