summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/tsrc/integration/perffuncsuite/src/concurrenttimeoutnotifierstep.cpp
blob: 6587c7bdebb29b0bd8a86afeb3a546c104704903 (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
/*
* 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: 
* Notifier step / thread, locks a contact / database, sends message to
* concurrent running listener thread / step informing it what has been locked
* waits for message from  listner to start countdown to release of lock
* listener will send message and wait for specified lock to be released
* or for timeout to be invoked by cntmodel.
* Sending Messages:
* Set shared string to contain length of time resource will be locked for in seconds. KSharedEvents. (6)
* Set shared string to contain  id of contact that is locked. KSharedContact. (1)
* Set shared string to contain a value, specify that new test case can start. KSharedNextTest. (aa)
* Receiving messages:
* Read shared string length signifying that thread should start countdown 
* until realease of resource. KSharedClients. (AA)
*
*/


/**
 @file 
 @publishedAll
 @released
*/
 
#include "concurrenttimeoutnotifierstep.h"
#include "performancefunctionalitydefs.h"

_LIT(KRun1,"NonTrans");
_LIT(KRun2,"Transaction");

_LIT(KTest1, "Contacts timeout test");
_LIT(KTest2, "Transaction timeout test");

const static TInt KTimeout = 50000000;//50 seconds timeout
const static TInt KOneSecond = 1000000;

_LIT(KDoubleChar,"AA");
	
CConcurrentTimeOutNotifierStep::CConcurrentTimeOutNotifierStep() : 	
									CPerformanceFunctionalityBase(KConcurrentTimeoutContacts),
									iSeconds( 10 )
	{
	iConcurrent = ETrue;
	SetTestStepName(KConcurrentTimeoutNotifierStep);
	}
/**
runs the next test that will lock a particular resource
*/
void CConcurrentTimeOutNotifierStep::CConcurrentTimeOutNotifierMyActive::RunL()
	{
	const static TInt KTestCount = iStep->iTests->Count();
	if( iStep->iNextTest >= KTestCount )
		{
		CActiveScheduler::Stop();
		iStep->iNextTest = 0;
		}
	else
		{
		RArray< void (CConcurrentTimeOutNotifierStep::*)() > &Tests = *( iStep->iTests );
		//select test to run
		void (CConcurrentTimeOutNotifierStep::*TestFunction)() = Tests[ iStep->iNextTest ];
		//execute test
		( iStep->*TestFunction )();
		Activate();
		}
	}
	
void CConcurrentTimeOutNotifierStep::CConcurrentTimeOutNotifierMyActive::DoCancel()
	{
	//nothing to cleanup, does nothing.
	}

TInt CConcurrentTimeOutNotifierStep::CConcurrentTimeOutNotifierMyActive::RunError(TInt aError)
	{
	 _LIT(KActiveError,"CConcurrentTimeOutNotifierStep:: Error in doTest runL: %d");
	iStep->ERR_PRINTF2(KActiveError, aError );
	return aError;
	}

void CConcurrentTimeOutNotifierStep::CConcurrentTimeOutNotifierMyActive::Activate()
	{
	if(!IsActive())
		{	
		TRequestStatus *pS=&iStatus;
		User::RequestComplete(pS,KErrNone);
		SetActive();
		}
	}

CConcurrentTimeOutNotifierStep::~CConcurrentTimeOutNotifierStep()
	{
	if( iTests )
		{
		iTests->Close();
		CLEAR(iTests);
		}
	CLEAR(iMyActive);
	}

/**
create active object and test array
append contact lock or transaction lock test as necessary
*/	
void CConcurrentTimeOutNotifierStep::PreTestL()
	{
	iMyActive = new (ELeave) CConcurrentTimeOutNotifierStep::CConcurrentTimeOutNotifierMyActive( this );
	iTests = new(ELeave) RArray< void (CConcurrentTimeOutNotifierStep::*)() >();
	
	const TDesC &run = ConfigSection();
	
	if( run == KRun1 )
		{
		iTests->AppendL( &CConcurrentTimeOutNotifierStep::LockContactTestL );
		}
	else if( run == KRun2 )
		{
		iTests->AppendL( &CConcurrentTimeOutNotifierStep::LockDatabaseTestL );
		}
	else
		{
		MissingTestPanic();
		}
	}

TVerdict CConcurrentTimeOutNotifierStep::doTestStepL()
	{
	__UHEAP_MARK;
	InitializeL();
	_LIT(KDoStepPrint,"CConcurrentTimeOutNotifierStep::doTestStepL()");
	INFO_PRINTF1(KDoStepPrint);  //Block start 
	iIterate->Reset();
	SetTimerL(-1);
	SetContactL( -1 );
	SetSharedTextL(KSharedNextTest, KDoubleChar, EFalse);
	CActiveScheduler::Add(iMyActive);
	iMyActive->Activate();
	CActiveScheduler::Start();
	
	Cleanup();
	__UHEAP_MARKEND;

	return TestStepResult();
	}

/**
sends message to listener specifying the length of time resource will be locked for
*/
void CConcurrentTimeOutNotifierStep::SetTimerL(const TInt aTime)
	{
	
	ShareIntL(KSharedEvents, aTime);
	
	}

/**
sends message to listener specifying the contact that will be locked
*/
void CConcurrentTimeOutNotifierStep::SetContactL(const TInt aCid)
	{
	
	ShareIntL(KSharedContact, aCid);
	
	}

/**
wait for message from listener specifying that countdown to release of resource should commence
*/
void CConcurrentTimeOutNotifierStep::StartCountdownL()
	{
	if ( iCountdown )
		{
		return;
		}
	iCountdown = SharedCountL(KSharedClients) > 0;
	if (iCountdown)
		{
		iStart.UniversalTime();
		SetSharedTextL(KSharedClients, KNullDesC, EFalse);
		}
	}
	
/**
either release resource after countdown has reached the necessary value
or timeout test if countdown is not started after the timeout period has passed
*/
void CConcurrentTimeOutNotifierStep::ProcessWaitL(const TBool aTransaction)
	{
	StartCountdownL();
	iEnd.UniversalTime();
	const TInt64 KLockTime = iEnd.MicroSecondsFrom( iStart ).Int64();
	const TInt64 KTestTime = iEnd.MicroSecondsFrom( iTestStart ).Int64();
	if( iCountdown && ( KLockTime >= ((iSeconds - KTimeDiff) * KOneSecond) ) )
		{
		iWaiting = EFalse;
		iCountdown = EFalse;
		if(aTransaction)
			{
			iContactsDatabase->DatabaseCommitL( EFalse );//unlock database
			}
		else
			{
			CloseL( ETrue );//unlock contact
			}
		++iNextTest;
		SetSharedTextL(KSharedNextTest, KDoubleChar, EFalse);
		}
	else if( KTestTime > KTimeout ) //test has timed out
		{
		_LIT(KTimedOut,"Notifier test %d has timed out");
		ERR_PRINTF2(KTimedOut, ++iNextTest);
		iWaiting = EFalse;
		iCountdown = EFalse;
		TESTPRINT( EFalse );
		SetSharedTextL(KSharedNextTest, KDoubleChar, EFalse);
		iNextTest = iTests->Count();
		}
	//else test is not complete and has not timed out... continue waiting
	}
	
/*
open a contact, this causes that contact to be locked
*/
void CConcurrentTimeOutNotifierStep::LockContactTestL()
	{
	if(iWaiting)
		{
		ProcessWaitL( EFalse );
		}
	else
		{
		INFO_PRINTF1(KTest1);
		iWaiting = ETrue;
		TContactItemId cid = iIterate->NextL();
		OpenL( cid );
		//notify listener that database will be unlocked after x amount of time
		SetTimerL( iSeconds - KTimeDiff );
		SetContactL( cid );
		iTestStart.UniversalTime();
		}
	}
	
/*
starts a transactions
this causes the database to be locked	
*/
void CConcurrentTimeOutNotifierStep::LockDatabaseTestL()
	{
	if(iWaiting)
		{
		ProcessWaitL( ETrue );
		}
	else
		{
		INFO_PRINTF1(KTest2);
		iWaiting = ETrue;
		TContactItemId cid = iIterate->NextL();
		iContactsDatabase->DatabaseBeginLC(EFalse);
		//notify listener that contact will be unlocked after x amount of time
		SetTimerL( iSeconds - KTimeDiff );
		SetContactL( cid );
		CleanupStack::Pop(); // cleanup item from the CContactDatabase::DatabaseBeginLC() 
		iTestStart.UniversalTime();
		}
	}