phonebookengines/contactsmodel/tsrc/TestSyncPlugIn/cnttestsync.cpp
changeset 0 e686773b3f54
child 24 0ba2181d7c28
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 // Copyright (c) 2001-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 //
       
    15 
       
    16 #include <cntsync.h>
       
    17 #include <cntfield.h>
       
    18 #include <cntfldst.h>
       
    19 #include <cntdef.h>
       
    20 #include <cntitem.h>
       
    21 #include <cntdb.h>
       
    22 #include "cnttestsynchroniser.h"
       
    23 #include <ecom/implementationproxy.h>
       
    24 
       
    25 
       
    26 CContactActiveTestSync::CContactActiveTestSync(CContactSyncChecker& aSyncChecker, TUid aPhoneBookUid) 
       
    27 : CActive(EPriorityMuchMore), iStatusArray(3), iSyncChecker(aSyncChecker), iPhoneBookUid(aPhoneBookUid)
       
    28 	{
       
    29 	CActiveScheduler::Add(this);
       
    30 	}
       
    31 
       
    32 CContactActiveTestSync::~CContactActiveTestSync()
       
    33 	{	
       
    34 	Cancel();	
       
    35 	}
       
    36 
       
    37 void CContactActiveTestSync::RunL()
       
    38 	{
       
    39 	const TInt result = iSyncChecker.FetchNotificationErrorL(iPhoneBookUid);
       
    40 	for(TInt i = 0; i < iStatusArray.Count();  ++i)
       
    41 		{
       
    42 		User::RequestComplete(iStatusArray[i], result);
       
    43 		}
       
    44 	iStatusArray.Reset();
       
    45 	}
       
    46 
       
    47 TInt CContactActiveTestSync::RunError(TInt /*aError*/)
       
    48 	{
       
    49 	TRAP_IGNORE(RunL() );
       
    50 	return KErrNone;
       
    51 	}
       
    52 
       
    53 void CContactActiveTestSync::DoCancel()
       
    54 	{
       
    55 	iSyncChecker.CompleteNotificationRequestL(KErrCancel, iPhoneBookUid);
       
    56 	for(TInt i = 0; i < iStatusArray.Count();  ++i)
       
    57 		{
       
    58 		User::RequestComplete(iStatusArray[i], KErrCancel);
       
    59 		}
       
    60 	iStatusArray.Reset();	
       
    61 	}
       
    62 	
       
    63 void CContactActiveTestSync::StartL(TRequestStatus& aStatus)
       
    64 	{
       
    65 	aStatus = KRequestPending;
       
    66 	iStatusArray.AppendL(&aStatus);
       
    67 	if (!IsActive())
       
    68 		{
       
    69 		__ASSERT_ALWAYS(iStatusArray.Count() == 1, User::Invariant());
       
    70 		iStatus = KRequestPending;
       
    71 		SetActive();
       
    72 		iSyncChecker.StoreNotificationRequestL(iStatus, iPhoneBookUid);
       
    73 		}
       
    74 	}
       
    75 	
       
    76 TUid CContactActiveTestSync::PhoneBookUid()
       
    77 {
       
    78 	return iPhoneBookUid;
       
    79 }
       
    80 
       
    81 
       
    82 
       
    83 
       
    84 TInt CContactTestSynchroniser::ValidateContact(TValidateOperation aOp, TContactItemId /*aId*/)
       
    85 	{
       
    86 	iContactSyncChecker->ValidateMethodCalledL();
       
    87 	TInt ret=iContactSyncChecker->ValidateResponseL(aOp);
       
    88 	if (iContactSyncChecker->VerboseLoggingEnabledL())
       
    89 		{
       
    90 		switch (aOp)
       
    91 			{
       
    92 		case ERead:		
       
    93 			User::InfoPrint(_L("Validate ERead"));
       
    94 			break;
       
    95 		case ESearch:
       
    96 			User::InfoPrint(_L("Validate ESearch"));
       
    97 			break;
       
    98 		case EEdit:
       
    99 			User::InfoPrint(_L("Validate EEdit"));
       
   100 			break;
       
   101 		default:
       
   102 			break;
       
   103 			}
       
   104 		}
       
   105 	return ret;
       
   106 	}
       
   107 	
       
   108 TInt CContactTestSynchroniser::ValidateWriteContact(CContactICCEntry& aContactItem)
       
   109 	{
       
   110 	TRAPD(err, iContactSyncChecker->ValidateMethodCalledL() );
       
   111 	__ASSERT_ALWAYS(err == KErrNone, User::Invariant() );
       
   112 	
       
   113 	TBool verboseLoggingEnabled(EFalse);
       
   114 	TRAP(err, verboseLoggingEnabled = iContactSyncChecker->VerboseLoggingEnabledL() );
       
   115 	__ASSERT_ALWAYS(err == KErrNone, User::Invariant() );
       
   116 	if (verboseLoggingEnabled)
       
   117 		{
       
   118 		User::InfoPrint(_L("ValidateWriteContact"));
       
   119 		}
       
   120 
       
   121 	// Set the phonebook field, if the field doesn't exist, it should be added
       
   122 	CContactItemFieldSet& fieldset = aContactItem.CardFields();
       
   123 	TInt n = fieldset.Find(KUidContactFieldICCPhonebook);
       
   124 	if(n == KErrNotFound)
       
   125 		{
       
   126 		CContactItemField* field(NULL);
       
   127 		TRAP_IGNORE(field = CContactItemField::NewL(KStorageTypeText, KUidContactFieldICCPhonebook) );
       
   128 		TRAP(err, aContactItem.AddFieldL(*field) );
       
   129 		CContactItemFieldSet& fieldset = aContactItem.CardFields();
       
   130 		n = fieldset.Find(KUidContactFieldICCPhonebook);
       
   131 		__ASSERT_ALWAYS(err == KErrNone && n != KErrNotFound, User::Invariant() );
       
   132 		}
       
   133 
       
   134 	CContactItemField& field = fieldset[n];
       
   135 	CContactTextField* textField = field.TextStorage();
       
   136 	TUid phonebookUid(TUid::Null() );
       
   137 	TRAP(err, phonebookUid = iContactSyncChecker->PhonebookUidL(aContactItem.TemplateRefId() ) );
       
   138 	__ASSERT_ALWAYS(err == KErrNone, User::Invariant() );
       
   139 
       
   140 	TBuf<128> buf;
       
   141 	if(phonebookUid != KUidIccPhonebookNotFound)
       
   142 		{
       
   143 		TInt phonebookUidNum = phonebookUid.iUid;
       
   144 		buf.AppendNum(phonebookUidNum);
       
   145 		TRAP(err, textField->SetTextL(buf));
       
   146 		__ASSERT_ALWAYS(err == KErrNone, User::Invariant() );
       
   147 		}
       
   148 
       
   149 	TBool validateWriteResponse(EFalse);
       
   150 	TRAP(err, validateWriteResponse = iContactSyncChecker->ValidateWriteResponseL() );
       
   151 	__ASSERT_ALWAYS(err == KErrNone, User::Invariant() );
       
   152 
       
   153 	return validateWriteResponse;
       
   154 	}
       
   155 
       
   156 TInt CContactTestSynchroniser::DeleteContact(TContactItemId /*aId*/)
       
   157 	{
       
   158 	iContactSyncChecker->ValidateMethodCalledL();
       
   159 	if (iContactSyncChecker->VerboseLoggingEnabledL())
       
   160 		User::InfoPrint(_L("DeleteContact"));
       
   161 	return iContactSyncChecker->DeleteContactResponseL();
       
   162 	}
       
   163 
       
   164 
       
   165 /** 
       
   166  * Update the lookup tables in the server.
       
   167  * This method is called by the Contacts model when a new CContactICCEntry
       
   168  * has been added to the database. The plug-in should extract the 
       
   169  * appropriate details from the item (eg. item UID and slot number) 
       
   170  * and call the sync server to update the lookup tables.
       
   171  */
       
   172 void CContactTestSynchroniser::UpdatePostWriteL(const CContactICCEntry& /*aContactItem*/)
       
   173 	{
       
   174 	iContactSyncChecker->ValidateMethodCalledL();
       
   175 	if (iContactSyncChecker->VerboseLoggingEnabledL())
       
   176 		User::InfoPrint(_L("UpdateLookupTable"));
       
   177 	}	
       
   178 
       
   179 TContactItemId CContactTestSynchroniser::ICCTemplateIdL(TUid aPhonebookUid)
       
   180 	{
       
   181 	iContactSyncChecker->ValidateMethodCalledL();
       
   182 	User::InfoPrint(_L("TemplateId"));
       
   183 	return iContactSyncChecker->ICCTemplateIdL(aPhonebookUid);
       
   184 	}
       
   185 
       
   186 TContactItemId CContactTestSynchroniser::GroupIdL(TUid aPhonebookUid)
       
   187 	{
       
   188 	
       
   189 	iContactSyncChecker->ValidateMethodCalledL();
       
   190 	User::InfoPrint(_L("GroupId"));
       
   191 	return iContactSyncChecker->GroupIdL(aPhonebookUid);
       
   192 	}
       
   193 
       
   194 void CContactTestSynchroniser::NotifySyncStateChange(TRequestStatus& aStatus, TUid aPhonebookUid)
       
   195 	{
       
   196 	TRAPD(err, iContactSyncChecker->SyncMethodCalledL() );
       
   197 	__ASSERT_ALWAYS(err == KErrNone, User::Invariant() );
       
   198 	
       
   199 	TBool exist(EFalse);
       
   200 	CContactActiveTestSync* temp(NULL);
       
   201 	TInt i(0);
       
   202 	TRAP(err, 
       
   203 		for (i = 0 ; i < iActiveTestSync.Count() ; ++i)
       
   204 			{
       
   205 			temp = iActiveTestSync[i];		
       
   206 			if (temp->PhoneBookUid().iUid == aPhonebookUid.iUid)
       
   207 				{
       
   208 				exist = ETrue;	
       
   209 				temp->StartL(aStatus);
       
   210 				break;	
       
   211 				}
       
   212 			}
       
   213 	);
       
   214 	__ASSERT_ALWAYS(err == KErrNone, User::Invariant() );
       
   215 
       
   216 	if (!exist)
       
   217 		{
       
   218 		temp = new CContactActiveTestSync(*iContactSyncChecker, aPhonebookUid);
       
   219 		__ASSERT_ALWAYS(temp != NULL, User::Invariant() );
       
   220 		iActiveTestSync.Append(temp);
       
   221 		TRAP(err, temp->StartL(aStatus) );	
       
   222 		__ASSERT_ALWAYS(err == KErrNone, User::Invariant() );
       
   223 		}
       
   224 	}
       
   225 
       
   226 void CContactTestSynchroniser::CancelNotifyRequest(TUid aPhonebookUid)
       
   227 	{
       
   228 	iContactSyncChecker->SyncMethodCalledL();
       
   229 	if (iContactSyncChecker->VerboseLoggingEnabledL())
       
   230 		{
       
   231 		RDebug::Print(_L("PhonebookSync - CancelNotifyRequest(Phonebook Uid = 0x%08X)\r\n"),
       
   232 			aPhonebookUid.iUid);
       
   233 		}
       
   234 	for (TInt i = 0 ; i < iActiveTestSync.Count() ; ++i)
       
   235 		{
       
   236 		CContactActiveTestSync* temp = iActiveTestSync[i];		
       
   237 		if (temp->PhoneBookUid().iUid == aPhonebookUid.iUid)
       
   238 			{
       
   239   			temp->Cancel();
       
   240 			break;	
       
   241 			}
       
   242 		}
       
   243 	}
       
   244 
       
   245 TBool CContactTestSynchroniser::IsSynchronisedL(TUid aPhonebookUid)
       
   246 	{
       
   247 	iContactSyncChecker->SyncMethodCalledL();
       
   248 	if (iContactSyncChecker->VerboseLoggingEnabledL())
       
   249 		{
       
   250 		RDebug::Print(_L("PhonebookSync - IsSynchronisedL(Phonebook Uid = 0x%08X)\r\n"),
       
   251 			aPhonebookUid.iUid);
       
   252 		}
       
   253 	return iContactSyncChecker->IsSynchronisedL(aPhonebookUid);
       
   254 	}
       
   255 	
       
   256 TInt CContactTestSynchroniser::PhonebookList(RArray<TUid>& aPhonebookList) //Lots to do here
       
   257 	{
       
   258 	iContactSyncChecker->SyncMethodCalledL();
       
   259 	if (iContactSyncChecker->VerboseLoggingEnabledL())
       
   260 		{
       
   261 		RDebug::Print(_L("PhonebookSync - PhonebookList()\r\n"));
       
   262 		}
       
   263 	return iContactSyncChecker->PhonebookListL(aPhonebookList);
       
   264 	}
       
   265 	
       
   266 CContactTestSynchroniser* CContactTestSynchroniser::NewL()
       
   267 	{
       
   268 	RDebug::Print(_L("**********CContactTestSynchroniser::NewL\n"));
       
   269 	CContactTestSynchroniser* self = new(ELeave) CContactTestSynchroniser();
       
   270 	CleanupStack::PushL(self);
       
   271 	self->ConstructL();
       
   272 	CleanupStack::Pop(self);
       
   273 	return self;
       
   274 	}
       
   275 
       
   276 void CContactTestSynchroniser::ConstructL()
       
   277 	{
       
   278 	iContactSyncChecker = iContactSyncChecker->NewL();
       
   279 	//iActiveTestSync = new (ELeave) CContactActiveTestSync(*iContactSyncChecker);
       
   280 	iContactSyncChecker->PluginLoadedL();
       
   281 	}
       
   282 
       
   283 
       
   284 void CContactTestSynchroniser::Release()
       
   285 	{
       
   286 	User::InfoPrint(_L("Release"));
       
   287 	TRAP_IGNORE(iContactSyncChecker->PluginUnloadedL());
       
   288 	delete this;
       
   289 	}
       
   290 	
       
   291 CContactTestSynchroniser::~CContactTestSynchroniser()
       
   292 	{
       
   293 	RDebug::Print(_L("**********CContactTestSynchroniser::~CContactTestSynchroniser\n"));
       
   294 	delete iContactSyncChecker;
       
   295 	iContactSyncChecker = NULL;
       
   296 	iActiveTestSync.ResetAndDestroy();
       
   297 	}
       
   298 
       
   299 // Export the implementation collection function
       
   300 const TImplementationProxy ImplementationTable[] = 
       
   301     {
       
   302     IMPLEMENTATION_PROXY_ENTRY(0x102035FF, 	CContactTestSynchroniser::NewL)
       
   303     };
       
   304 
       
   305 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
   306     {
       
   307     aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
   308     return ImplementationTable;
       
   309     }
       
   310 /**
       
   311  * Standard Epoc32 Dll Entry point
       
   312  */