os/persistentdata/persistentstorage/centralrepository/cenrepsrv/srvsess.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/centralrepository/cenrepsrv/srvsess.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,330 @@
     1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include "panic.h"
    1.20 +#include "srvreqs.h"
    1.21 +#include "sessmgr.h"
    1.22 +#include "cachemgr.h"
    1.23 +#include "srvsubsess.h"
    1.24 +#include "srvsess.h"
    1.25 +
    1.26 +CServerSession::~CServerSession()
    1.27 +	{
    1.28 +	// Delete the subsession index.
    1.29 +	delete iSubSessionIx;
    1.30 +	
    1.31 +	//Delete the subsession container via the CObjectConIx's remove function  
    1.32 +	((CSessionManager*)Server())->RemoveContainer(iContainer);
    1.33 +	}
    1.34 +
    1.35 +//Called by client/server framework after session has been successfully created.
    1.36 +//In effect, a second-phase constructor.
    1.37 +//Creates the object index and the object container for this session.
    1.38 +void CServerSession::CreateL()
    1.39 +	{
    1.40 +	// Create new object index
    1.41 +	iSubSessionIx = CObjectIx::NewL();
    1.42 +	
    1.43 +	// Initialize the object container
    1.44 +	// using the object container index in the server.
    1.45 +	iContainer = ((CSessionManager*)Server())->NewContainerL();
    1.46 +	}
    1.47 +
    1.48 +//helper method to resolve and verify subsession using RMessage and subsession handle
    1.49 +CServerSubSession* CServerSession::SubSessionFromHandle(const RMessage2& aMessage, TInt aHandle)
    1.50 +	{
    1.51 +	CServerSubSession* subSession = (CServerSubSession*)iSubSessionIx->At(aHandle);
    1.52 +	if (subSession == NULL)
    1.53 +	    {
    1.54 +		PanicClient(EBadSubsessionHandle, aMessage);	    
    1.55 +	    }
    1.56 +	    
    1.57 +	return subSession;
    1.58 +	}
    1.59 +
    1.60 +// if ServiceL Leaves, execution resumes in this method.
    1.61 +// this allows us to panic clients using bad descriptors, to deal with OOM conditions
    1.62 +// and to fail transactions with the correct reason: OOM etc.
    1.63 +void CServerSession::ServiceError(const RMessage2 &aMessage, TInt aError)
    1.64 +	{
    1.65 +	TServerRequest fn = static_cast<TServerRequest>(aMessage.Function());
    1.66 +
    1.67 +	// If we have failed during initialisation the subsession is no longer available.
    1.68 +	// Perform additional cleanup by removing the subsession's handle from the server's 
    1.69 +	// subsession index. 
    1.70 +	if (fn == EInitialise)
    1.71 +		{
    1.72 +		// Retrieve handle
    1.73 +		TPckgBuf<TInt> handlePckg;
    1.74 +		TRAPD(res,aMessage.ReadL(3,handlePckg));
    1.75 +		 
    1.76 +		if (res == KErrNone)
    1.77 +		 	{
    1.78 +		 	TInt subSessionHandle = handlePckg();
    1.79 +			iSubSessionIx->Remove(subSessionHandle);
    1.80 +		 	}
    1.81 +		#ifdef _DEBUG
    1.82 +			else
    1.83 +				{
    1.84 +				RDebug::Print(_L("CServerSession::ServiceError - Can't remove subsession handle; aError = %d; res = %d"), aError, res); 
    1.85 +				}   	
    1.86 +		#endif 	 
    1.87 +		}
    1.88 +	
    1.89 +	//under following conditions the subsession handles the error
    1.90 +	if(fn > EInitialise && fn < ELastInTable)
    1.91 +		{
    1.92 +		CServerSubSession* subSession = SubSessionFromHandle(aMessage, aMessage.Int3());
    1.93 +		if(subSession)
    1.94 +			{
    1.95 +			subSession->ServiceError(aError);   
    1.96 +			}
    1.97 +		#ifdef _DEBUG
    1.98 +			else
    1.99 +				{
   1.100 +				RDebug::Print(_L("CServerSession::ServiceError - bad subsession handle. aError = %d"), aError); 
   1.101 +				}   	
   1.102 +		#endif  
   1.103 +		}
   1.104 +#ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS		
   1.105 +	//for multi ROFS instead of leaving we panic the client instead
   1.106 +	switch (aError)
   1.107 +		{
   1.108 +		case KErrMultiRofsOldCreUsed:
   1.109 +			PanicClient(EMultiRofsPanicOldCre,aMessage);
   1.110 +			return;
   1.111 +		case KErrMultiRofsGlobalOverride:
   1.112 +			PanicClient(EMultiRofsPanicGlobalOverride,aMessage);
   1.113 +			return;
   1.114 +		case KErrMultiRofsTypeOverride:
   1.115 +			PanicClient(EMultiRofsPanicTypeOveride,aMessage);
   1.116 +			return;
   1.117 +		case KErrMultiRofsIllegalRofs:
   1.118 +			PanicClient(EMultiRofsPanicIllegalRofs,aMessage);
   1.119 +			return;				
   1.120 +		}
   1.121 +#endif				
   1.122 +		
   1.123 +	CSession2::ServiceError(aMessage, aError);
   1.124 +	}
   1.125 +
   1.126 +void CServerSession::ServiceL(const RMessage2& aMessage)
   1.127 +	{
   1.128 +	TServerRequest fn = static_cast<TServerRequest>(aMessage.Function());
   1.129 +	
   1.130 +#if defined(__CENTREP_SERVER_PERFTEST__) || defined(__CENTREP_SERVER_MEMTEST__) || defined(__CENTREP_SERVER_CACHETEST__)
   1.131 +	if (fn == EGetSetParameters)
   1.132 +		{
   1.133 +		TInt r = GetSetParameters(aMessage);
   1.134 +		aMessage.Complete(r);
   1.135 +		return;
   1.136 +		}
   1.137 +#endif
   1.138 +
   1.139 +	if(fn > ELastInTable)
   1.140 +		{
   1.141 +		PanicClient(EBadMessageNumber, aMessage);
   1.142 +		}
   1.143 +	
   1.144 +	CServerSubSession* subSession = NULL;
   1.145 +
   1.146 +#if defined (SYMBIAN_CENTREP_SUPPORT_MULTIROFS) && defined(CENTREP_TRACE)
   1.147 +	TUint32 startTick=0;
   1.148 +	TUid repUid;
   1.149 +	startTick=User::FastCounter();
   1.150 +#endif
   1.151 +	PERF_TEST_EVENT_START(subSession, aMessage);
   1.152 +
   1.153 +	if(fn == EInitialise)
   1.154 +		{
   1.155 +		//create subsession
   1.156 +		subSession = NewSubSessionL(aMessage);
   1.157 +#if defined (SYMBIAN_CENTREP_SUPPORT_MULTIROFS) && defined(CENTREP_TRACE)		
   1.158 +		repUid=TUid::Uid(aMessage.Int0());
   1.159 +		subSession->iRepositoryUid=repUid;
   1.160 +#endif		
   1.161 +		}
   1.162 +	else
   1.163 +		{
   1.164 +		subSession = SubSessionFromHandle(aMessage, aMessage.Int3());
   1.165 +#if defined (SYMBIAN_CENTREP_SUPPORT_MULTIROFS) && defined(CENTREP_TRACE)
   1.166 +		repUid=subSession->iRepositoryUid;
   1.167 +#endif		
   1.168 +		}
   1.169 +
   1.170 +	if(subSession)
   1.171 +		{
   1.172 +		
   1.173 +		TInt r = KErrNone;
   1.174 +		
   1.175 +		if(fn == EClose)
   1.176 +			{
   1.177 +			//delete subsession	
   1.178 +			DeleteSubSession(aMessage.Int3());
   1.179 +			}
   1.180 +		else
   1.181 +			{
   1.182 +			//ask subsession to handle the message
   1.183 +			r = subSession->ServiceL(aMessage);
   1.184 +			}
   1.185 +
   1.186 +		PERF_TEST_EVENT_END(subSession, aMessage);
   1.187 +	
   1.188 +#if defined (SYMBIAN_CENTREP_SUPPORT_MULTIROFS) && defined(CENTREP_TRACE)
   1.189 +		TUint32 endTick=User::FastCounter();
   1.190 +		RDebug::Print(_L("[CENTREP],TimeStamp=,%d,Repository=,%x,Function=,%d,TickCount=,%d"),startTick,repUid.iUid,fn,endTick-startTick);
   1.191 +#endif
   1.192 +		if (r != CServerSubSession::KDontCompleteMessage)
   1.193 +			{
   1.194 +			aMessage.Complete(r);
   1.195 +			}
   1.196 +		}
   1.197 +	//If (subsession == NULL) we don't need to complete the message, as the message is completed already when the client panicked
   1.198 +	#ifdef _DEBUG   
   1.199 +		else
   1.200 +			{
   1.201 +			RDebug::Print(_L("CServerSession::ServiceL - bad subsession handle. TServerRequest = %d"), fn); 
   1.202 +			}
   1.203 +	#endif
   1.204 +	}
   1.205 +
   1.206 +//Creates a new subsession object, and writes its handle to the message.
   1.207 +//A subsession object is the server side "partner" to the client side subsession.
   1.208 +//On return last parameter of aMessage is filled with the handle of the subsession
   1.209 +//and handle is also returned
   1.210 +CServerSubSession* CServerSession::NewSubSessionL(const RMessage2& aMessage)
   1.211 +	{
   1.212 +	//create a new subsession
   1.213 +	CServerSubSession* subSession = new (ELeave) CServerSubSession(this);
   1.214 +	CleanupStack::PushL(subSession);
   1.215 +	
   1.216 +	//add the subsession object to this session's object container to generate a unique ID
   1.217 +	iContainer->AddL(subSession);
   1.218 +	CleanupStack::Pop(subSession);
   1.219 +	
   1.220 +	//add the object to the subsessions index, this returns a unique handle so that we can
   1.221 +	//refer to the object later
   1.222 +	TInt handle = iSubSessionIx->AddL(subSession);
   1.223 +	
   1.224 +	//write the handle to the client's message
   1.225 +	TPckgBuf<TInt> handlePckg(handle);
   1.226 +	TRAPD(res,aMessage.WriteL(3,handlePckg));
   1.227 +	if (res!=KErrNone)
   1.228 +		{
   1.229 +		iSubSessionIx->Remove(handle);
   1.230 +		PanicClient(EBadSubsessionHandle, aMessage);
   1.231 +		subSession = NULL;
   1.232 +		}
   1.233 +
   1.234 +	return subSession;
   1.235 +	}
   1.236 +	
   1.237 +//Deletes a subsession object through its handle.
   1.238 +void CServerSession::DeleteSubSession(TInt aHandle)
   1.239 +	{
   1.240 +	iSubSessionIx->Remove(aHandle);
   1.241 +	}
   1.242 +	
   1.243 +inline CSessionManager* CServerSession::Server()
   1.244 +	{
   1.245 +	return static_cast<CSessionManager*>(const_cast<CServer2*>(CSession2::Server()));
   1.246 +	}
   1.247 +
   1.248 +#if defined(__CENTREP_SERVER_PERFTEST__) || defined (__CENTREP_SERVER_MEMTEST__) || defined(__CENTREP_SERVER_CACHETEST__)
   1.249 +// GetSetParameters
   1.250 +// The function code EGetSetParameters is a generic msg reserved
   1.251 +// for testing purpose. Int0 specifies the function to perform.
   1.252 +TInt CServerSession::GetSetParameters(const TClientRequest& aMessage)
   1.253 +	{
   1.254 +	TServerGetSetParametersSubCmd cmd = static_cast<TServerGetSetParametersSubCmd>(aMessage.Int0());
   1.255 +
   1.256 +#ifdef __CENTREP_SERVER_PERFTEST__
   1.257 +	if (cmd == EGetPerfResults)
   1.258 +		{
   1.259 +		TInt desSize = aMessage.GetDesMaxLength(1);
   1.260 +		TInt numVals = desSize / sizeof(TUint32);
   1.261 +		if (numVals < KCentRepPerfTestArraySize)
   1.262 +			{
   1.263 +			return KErrOverflow;
   1.264 +			}
   1.265 +		TPtrC8 p(reinterpret_cast<const TUint8*>(TServerResources::iPerfTestMgr.Entries()),
   1.266 +				   KCentRepPerfTestArraySize * sizeof(TUint32));
   1.267 +		TInt ret = aMessage.Write(1, p);
   1.268 +		if (ret == KErrNone)
   1.269 +			{
   1.270 +			TUint lastCompleteAccess = TServerResources::iPerfTestMgr.LastCompleteAccess();
   1.271 +			TPckg<TUint> p2(lastCompleteAccess);
   1.272 +			ret = aMessage.Write(2, p2);
   1.273 +			}
   1.274 +		return ret;
   1.275 +		}
   1.276 +	else if (cmd == ERestartPerfTests)
   1.277 +		{
   1.278 +		TServerResources::iPerfTestMgr.Reset();
   1.279 +		return KErrNone;
   1.280 +		}
   1.281 +	else if (cmd == EStopPerfTests)
   1.282 +		{
   1.283 +		TServerResources::iPerfTestMgr.Stop();
   1.284 +		return KErrNone;
   1.285 +		}
   1.286 +#endif // __CENTREP_SERVER_PERFTEST__
   1.287 +
   1.288 +#ifdef __CENTREP_SERVER_MEMTEST__
   1.289 +	if(cmd == ERestartMemTests)
   1.290 +		{
   1.291 +		TServerResources::StartRecordTimerResult();
   1.292 +		return KErrNone;
   1.293 +		}
   1.294 +	else if(cmd == ESingleMemTest)
   1.295 +		{
   1.296 +		RECORD_HEAP_SIZE(EMemLcnOnDemand, aMessage.Int1());
   1.297 +		return KErrNone;
   1.298 +		}
   1.299 +	else if(cmd == EGetMemResults)
   1.300 +		{
   1.301 +		TInt count = TServerResources::iMemTestDataCount;
   1.302 +		TPckg<TInt> pCount(count);
   1.303 +		
   1.304 +		TInt err = aMessage.Write(1, pCount);
   1.305 +		if(err == KErrNone && count > 0)
   1.306 +			{
   1.307 +			TPtrC8 pBuf(reinterpret_cast<TUint8*>(TServerResources::iMemTestData), (TServerResources::iMemTestDataCount)*sizeof(TInt32));
   1.308 +			err = aMessage.Write(2, pBuf);
   1.309 +			}
   1.310 +		// Stop recording results
   1.311 +		TServerResources::StopRecordTimerResult();
   1.312 +		return err;
   1.313 +		}
   1.314 +#endif // __CENTREP_SERVER_MEMTEST__
   1.315 +
   1.316 +#ifdef __CENTREP_SERVER_CACHETEST__
   1.317 +	if (cmd == EEnableCache)
   1.318 +		{
   1.319 +		// First parameter is Timer Interval, second is cache size
   1.320 +		TServerResources::iCacheManager->EnableCache(aMessage.Int1(), aMessage.Int2());
   1.321 +		return KErrNone;
   1.322 +		}
   1.323 +	else if (cmd == EDisableCache)
   1.324 +		{
   1.325 +		TServerResources::iCacheManager->DisableCache(ETrue);
   1.326 +		return KErrNone;
   1.327 +		}
   1.328 +#endif  // __CENTREP_SERVER_CACHETEST__
   1.329 +
   1.330 +	return KErrNotSupported;
   1.331 +	}
   1.332 +#endif // __CENTREP_SERVER_PERFTEST__ || __CENTREP_SERVER_MEMTEST__ || __CENTREP_SERVER_CACHETEST__
   1.333 +