backupandrestore/backupengine/src/sbeserver.cpp
changeset 47 63cf70d3ecd8
parent 33 883e91c086aa
equal deleted inserted replaced
44:a5deb6b96675 47:63cf70d3ecd8
    24 #include "sbeclientserver.h"
    24 #include "sbeclientserver.h"
    25 #include "sbeserver.h"
    25 #include "sbeserver.h"
    26 #include "sbesession.h"
    26 #include "sbesession.h"
    27 #include "sbepanic.h"
    27 #include "sbepanic.h"
    28 #include "sbedataownermanager.h"
    28 #include "sbedataownermanager.h"
    29 #include "sblog.h"
    29 #include "OstTraceDefinitions.h"
    30 //#include <stdlib.h>
    30 #include "sbtrace.h"
       
    31 #ifdef OST_TRACE_COMPILER_IN_USE
       
    32 #include "sbeserverTraces.h"
       
    33 #endif
    31 
    34 
    32 namespace conn
    35 namespace conn
    33 	{
    36 	{
    34 
       
    35 
       
    36 	/** Secure Backup Engine security request ranges
    37 	/** Secure Backup Engine security request ranges
    37 	
    38 	
    38 	This is a breakdown of the SBE requests into ranges
    39 	This is a breakdown of the SBE requests into ranges
    39 	for security checking purposes.
    40 	for security checking purposes.
    40 
    41 
    88 		: CPolicyServer(EPriorityNormal,mySBEPolicy), iDOM(aDOM)
    89 		: CPolicyServer(EPriorityNormal,mySBEPolicy), iDOM(aDOM)
    89     /** 
    90     /** 
    90     Class constructor
    91     Class constructor
    91     */
    92     */
    92 		{
    93 		{
       
    94 		OstTraceFunctionEntry0( CSBESERVER_CSBESERVER_CONS_ENTRY );
    93 		__ASSERT_DEBUG(aDOM, Panic(KErrArgument));
    95 		__ASSERT_DEBUG(aDOM, Panic(KErrArgument));
       
    96 		OstTraceFunctionExit0( CSBESERVER_CSBESERVER_CONS_EXIT );
    94 		}
    97 		}
    95 
    98 
    96 	CSBEServer::~CSBEServer()
    99 	CSBEServer::~CSBEServer()
    97     /**
   100     /**
    98     Class destructor
   101     Class destructor
    99     */
   102     */
   100 		{
   103 		{
       
   104 		OstTraceFunctionEntry0( CSBESERVER_CSBESERVER_DES_ENTRY );
   101 		iGlobalSharedHeap.Close();
   105 		iGlobalSharedHeap.Close();
   102 		delete iGSHInterface;
   106 		delete iGSHInterface;
       
   107 		OstTraceFunctionExit0( CSBESERVER_CSBESERVER_DES_EXIT );
   103 		}
   108 		}
   104 		
   109 		
   105 	CSBEServer* CSBEServer::NewLC(CDataOwnerManager* aDOM)
   110 	CSBEServer* CSBEServer::NewLC(CDataOwnerManager* aDOM)
   106 	/**
   111 	/**
   107 	Constructs a new instance of the CSBEServer, calls ConstructL, 
   112 	Constructs a new instance of the CSBEServer, calls ConstructL, 
   108 	and returns it to the caller leaving it on the cleanup stack.
   113 	and returns it to the caller leaving it on the cleanup stack.
   109 
   114 
   110 	@return The new instance of CSBEServer.
   115 	@return The new instance of CSBEServer.
   111 	*/
   116 	*/
   112 		{
   117 		{
       
   118 		OstTraceFunctionEntry0( CSBESERVER_NEWLC_ENTRY );
   113 		CSBEServer* pSelf = new (ELeave) CSBEServer(aDOM);
   119 		CSBEServer* pSelf = new (ELeave) CSBEServer(aDOM);
   114 		CleanupStack::PushL(pSelf);
   120 		CleanupStack::PushL(pSelf);
   115 		pSelf->ConstructL();
   121 		pSelf->ConstructL();
       
   122 		OstTraceFunctionExit0( CSBESERVER_NEWLC_EXIT );
   116 		return pSelf;
   123 		return pSelf;
   117 		}
   124 		}
   118 
   125 
   119 	void CSBEServer::ConstructL()
   126 	void CSBEServer::ConstructL()
   120 	/**
   127 	/**
   121 	Construct this instance of CSBEServer.
   128 	Construct this instance of CSBEServer.
   122 	*/
   129 	*/
   123 		{
   130 		{
       
   131 		OstTraceFunctionEntry0( CSBESERVER_CONSTRUCTL_ENTRY );
   124 		AllocateGlobalSharedHeapL();
   132 		AllocateGlobalSharedHeapL();
   125 
   133 
   126 		iGSHInterface = CHeapWrapper::NewL();
   134 		iGSHInterface = CHeapWrapper::NewL();
   127 		
   135 		
   128 		// Initialise the locked flag to be unlock
   136 		// Initialise the locked flag to be unlock
   132 		StartL(KSBEServerName);
   140 		StartL(KSBEServerName);
   133 		iShutdown.ConstructL();
   141 		iShutdown.ConstructL();
   134 		#ifndef _DEBUG
   142 		#ifndef _DEBUG
   135 			iShutdown.Start();
   143 			iShutdown.Start();
   136 		#endif
   144 		#endif
       
   145 		OstTraceFunctionExit0( CSBESERVER_CONSTRUCTL_EXIT );
   137 		}
   146 		}
   138 		
   147 		
   139 	void CSBEServer::AllocateGlobalSharedHeapL()
   148 	void CSBEServer::AllocateGlobalSharedHeapL()
   140 	/**
   149 	/**
   141 	Attempts to allocate the GSH. If initial attempts fail, it tries to allocate with
   150 	Attempts to allocate the GSH. If initial attempts fail, it tries to allocate with
   142 	progressively smaller chunk sizes
   151 	progressively smaller chunk sizes
   143 	*/
   152 	*/
   144 		{	
   153 		{	
       
   154 		OstTraceFunctionEntry0( CSBESERVER_ALLOCATEGLOBALSHAREDHEAPL_ENTRY );
   145 		TInt attemptedSize;
   155 		TInt attemptedSize;
   146 		TInt retryCount;
   156 		TInt retryCount;
   147 		TInt redFactor;
   157 		TInt redFactor;
   148 		iDOM->Config().HeapValues(attemptedSize, retryCount, redFactor);
   158 		iDOM->Config().HeapValues(attemptedSize, retryCount, redFactor);
   149 		
   159 		
   163 				// Reduce the size of the GSH by a scale factor
   173 				// Reduce the size of the GSH by a scale factor
   164 				attemptedSize = attemptedSize / redFactor;
   174 				attemptedSize = attemptedSize / redFactor;
   165 				}
   175 				}
   166 			}
   176 			}
   167 			
   177 			
   168 		User::LeaveIfError(result);
   178 		LEAVEIFERROR(result, OstTrace1(TRACE_ERROR, CSBESERVER_ALLOCATEGLOBALSHAREDHEAPL, "error = %d", result));
       
   179 		OstTraceFunctionExit0( CSBESERVER_ALLOCATEGLOBALSHAREDHEAPL_EXIT );
   169 		}
   180 		}
   170 
   181 
   171 	void CSBEServer::AddSession()
   182 	void CSBEServer::AddSession()
   172 	/** Increments the server session count.
   183 	/** Increments the server session count.
   173 	
   184 	
   174 	The server will shutdown when its 
   185 	The server will shutdown when its 
   175 	session count drops to zero.
   186 	session count drops to zero.
   176 	*/
   187 	*/
   177 		{
   188 		{
       
   189 		OstTraceFunctionEntry0( CSBESERVER_ADDSESSION_ENTRY );
   178 		++iSessionCount;
   190 		++iSessionCount;
   179 		iShutdown.Cancel();
   191 		iShutdown.Cancel();
       
   192 		OstTraceFunctionExit0( CSBESERVER_ADDSESSION_EXIT );
   180 		}
   193 		}
   181 
   194 
   182 	void CSBEServer::DropSession()
   195 	void CSBEServer::DropSession()
   183 	/** Decrements the server session count.  
   196 	/** Decrements the server session count.  
   184 	
   197 	
   185 	The server will shutdown when its 
   198 	The server will shutdown when its 
   186 	session count drops to zero.
   199 	session count drops to zero.
   187 	*/
   200 	*/
   188 		{		
   201 		{		
       
   202 		OstTraceFunctionEntry0( CSBESERVER_DROPSESSION_ENTRY );
   189 		if(--iSessionCount == 0)
   203 		if(--iSessionCount == 0)
   190 			{
   204 			{
   191 			iShutdown.Start();
   205 			iShutdown.Start();
   192 			}
   206 			}
       
   207 		OstTraceFunctionExit0( CSBESERVER_DROPSESSION_EXIT );
   193 		}
   208 		}
   194 
   209 
   195 
   210 
   196 	CSession2* CSBEServer::NewSessionL(const TVersion& aVersion,
   211 	CSession2* CSBEServer::NewSessionL(const TVersion& aVersion,
   197 		const RMessage2& /*aMessage*/) const
   212 		const RMessage2& /*aMessage*/) const
   204 	@param aMessage Is ignored
   219 	@param aMessage Is ignored
   205 	@return A new instance of CSBESession
   220 	@return A new instance of CSBESession
   206 	@leave KErrNotSupported if the version passed in aVersion is not the same as this one
   221 	@leave KErrNotSupported if the version passed in aVersion is not the same as this one
   207 	*/
   222 	*/
   208 		{
   223 		{
       
   224 		OstTraceFunctionEntry0( CSBESERVER_NEWSESSIONL_ENTRY );
   209 		TVersion thisVersion(KSBEMajorVersionNumber, 
   225 		TVersion thisVersion(KSBEMajorVersionNumber, 
   210 								KSBEMinorVersionNumber,
   226 								KSBEMinorVersionNumber,
   211 								KSBEBuildVersionNumber);
   227 								KSBEBuildVersionNumber);
   212 		
   228 		
   213 	    if (!User::QueryVersionSupported(thisVersion, aVersion))
   229 	    if (!User::QueryVersionSupported(thisVersion, aVersion))
   214 			{
   230 			{
       
   231 	        OstTrace0(TRACE_ERROR, CSBESERVER_NEWSESSIONL, "Leave: KErrNotSupported");
   215 			User::Leave(KErrNotSupported);
   232 			User::Leave(KErrNotSupported);
   216 			}
   233 			}
   217 
   234 
   218 		return new (ELeave) CSBESession();
   235 	    CSession2* session = new (ELeave) CSBESession();
       
   236 	    OstTraceFunctionExit0( CSBESERVER_NEWSESSIONL_EXIT );
       
   237 		return session;
   219 		}
   238 		}
   220 
   239 
   221 	TInt CSBEServer::RunError(TInt aError)
   240 	TInt CSBEServer::RunError(TInt aError)
   222 	/** Called when this active objects RunL leaves. 
   241 	/** Called when this active objects RunL leaves. 
   223 	
   242 	
   227 
   246 
   228     @param aError  Standard Symbian OS error code
   247     @param aError  Standard Symbian OS error code
   229 	@return The error code to be passed back to the active scheduler framework.
   248 	@return The error code to be passed back to the active scheduler framework.
   230 	*/
   249 	*/
   231 		{
   250 		{
       
   251 		OstTraceFunctionEntry0( CSBESERVER_RUNERROR_ENTRY );
   232 		//
   252 		//
   233 		// A Bad descriptor is a bad client - panic it.
   253 		// A Bad descriptor is a bad client - panic it.
   234 		if(aError == KErrBadDescriptor)
   254 		if(aError == KErrBadDescriptor)
   235 			{
   255 			{
   236 			PanicClient(KErrBadDescriptor);
   256 			PanicClient(KErrBadDescriptor);
   238 
   258 
   239 		//
   259 		//
   240 		// Complete the message and continue handling requests.
   260 		// Complete the message and continue handling requests.
   241 		Message().Complete(aError);
   261 		Message().Complete(aError);
   242 		ReStart();
   262 		ReStart();
       
   263 		OstTraceFunctionExit0( CSBESERVER_RUNERROR_EXIT );
   243 		return KErrNone;
   264 		return KErrNone;
   244 		}
   265 		}
   245 
   266 
   246 
   267 
   247 	void CSBEServer::PanicClient(TInt aPanic) const
   268 	void CSBEServer::PanicClient(TInt aPanic) const
   248 	/** Panic a client.
   269 	/** Panic a client.
   249 
   270 
   250 	@param aPanic The panic code.
   271 	@param aPanic The panic code.
   251 	*/
   272 	*/
   252 		{
   273 		{
       
   274 		OstTraceFunctionEntry0( CSBESERVER_PANICCLIENT_ENTRY );
   253 		__DEBUGGER()
   275 		__DEBUGGER()
   254 		_LIT(KPanicCategory,"SBE Server");
   276 		_LIT(KPanicCategory,"SBE Server");
   255 		RThread client;
   277 		RThread client;
   256 		Message().Client(client);
   278 		Message().Client(client);
   257 		client.Panic(KPanicCategory, aPanic);
   279 		client.Panic(KPanicCategory, aPanic);
       
   280 		OstTraceFunctionExit0( CSBESERVER_PANICCLIENT_EXIT );
   258 		}
   281 		}
   259 
   282 
   260 	} // end namespace
   283 	} // end namespace