748
|
1 |
// Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
872
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
748
|
5 |
// which accompanies this distribution, and is available
|
872
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
748
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
//
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
// INCLUDES
|
|
19 |
#include "ctlbsposclientholder.h"
|
|
20 |
#include "ctlbsposclient.h"
|
|
21 |
|
|
22 |
// CONSTANTS
|
|
23 |
|
|
24 |
// ================= MEMBER FUNCTIONS =======================
|
|
25 |
|
|
26 |
// C++ default constructor can NOT contain any code, that
|
|
27 |
// might leave.
|
|
28 |
//
|
|
29 |
CT_LbsPosClientHolder::CT_LbsPosClientHolder()
|
|
30 |
: CActive(EPriorityHigh), iRequestsActive(EFalse), iCancelTime(0)
|
|
31 |
{
|
|
32 |
}
|
|
33 |
|
|
34 |
// ---------------------------------------------------------
|
|
35 |
// CT_LbsPosClientHolder::ConstructL
|
|
36 |
//
|
|
37 |
// (other items were commented in a header).
|
|
38 |
// ---------------------------------------------------------
|
|
39 |
//
|
|
40 |
void CT_LbsPosClientHolder::ConstructL(TInt aRequestCount, TUid aPsy, TBool aSameServer)
|
|
41 |
{
|
|
42 |
User::LeaveIfError(iTimer.CreateLocal());
|
|
43 |
CActiveScheduler::Add(this);
|
|
44 |
User::LeaveIfError(iPosServer.Connect());
|
|
45 |
CT_LbsPosClient* requester = NULL;
|
|
46 |
for (TInt i = 0; i < aRequestCount; i++)
|
|
47 |
{
|
|
48 |
if (aSameServer)
|
|
49 |
{
|
|
50 |
requester = CT_LbsPosClient::NewL(this, aPsy,iPosServer);
|
|
51 |
}
|
|
52 |
else
|
|
53 |
{
|
|
54 |
requester = CT_LbsPosClient::NewL(this, aPsy);
|
|
55 |
}
|
|
56 |
CleanupStack::PushL(requester);
|
|
57 |
User::LeaveIfError(iRequesters.Append(requester));
|
|
58 |
CleanupStack::Pop(requester);
|
|
59 |
}
|
|
60 |
}
|
|
61 |
|
|
62 |
// ---------------------------------------------------------
|
|
63 |
// CT_LbsPosClientHolder::NewLC
|
|
64 |
//
|
|
65 |
// (other items were commented in a header).
|
|
66 |
// ---------------------------------------------------------
|
|
67 |
//
|
|
68 |
CT_LbsPosClientHolder* CT_LbsPosClientHolder::NewLC(TInt aRequestCount, TUid aPsy, TBool aSameServer)
|
|
69 |
{
|
|
70 |
CT_LbsPosClientHolder* self = new (ELeave) CT_LbsPosClientHolder;
|
|
71 |
CleanupStack::PushL(self);
|
|
72 |
self->ConstructL(aRequestCount, aPsy, aSameServer);
|
|
73 |
return self;
|
|
74 |
}
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
// Destructor
|
|
79 |
CT_LbsPosClientHolder::~CT_LbsPosClientHolder()
|
|
80 |
{
|
|
81 |
Cancel();
|
|
82 |
iTimer.Close();
|
|
83 |
iRequesters.ResetAndDestroy();
|
|
84 |
iRequesters.Close();
|
|
85 |
iRequestersWhoWillCancel.Close();
|
|
86 |
iPosServer.Close();
|
|
87 |
}
|
|
88 |
|
|
89 |
// ---------------------------------------------------------
|
|
90 |
// CT_LbsPosClientHolder::MakeRequests
|
|
91 |
//
|
|
92 |
// (other items were commented in a header).
|
|
93 |
// ---------------------------------------------------------
|
|
94 |
//
|
|
95 |
void CT_LbsPosClientHolder::MakeRequests()
|
|
96 |
{
|
|
97 |
if (iRequestsActive)
|
|
98 |
{
|
|
99 |
return;
|
|
100 |
}
|
|
101 |
iRequestsActive = ETrue;
|
|
102 |
TInt requesterCount = iRequesters.Count();
|
|
103 |
iNofRequestsDone = 0;
|
|
104 |
for (TInt i = 0; i < requesterCount; i++)
|
|
105 |
{
|
|
106 |
iRequesters[i]->MakeRequest();
|
|
107 |
}
|
|
108 |
|
|
109 |
// initiate cancelling if this is set.
|
|
110 |
if (iRequestersWhoWillCancel.Count() > 0)
|
|
111 |
{
|
|
112 |
iTimer.After(iStatus, iCancelTime);
|
|
113 |
SetActive();
|
|
114 |
}
|
|
115 |
|
|
116 |
CActiveScheduler::Start();
|
|
117 |
}
|
|
118 |
|
|
119 |
// ---------------------------------------------------------
|
|
120 |
// CT_LbsPosClientHolder::HandleRequestDone
|
|
121 |
//
|
|
122 |
// (other items were commented in a header).
|
|
123 |
// ---------------------------------------------------------
|
|
124 |
//
|
|
125 |
void CT_LbsPosClientHolder::HandleRequestDone()
|
|
126 |
{
|
|
127 |
iNofRequestsDone++;
|
|
128 |
if (iNofRequestsDone == iRequesters.Count())
|
|
129 |
{
|
|
130 |
iRequestsActive = EFalse;
|
|
131 |
CActiveScheduler::Stop();
|
|
132 |
}
|
|
133 |
}
|
|
134 |
|
|
135 |
// ---------------------------------------------------------
|
|
136 |
// CT_LbsPosClientHolder::RunL
|
|
137 |
//
|
|
138 |
// (other items were commented in a header).
|
|
139 |
// ---------------------------------------------------------
|
|
140 |
//
|
|
141 |
void CT_LbsPosClientHolder::RunL()
|
|
142 |
{
|
|
143 |
// Cancel certain requests.
|
|
144 |
TInt nofRequestersWhoWillCancel = iRequestersWhoWillCancel.Count();
|
|
145 |
for (TInt i = 0; i < nofRequestersWhoWillCancel; i++)
|
|
146 |
{
|
|
147 |
iRequesters[iRequestersWhoWillCancel[i]]->Cancel();
|
|
148 |
HandleRequestDone();
|
|
149 |
}
|
|
150 |
}
|
|
151 |
|
|
152 |
// ---------------------------------------------------------
|
|
153 |
// CT_LbsPosClientHolder::DoCancel
|
|
154 |
//
|
|
155 |
// (other items were commented in a header).
|
|
156 |
// ---------------------------------------------------------
|
|
157 |
//
|
|
158 |
void CT_LbsPosClientHolder::DoCancel()
|
|
159 |
{
|
|
160 |
iTimer.Cancel();
|
|
161 |
}
|
|
162 |
|
|
163 |
void CT_LbsPosClientHolder::StopRequests()
|
|
164 |
{
|
|
165 |
if (!iRequestsActive)
|
|
166 |
{
|
|
167 |
return;
|
|
168 |
}
|
|
169 |
Cancel();
|
|
170 |
TInt requesterCount = iRequesters.Count();
|
|
171 |
for (TInt i = 0; i < requesterCount; i++)
|
|
172 |
{
|
|
173 |
iRequesters[i]->Cancel();
|
|
174 |
}
|
|
175 |
CActiveScheduler::Stop();
|
|
176 |
iRequestsActive = EFalse;
|
|
177 |
}
|
|
178 |
|
|
179 |
// ---------------------------------------------------------
|
|
180 |
// CT_LbsPosClientHolder::GetResult
|
|
181 |
//
|
|
182 |
// (other items were commented in a header).
|
|
183 |
// ---------------------------------------------------------
|
|
184 |
//
|
|
185 |
void CT_LbsPosClientHolder::GetResult(
|
|
186 |
TInt& aStatus,
|
|
187 |
TPositionInfo& aModuleInfo,
|
|
188 |
TTimeIntervalMicroSeconds& aRequestTime,
|
|
189 |
TInt aRequesterIndex)
|
|
190 |
{
|
|
191 |
iRequesters[aRequesterIndex]->GetResult(aStatus, aModuleInfo, aRequestTime);
|
|
192 |
}
|
|
193 |
|
|
194 |
|
|
195 |
|
|
196 |
// ---------------------------------------------------------
|
|
197 |
// CT_LbsPosClientHolder::SetRequesterWillCancelL
|
|
198 |
//
|
|
199 |
// (other items were commented in a header).
|
|
200 |
// ---------------------------------------------------------
|
|
201 |
//
|
|
202 |
void CT_LbsPosClientHolder::SetCancelTime(TTimeIntervalMicroSeconds32 aTimeInterval)
|
|
203 |
{
|
|
204 |
iCancelTime = aTimeInterval;
|
|
205 |
}
|
|
206 |
|
|
207 |
// ---------------------------------------------------------
|
|
208 |
// CT_LbsPosClientHolder::SetRequesterWillCancelL
|
|
209 |
//
|
|
210 |
// (other items were commented in a header).
|
|
211 |
// ---------------------------------------------------------
|
|
212 |
//
|
|
213 |
void CT_LbsPosClientHolder::SetRequesterWillCancelL(TInt aIndex)
|
|
214 |
{
|
|
215 |
TInt length = iRequestersWhoWillCancel.Count();
|
|
216 |
for (TInt i = 0; i < length; i++)
|
|
217 |
{
|
|
218 |
if (iRequestersWhoWillCancel[i] == aIndex) return;
|
|
219 |
}
|
|
220 |
User::LeaveIfError(iRequestersWhoWillCancel.Append(aIndex));
|
|
221 |
}
|
|
222 |
|
|
223 |
|
|
224 |
// End of File
|