summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/tsrc/testsyncplugin/cnttestsync.cpp
blob: 282d399e6c50cc086e858629f027b04f34329e3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
/*
* Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
* Contact: http://www.qt-project.org/legal
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description: 
*
*/


#include <cntsync.h>
#include <cntfield.h>
#include <cntfldst.h>
#include <cntdef.h>
#include <cntitem.h>
#include <cntdb.h>
#include "cnttestsynchroniser.h"
#include <ecom/implementationproxy.h>


CContactActiveTestSync::CContactActiveTestSync(CContactSyncChecker& aSyncChecker, TUid aPhoneBookUid) 
: CActive(EPriorityMuchMore), iStatusArray(3), iSyncChecker(aSyncChecker), iPhoneBookUid(aPhoneBookUid)
	{
	CActiveScheduler::Add(this);
	}

CContactActiveTestSync::~CContactActiveTestSync()
	{	
	Cancel();	
	}

void CContactActiveTestSync::RunL()
	{
	const TInt result = iSyncChecker.FetchNotificationErrorL(iPhoneBookUid);
	for(TInt i = 0; i < iStatusArray.Count();  ++i)
		{
		User::RequestComplete(iStatusArray[i], result);
		}
	iStatusArray.Reset();
	}

TInt CContactActiveTestSync::RunError(TInt /*aError*/)
	{
	TRAP_IGNORE(RunL() );
	return KErrNone;
	}

void CContactActiveTestSync::DoCancel()
	{
	iSyncChecker.CompleteNotificationRequestL(KErrCancel, iPhoneBookUid);
	for(TInt i = 0; i < iStatusArray.Count();  ++i)
		{
		User::RequestComplete(iStatusArray[i], KErrCancel);
		}
	iStatusArray.Reset();	
	}
	
void CContactActiveTestSync::StartL(TRequestStatus& aStatus)
	{
	aStatus = KRequestPending;
	iStatusArray.AppendL(&aStatus);
	if (!IsActive())
		{
		__ASSERT_ALWAYS(iStatusArray.Count() == 1, User::Invariant());
		iStatus = KRequestPending;
		SetActive();
		iSyncChecker.StoreNotificationRequestL(iStatus, iPhoneBookUid);
		}
	}
	
TUid CContactActiveTestSync::PhoneBookUid()
{
	return iPhoneBookUid;
}




TInt CContactTestSynchroniser::ValidateContact(TValidateOperation aOp, TContactItemId /*aId*/)
	{
	iContactSyncChecker->ValidateMethodCalledL();
	TInt ret=iContactSyncChecker->ValidateResponseL(aOp);
	if (iContactSyncChecker->VerboseLoggingEnabledL())
		{
		switch (aOp)
			{
		case ERead:		
			User::InfoPrint(_L("Validate ERead"));
			break;
		case ESearch:
			User::InfoPrint(_L("Validate ESearch"));
			break;
		case EEdit:
			User::InfoPrint(_L("Validate EEdit"));
			break;
		default:
			break;
			}
		}
	return ret;
	}
	
TInt CContactTestSynchroniser::ValidateWriteContact(CContactICCEntry& aContactItem)
	{
	TRAPD(err, iContactSyncChecker->ValidateMethodCalledL() );
	__ASSERT_ALWAYS(err == KErrNone, User::Invariant() );
	
	TBool verboseLoggingEnabled(EFalse);
	TRAP(err, verboseLoggingEnabled = iContactSyncChecker->VerboseLoggingEnabledL() );
	__ASSERT_ALWAYS(err == KErrNone, User::Invariant() );
	if (verboseLoggingEnabled)
		{
		User::InfoPrint(_L("ValidateWriteContact"));
		}

	// Set the phonebook field, if the field doesn't exist, it should be added
	CContactItemFieldSet& fieldset = aContactItem.CardFields();
	TInt n = fieldset.Find(KUidContactFieldICCPhonebook);
	if(n == KErrNotFound)
		{
		CContactItemField* field(NULL);
		TRAP_IGNORE(field = CContactItemField::NewL(KStorageTypeText, KUidContactFieldICCPhonebook) );
		TRAP(err, aContactItem.AddFieldL(*field) );
		CContactItemFieldSet& fieldset = aContactItem.CardFields();
		n = fieldset.Find(KUidContactFieldICCPhonebook);
		__ASSERT_ALWAYS(err == KErrNone && n != KErrNotFound, User::Invariant() );
		}

	CContactItemField& field = fieldset[n];
	CContactTextField* textField = field.TextStorage();
	TUid phonebookUid(TUid::Null() );
	TRAP(err, phonebookUid = iContactSyncChecker->PhonebookUidL(aContactItem.TemplateRefId() ) );
	__ASSERT_ALWAYS(err == KErrNone, User::Invariant() );

	TBuf<128> buf;
	if(phonebookUid != KUidIccPhonebookNotFound)
		{
		TInt phonebookUidNum = phonebookUid.iUid;
		buf.AppendNum(phonebookUidNum);
		TRAP(err, textField->SetTextL(buf));
		__ASSERT_ALWAYS(err == KErrNone, User::Invariant() );
		}

	TBool validateWriteResponse(EFalse);
	TRAP(err, validateWriteResponse = iContactSyncChecker->ValidateWriteResponseL() );
	__ASSERT_ALWAYS(err == KErrNone, User::Invariant() );

	return validateWriteResponse;
	}

TInt CContactTestSynchroniser::DeleteContact(TContactItemId /*aId*/)
	{
	iContactSyncChecker->ValidateMethodCalledL();
	if (iContactSyncChecker->VerboseLoggingEnabledL())
		User::InfoPrint(_L("DeleteContact"));
	return iContactSyncChecker->DeleteContactResponseL();
	}


/** 
 * Update the lookup tables in the server.
 * This method is called by the Contacts model when a new CContactICCEntry
 * has been added to the database. The plug-in should extract the 
 * appropriate details from the item (eg. item UID and slot number) 
 * and call the sync server to update the lookup tables.
 */
void CContactTestSynchroniser::UpdatePostWriteL(const CContactICCEntry& /*aContactItem*/)
	{
	iContactSyncChecker->ValidateMethodCalledL();
	if (iContactSyncChecker->VerboseLoggingEnabledL())
		User::InfoPrint(_L("UpdateLookupTable"));
	}	

TContactItemId CContactTestSynchroniser::ICCTemplateIdL(TUid aPhonebookUid)
	{
	iContactSyncChecker->ValidateMethodCalledL();
	User::InfoPrint(_L("TemplateId"));
	return iContactSyncChecker->ICCTemplateIdL(aPhonebookUid);
	}

TContactItemId CContactTestSynchroniser::GroupIdL(TUid aPhonebookUid)
	{
	
	iContactSyncChecker->ValidateMethodCalledL();
	User::InfoPrint(_L("GroupId"));
	return iContactSyncChecker->GroupIdL(aPhonebookUid);
	}

void CContactTestSynchroniser::NotifySyncStateChange(TRequestStatus& aStatus, TUid aPhonebookUid)
	{
	TRAPD(err, iContactSyncChecker->SyncMethodCalledL() );
	__ASSERT_ALWAYS(err == KErrNone, User::Invariant() );
	
	TBool exist(EFalse);
	CContactActiveTestSync* temp(NULL);
	TInt i(0);
	TRAP(err, 
		for (i = 0 ; i < iActiveTestSync.Count() ; ++i)
			{
			temp = iActiveTestSync[i];		
			if (temp->PhoneBookUid().iUid == aPhonebookUid.iUid)
				{
				exist = ETrue;	
				temp->StartL(aStatus);
				break;	
				}
			}
	);
	__ASSERT_ALWAYS(err == KErrNone, User::Invariant() );

	if (!exist)
		{
		temp = new CContactActiveTestSync(*iContactSyncChecker, aPhonebookUid);
		__ASSERT_ALWAYS(temp != NULL, User::Invariant() );
		iActiveTestSync.Append(temp);
		TRAP(err, temp->StartL(aStatus) );	
		__ASSERT_ALWAYS(err == KErrNone, User::Invariant() );
		}
	}

void CContactTestSynchroniser::CancelNotifyRequest(TUid aPhonebookUid)
	{
	iContactSyncChecker->SyncMethodCalledL();
	if (iContactSyncChecker->VerboseLoggingEnabledL())
		{
		RDebug::Print(_L("PhonebookSync - CancelNotifyRequest(Phonebook Uid = 0x%08X)\r\n"),
			aPhonebookUid.iUid);
		}
	for (TInt i = 0 ; i < iActiveTestSync.Count() ; ++i)
		{
		CContactActiveTestSync* temp = iActiveTestSync[i];		
		if (temp->PhoneBookUid().iUid == aPhonebookUid.iUid)
			{
  			temp->Cancel();
			break;	
			}
		}
	}

TBool CContactTestSynchroniser::IsSynchronisedL(TUid aPhonebookUid)
	{
	iContactSyncChecker->SyncMethodCalledL();
	if (iContactSyncChecker->VerboseLoggingEnabledL())
		{
		RDebug::Print(_L("PhonebookSync - IsSynchronisedL(Phonebook Uid = 0x%08X)\r\n"),
			aPhonebookUid.iUid);
		}
	return iContactSyncChecker->IsSynchronisedL(aPhonebookUid);
	}
	
TInt CContactTestSynchroniser::PhonebookList(RArray<TUid>& aPhonebookList) //Lots to do here
	{
	iContactSyncChecker->SyncMethodCalledL();
	if (iContactSyncChecker->VerboseLoggingEnabledL())
		{
		RDebug::Print(_L("PhonebookSync - PhonebookList()\r\n"));
		}
	return iContactSyncChecker->PhonebookListL(aPhonebookList);
	}
	
CContactTestSynchroniser* CContactTestSynchroniser::NewL()
	{
	RDebug::Print(_L("**********CContactTestSynchroniser::NewL\n"));
	CContactTestSynchroniser* self = new(ELeave) CContactTestSynchroniser();
	CleanupStack::PushL(self);
	self->ConstructL();
	CleanupStack::Pop(self);
	return self;
	}

void CContactTestSynchroniser::ConstructL()
	{
	iContactSyncChecker = iContactSyncChecker->NewL();
	//iActiveTestSync = new (ELeave) CContactActiveTestSync(*iContactSyncChecker);
	iContactSyncChecker->PluginLoadedL();
	}


void CContactTestSynchroniser::Release()
	{
	User::InfoPrint(_L("Release"));
	TRAP_IGNORE(iContactSyncChecker->PluginUnloadedL());
	delete this;
	}
	
CContactTestSynchroniser::~CContactTestSynchroniser()
	{
	RDebug::Print(_L("**********CContactTestSynchroniser::~CContactTestSynchroniser\n"));
	delete iContactSyncChecker;
	iContactSyncChecker = NULL;
	iActiveTestSync.ResetAndDestroy();
	}

// Export the implementation collection function
const TImplementationProxy ImplementationTable[] = 
    {
    IMPLEMENTATION_PROXY_ENTRY(0x102035FF, 	CContactTestSynchroniser::NewL)
    };

EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
    {
    aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
    return ImplementationTable;
    }
/**
 * Standard Epoc32 Dll Entry point
 */