pimprotocols/phonebooksync/Server/phbksyncsess.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 // Copyright (c) 2002-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 // Contains method implementations for CPhonebookSession.
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22 
       
    23 #include "Phonebook.h"
       
    24 #include "PhonebookManager.h"
       
    25 #include "SyncContactICCEntry.h"
       
    26 #include "phbksyncsvr.h"
       
    27 #include "phbksyncsess.h"
       
    28 #include "phbksynclog.h"
       
    29 
       
    30 
       
    31 #ifdef _DEBUG
       
    32 /**
       
    33  *  Debug text names for the Phonebook Sync IPC Requests.
       
    34  */
       
    35 const char*  KPhonebookSyncRequestNames[26] = {
       
    36 		"ESyncDoSynchronisation", "ESyncGetContactFormat", "ESyncGetSyncMode",
       
    37 		"ESyncSetSyncMode", "ESyncDeleteCntFromICC", "ESyncWriteCntToICC",
       
    38 		"ESyncValidateContact", "ESyncUpdateLookupTable",
       
    39 		"ESyncGetPhoneBookId", "ESyncGetCacheState", "ESyncDbgMarkHeap",
       
    40 		"ESyncDbgCheckHeap", "ESyncDbgMarkEnd", "ESyncDbgFailNext",
       
    41 		"ESyncDoSynchronisationCancel", "ESyncDeleteCntFromICCCancel",
       
    42 		"ESyncWriteCntToICCCancel", "ESyncNotifyCacheStateChange",
       
    43 		"ESyncNotifyCacheStateChangeCancel", "ESyncGetLastSyncError",
       
    44 		"ESyncGetNumSlots", "ESyncGetNumFreeSlots", "ESyncGetFreeSlots",
       
    45 		"ESyncGetSlotId", "ESyncFlushInterfaceQueue", "ESyncShutdownServer"};
       
    46 #endif
       
    47 
       
    48 
       
    49 /**
       
    50  *  Second phase constructor for sessions. Called by the CServer2 framework
       
    51  *  when a session is created (e.g. a connection is made to the server).
       
    52  */
       
    53 void CPhoneBookSession::CreateL()
       
    54 	{
       
    55 	LOGSESSION1(_L8("CreateL()"));
       
    56 
       
    57 	Server().AddSessionL(this);
       
    58 	} // CPhoneBookSession::CreateL()
       
    59 
       
    60 
       
    61 /**
       
    62  *  Destructor for session classes. When this is called it indicates that
       
    63  *  a session is closing its connection with the server.
       
    64  */
       
    65 CPhoneBookSession::~CPhoneBookSession()
       
    66 	{
       
    67 	LOGSESSION1(_L8("~CPhoneBookSession()"));
       
    68 
       
    69 	Server().DropSession(this);
       
    70 	} // CPhoneBookSession::~CPhoneBookSession()
       
    71 
       
    72 
       
    73 /**
       
    74  *  Handle message requests for this session. Leaving is handled by
       
    75  *  CPhoneBookServer::RunError() which reports the error code to the client.
       
    76  *
       
    77  *  @param aMessage  RMessage2 reference which encapsulates a client request.
       
    78  */
       
    79 void CPhoneBookSession::ServiceL(const RMessage2& aMessage)
       
    80 
       
    81 	{
       
    82 	LOGSESSION4(_L8("ServiceL(): Session=0x%08x IPC=%d (%s)"),
       
    83 	           this, aMessage.Function(),
       
    84 	           KPhonebookSyncRequestNames[aMessage.Function()]);
       
    85 	LOGSESSIONTIMESTAMP();
       
    86 	
       
    87 	switch (aMessage.Function())
       
    88 		{
       
    89 		case ESyncDoSynchronisation:
       
    90 			{
       
    91 			DoSynchronisationL(aMessage);
       
    92 			}
       
    93 			break;
       
    94 
       
    95 		case ESyncGetContactFormat:
       
    96 			{
       
    97 			GetContactFormatL(aMessage);
       
    98 			}
       
    99 			break;
       
   100 
       
   101 		case ESyncGetSyncMode:
       
   102 			{
       
   103 			GetSyncModeL(aMessage);
       
   104 			}
       
   105 			break;
       
   106 
       
   107 		case ESyncSetSyncMode:
       
   108 			{
       
   109 			SetSyncModeL(aMessage);
       
   110 			}
       
   111 			break;
       
   112 
       
   113 		case ESyncDeleteCntFromICC:
       
   114 			{
       
   115 			DeleteCntFromICCL(aMessage);
       
   116 			}
       
   117 			break;
       
   118 
       
   119 		case ESyncWriteCntToICC:
       
   120 			{
       
   121 			WriteCntToICCL(aMessage);
       
   122 			}
       
   123 			break;
       
   124 
       
   125 		case ESyncValidateContact:
       
   126 			{
       
   127 			ValidateContactL(aMessage);
       
   128 			}
       
   129 			break;
       
   130 
       
   131 		case ESyncUpdateLookupTable:
       
   132 			{
       
   133 			UpdateLookupTableL(aMessage);
       
   134 			}
       
   135 			break;
       
   136 
       
   137 		case ESyncGetPhoneBookId:
       
   138 			{
       
   139 			GetPhoneBookIdL(aMessage);
       
   140 			}
       
   141 			break;
       
   142 
       
   143 		case ESyncGetCacheState:
       
   144 			{
       
   145 			GetCacheStateL(aMessage);
       
   146 			}
       
   147 			break;
       
   148 
       
   149 		case ESyncDbgMarkHeap:
       
   150 			{
       
   151 			DbgMarkHeapL(aMessage);
       
   152 			}
       
   153 			break;
       
   154 
       
   155 		case ESyncDbgCheckHeap:
       
   156 			{
       
   157 			DbgCheckHeapL(aMessage);
       
   158 			}
       
   159 			break;
       
   160 
       
   161 		case ESyncDbgMarkEnd:
       
   162 			{
       
   163 			DbgMarkEndL(aMessage);
       
   164 			}
       
   165 			break;
       
   166 
       
   167 		case ESyncDbgFailNext:
       
   168 			{
       
   169 			DbgFailNextL(aMessage);
       
   170 			}
       
   171 			break;
       
   172 
       
   173 		case ESyncDoSynchronisationCancel:
       
   174 			{
       
   175 			DoSynchronisationCancelL(aMessage);
       
   176 			}
       
   177 			break;
       
   178 
       
   179 		case ESyncDeleteCntFromICCCancel:
       
   180 			{
       
   181 			DeleteCntFromICCCancelL(aMessage);
       
   182 			}
       
   183 			break;
       
   184 
       
   185 		case ESyncWriteCntToICCCancel:
       
   186 			{
       
   187 			WriteCntToICCCancelL(aMessage);
       
   188 			}
       
   189 			break;
       
   190 
       
   191 		case ESyncNotifyCacheStateChange:
       
   192 			{
       
   193 			NotifyCacheStateChangeL(aMessage);
       
   194 			}
       
   195 			break;
       
   196 
       
   197 		case ESyncNotifyCacheStateChangeCancel:
       
   198 			{
       
   199 			NotifyCacheStateChangeCancelL(aMessage);
       
   200 			}
       
   201 			break;
       
   202 
       
   203 		case ESyncGetLastSyncError:
       
   204 			{
       
   205 			GetLastSyncErrorL(aMessage);
       
   206 			}
       
   207 			break;
       
   208 
       
   209 		case ESyncGetNumSlots:
       
   210 			{
       
   211 			GetNumSlotsL(aMessage);
       
   212 			}
       
   213 			break;
       
   214 
       
   215 		case ESyncGetNumFreeSlots:
       
   216 			{
       
   217 			GetNumFreeSlotsL(aMessage);
       
   218 			}
       
   219 			break;
       
   220 
       
   221 		case ESyncGetFreeSlots:
       
   222 			{
       
   223 			GetFreeSlotsL(aMessage);
       
   224 			}
       
   225 			break;
       
   226 
       
   227 		case ESyncGetSlotId:
       
   228 			{
       
   229 			GetSlotIdL(aMessage);
       
   230 			}
       
   231 			break;
       
   232 
       
   233 		case ESyncFlushInterfaceQueue:
       
   234 			{
       
   235 			CompleteRequest(aMessage, KErrNone);
       
   236 			}
       
   237 			break;
       
   238 
       
   239 		case ESyncShutdownServer:
       
   240 			{
       
   241 			ShutdownServerL(aMessage);
       
   242 			}
       
   243 			break;
       
   244 
       
   245 		default:
       
   246 			{
       
   247 			aMessage.Panic(PHBKSYNC_SERVER_NAME,
       
   248 						   EPhBkSyncPanicIllegalFunction);
       
   249 			}
       
   250 			break;
       
   251 		}
       
   252 	} // CPhoneBookSession::ServiceL()
       
   253 
       
   254 
       
   255 /**
       
   256  *  Completes a client request. This function provides a single point of
       
   257  *  message completion which benefits debugging and maintenance.
       
   258  *
       
   259  *  @param aMessage  The RMessage2 client request.
       
   260  *  @param aResult   Result of the request.
       
   261  */
       
   262 void CPhoneBookSession::CompleteRequest(const RMessage2& aMessage,
       
   263 										TInt aResult) const
       
   264 	{
       
   265 	LOGSESSION5(_L8("CompleteRequest(): Session=0x%08x "
       
   266 					"IPC=%d (%s) Result=%d"), this, aMessage.Function(),
       
   267 	           KPhonebookSyncRequestNames[aMessage.Function()], aResult);
       
   268 	LOGSESSIONTIMESTAMP();
       
   269 
       
   270 	if (aMessage.IsNull() == EFalse)
       
   271 		{
       
   272 	    aMessage.Complete(aResult);
       
   273 		}
       
   274     } // CPhoneBookSession::CompleteRequest()
       
   275 
       
   276 
       
   277 /**
       
   278  *  Requests a synchronisation from the server. This is an asynchronous
       
   279  *  request.
       
   280  *
       
   281  *  @param aMessage  RMessage2 client request.
       
   282  */
       
   283 void CPhoneBookSession::DoSynchronisationL(const RMessage2& aMessage)
       
   284 	{
       
   285 	TUid  phonebookUid = TUid::Uid(aMessage.Int0());
       
   286 
       
   287 	Server().DoSynchronisationL(*this, aMessage, phonebookUid);
       
   288 	} // CPhoneBookSession::DoSynchronisationL()
       
   289 
       
   290 
       
   291 /**
       
   292  *  Requests the supported phonebook field formats from the server. This is a
       
   293  *  synchronous request which will be completed when the procedure returns.
       
   294  *
       
   295  *  @param aMessage  RMessage2 client request.
       
   296  */
       
   297 void CPhoneBookSession::GetContactFormatL(const RMessage2& aMessage)
       
   298 	{
       
   299 	TUid  phonebookUid = TUid::Uid(aMessage.Int0());
       
   300 
       
   301 	//
       
   302 	// Get the contact format from the server...
       
   303 	//
       
   304 	RPhoneBookSession::TContactFieldsV3  contactFieldsV3;
       
   305 	TInt  result;
       
   306 	
       
   307 	result = Server().GetContactFormatL(phonebookUid, contactFieldsV3);
       
   308 
       
   309 	//
       
   310 	// If the contact format was retrieved from the server, then write it to
       
   311 	// the client.
       
   312 	//
       
   313 	if (result == KErrNone)
       
   314 		{
       
   315 		RPhoneBookSession::TContactFieldsV1::TContactFieldsExtensionId  extensionId;
       
   316 		
       
   317 		extensionId = static_cast<RPhoneBookSession::TContactFieldsV1::TContactFieldsExtensionId>(aMessage.Int1());
       
   318 		if (extensionId == RPhoneBookSession::TContactFieldsV1::KPhBkSyncTContactFieldsV1)
       
   319 			{
       
   320 			RPhoneBookSession::TContactFieldsV1  contactFieldsV1;
       
   321 			RPhoneBookSession::TContactFieldsV1Pckg  contactFieldsV1Pckg(contactFieldsV1);
       
   322 			
       
   323 			contactFieldsV1 = static_cast<RPhoneBookSession::TContactFieldsV1>(contactFieldsV3);
       
   324 
       
   325 			aMessage.WriteL(2, contactFieldsV1Pckg);
       
   326 			}
       
   327 		else if (extensionId == RPhoneBookSession::TContactFieldsV1::KPhBkSyncTContactFieldsV2)
       
   328 			{
       
   329 			RPhoneBookSession::TContactFieldsV2  contactFieldsV2;
       
   330 			RPhoneBookSession::TContactFieldsV2Pckg  contactFieldsV2Pckg(contactFieldsV2);
       
   331 			
       
   332 			contactFieldsV2 = static_cast<RPhoneBookSession::TContactFieldsV2>(contactFieldsV3);
       
   333 
       
   334 			aMessage.WriteL(2, contactFieldsV2Pckg);
       
   335 			}
       
   336 		else
       
   337 			{
       
   338 			RPhoneBookSession::TContactFieldsV3Pckg  contactFieldsV3Pckg(contactFieldsV3);
       
   339 
       
   340 			aMessage.WriteL(2, contactFieldsV3Pckg);
       
   341 			}
       
   342 		}
       
   343 
       
   344 	//
       
   345 	// Complete the request...
       
   346 	//
       
   347 	CompleteRequest(aMessage, result);
       
   348 	} // CPhoneBookSession::GetContactFormatL()
       
   349 
       
   350 
       
   351 /**
       
   352  *  Requests the current setting for the Synchronisation Mode from the server.
       
   353  *  This is a synchronous request which will be completed when the procedure
       
   354  *  returns.
       
   355  *
       
   356  *  @param aMessage  RMessage2 client request.
       
   357  */
       
   358 void CPhoneBookSession::GetSyncModeL(const RMessage2& aMessage)
       
   359 	{
       
   360 	TUid  phonebookUid = TUid::Uid(aMessage.Int0());
       
   361 
       
   362 	//
       
   363 	// Get the sync mode from the server...
       
   364 	//
       
   365 	RPhoneBookSession::TPhonebookSyncMode  syncMode;
       
   366 	TInt  result;
       
   367 	
       
   368 	result = Server().GetSyncModeL(phonebookUid, syncMode);
       
   369 
       
   370 	//
       
   371 	// If the sync mode was retrieved then write it back to the client.
       
   372 	//
       
   373 	if (result == KErrNone)
       
   374 		{
       
   375 		TPckg<RPhoneBookSession::TPhonebookSyncMode>  syncModePckg(syncMode);
       
   376 
       
   377 		aMessage.WriteL(1, syncModePckg);
       
   378 		}
       
   379 
       
   380 	//
       
   381 	// Complete the request...
       
   382 	//
       
   383 	CompleteRequest(aMessage, result);
       
   384 	} // CPhoneBookSession::GetSyncModeL()
       
   385 
       
   386 
       
   387 /**
       
   388  *  Requests the server to set the sync mode. This is a synchronous request
       
   389  *  which will be completed when the procedure returns.
       
   390  *
       
   391  *  @param aMessage  RMessage2 client request.
       
   392  */
       
   393 void CPhoneBookSession::SetSyncModeL(const RMessage2& aMessage)
       
   394 	{
       
   395 	TUid  phonebookUid = TUid::Uid(aMessage.Int0());
       
   396 
       
   397 	//
       
   398 	// Set the sync mode via the server...
       
   399 	//
       
   400 	RPhoneBookSession::TPhonebookSyncMode  syncMode = static_cast<RPhoneBookSession::TPhonebookSyncMode>(aMessage.Int1());
       
   401 	TInt  result;
       
   402 	
       
   403 	result = Server().SetSyncModeL(phonebookUid, syncMode);
       
   404 
       
   405 	//
       
   406 	// Complete the request...
       
   407 	//
       
   408 	CompleteRequest(aMessage, result);
       
   409 	} // CPhoneBookSession::SetSyncModeL()
       
   410 
       
   411 
       
   412 /**
       
   413  *  Requests the server to delete a contact from the ICC. This is an
       
   414  *  asynchronous request.
       
   415  *
       
   416  *  @param aMessage  RMessage2 client request.
       
   417  */
       
   418 void CPhoneBookSession::DeleteCntFromICCL(const RMessage2& aMessage)
       
   419 	{
       
   420 	TContactItemId  contactItemId = aMessage.Int0();
       
   421 	
       
   422 	Server().DeleteCntFromICCL(*this, aMessage, contactItemId);
       
   423 	} // CPhoneBookSession::DeleteCntFromICCL()
       
   424 
       
   425 
       
   426 /**
       
   427  *  Requests the server to write a contact to the ICC. This is an asynchronous
       
   428  *  request.
       
   429  *
       
   430  *  @param aMessage  RMessage2 client request.
       
   431  */
       
   432 void CPhoneBookSession::WriteCntToICCL(const RMessage2& aMessage)
       
   433 	{
       
   434 	//	
       
   435 	// Extract the request parameters from aMessage. These are the template ID,
       
   436 	// buffer size, slot number and ICC Entry pointer.
       
   437 	//
       
   438 	RPhoneBookSession::TTemplateAndBufferSize  templateIdAndBufferSize;
       
   439 	TInt  slotNum;
       
   440 	TPtr8 iccEntryPtr(NULL, 0);
       
   441 	TPckg<RPhoneBookSession::TTemplateAndBufferSize>  templateIdAndBufferSizePckg(templateIdAndBufferSize);
       
   442 	TPckg<TInt>  slotNumPckg(slotNum);
       
   443 
       
   444 	aMessage.ReadL(0, templateIdAndBufferSizePckg); 
       
   445 	aMessage.ReadL(1, slotNumPckg);
       
   446 
       
   447 	//
       
   448 	// Pass the request to the server for further processing.
       
   449 	//
       
   450 	Server().WriteCntToICCL(*this, aMessage, slotNum,
       
   451 	                        templateIdAndBufferSize.templateId);
       
   452 	} // CPhoneBookSession::WriteCntToICCL()
       
   453 
       
   454 
       
   455 /**
       
   456  *  Requests the server to validate a contact. This is an asynchronous
       
   457  *  request.
       
   458  *
       
   459  *  @param aMessage  RMessage2 client request.
       
   460  */
       
   461 void CPhoneBookSession::ValidateContactL(const RMessage2& aMessage)
       
   462 	{
       
   463 	TContactItemId  contactItemId = aMessage.Int0();
       
   464 	MContactSynchroniser::TValidateOperation  validateOp = static_cast<MContactSynchroniser::TValidateOperation>(aMessage.Int1());
       
   465 	TInt  result;
       
   466 	
       
   467 	result = Server().ValidateContactL(contactItemId, validateOp);
       
   468 	//
       
   469 	// Complete the request...
       
   470 	//
       
   471 	CompleteRequest(aMessage, result);
       
   472 	} // CPhoneBookSession::ValidateContactL()
       
   473 
       
   474 
       
   475 /**
       
   476  *  Requests the server to update its Look Up Table with new contact
       
   477  *  information. This is a synchronous request which will be completed when
       
   478  *  the procedure returns.
       
   479  *
       
   480  *  @param aMessage  RMessage2 client request.
       
   481  */
       
   482 void CPhoneBookSession::UpdateLookupTableL(const RMessage2& aMessage)
       
   483 	{
       
   484 	TUid  phonebookUid = TUid::Uid(aMessage.Int0());
       
   485 	TContactItemId  contactItemId = aMessage.Int1();
       
   486 	TInt  index = aMessage.Int2();
       
   487 	TInt  result;
       
   488 	
       
   489 	result = Server().UpdateLookupTableL(phonebookUid, contactItemId, index);
       
   490 
       
   491 	//
       
   492 	// Complete the request...
       
   493 	//
       
   494 	CompleteRequest(aMessage, result);
       
   495 	} // CPhoneBookSession::UpdateLookupTableL()
       
   496 
       
   497 
       
   498 /**
       
   499  *  Requests the Phonebook template or group ID from the server for a
       
   500  *  particular phonebook. This is a synchronous request which will be
       
   501  *  completed when the procedure returns.
       
   502  *
       
   503  *  @param aMessage  RMessage2 client request.
       
   504  */
       
   505 void CPhoneBookSession::GetPhoneBookIdL(const RMessage2& aMessage)
       
   506 	{
       
   507 	TUid  phonebookUid = TUid::Uid(aMessage.Int0());
       
   508 	RPhoneBookSession::TSyncIdType  syncIdType = static_cast<RPhoneBookSession::TSyncIdType>(aMessage.Int1());
       
   509 	TContactItemId  contactItemId;
       
   510 	TInt  result;
       
   511 	
       
   512 	result = Server().GetPhoneBookIdL(phonebookUid, syncIdType, contactItemId);
       
   513 
       
   514 	//
       
   515 	// If the phonebook ID was retrieved then write it back to the client.
       
   516 	//
       
   517 	if (result == KErrNone)
       
   518 		{
       
   519 		TPckg<TContactItemId>  contactItemIdPckg(contactItemId);
       
   520 
       
   521 		aMessage.WriteL(2, contactItemIdPckg);
       
   522 		}
       
   523 
       
   524 	//
       
   525 	// Complete the request...
       
   526 	//
       
   527 	CompleteRequest(aMessage, result);
       
   528 	} // CPhoneBookSession::GetPhoneBookIdL()
       
   529 
       
   530 
       
   531 /**
       
   532  *  Requests the current cache state for a phonebook from the server.
       
   533  *  This is a synchronous request which will be completed when the procedure
       
   534  *  returns.
       
   535  *
       
   536  *  @param aMessage  RMessage2 client request.
       
   537  */
       
   538 void CPhoneBookSession::GetCacheStateL(const RMessage2& aMessage)
       
   539 	{
       
   540 	TUid phonebookUid = TUid::Uid(aMessage.Int0());
       
   541 	RPhoneBookSession::TSyncState  syncState;
       
   542 	TInt  result;
       
   543 	
       
   544 	result = Server().GetCacheStateL(phonebookUid, syncState);
       
   545 
       
   546 	//
       
   547 	// If the phonebook ID was retrieved then write it back to the client.
       
   548 	//
       
   549 	if (result == KErrNone)
       
   550 		{
       
   551 		TPckgC<RPhoneBookSession::TSyncState>  syncStatePckg(syncState);
       
   552 		
       
   553 		aMessage.WriteL(1, syncStatePckg);
       
   554 		}
       
   555 
       
   556 	//
       
   557 	// Complete the request...
       
   558 	//
       
   559 	CompleteRequest(aMessage, result);
       
   560 	} // CPhoneBookSession::GetCacheStateL()
       
   561 
       
   562 
       
   563 /**
       
   564  *  Requests the server to mark the start of checking the server's and
       
   565  *  engine's heap. This function only works in debug releases and is a
       
   566  *  synchronous request which will be completed when the procedure returns.
       
   567  *
       
   568  *  @param aMessage  RMessage2 client request.
       
   569  */
       
   570 void CPhoneBookSession::DbgMarkHeapL(const RMessage2& aMessage)
       
   571 	{
       
   572 	TInt  count = aMessage.Int0();
       
   573 	TInt  result;
       
   574 	
       
   575 	result = Server().DbgMarkHeap();
       
   576 
       
   577 	//
       
   578 	// Complete the request...
       
   579 	//
       
   580 	CompleteRequest(aMessage, result);
       
   581 	} // CPhoneBookSession::DbgMarkHeapL()
       
   582 
       
   583 
       
   584 /**
       
   585  *  Requests the server to check that the number of allocated cells at the
       
   586  *  current nested level on the server's and engine's heaps are the same as
       
   587  *  the specified value. This function only works for debug builds and is a
       
   588  *  synchronous request which will be completed when the procedure returns.
       
   589  *
       
   590  *  @param aMessage  RMessage2 client request.
       
   591  */
       
   592 void CPhoneBookSession::DbgCheckHeapL(const RMessage2& aMessage)
       
   593 	{
       
   594 	TInt  count = aMessage.Int0();
       
   595 	TInt  result;
       
   596 	
       
   597 	result = Server().DbgCheckHeap(count);
       
   598 
       
   599 	//
       
   600 	// Complete the request...
       
   601 	//
       
   602 	CompleteRequest(aMessage, result);
       
   603 	} // CPhoneBookSession::DbgCheckHeapL()
       
   604 
       
   605 
       
   606 /**
       
   607  *  Requests the server to mark the end of checking the server's and
       
   608  *  engines's heap. This function must match an earlier call to
       
   609  *  DbgMarkHeap() and only functions on debug releases. This is a
       
   610  *  synchronous request which will be completed when the procedure returns.
       
   611  *
       
   612  *  @param aMessage  RMessage2 client request.
       
   613  */
       
   614 void CPhoneBookSession::DbgMarkEndL(const RMessage2& aMessage)
       
   615 	{
       
   616 	TInt  count = aMessage.Int0();
       
   617 	TInt  result;
       
   618 	
       
   619 	result = Server().DbgMarkEnd(count);
       
   620 
       
   621 	//
       
   622 	// Complete the request...
       
   623 	//
       
   624 	CompleteRequest(aMessage, result);
       
   625 	} // CPhoneBookSession::DbgMarkEndL()
       
   626 
       
   627 
       
   628 /**
       
   629  *  Simulates heap allocation failure for the sever and engine.
       
   630  *  The failure occurs on the next call to new or any of the functions which 
       
   631  *  allocate memory from the heap. This is defined only for debug builds and
       
   632  *  is a synchronous request which will be completed when the procedure
       
   633  *  returns.
       
   634  *
       
   635  *  @param aMessage  RMessage2 client request.
       
   636  */
       
   637 void CPhoneBookSession::DbgFailNextL(const RMessage2& aMessage)
       
   638 	{
       
   639 	TInt  count = aMessage.Int0();
       
   640 	TInt  result;
       
   641 	
       
   642 	result = Server().DbgFailNext(count);
       
   643 
       
   644 	//
       
   645 	// Complete the request...
       
   646 	//
       
   647 	CompleteRequest(aMessage, result);
       
   648 	} // CPhoneBookSession::DbgFailNextL()
       
   649 
       
   650 
       
   651 /**
       
   652  *  Requests the server to cancel a previous synchronisation request.
       
   653  *  This is a synchronous request which will be completed when the procedure
       
   654  *  returns.
       
   655  *
       
   656  *  @param aMessage  RMessage2 client request.
       
   657  */
       
   658 void CPhoneBookSession::DoSynchronisationCancelL(const RMessage2& aMessage)
       
   659 	{
       
   660 	TUid  phonebookUid = TUid::Uid(aMessage.Int0());
       
   661 	TInt  result;
       
   662 	
       
   663 	result = Server().DoSynchronisationCancelL(*this, phonebookUid);
       
   664 
       
   665 	//
       
   666 	// Complete the request...
       
   667 	//
       
   668 	CompleteRequest(aMessage, result);
       
   669 	} // CPhoneBookSession::DoSynchronisationCancelL()
       
   670 
       
   671 
       
   672 /**
       
   673  *  Requests the server to cancel a previous delete contact request.
       
   674  *  This is a synchronous request which will be completed when the procedure
       
   675  *  returns.
       
   676  *
       
   677  *  @param aMessage  RMessage2 client request.
       
   678  */
       
   679 void CPhoneBookSession::DeleteCntFromICCCancelL(const RMessage2& aMessage)
       
   680 	{
       
   681 	TUid  phonebookUid = TUid::Uid(aMessage.Int0());
       
   682 	TInt  result;
       
   683 	
       
   684 	result = Server().DeleteCntFromICCCancelL(*this, phonebookUid);
       
   685 
       
   686 	//
       
   687 	// Complete the request...
       
   688 	//
       
   689 	CompleteRequest(aMessage, result);
       
   690 	} // CPhoneBookSession::DeleteCntFromICCCancelL()
       
   691 
       
   692 
       
   693 /**
       
   694  *  Requests the server to cancel a previous write contact request.
       
   695  *  This is a synchronous request which will be completed when the procedure
       
   696  *  returns.
       
   697  *
       
   698  *  @param aMessage  RMessage2 client request.
       
   699  */
       
   700 void CPhoneBookSession::WriteCntToICCCancelL(const RMessage2& aMessage)
       
   701 	{
       
   702 	TUid  phonebookUid = TUid::Uid(aMessage.Int0());
       
   703 	TInt  result;
       
   704 	
       
   705 	result = Server().WriteCntToICCCancelL(*this, phonebookUid);
       
   706 
       
   707 	//
       
   708 	// Complete the request...
       
   709 	//
       
   710 	CompleteRequest(aMessage, result);
       
   711 	} // CPhoneBookSession::WriteCntToICCCancelL()
       
   712 	
       
   713 
       
   714 /**
       
   715  *  Requests the server to post a notification of cache state change.
       
   716  *  This is an asynchronous request which will be completed when the
       
   717  *  cache state changes or the request is canceled.
       
   718  *
       
   719  *  @param aMessage  RMessage2 client request.
       
   720  */
       
   721 void CPhoneBookSession::NotifyCacheStateChangeL(const RMessage2& aMessage)
       
   722 	{
       
   723 	TUid  phonebookUid = TUid::Uid(aMessage.Int0());
       
   724 
       
   725 	Server().NotifyCacheStateChangeL(*this, aMessage, phonebookUid);
       
   726 	} // CPhoneBookSession::NotifyCacheStateChangeL()
       
   727 	
       
   728 
       
   729 /**
       
   730  *  Requests the server to cancel a previous notify cache state change request.
       
   731  *  This is a synchronous request which will be completed when the procedure
       
   732  *  returns.
       
   733  *
       
   734  *  @param aMessage  RMessage2 client request.
       
   735  */
       
   736 void CPhoneBookSession::NotifyCacheStateChangeCancelL(const RMessage2& aMessage)
       
   737 	{
       
   738 	TUid  phonebookUid = TUid::Uid(aMessage.Int0());
       
   739 	TInt  result;
       
   740 	
       
   741 	result = Server().NotifyCacheStateChangeCancelL(*this, phonebookUid);
       
   742 
       
   743 	//
       
   744 	// Complete the request...
       
   745 	//
       
   746 	CompleteRequest(aMessage, result);
       
   747 	} // CPhoneBookSession::NotifyCacheStateChangeCancelL()
       
   748 	
       
   749 
       
   750 /**
       
   751  *  Requests the last sync error for a phonebook from the server.
       
   752  *  This is a synchronous request which will be completed when the procedure
       
   753  *  returns.
       
   754  *
       
   755  *  @param aMessage  RMessage2 client request.
       
   756  */
       
   757 void CPhoneBookSession::GetLastSyncErrorL(const RMessage2& aMessage)
       
   758 	{
       
   759 	TUid  phonebookUid = TUid::Uid(aMessage.Int0());
       
   760 	TInt  lastSyncError;
       
   761 	TInt  result;
       
   762 	
       
   763 	result = Server().GetLastSyncErrorL(phonebookUid, lastSyncError);
       
   764 
       
   765 	//
       
   766 	// If the last sync error was retrieved then write it back to the client.
       
   767 	//
       
   768 	if (result == KErrNone)
       
   769 		{
       
   770 		TPckg<TInt> lastSyncErrorPckg(lastSyncError);
       
   771 		
       
   772 		aMessage.WriteL(1, lastSyncErrorPckg);
       
   773 		}
       
   774 
       
   775 	//
       
   776 	// Complete the request...
       
   777 	//
       
   778 	CompleteRequest(aMessage, result);
       
   779 	} // CPhoneBookSession::GetLastSyncErrorL()
       
   780 	
       
   781 
       
   782 /**
       
   783  *  Requests the current number of slots in a phonebook from the server.
       
   784  *  This is a synchronous request which will be completed when the procedure
       
   785  *  returns.
       
   786  *
       
   787  *  @param aMessage  RMessage2 client request.
       
   788  */
       
   789 void CPhoneBookSession::GetNumSlotsL(const RMessage2& aMessage)
       
   790 	{
       
   791 	TUid  phonebookUid = TUid::Uid(aMessage.Int0());
       
   792 	TInt  numSlots;
       
   793 	TInt  result;
       
   794 	
       
   795 	result = Server().GetNumSlotsL(phonebookUid, numSlots);
       
   796 
       
   797 	//
       
   798 	// If the number of slots was retrieved then write it back to the client.
       
   799 	//
       
   800 	if (result == KErrNone)
       
   801 		{
       
   802 		TPckg<TInt> numSlotsPckg(numSlots);
       
   803 		
       
   804 		aMessage.WriteL(1, numSlotsPckg);
       
   805 		}
       
   806 
       
   807 	//
       
   808 	// Complete the request...
       
   809 	//
       
   810 	CompleteRequest(aMessage, result);
       
   811 	} // CPhoneBookSession::GetNumSlotsL()
       
   812 	
       
   813 
       
   814 /**
       
   815  *  Requests the current number of free slots in a phonebook from the server.
       
   816  *  This is a synchronous request which will be completed when the procedure
       
   817  *  returns.
       
   818  *
       
   819  *  @param aMessage  RMessage2 client request.
       
   820  */
       
   821 void CPhoneBookSession::GetNumFreeSlotsL(const RMessage2& aMessage)
       
   822 	{
       
   823 	TUid  phonebookUid = TUid::Uid(aMessage.Int0());
       
   824 	TInt  numFreeSlots, result;
       
   825 	
       
   826 	result = Server().GetNumFreeSlotsL(phonebookUid, numFreeSlots);
       
   827 
       
   828 	//
       
   829 	// If the number of free slots was retrieved then write it back to the client.
       
   830 	//
       
   831 	if (result == KErrNone)
       
   832 		{
       
   833 		TPckg<TInt> numFreeSlotsPckg(numFreeSlots);
       
   834 		
       
   835 		aMessage.WriteL(1, numFreeSlotsPckg);
       
   836 		}
       
   837 
       
   838 	//
       
   839 	// Complete the request...
       
   840 	//
       
   841 	CompleteRequest(aMessage, result);
       
   842 	} // CPhoneBookSession::GetNumFreeSlotsL()
       
   843 	
       
   844 
       
   845 /**
       
   846  *  Requests a list of the current free slots from the server. This is a
       
   847  *  synchronous request which will be completed when the procedure returns.
       
   848  *
       
   849  *  @param aMessage  RMessage2 client request.
       
   850  */
       
   851 void CPhoneBookSession::GetFreeSlotsL(const RMessage2& aMessage)
       
   852 	{
       
   853 	TUid phonebookUid = TUid::Uid(aMessage.Int0());
       
   854 
       
   855 	//
       
   856 	// Get the list of free slots from the server...
       
   857 	//
       
   858 	RArray<TInt>  freeSlots;
       
   859 	CleanupClosePushL(freeSlots);
       
   860 	TInt result;
       
   861 
       
   862 	result = Server().GetFreeSlotsL(phonebookUid, freeSlots);
       
   863 
       
   864 	//
       
   865 	// If the number of free slots was retrieved then write it back to the client.
       
   866 	//
       
   867 	if (result == KErrNone)
       
   868 		{
       
   869 		TInt  numSlots = freeSlots.Count();
       
   870 		HBufC8*  transferBuf = HBufC8::NewLC(sizeof(TInt) * numSlots);
       
   871 		TPtr8  transferBufPtr(transferBuf->Des());
       
   872 
       
   873 		RDesWriteStream  writeStream(transferBufPtr);
       
   874 		CleanupClosePushL(writeStream);
       
   875 
       
   876 		for (TInt slot = 0;  slot < numSlots;  slot++)
       
   877 			{
       
   878 			writeStream.WriteInt32L(freeSlots[slot]);
       
   879 			}
       
   880 
       
   881 		transferBufPtr.SetLength(sizeof(TInt) * numSlots);
       
   882 		aMessage.WriteL(1, *transferBuf);
       
   883 
       
   884 		CleanupStack::PopAndDestroy(2, transferBuf); // writeStream & transferBuf
       
   885 		}
       
   886 
       
   887 	CleanupStack::PopAndDestroy(&freeSlots);
       
   888 
       
   889 	//
       
   890 	// Complete the request...
       
   891 	//
       
   892 	CompleteRequest(aMessage, result);
       
   893 	} // CPhoneBookSession::GetFreeSlotsL()
       
   894 	
       
   895 
       
   896 /**
       
   897  *  Requests the contact ID of the slot in a particular phonebook from the
       
   898  *  server. This is a synchronous request which will be completed when the
       
   899  *  procedure returns.
       
   900  *
       
   901  *  @param aMessage  RMessage2 client request.
       
   902  */
       
   903 void CPhoneBookSession::GetSlotIdL(const RMessage2& aMessage)
       
   904 	{
       
   905 	TUid  phonebookUid = TUid::Uid(aMessage.Int0());
       
   906 	TInt  slotNum = aMessage.Int1();
       
   907 	TContactItemId  contactItemId;
       
   908 	TInt  result;
       
   909 	
       
   910 	result = Server().GetSlotIdL(phonebookUid, slotNum, contactItemId);
       
   911 
       
   912 	//
       
   913 	// If the slot ID was retrieved then write it back to the client.
       
   914 	//
       
   915 	if (result == KErrNone)
       
   916 		{
       
   917 		TPckg<TContactItemId>  contactItemIdPckg(contactItemId);
       
   918 		
       
   919 		aMessage.WriteL(2, contactItemIdPckg);
       
   920 		}
       
   921 
       
   922 	//
       
   923 	// Complete the request...
       
   924 	//
       
   925 	CompleteRequest(aMessage, result);
       
   926 	} // CPhoneBookSession::GetSlotIdL()
       
   927 	
       
   928 
       
   929 /**
       
   930  *  Requests the server to shut down when it no longer has any connected
       
   931  *  sessions. This procedure is only premitted in debug builds for security
       
   932  *  reasons (e.g. to prevent a denial of service attack) and is provided
       
   933  *  for testing purposes. This is a synchronous request which will be
       
   934  *  completed when the procedure returns. The server will shutdown when the
       
   935  *  last session disconnects.
       
   936  *
       
   937  *  @param aMessage  RMessage2 client request.
       
   938  */
       
   939 void CPhoneBookSession::ShutdownServerL(const RMessage2& aMessage)
       
   940 	{
       
   941 	TBool  conditional = aMessage.Int0();
       
   942 	TInt  result;
       
   943 	
       
   944 	result = Server().ShutdownServer(conditional);
       
   945 	
       
   946 	//
       
   947 	// Complete the request...
       
   948 	//
       
   949 	CompleteRequest(aMessage, result);
       
   950 	} // CPhoneBookSession::ShutdownServerL()
       
   951