pimprotocols/phonebooksync/Server/SyncEngineSession.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 // Implementation of the Background Sync Engine session class. This class is
       
    15 // responsible for passing the requests that have come from the main
       
    16 // front-end server's engine handle to the main engine class.
       
    17 // 
       
    18 //
       
    19 
       
    20 /**
       
    21  @file
       
    22  @internalComponent
       
    23 */
       
    24 
       
    25 #include "Phonebook.h"
       
    26 #include "PhonebookManager.h"
       
    27 #include "SyncContactICCEntry.h"
       
    28 #include "SyncEngineServer.h"
       
    29 #include "SyncEngineSession.h"
       
    30 #include "phbksynclog.h"
       
    31 
       
    32 
       
    33 #ifdef _DEBUG
       
    34 /**
       
    35  *  Debug text names to the Phonebook Sync IPC Requests.
       
    36  */
       
    37 const char*  KEnginePhonebookSyncRequestNames[26] = {
       
    38 		"ESyncDoSynchronisation", "ESyncGetContactFormat", "ESyncGetSyncMode",
       
    39 		"ESyncSetSyncMode", "ESyncDeleteCntFromICC", "ESyncWriteCntToICC",
       
    40 		"ESyncValidateContact", "ESyncUpdateLookupTable",
       
    41 		"ESyncGetPhoneBookId", "ESyncGetCacheState", "ESyncDbgMarkHeap",
       
    42 		"ESyncDbgCheckHeap", "ESyncDbgMarkEnd", "ESyncDbgFailNext",
       
    43 		"ESyncDoSynchronisationCancel", "ESyncDeleteCntFromICCCancel",
       
    44 		"ESyncWriteCntToICCCancel", "ESyncNotifyCacheStateChange",
       
    45 		"ESyncNotifyCacheStateChangeCancel", "ESyncGetLastSyncError",
       
    46 		"ESyncGetNumSlots", "ESyncGetNumFreeSlots", "ESyncGetFreeSlots",
       
    47 		"ESyncGetSlotId", "ESyncFlushInterfaceQueue", "ESyncShutdownServer"};
       
    48 #endif
       
    49 
       
    50 
       
    51 /**
       
    52  *  Second phase construct for sessions. Called by the CServer2 framework
       
    53  *  when a session is created (e.g. a connection is made to the server).
       
    54  */
       
    55 void CSyncEngineSession::CreateL()
       
    56 	{
       
    57 	LOGENGINE1(_L8("CreateL()"));
       
    58 
       
    59 	Server().AddSessionL(this);
       
    60 	} // CSyncEngineSession::CreateL()
       
    61 
       
    62 
       
    63 /**
       
    64  *  Destructor from session classes. When this is called it indicates that
       
    65  *  a session is closing its connection with the server.
       
    66  */
       
    67 CSyncEngineSession::~CSyncEngineSession()
       
    68 	{
       
    69 	LOGENGINE1(_L8("~CSyncEngineSession()"));
       
    70 
       
    71 	Server().DropSession(this);
       
    72 	} // CSyncEngineSession::~CSyncEngineSession()
       
    73 
       
    74 
       
    75 /**
       
    76  *  Handle message requests for this session. Leaving is handled by
       
    77  *  CPhoneBookServer::RunError() which reports the error code to the client.
       
    78  *
       
    79  *  @param aMessage  RMessage2 reference which encapsulates a client request.
       
    80  */
       
    81 void CSyncEngineSession::ServiceL(const RMessage2& aMessage)
       
    82 
       
    83 	{
       
    84 	LOGENGINE4(_L8("ServiceL(): Session=0x%08x IPC=%d (%s)"),
       
    85 	           this, aMessage.Function(),
       
    86 	           KEnginePhonebookSyncRequestNames[aMessage.Function()]);
       
    87 	LOGENGINETIMESTAMP();
       
    88 	
       
    89 	switch (aMessage.Function())
       
    90 		{
       
    91 		case ESyncDoSynchronisation:
       
    92 			{
       
    93 			DoSynchronisationL(aMessage);
       
    94 			}
       
    95 			break;
       
    96 
       
    97 		case ESyncDeleteCntFromICC:
       
    98 			{
       
    99 			DeleteCntFromICCL(aMessage);
       
   100 			}
       
   101 			break;
       
   102 
       
   103 		case ESyncWriteCntToICC:
       
   104 			{
       
   105 			WriteCntToICCL(aMessage);
       
   106 			}
       
   107 			break;
       
   108 
       
   109 		case ESyncDoSynchronisationCancel:
       
   110 			{
       
   111 			DoSynchronisationCancelL(aMessage);
       
   112 			}
       
   113 			break;
       
   114 
       
   115 		case ESyncDeleteCntFromICCCancel:
       
   116 			{
       
   117 			DeleteCntFromICCCancelL(aMessage);
       
   118 			}
       
   119 			break;
       
   120 
       
   121 		case ESyncWriteCntToICCCancel:
       
   122 			{
       
   123 			WriteCntToICCCancelL(aMessage);
       
   124 			}
       
   125 			break;
       
   126 
       
   127 		default:
       
   128 			{
       
   129 			CompleteRequest(aMessage, KErrNotSupported);
       
   130 			}
       
   131 			break;
       
   132 		}
       
   133 	} // CSyncEngineSession::ServiceL()
       
   134 
       
   135 
       
   136 /**
       
   137  *  Completes a client request. This function provides a single point of
       
   138  *  message completion which benefits debugging and maintenance.
       
   139  *
       
   140  *  @param aMessage  The RMessage2 client request.
       
   141  *  @param aResult   Result of the request.
       
   142  */
       
   143 void CSyncEngineSession::CompleteRequest(const RMessage2& aMessage,
       
   144 										TInt aResult) const
       
   145 	{
       
   146 	LOGENGINE5(_L8("CSyncEngineSession::CompleteRequest: Session=0x%08x "
       
   147 					"IPC=%d (%s) Result=%d"), this, aMessage.Function(),
       
   148 	           KEnginePhonebookSyncRequestNames[aMessage.Function()], aResult);
       
   149 	LOGENGINETIMESTAMP();
       
   150 
       
   151 	if (aMessage.IsNull() == EFalse)
       
   152 		{
       
   153 	    aMessage.Complete(aResult);
       
   154 		}
       
   155     } // CSyncEngineSession::CompleteRequest()
       
   156 
       
   157 
       
   158 /**
       
   159  *  Requests a synchronisation from the server. This is an asynchronous
       
   160  *  request.
       
   161  *
       
   162  *  @param aMessage  RMessage2 client request.
       
   163  */
       
   164 void CSyncEngineSession::DoSynchronisationL(const RMessage2& aMessage)
       
   165 	{
       
   166 	TUid  phonebookUid = TUid::Uid(aMessage.Int0());
       
   167 
       
   168 	Server().DoSynchronisationL(aMessage, phonebookUid);
       
   169 	} // CSyncEngineSession::DoSynchronisationL()
       
   170 
       
   171 
       
   172 /**
       
   173  *  Requests the server to delete a contact from the ICC. This is an
       
   174  *  asynchronous request.
       
   175  *
       
   176  *  @param aMessage  RMessage2 client request.
       
   177  */
       
   178 void CSyncEngineSession::DeleteCntFromICCL(const RMessage2& aMessage)
       
   179 	{
       
   180 	TUid  phonebookUid = TUid::Uid(aMessage.Int0());
       
   181 	TContactItemId  contactItemId = aMessage.Int1();
       
   182 	
       
   183 	Server().DeleteCntFromICCL(aMessage, phonebookUid, contactItemId);
       
   184 	} // CSyncEngineSession::DeleteCntFromICCL()
       
   185 
       
   186 
       
   187 /**
       
   188  *  Requests the server to write a contact to the ICC. This is an asynchronous
       
   189  *  request.
       
   190  *
       
   191  *  @param aMessage  RMessage2 client request.
       
   192  */
       
   193 void CSyncEngineSession::WriteCntToICCL(const RMessage2& aMessage)
       
   194 	{
       
   195 	//	
       
   196 	// Extract the request parameters from aMessage. These are the template ID,
       
   197 	// buffer size, slot number and ICC Entry pointer.
       
   198 	//
       
   199 	RPhoneBookSession::TTemplateAndBufferSize  templateIdAndBufferSize;
       
   200 	TPtr8 iccEntryPtr(NULL, 0);
       
   201 	TPckg<RPhoneBookSession::TTemplateAndBufferSize>  templateIdAndBufferSizePckg(templateIdAndBufferSize);
       
   202 
       
   203 	aMessage.ReadL(0, templateIdAndBufferSizePckg); 
       
   204 
       
   205 	//
       
   206 	// Pass the request to the server for further processing.
       
   207 	//
       
   208 	Server().WriteCntToICCL(aMessage, templateIdAndBufferSize.templateId,
       
   209 	                        templateIdAndBufferSize.bufferSize);
       
   210 	} // CSyncEngineSession::WriteCntToICCL()
       
   211 
       
   212 
       
   213 /**
       
   214  *  Requests the server to cancel a previous synchronisation request.
       
   215  *  This is a synchronous request which will be completed when the procedure
       
   216  *  returns.
       
   217  *
       
   218  *  @param aMessage  RMessage2 client request.
       
   219  */
       
   220 void CSyncEngineSession::DoSynchronisationCancelL(const RMessage2& aMessage)
       
   221 	{
       
   222 	TUid  phonebookUid = TUid::Uid(aMessage.Int0());
       
   223 	TInt  result;
       
   224 	
       
   225 	result = Server().DoSynchronisationCancelL(phonebookUid);
       
   226 
       
   227 	//
       
   228 	// Complete the request...
       
   229 	//
       
   230 	CompleteRequest(aMessage, result);
       
   231 	} // CSyncEngineSession::DoSynchronisationCancelL()
       
   232 
       
   233 
       
   234 /**
       
   235  *  Requests the server to cancel a previous delete contact request.
       
   236  *  This is a synchronous request which will be completed when the procedure
       
   237  *  returns.
       
   238  *
       
   239  *  @param aMessage  RMessage2 client request.
       
   240  */
       
   241 void CSyncEngineSession::DeleteCntFromICCCancelL(const RMessage2& aMessage)
       
   242 	{
       
   243 	TUid  phonebookUid = TUid::Uid(aMessage.Int0());
       
   244 	TInt  result;
       
   245 	
       
   246 	result = Server().DeleteCntFromICCCancelL(phonebookUid);
       
   247 
       
   248 	//
       
   249 	// Complete the request...
       
   250 	//
       
   251 	CompleteRequest(aMessage, result);
       
   252 	} // CSyncEngineSession::DeleteCntFromICCCancelL()
       
   253 
       
   254 
       
   255 /**
       
   256  *  Requests the server to cancel a previous write contact request.
       
   257  *  This is a synchronous request which will be completed when the procedure
       
   258  *  returns.
       
   259  *
       
   260  *  @param aMessage  RMessage2 client request.
       
   261  */
       
   262 void CSyncEngineSession::WriteCntToICCCancelL(const RMessage2& aMessage)
       
   263 	{
       
   264 	TUid  phonebookUid = TUid::Uid(aMessage.Int0());
       
   265 	TInt  result;
       
   266 	
       
   267 	result = Server().WriteCntToICCCancelL(phonebookUid);
       
   268 
       
   269 	//
       
   270 	// Complete the request...
       
   271 	//
       
   272 	CompleteRequest(aMessage, result);
       
   273 	} // CSyncEngineSession::WriteCntToICCCancelL()
       
   274 	
       
   275