networkprotocolmodules/networkprotocolmodule/LbsNetSim/src/lbsnetsimserver.cpp
changeset 0 9cfd9a3ee49c
equal deleted inserted replaced
-1:000000000000 0:9cfd9a3ee49c
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <ecom/ecom.h>
       
    17 #include "lbsnetsim.h"
       
    18 #include "lbsnetsimserver.h"
       
    19 #include "lbsnetsimsession.h"
       
    20 #include "lbsnetsimtesthandler.h"
       
    21 #include "lbsnetsimgatewayhandler.h"
       
    22 #include "lbsnetsimassistancedataprovider.h"
       
    23 
       
    24 
       
    25 //
       
    26 // Policy Stuff
       
    27 const TUint KRangeCount = 6;
       
    28 
       
    29 const TInt KRanges[KRangeCount] = {0, 3, 1000, 1017, 2000, 2020};
       
    30 const TUint8 KElementsIndex[KRangeCount] = { CPolicyServer::EAlwaysPass, 
       
    31 											 CPolicyServer::ENotSupported, 
       
    32 											 CPolicyServer::EAlwaysPass,
       
    33 											 CPolicyServer::ENotSupported,
       
    34 											 CPolicyServer::EAlwaysPass,
       
    35 											 CPolicyServer::ENotSupported };
       
    36 const CPolicyServer::TPolicyElement KPolicies[1] = 
       
    37 	{{_INIT_SECURITY_POLICY_C1(ECapabilityDiskAdmin), CPolicyServer::EFailClient}};
       
    38 const CPolicyServer::TPolicy KPolicy = 
       
    39 	{
       
    40 	CPolicyServer::EAlwaysPass,
       
    41 	KRangeCount,
       
    42 	KRanges,
       
    43 	KElementsIndex,
       
    44 	KPolicies
       
    45 	};
       
    46 //
       
    47 
       
    48 
       
    49 /**
       
    50 */
       
    51 CSession2* CLbsNetSimServer::NewSessionL(const TVersion& /*aVersion*/, const RMessage2& /*aMessage*/) const
       
    52 	{
       
    53 	// Need to castaway the const
       
    54 	CLbsNetSimServer* self = const_cast<CLbsNetSimServer*>(this);
       
    55 	CSession2* newSession = new (ELeave) CLbsNetSimSession(self);
       
    56 	self->IncClientCount();	
       
    57 	return newSession;
       
    58 	}
       
    59 
       
    60 
       
    61 /**
       
    62 */
       
    63 TInt CLbsNetSimServer::StartServer()
       
    64 	{
       
    65 	__UHEAP_MARK;
       
    66 	
       
    67 	CTrapCleanup* cleanupStack = CTrapCleanup::New();
       
    68 
       
    69 	TInt ret = KErrNoMemory;
       
    70 	if (cleanupStack)
       
    71 		{
       
    72 		TRAP(ret, StartServerL());
       
    73 		delete cleanupStack;
       
    74 		}
       
    75 	
       
    76 	__UHEAP_MARKEND;
       
    77 	
       
    78 	return ret;
       
    79 	}
       
    80 	
       
    81 CLbsNetSimServer::~CLbsNetSimServer()
       
    82 	{
       
    83 	delete iAssistanceDataProvider;
       
    84 	delete iTestHandler;
       
    85 	delete iGatewayHandler;
       
    86 	
       
    87 	REComSession::FinalClose();
       
    88 	}
       
    89 
       
    90 		
       
    91 /**
       
    92 */		
       
    93 MLbsNetSimSessionHandler* CLbsNetSimServer::GetGatewayHandler()
       
    94 	{
       
    95 	return iGatewayHandler;
       
    96 	}
       
    97 
       
    98 
       
    99 /**
       
   100 */
       
   101 MLbsNetSimSessionHandler* CLbsNetSimServer::GetTestHandler()
       
   102 	{
       
   103 	return iTestHandler;
       
   104 	}
       
   105 
       
   106 void CLbsNetSimServer::IncClientCount()
       
   107 	{
       
   108 	++iClientCount;
       
   109 	}
       
   110 	
       
   111 void CLbsNetSimServer::DecClientCount()
       
   112 	{
       
   113 	--iClientCount;
       
   114 	if (iClientCount <=0)
       
   115 		{
       
   116 		CActiveScheduler::Stop();
       
   117 		}
       
   118 	}
       
   119 
       
   120 //
       
   121 // Private Methods
       
   122 
       
   123 /**
       
   124 */
       
   125 CLbsNetSimServer::CLbsNetSimServer(TInt aPriority) :
       
   126 	CPolicyServer(aPriority, KPolicy)
       
   127 	{
       
   128 	}
       
   129 
       
   130 
       
   131 /**
       
   132 */
       
   133 CLbsNetSimServer* CLbsNetSimServer::NewL()
       
   134 	{
       
   135 	CLbsNetSimServer* self = new(ELeave) CLbsNetSimServer(EPriorityStandard);
       
   136 	CleanupStack::PushL(self);
       
   137 	self->ConstructL();
       
   138 	CleanupStack::Pop();
       
   139 	
       
   140 	return self;
       
   141 	}
       
   142 
       
   143 
       
   144 /**
       
   145 */
       
   146 void CLbsNetSimServer::ConstructL()
       
   147 	{
       
   148 	iAssistanceDataProvider = CLbsNetSimAssistanceDataProvider::NewL();
       
   149 	iTestHandler = CLbsNetSimTestHandler::NewL(*iAssistanceDataProvider);
       
   150 	iGatewayHandler = CLbsNetSimGatewayHandler::NewL(*iAssistanceDataProvider);
       
   151 	
       
   152 	iTestHandler->SetGatewayHandler(iGatewayHandler);
       
   153 	iGatewayHandler->SetTestHandler(iTestHandler);
       
   154 	}
       
   155 
       
   156 /**
       
   157 */
       
   158 void CLbsNetSimServer::StartServerL()
       
   159 	{
       
   160 #ifndef EKA2
       
   161 	// Rename thread to aid debugging
       
   162 	User::LeaveIfError(RThread().Rename(KLbsNetSimServerName));
       
   163 #endif
       
   164 
       
   165 	// Start scheduler
       
   166 	CActiveScheduler* scheduler = new(ELeave) CActiveScheduler;
       
   167 	CleanupStack::PushL(scheduler);
       
   168 	CActiveScheduler::Install(scheduler);
       
   169 
       
   170 	// Start server
       
   171 	CLbsNetSimServer* server = CLbsNetSimServer::NewL();
       
   172 	CleanupStack::PushL(server);
       
   173 
       
   174 	server->StartL(KLbsNetSimServerName);
       
   175 
       
   176 	// Signal we have started
       
   177 	RProcess().Rendezvous(KErrNone);
       
   178 
       
   179 	// Start the active schedular
       
   180 	CActiveScheduler::Start();
       
   181 
       
   182 	// Cleanup
       
   183 	CleanupStack::PopAndDestroy(2, scheduler);
       
   184 	}
       
   185 
       
   186 
       
   187 //
       
   188 // Global start up
       
   189 int E32Main(void)
       
   190 	{
       
   191 	return CLbsNetSimServer::StartServer();
       
   192 	}