backupandrestore/backupengine/src/abserver.cpp
changeset 47 63cf70d3ecd8
parent 33 883e91c086aa
equal deleted inserted replaced
44:a5deb6b96675 47:63cf70d3ecd8
    25 #include "abserver.h"
    25 #include "abserver.h"
    26 #include "absession.h"
    26 #include "absession.h"
    27 #include "absessionmap.h"
    27 #include "absessionmap.h"
    28 #include "sbedataownermanager.h"
    28 #include "sbedataownermanager.h"
    29 #include "sbepanic.h"
    29 #include "sbepanic.h"
    30 #include "sblog.h"
    30 #include "OstTraceDefinitions.h"
       
    31 #include "sbtrace.h"
       
    32 #ifdef OST_TRACE_COMPILER_IN_USE
       
    33 #include "abserverTraces.h"
       
    34 #endif
    31 
    35 
    32 namespace conn
    36 namespace conn
    33 	{
    37 	{
    34 
       
    35 
       
    36 	/** Active Backup security request ranges
    38 	/** Active Backup security request ranges
    37 	
    39 	
    38 	This is a breakdown of the active backup requests into ranges
    40 	This is a breakdown of the active backup requests into ranges
    39 	for security checking purposes.
    41 	for security checking purposes.
    40 
    42 
    85 		: CPolicyServer(EPriorityNormal,myABPolicy), iDOM(aDOM)
    87 		: CPolicyServer(EPriorityNormal,myABPolicy), iDOM(aDOM)
    86     /** 
    88     /** 
    87     Class constructor
    89     Class constructor
    88     */
    90     */
    89 		{
    91 		{
       
    92 		OstTraceFunctionEntry0( CABSERVER_CABSERVER_CONS_ENTRY );
    90 		__ASSERT_DEBUG(iDOM, Panic(KErrArgument));
    93 		__ASSERT_DEBUG(iDOM, Panic(KErrArgument));
       
    94 		OstTraceFunctionExit0( CABSERVER_CABSERVER_CONS_EXIT );
    91 		}
    95 		}
    92 
    96 
    93 	CABServer::~CABServer()
    97 	CABServer::~CABServer()
    94     /**
    98     /**
    95     Class destructor
    99     Class destructor
    96     */
   100     */
    97 		{
   101 		{
       
   102 		OstTraceFunctionEntry0( CABSERVER_CABSERVER_DES_ENTRY );
    98 		delete iSessionMap;
   103 		delete iSessionMap;
       
   104 		OstTraceFunctionExit0( CABSERVER_CABSERVER_DES_EXIT );
    99 		}
   105 		}
   100 		
   106 		
   101 	CABServer* CABServer::NewLC(CDataOwnerManager* aDOM)
   107 	CABServer* CABServer::NewLC(CDataOwnerManager* aDOM)
   102 	/**
   108 	/**
   103 	Constructs a new instance of the CABServer, calls ConstructL, 
   109 	Constructs a new instance of the CABServer, calls ConstructL, 
   104 	and returns it to the caller leaving it on the cleanup stack.
   110 	and returns it to the caller leaving it on the cleanup stack.
   105 
   111 
   106 	@return The new instance of CABServer.
   112 	@return The new instance of CABServer.
   107 	*/
   113 	*/
   108 		{
   114 		{
       
   115 		OstTraceFunctionEntry0( CABSERVER_NEWLC_ENTRY );
   109 		CABServer* pSelf = new (ELeave) CABServer(aDOM);
   116 		CABServer* pSelf = new (ELeave) CABServer(aDOM);
   110 		CleanupStack::PushL(pSelf);
   117 		CleanupStack::PushL(pSelf);
   111 		pSelf->ConstructL();
   118 		pSelf->ConstructL();
       
   119 		OstTraceFunctionExit0( CABSERVER_NEWLC_EXIT );
   112 		return pSelf;
   120 		return pSelf;
   113 		}
   121 		}
   114 
   122 
   115 	void CABServer::ConstructL()
   123 	void CABServer::ConstructL()
   116 	/**
   124 	/**
   117 	Construct this instance of CABServer.
   125 	Construct this instance of CABServer.
   118 	*/
   126 	*/
   119 		{
   127 		{
       
   128 		OstTraceFunctionEntry0( CABSERVER_CONSTRUCTL_ENTRY );
   120 		iSessionMap = CABSessionMap::NewL();
   129 		iSessionMap = CABSessionMap::NewL();
   121 		//
   130 		//
   122 		// Start the server 
   131 		// Start the server 
   123 		StartL(KABServerName);
   132 		StartL(KABServerName);
       
   133 		OstTraceFunctionExit0( CABSERVER_CONSTRUCTL_EXIT );
   124 		}
   134 		}
   125 
   135 
   126 	void CABServer::AddSession()
   136 	void CABServer::AddSession()
   127 	/** Increments the server session count.
   137 	/** Increments the server session count.
   128 	
   138 	
   148 	Remove the element with key aSecureId from the session map
   158 	Remove the element with key aSecureId from the session map
   149 	
   159 	
   150 	@param aSecureId The key of the element to be removed
   160 	@param aSecureId The key of the element to be removed
   151 	*/
   161 	*/
   152 		{
   162 		{
       
   163 		OstTraceFunctionEntry0( CABSERVER_REMOVEELEMENT_ENTRY );
   153 		iSessionMap->Delete(aSecureId);
   164 		iSessionMap->Delete(aSecureId);
       
   165 		OstTraceFunctionExit0( CABSERVER_REMOVEELEMENT_EXIT );
   154 		}
   166 		}
   155 
   167 
   156 	void CABServer::SupplyDataL(TSecureId aSID, TDriveNumber aDriveNumber, TTransferDataType aTransferType, 
   168 	void CABServer::SupplyDataL(TSecureId aSID, TDriveNumber aDriveNumber, TTransferDataType aTransferType, 
   157 		TDesC8& aBuffer, TBool aLastSection, TBool aSuppressInitDataOwner, TSecureId aProxySID)
   169 		TDesC8& aBuffer, TBool aLastSection, TBool aSuppressInitDataOwner, TSecureId aProxySID)
   158 	/**
   170 	/**
   165 	@param aLastSection Flag to indicate whether this is the last operation in a multi-part transfer
   177 	@param aLastSection Flag to indicate whether this is the last operation in a multi-part transfer
   166 	@param aSuppressInitDataOwner Suppress the initialisation of Data Owner
   178 	@param aSuppressInitDataOwner Suppress the initialisation of Data Owner
   167 	@param aProxySID The secure ID of the proxy
   179 	@param aProxySID The secure ID of the proxy
   168 	*/
   180 	*/
   169 		{
   181 		{
       
   182 		OstTraceFunctionEntry0( CABSERVER_SUPPLYDATAL_ENTRY );
   170 		CABSession& session = iSessionMap->SessionL(aSID);
   183 		CABSession& session = iSessionMap->SessionL(aSID);
   171 		
   184 		
   172 		session.SupplyDataL(aDriveNumber, aTransferType, aBuffer, aLastSection, aSuppressInitDataOwner, aProxySID);
   185 		session.SupplyDataL(aDriveNumber, aTransferType, aBuffer, aLastSection, aSuppressInitDataOwner, aProxySID);
       
   186 		OstTraceFunctionExit0( CABSERVER_SUPPLYDATAL_EXIT );
   173 		}
   187 		}
   174 
   188 
   175 	void CABServer::RequestDataL(TSecureId aSID, TDriveNumber aDriveNumber, TTransferDataType aTransferType, 
   189 	void CABServer::RequestDataL(TSecureId aSID, TDriveNumber aDriveNumber, TTransferDataType aTransferType, 
   176 		TPtr8& aBuffer, TBool& aLastSection, TBool aSuppressInitDataOwner, TSecureId aProxySID)
   190 		TPtr8& aBuffer, TBool& aLastSection, TBool aSuppressInitDataOwner, TSecureId aProxySID)
   177 	/**
   191 	/**
   184 	@param aLastSection Flag to indicate whether this is the last operation in a multi-part transfer
   198 	@param aLastSection Flag to indicate whether this is the last operation in a multi-part transfer
   185 	@param aSuppressInitDataOwner Suppress the initialisation of Data Owner
   199 	@param aSuppressInitDataOwner Suppress the initialisation of Data Owner
   186 	@param aProxySID The secure ID of the proxy
   200 	@param aProxySID The secure ID of the proxy
   187 	*/
   201 	*/
   188 		{
   202 		{
       
   203 		OstTraceFunctionEntry0( CABSERVER_REQUESTDATAL_ENTRY );
   189 		CABSession& session = iSessionMap->SessionL(aSID);
   204 		CABSession& session = iSessionMap->SessionL(aSID);
   190 		
   205 		
   191 		session.RequestDataL(aDriveNumber, aTransferType, aBuffer, aLastSection, aSuppressInitDataOwner, aProxySID);
   206 		session.RequestDataL(aDriveNumber, aTransferType, aBuffer, aLastSection, aSuppressInitDataOwner, aProxySID);
       
   207 		OstTraceFunctionExit0( CABSERVER_REQUESTDATAL_EXIT );
   192 		}
   208 		}
   193 
   209 
   194 	void CABServer::GetExpectedDataSizeL(TSecureId aSID, TDriveNumber aDriveNumber, TUint& aSize)
   210 	void CABServer::GetExpectedDataSizeL(TSecureId aSID, TDriveNumber aDriveNumber, TUint& aSize)
   195 	/**
   211 	/**
   196 	Get the expected size of the data that will be returned
   212 	Get the expected size of the data that will be returned
   198 	@param aSID The secure ID of the data owner to signal
   214 	@param aSID The secure ID of the data owner to signal
   199 	@param aDriveNumber The drive number that the data corresponds to
   215 	@param aDriveNumber The drive number that the data corresponds to
   200 	@param aSize The size of the data owner's data
   216 	@param aSize The size of the data owner's data
   201 	*/
   217 	*/
   202 		{
   218 		{
       
   219 		OstTraceFunctionEntry0( CABSERVER_GETEXPECTEDDATASIZEL_ENTRY );
   203 		CABSession& session = iSessionMap->SessionL(aSID);
   220 		CABSession& session = iSessionMap->SessionL(aSID);
   204 		
   221 		
   205 		session.GetExpectedDataSizeL(aDriveNumber, aSize);
   222 		session.GetExpectedDataSizeL(aDriveNumber, aSize);
       
   223 		OstTraceFunctionExit0( CABSERVER_GETEXPECTEDDATASIZEL_EXIT );
   206 		}
   224 		}
   207 		
   225 		
   208 	void CABServer::AllSnapshotsSuppliedL(TSecureId aSID)
   226 	void CABServer::AllSnapshotsSuppliedL(TSecureId aSID)
   209 	/** Lets the client know that all its snapshots have been supplied
   227 	/** Lets the client know that all its snapshots have been supplied
   210 	
   228 	
   211 	@param aSID The secure ID of the data owner to signal
   229 	@param aSID The secure ID of the data owner to signal
   212 	*/
   230 	*/
   213 		{
   231 		{
       
   232 		OstTraceFunctionEntry0( CABSERVER_ALLSNAPSHOTSSUPPLIEDL_ENTRY );
   214 		CABSession& session = iSessionMap->SessionL(aSID);
   233 		CABSession& session = iSessionMap->SessionL(aSID);
   215 		
   234 		
   216 		session.AllSnapshotsSuppliedL();
   235 		session.AllSnapshotsSuppliedL();
       
   236 		OstTraceFunctionExit0( CABSERVER_ALLSNAPSHOTSSUPPLIEDL_EXIT );
   217 		}
   237 		}
   218 
   238 
   219 	void CABServer::InvalidateABSessions()
   239 	void CABServer::InvalidateABSessions()
   220 	/** Set each CABSession currently hold for each active backup
   240 	/** Set each CABSession currently hold for each active backup
   221 	 * client as invalid, since there maybe some delay for the
   241 	 * client as invalid, since there maybe some delay for the
   222 	 * arrival of disconnect request from client. Within this time,
   242 	 * arrival of disconnect request from client. Within this time,
   223 	 * this session can not be used for another backup/restore.
   243 	 * this session can not be used for another backup/restore.
   224 	 */
   244 	 */
   225 		{
   245 		{
       
   246 		OstTraceFunctionEntry0( CABSERVER_INVALIDATEABSESSIONS_ENTRY );
   226 		iSessionMap->InvalidateABSessions();
   247 		iSessionMap->InvalidateABSessions();
       
   248 		OstTraceFunctionExit0( CABSERVER_INVALIDATEABSESSIONS_EXIT );
   227 		}
   249 		}
   228 	
   250 	
   229 	TDataOwnerStatus CABServer::SessionReadyStateL(TSecureId aSID)
   251 	TDataOwnerStatus CABServer::SessionReadyStateL(TSecureId aSID)
   230 	/**
   252 	/**
   231 	Returns the status of the active backup client
   253 	Returns the status of the active backup client
   232 	
   254 	
   233 	@param aSID The SecureId of the session to query for
   255 	@param aSID The SecureId of the session to query for
   234 	@return Data owner status of the session
   256 	@return Data owner status of the session
   235 	*/
   257 	*/
   236 		{
   258 		{
       
   259 		OstTraceFunctionEntry0( CABSERVER_SESSIONREADYSTATEL_ENTRY );
   237 		CABSession& session = iSessionMap->SessionL(aSID);
   260 		CABSession& session = iSessionMap->SessionL(aSID);
   238 		
   261 		
   239 		TDataOwnerStatus doStatus = EDataOwnerNotConnected;
   262 		TDataOwnerStatus doStatus = EDataOwnerNotConnected;
   240 		if (session.Invalidated())
   263 		if (session.Invalidated())
   241 			{
   264 			{
   242 			__LOG1("CABServer::SessionReadyStateL session for 0x%08x has been invalidated, return NotConnected",
   265 			OstTrace1(TRACE_NORMAL, CABSERVER_SESSIONREADYSTATEL, "session for 0x%08x has been invalidated, return NotConnected",
   243 					aSID.iId);
   266                     aSID.iId);
   244 			
   267 			
       
   268 			OstTraceFunctionExit0( CABSERVER_SESSIONREADYSTATEL_EXIT );
   245 			return doStatus;	
   269 			return doStatus;	
   246 			}
   270 			}
   247 		
   271 		
   248 		if (session.CallbackInterfaceAvailable())
   272 		if (session.CallbackInterfaceAvailable())
   249 			{
   273 			{
   250 			__LOG2("CABServer::SessionReadyStateL session for 0x%08x already have interface, confirmed:%d ",
   274 			OstTraceExt2(TRACE_NORMAL, DUP1_CABSERVER_SESSIONREADYSTATEL, "session for 0x%08x already have interface, confirmed:%d ",
   251 					aSID.iId, session.ConfirmedReadyForBUR());
   275                     aSID.iId, static_cast<TInt32>(session.ConfirmedReadyForBUR()));
   252 			
   276 			
   253 			doStatus = EDataOwnerNotReady;
   277 			doStatus = EDataOwnerNotReady;
   254 			
   278 			
   255 			if (session.ConfirmedReadyForBUR())
   279 			if (session.ConfirmedReadyForBUR())
   256 				{
   280 				{
   257 				doStatus = EDataOwnerReady;
   281 				doStatus = EDataOwnerReady;
   258 				}
   282 				}
   259 			}
   283 			}
   260 		else 
   284 		else 
   261 			{
   285 			{
   262 			__LOG2("CABServer::SessionReadyStateL session for 0x%08x does not have interface, confimed:%d",
   286 			OstTraceExt2(TRACE_NORMAL, DUP2_CABSERVER_SESSIONREADYSTATEL, "session for 0x%08x does not have interface, confimed:%d",
   263 								aSID.iId, session.ConfirmedReadyForBUR());
   287                     aSID.iId, static_cast<TInt32>(session.ConfirmedReadyForBUR()));
   264 			
   288 			
   265 			doStatus = EDataOwnerNotReady;
   289 			doStatus = EDataOwnerNotReady;
   266 			
   290 			
   267 			if (session.ConfirmedReadyForBUR())
   291 			if (session.ConfirmedReadyForBUR())
   268 				{
   292 				{
   269 				doStatus = EDataOwnerReadyNoImpl;
   293 				doStatus = EDataOwnerReadyNoImpl;
   270 				}				
   294 				}				
   271 			}
   295 			}
   272 			
   296 			
       
   297 		OstTraceFunctionExit0( DUP1_CABSERVER_SESSIONREADYSTATEL_EXIT );
   273 		return doStatus;
   298 		return doStatus;
   274 		}
   299 		}
   275 		
   300 		
   276 	void CABServer::RestoreCompleteL(TSecureId aSID, TDriveNumber aDrive)
   301 	void CABServer::RestoreCompleteL(TSecureId aSID, TDriveNumber aDrive)
   277 	/**
   302 	/**
   279 	
   304 	
   280 	@param aSID The secure Id of the active client for which the restore has completed
   305 	@param aSID The secure Id of the active client for which the restore has completed
   281 	@param aDrive The drive number for which the restore has completed
   306 	@param aDrive The drive number for which the restore has completed
   282 	*/
   307 	*/
   283 		{
   308 		{
       
   309 		OstTraceFunctionEntry0( CABSERVER_RESTORECOMPLETEL_ENTRY );
   284 		CABSession& session = iSessionMap->SessionL(aSID);
   310 		CABSession& session = iSessionMap->SessionL(aSID);
   285 
   311 
   286 		session.RestoreCompleteL(aDrive);
   312 		session.RestoreCompleteL(aDrive);
       
   313 		OstTraceFunctionExit0( CABSERVER_RESTORECOMPLETEL_EXIT );
   287 		}
   314 		}
   288 		
   315 		
   289 	CSession2* CABServer::NewSessionL(const TVersion& aVersion,
   316 	CSession2* CABServer::NewSessionL(const TVersion& aVersion,
   290 		const RMessage2& aMessage) const
   317 		const RMessage2& aMessage) const
   291 	/** Constructs a new AB session.
   318 	/** Constructs a new AB session.
   297 	@param aMessage Is ignored
   324 	@param aMessage Is ignored
   298 	@return A new instance of CABSession
   325 	@return A new instance of CABSession
   299 	@leave KErrNotSupported if the version passed in aVersion is not the same as this one
   326 	@leave KErrNotSupported if the version passed in aVersion is not the same as this one
   300 	*/
   327 	*/
   301 		{
   328 		{
       
   329 		OstTraceFunctionEntry0( CABSERVER_NEWSESSIONL_ENTRY );
   302 		TVersion thisVersion(KABMajorVersionNumber, 
   330 		TVersion thisVersion(KABMajorVersionNumber, 
   303 								KABMinorVersionNumber,
   331 								KABMinorVersionNumber,
   304 								KABBuildVersionNumber);
   332 								KABBuildVersionNumber);
   305 		
   333 		
   306 	    if (!User::QueryVersionSupported(thisVersion, aVersion))
   334 	    if (!User::QueryVersionSupported(thisVersion, aVersion))
   307 			{
   335 			{
       
   336 	        OstTrace0(TRACE_ERROR, CABSERVER_NEWSESSIONL, "Leave: KErrNotSupported");
   308 			User::Leave(KErrNotSupported);
   337 			User::Leave(KErrNotSupported);
   309 			}
   338 			}
   310 			
   339 			
   311 		TSecureId sid = aMessage.SecureId();
   340 		TSecureId sid = aMessage.SecureId();
   312 
   341 
   313 		// The map creates the session and a map entry, then session ownership is passed to the server
   342 		// The map creates the session and a map entry, then session ownership is passed to the server
   314 		return &(iSessionMap->CreateL(sid));
   343 		CSession2* newSession = &(iSessionMap->CreateL(sid));
       
   344 		OstTraceFunctionExit0( CABSERVER_NEWSESSIONL_EXIT );
       
   345 		return newSession;
   315 		}
   346 		}
   316 
   347 
   317 	TInt CABServer::RunError(TInt aError)
   348 	TInt CABServer::RunError(TInt aError)
   318 	/** Called when this active objects RunL leaves. 
   349 	/** Called when this active objects RunL leaves. 
   319 	
   350 	
   323 
   354 
   324     @param aError  Standard Symbian OS error code
   355     @param aError  Standard Symbian OS error code
   325 	@return The error code to be passed back to the active scheduler framework.
   356 	@return The error code to be passed back to the active scheduler framework.
   326 	*/
   357 	*/
   327 		{
   358 		{
       
   359 		OstTraceFunctionEntry0( CABSERVER_RUNERROR_ENTRY );
   328 		//
   360 		//
   329 		// A Bad descriptor is a bad client - panic it.
   361 		// A Bad descriptor is a bad client - panic it.
   330 		if(aError == KErrBadDescriptor)
   362 		if(aError == KErrBadDescriptor)
   331 			{
   363 			{
   332 			PanicClient(KErrBadDescriptor);
   364 			PanicClient(KErrBadDescriptor);
   334 
   366 
   335 		//
   367 		//
   336 		// Complete the message and continue handling requests.
   368 		// Complete the message and continue handling requests.
   337 		Message().Complete(aError);
   369 		Message().Complete(aError);
   338 		ReStart();
   370 		ReStart();
       
   371 		OstTraceFunctionExit0( CABSERVER_RUNERROR_EXIT );
   339 		return KErrNone;
   372 		return KErrNone;
   340 		}
   373 		}
   341 
   374 
   342 	void CABServer::PanicClient(TInt aPanic) const
   375 	void CABServer::PanicClient(TInt aPanic) const
   343 	/** Panic a client.
   376 	/** Panic a client.
   344 
   377 
   345 	@param aPanic The panic code.
   378 	@param aPanic The panic code.
   346 	*/
   379 	*/
   347 		{
   380 		{
       
   381 		OstTraceFunctionEntry0( CABSERVER_PANICCLIENT_ENTRY );
   348 		__DEBUGGER()
   382 		__DEBUGGER()
   349 		_LIT(KPanicCategory,"AB Server");
   383 		_LIT(KPanicCategory,"AB Server");
   350 		RThread client;
   384 		RThread client;
   351 		Message().Client(client);
   385 		Message().Client(client);
   352 		client.Panic(KPanicCategory, aPanic);
   386 		client.Panic(KPanicCategory, aPanic);
       
   387 		OstTraceFunctionExit0( CABSERVER_PANICCLIENT_EXIT );
   353 		}
   388 		}
   354 
   389 
   355 	} // end namespace
   390 	} // end namespace