bluetoothmgmt/btmgr/BTManServer/BTManServer.cpp
branchRCL_3
changeset 11 20fda83a6398
parent 0 29b1cd4cb562
child 21 14e240312f6f
equal deleted inserted replaced
10:8a27654f7b62 11:20fda83a6398
     1 // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 1999-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
   107 	//Create the service providers...
   107 	//Create the service providers...
   108 	iRegistry = CBTRegistry::NewL();
   108 	iRegistry = CBTRegistry::NewL();
   109 
   109 
   110 	iContainerIndex = CObjectConIx::NewL();
   110 	iContainerIndex = CObjectConIx::NewL();
   111 	// don't stop the server if we can't provide this service...				   
   111 	// don't stop the server if we can't provide this service...				   
       
   112 	
       
   113 	//Start Backup/Restore Manager and obtain notification of backup/restore operations.
       
   114 	iBURManager=CBTManServerBURMgr::NewL(*this, this);
   112 	}
   115 	}
   113 
   116 
   114 
   117 
   115 CObjectCon* CBTManServer::NewContainerL()
   118 CObjectCon* CBTManServer::NewContainerL()
   116 /**
   119 /**
   138 	err = iProperty.Delete(KPropertyUidBluetoothCategory, KPropertyKeyBluetoothCorruptRegistryReset);
   141 	err = iProperty.Delete(KPropertyUidBluetoothCategory, KPropertyKeyBluetoothCorruptRegistryReset);
   139 	FLOGIFERR(err,_L("CBTManServer::~CBTManServer() - iProperty.Delete Failure"));
   142 	FLOGIFERR(err,_L("CBTManServer::~CBTManServer() - iProperty.Delete Failure"));
   140 	// Close the RProperty handle in case it is ever attached.
   143 	// Close the RProperty handle in case it is ever attached.
   141 	iProperty.Close();
   144 	iProperty.Close();
   142 
   145 
       
   146 	delete iBURManager;
   143 	delete iRegistry;
   147 	delete iRegistry;
   144 	delete iContainerIndex;
   148 	delete iContainerIndex;
   145 	}
   149 	}
   146 
   150 
   147 CSession2* CBTManServer::NewSessionL(const TVersion &aVersion, const RMessage2& aMessage) const
   151 CSession2* CBTManServer::NewSessionL(const TVersion &aVersion, const RMessage2& aMessage) const
   154 		}
   158 		}
   155 	// make new session
   159 	// make new session
   156 	return new(ELeave) CBTManSession(*iRegistry, aMessage);
   160 	return new(ELeave) CBTManSession(*iRegistry, aMessage);
   157 	}
   161 	}
   158 
   162 
       
   163 void CBTManServer::BUROperationStarted()
       
   164 /**
       
   165 A backup or restore operation has started.
       
   166 Cancel the shutdown timer if it was running
       
   167 **/
       
   168 	{
       
   169 	LOG_FUNC
       
   170 	__ASSERT_DEBUG(!iBUROperationStarted, PanicServer(EBTManBadState));
       
   171 
       
   172 	iBUROperationStarted = ETrue;
       
   173 	iShutdown.Cancel();
       
   174 	}
       
   175 
       
   176 void CBTManServer::BUROperationStopped()
       
   177 /**
       
   178 A backup or restore operation has finished.
       
   179 Start the shutdown timer if there are no sessions running.
       
   180 **/
       
   181 	{
       
   182 	LOG_FUNC
       
   183 	__ASSERT_DEBUG(iBUROperationStarted, PanicServer(EBTManBadState));
       
   184 
       
   185 	iBUROperationStarted = EFalse;
       
   186 	TryToStartShutdownTimer();
       
   187 	}
       
   188 
   159 void CBTManServer::AddSession()
   189 void CBTManServer::AddSession()
   160 /**
   190 /**
   161 A new session is being created
   191 A new session is being created
   162 Cancel the shutdown timer if it was running
   192 Cancel the shutdown timer if it was running
   163 **/
   193 **/
   178 **/
   208 **/
   179 	{
   209 	{
   180 	LOG_FUNC
   210 	LOG_FUNC
   181 	__ASSERT_DEBUG(iSessionCount > 0, PanicServer(EBTManBadState));
   211 	__ASSERT_DEBUG(iSessionCount > 0, PanicServer(EBTManBadState));
   182 	
   212 	
   183 	if (--iSessionCount==0)
   213 	--iSessionCount;
       
   214 	TryToStartShutdownTimer();
       
   215 	}
       
   216 
       
   217 void CBTManServer::TryToStartShutdownTimer()
       
   218 /**
       
   219 Starts the shutdown timer if the server is able to shutdown
       
   220 **/
       
   221 	{
       
   222 	LOG_FUNC
       
   223 	
       
   224 	if (iSessionCount == 0 && !iBUROperationStarted)
   184 		{
   225 		{
   185 		iShutdown.Start();
   226 		iShutdown.Start();
   186 		}
   227 		}
   187 	}
   228 	}
   188 
   229 
   202 	// For views owned by subsessions.
   243 	// For views owned by subsessions.
   203 	
   244 	
   204 	// Go through all sessions - they'll dispatch so all the subessions apart from the one calling here
   245 	// Go through all sessions - they'll dispatch so all the subessions apart from the one calling here
   205 	iSessionIter.SetToFirst();
   246 	iSessionIter.SetToFirst();
   206 
   247 
   207 	while (iSessionIter != NULL)
   248 	while (iSessionIter)
   208 		{
   249 		{
   209 		CBTManSession* s = static_cast<CBTManSession*>(iSessionIter++);
   250 		CBTManSession* s = static_cast<CBTManSession*>(iSessionIter++);
   210 		s->SubSessionHasOverlappingView(aSubSessionViewOwner, aViewDescriptor);
   251 		s->SubSessionHasOverlappingView(aSubSessionViewOwner, aViewDescriptor);
   211 		}
   252 		}
   212 	}
   253 	}
   213 
   254 
       
   255 void CBTManServer::NotifyViewChange(const TDesC& aViewDescriptor)
       
   256 	{
       
   257 	LOG_FUNC
       
   258 	// For views not owned by subsessions (e.g. views owned by Backup/Restore classes)
       
   259 
       
   260 	// Go through all sessions - they'll dispatch so all the subessions apart from the one calling here
       
   261 	iSessionIter.SetToFirst();
       
   262 
       
   263 	while (iSessionIter)
       
   264 		{
       
   265 		CBTManSession* s = static_cast<CBTManSession*>(iSessionIter++);
       
   266 		s->SubSessionHasOverlappingView(aViewDescriptor);
       
   267 		}
       
   268 	}
       
   269 	
   214 void PanicClient(const RMessage2& aMessage,TInt aPanic, CBTManSession* aSession)
   270 void PanicClient(const RMessage2& aMessage,TInt aPanic, CBTManSession* aSession)
   215 /**
   271 /**
   216 RMessage2::Panic() also completes the message. This is:
   272 RMessage2::Panic() also completes the message. This is:
   217 (a) important for efficient cleanup within the kernel
   273 (a) important for efficient cleanup within the kernel
   218 (b) a problem if the message is completed a second time
   274 (b) a problem if the message is completed a second time
  1095 		}
  1151 		}
  1096 
  1152 
  1097 	return overlapFound;
  1153 	return overlapFound;
  1098 	}
  1154 	}
  1099 
  1155 
       
  1156 TBool CBTManSession::SubSessionHasOverlappingView(const TDesC& aViewDescriptor)
       
  1157 	{
       
  1158 	LOG_FUNC
       
  1159 	// Iterate over all subsessions (view owner is not a subsession)
       
  1160 	TBool overlapFound = EFalse;
       
  1161 	for (TInt i = 0; i < iContainer->Count(); i++)
       
  1162 		{
       
  1163 		CBTManSubSession* ss = static_cast<CBTManSubSession*>((*iContainer)[i]);
       
  1164 		if (ss->IsOverlappingView(aViewDescriptor))
       
  1165 			{
       
  1166 			// Overlaps - subsession will have completed the Notify message
       
  1167 			// With bool return, we can test if indeed it did.
       
  1168 			overlapFound = ETrue;
       
  1169 			}
       
  1170 		}
       
  1171 
       
  1172 	return overlapFound;
       
  1173 	}
       
  1174 
  1100 
  1175 
  1101 //=====================================================================
  1176 //=====================================================================
  1102 //	CBTManSubSession
  1177 //	CBTManSubSession
  1103 //=====================================================================
  1178 //=====================================================================
  1104 
  1179