vpnengine/vpnmanager/src/vpnmanagerserver.cpp
changeset 0 33413c0669b9
child 2 ef893827b4d1
equal deleted inserted replaced
-1:000000000000 0:33413c0669b9
       
     1 /*
       
     2 * Copyright (c) 2003-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: 
       
    15 * Server component for VPN Manager, used by VPN API. 
       
    16 *
       
    17 */
       
    18 
       
    19 #include <e32svr.h>
       
    20 #include <e32math.h>
       
    21 
       
    22 #include "vpnmanagerserver.h"
       
    23 #include "vpnmanagersession.h"
       
    24 #include "requestdispatcher.h"
       
    25 
       
    26 
       
    27 const TUint CVpnManagerServer::iVpnManRangeCount = 3;
       
    28 	
       
    29 const TInt CVpnManagerServer::iVpnManRanges[iVpnManRangeCount] = 
       
    30 	{
       
    31 	0,
       
    32     EVpnImportPolicy,
       
    33     EVpnUpdatePolicyData+1
       
    34 	};
       
    35 
       
    36 const TUint8 CVpnManagerServer::iVpnManElementIndex[iVpnManRangeCount] = 
       
    37 	{
       
    38 	CPolicyServer::ENotSupported,
       
    39 	0,
       
    40 	CPolicyServer::ENotSupported
       
    41 	};
       
    42 
       
    43 const CPolicyServer::TPolicyElement CVpnManagerServer::iVpnManElements[] =
       
    44     {
       
    45     {_INIT_SECURITY_POLICY_C1(ECapabilityNetworkControl), CPolicyServer::EFailClient},
       
    46     };
       
    47 
       
    48 const CPolicyServer::TPolicy CVpnManagerServer::iVpnManPolicy =
       
    49     {
       
    50     0, 						// All connect attempts are checked
       
    51     iVpnManRangeCount,     	// Count of ranges
       
    52     iVpnManRanges,  		// 0-999, 1000-1008, 1009...
       
    53     iVpnManElementIndex,  	// Only range 1000-1008 are checked
       
    54     iVpnManElements 		// The list of policy elements
       
    55     };
       
    56 
       
    57 CVpnManagerServer::CVpnManagerServer(TInt aPriority) : CPolicyServer(aPriority,iVpnManPolicy)
       
    58     {
       
    59     }
       
    60 
       
    61 CVpnManagerServer::~CVpnManagerServer()
       
    62     {
       
    63     delete iRequestDispatcher;
       
    64     iFs.Close();
       
    65     }
       
    66 
       
    67 CVpnManagerServer* CVpnManagerServer::NewL()
       
    68     {
       
    69     CVpnManagerServer* server = CVpnManagerServer::NewLC();
       
    70     CleanupStack::Pop(); // server
       
    71     return server;
       
    72     }
       
    73 
       
    74 CVpnManagerServer* CVpnManagerServer::NewLC()
       
    75     {
       
    76     CVpnManagerServer* server = new (ELeave) CVpnManagerServer(EPriorityNormal);
       
    77     CleanupStack::PushL(server); 
       
    78     server->ConstructL();
       
    79     return server;
       
    80     }
       
    81 
       
    82 void CVpnManagerServer::ConstructL()
       
    83     {
       
    84     User::LeaveIfError(iFs.Connect());
       
    85     User::LeaveIfError(iFs.CreatePrivatePath(EDriveC));
       
    86     iRequestDispatcher = CRequestDispatcher::NewL(iFs);    
       
    87     StartL(KVpnManagerServer);
       
    88     }
       
    89 
       
    90 CSession2* CVpnManagerServer::NewSessionL(
       
    91     const TVersion &aVersion,
       
    92     const RMessage2& /*aMessage*/) const
       
    93     {
       
    94     // Check that the client is requesting a session with the right version
       
    95     if (!User::QueryVersionSupported(TVersion(KVpnManagerMajorVersionNumber,
       
    96                                               KVpnManagerMinorVersionNumber,
       
    97                                               KVpnManagerBuildVersionNumber),
       
    98                                      aVersion))
       
    99         {
       
   100         User::Leave(KErrNotSupported);
       
   101         }
       
   102 
       
   103     // Make new session
       
   104     return CVpnManagerSession::NewL(*const_cast<CVpnManagerServer*>(this),
       
   105                                     *iRequestDispatcher);
       
   106     }
       
   107 
       
   108 void CVpnManagerServer::IncrementSessions()
       
   109     {
       
   110     iSessionCount++;
       
   111     }
       
   112 
       
   113 void CVpnManagerServer::DecrementSessions()
       
   114     {
       
   115     iSessionCount--;
       
   116     
       
   117     // Terminate the server when there are no clients left
       
   118     if (iSessionCount <= 0)
       
   119         {
       
   120         CActiveScheduler::Stop();
       
   121         }    
       
   122     }
       
   123 
       
   124 TInt CVpnManagerServer::RunError(TInt aError)
       
   125     {
       
   126     Message().Complete(aError);
       
   127 
       
   128     // The leave will result in an early return from CServer::RunL(),
       
   129     // skipping the call to request another message. So we issue the
       
   130     // request here in order to keep the server running.
       
   131     ReStart();
       
   132 
       
   133     // Handled the error fully
       
   134     return KErrNone;    
       
   135     }