1 /* |
|
2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Processes requestor related data. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "lpdrequestorprocessor.h" |
|
21 #include "lpdverifnotiflbmodel.h" |
|
22 #include "lpdbasemodel.h" |
|
23 #include "locconsts.h" |
|
24 #include "locverifierdlgdebug.h" |
|
25 #include <lbs/epos_cposrequestor.h> |
|
26 #include <lbs/epos_cposcontactrequestor.h> |
|
27 #include <lbs/epos_cposservicerequestor.h> |
|
28 #include <EPos_CPosPrivacyNotifier.h> |
|
29 |
|
30 // CONSTANTS |
|
31 _LIT( KUnknownRequestor, "Unknown" ); |
|
32 |
|
33 // Unnamed namespace for local definitions |
|
34 |
|
35 const TInt KRequestorsGranularity = 5; |
|
36 #ifdef _DEBUG |
|
37 _LIT( KPanicText, "CLpdRequestorProcessor" ); |
|
38 enum TPanicCode |
|
39 { |
|
40 KLpdErrGeneral = 1 |
|
41 }; |
|
42 #endif |
|
43 |
|
44 |
|
45 // ============================ MEMBER FUNCTIONS =============================== |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CLpdRequestorProcessor::CLpdRequestorProcessor |
|
49 // C++ default constructor can NOT contain any code, that |
|
50 // might leave. |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 CLpdRequestorProcessor::CLpdRequestorProcessor() |
|
54 : iRequestors( KRequestorsGranularity), |
|
55 iSuplRequest ( 0 ), |
|
56 iSessionId ( 0 ) |
|
57 { |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CLpdRequestorProcessor::NewL |
|
62 // Two-phased constructor. |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 CLpdRequestorProcessor* CLpdRequestorProcessor::NewL() |
|
66 { |
|
67 CLpdRequestorProcessor* self = new( ELeave ) CLpdRequestorProcessor; |
|
68 // Nothing to do in the Second Phase Constructor |
|
69 return self; |
|
70 } |
|
71 |
|
72 // Destructor |
|
73 CLpdRequestorProcessor::~CLpdRequestorProcessor() |
|
74 { |
|
75 iRequestors.ResetAndDestroy(); |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CLpdRequestorProcessor::ReadRequestorsL |
|
80 // (other items were commented in a header). |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 TBool CLpdRequestorProcessor::ReadRequestorsL( |
|
84 const CPosPrivacyNotifier& aPosNotifier ) |
|
85 { |
|
86 __ASSERT_DEBUG( aPosNotifier.CurrentRequest() != KPosNullQNRequestId, |
|
87 HandleAssertErrorL() ); |
|
88 |
|
89 this->ResetAndDestroyRequestors(); |
|
90 |
|
91 TBool allRequestorIdsValid = ETrue; |
|
92 CLocRequestorUtilsResolver* reqUtils = CLocRequestorUtilsResolver::NewL(); |
|
93 CleanupStack::PushL(reqUtils); |
|
94 // Let's read the requestors associated with the current request: |
|
95 TInt nofRequestors = aPosNotifier.RequestorCountL(); |
|
96 |
|
97 for ( TInt i = 0; i < nofRequestors; i++ ) |
|
98 { |
|
99 CPosRequestor* requestor = aPosNotifier.RequestorLC( i ); |
|
100 if ( !reqUtils->RequestorIdValid( *requestor ) ) |
|
101 { // mark that some requestor id is invalid |
|
102 allRequestorIdsValid = EFalse; |
|
103 } |
|
104 |
|
105 if( iSuplRequest ) |
|
106 { |
|
107 TInt64 sessionId = RetrieveSessionId( requestor->RequestorIdString() ); |
|
108 SetSessionId( sessionId ); |
|
109 TPtrC RequestorName = RetrieveRequestorNameL(requestor->RequestorIdString()); |
|
110 requestor->SetRequestorIdL(requestor->RequestorIdFormat(), RequestorName); |
|
111 } |
|
112 User::LeaveIfError( iRequestors.Append( requestor ) ); |
|
113 CleanupStack::Pop( requestor ); // iRequestors owns now the requestor |
|
114 } |
|
115 |
|
116 if ( nofRequestors == 0 ) |
|
117 { |
|
118 allRequestorIdsValid = EFalse; // zero requestors == invalid |
|
119 } |
|
120 |
|
121 // Use Requestor Utils and resolve the requestor here itself |
|
122 reqUtils->ProcessRequestorsL(iRequestors); |
|
123 CleanupStack::PopAndDestroy(reqUtils); |
|
124 return allRequestorIdsValid; |
|
125 } |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // CLpdRequestorProcessor::RtorNamesForVerifNotifL |
|
129 // (other items were commented in a header). |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 CLpdBaseModel* CLpdRequestorProcessor::RtorNamesForVerifNotifL( |
|
133 CEikFormattedCellListBox& aListBox ) |
|
134 { |
|
135 return CLpdVerifNotifLBModel::NewL( *this, aListBox ); |
|
136 } |
|
137 |
|
138 // ----------------------------------------------------------------------------- |
|
139 // CLpdRequestorProcessor::ResetAndDestroyRequestors |
|
140 // (other items were commented in a header). |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 void CLpdRequestorProcessor::ResetAndDestroyRequestors() |
|
144 { |
|
145 iRequestors.ResetAndDestroy(); |
|
146 } |
|
147 |
|
148 void CLpdRequestorProcessor::SetRequestType( TInt aReqType ) |
|
149 { |
|
150 iSuplRequest = aReqType ; |
|
151 } |
|
152 // ----------------------------------------------------------------------------- |
|
153 // CLpdRequestorProcessor::Requestors |
|
154 // (other items were commented in a header). |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 const RPointerArray<CPosRequestor>& CLpdRequestorProcessor::Requestors() const |
|
158 { |
|
159 return iRequestors; |
|
160 } |
|
161 |
|
162 // ----------------------------------------------------------------------------- |
|
163 // CLpdRequestorProcessor::HandleAssertErrorL |
|
164 // (other items were commented in a header). |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 void CLpdRequestorProcessor::HandleAssertErrorL() const |
|
168 { |
|
169 #ifdef _DEBUG |
|
170 User::Panic( KPanicText, KLpdErrGeneral ); |
|
171 #else |
|
172 User::Leave( KErrCorrupt ); |
|
173 #endif |
|
174 } |
|
175 |
|
176 // ----------------------------------------------------------------------------- |
|
177 // CLpdRequestorProcessor::RetrieveRequestorsL |
|
178 // The Requestors information for the current request is read and returned. |
|
179 // ----------------------------------------------------------------------------- |
|
180 // |
|
181 RPosRequestorStack* CLpdRequestorProcessor::RetrieveRequestorsL( |
|
182 const CPosPrivacyNotifier& aPosNotifier ) |
|
183 { |
|
184 __ASSERT_DEBUG( aPosNotifier.CurrentRequest() != KPosNullQNRequestId, |
|
185 HandleAssertErrorL() ); |
|
186 |
|
187 RPosRequestorStack* requestors = new(ELeave) RPosRequestorStack; |
|
188 |
|
189 // Let's read the requestors associated with the current request: |
|
190 TInt nofRequestors = aPosNotifier.RequestorCountL(); |
|
191 |
|
192 for ( TInt i = 0; i < nofRequestors; i++ ) |
|
193 { |
|
194 CPosRequestor* requestor = aPosNotifier.RequestorLC( i ); |
|
195 requestors->AppendL( requestor ); |
|
196 CleanupStack::Pop( requestor ); // requestors owns now the requestor |
|
197 } |
|
198 |
|
199 // Return the Index of the Array where the requestor Arary is appended. |
|
200 return requestors; |
|
201 } |
|
202 |
|
203 // ----------------------------------------------------------------------------- |
|
204 // CLpdRequestorProcessor::ReadRequestorsL |
|
205 // Read the requestors passed as parameter. Resolve them and store in |
|
206 // iRequestors member variable. |
|
207 // ----------------------------------------------------------------------------- |
|
208 // |
|
209 void CLpdRequestorProcessor::ReadRequestorsL( |
|
210 const RPosRequestorStack& aRequestors ) |
|
211 { |
|
212 TInt nofRequestors = aRequestors.Count(); |
|
213 CLocRequestorUtilsResolver* reqUtils = CLocRequestorUtilsResolver::NewL(); |
|
214 CleanupStack::PushL(reqUtils); |
|
215 |
|
216 for ( TInt i = 0; i < nofRequestors; i++ ) |
|
217 { |
|
218 CPosRequestor* requestor; |
|
219 if( iSuplRequest ) |
|
220 { |
|
221 TInt64 sessionId = RetrieveSessionId( aRequestors[i]->RequestorIdString() ); |
|
222 SetSessionId( sessionId ); |
|
223 TPtrC RequestorName = RetrieveRequestorNameL(aRequestors[i]->RequestorIdString()); |
|
224 aRequestors[i]->SetRequestorIdL(aRequestors[i]->RequestorIdFormat(), RequestorName); |
|
225 } |
|
226 if (aRequestors[i]->RequestorType() == |
|
227 CPosRequestor::ERequestorService) |
|
228 { |
|
229 requestor = CPosServiceRequestor::NewLC( |
|
230 aRequestors[i]->RequestorIdFormat(), |
|
231 aRequestors[i]->RequestorIdString()); |
|
232 } |
|
233 else |
|
234 { |
|
235 requestor = CPosContactRequestor::NewLC( |
|
236 aRequestors[i]->RequestorIdFormat(), |
|
237 aRequestors[i]->RequestorIdString()); |
|
238 } |
|
239 |
|
240 iRequestors.AppendL( requestor ); |
|
241 CleanupStack::Pop( requestor ); // requestors owns now the requestor |
|
242 } |
|
243 |
|
244 // Return the Index of the Array where the requestor Arary is appended. |
|
245 // Use Requestor Utils and resolve the requestor here itself |
|
246 reqUtils->ProcessRequestorsL(iRequestors); |
|
247 CleanupStack::PopAndDestroy(reqUtils); |
|
248 } |
|
249 |
|
250 TPtrC CLpdRequestorProcessor::RetrieveRequestorNameL( const TDesC& aString ) |
|
251 { |
|
252 //Parse string and extract characters leaving last |
|
253 // 3 characters and return as requestor name. |
|
254 //If requestor name not there, say unknown requestor |
|
255 if( aString.Length() > 3 ) |
|
256 { |
|
257 TPtrC requestorName = aString.Left( aString.Length() - 3 ); |
|
258 return requestorName; |
|
259 } |
|
260 else |
|
261 { |
|
262 HBufC* buf = HBufC::NewL( KUnknownRequestor().Length() ); |
|
263 buf->Des().Append( KUnknownRequestor ); |
|
264 return buf->Des(); |
|
265 } |
|
266 } |
|
267 |
|
268 |
|
269 TInt64 CLpdRequestorProcessor::RetrieveSessionId( const TDesC& aString ) |
|
270 { |
|
271 //Parse string and return session id(last 3 characters) |
|
272 //after converting to TInt |
|
273 TInt sessId; |
|
274 TInt64 sessionId; |
|
275 TPtrC sessionIdPart = aString.Right( 3 ); |
|
276 |
|
277 TLex lex( sessionIdPart ); |
|
278 lex.Val( sessId ); |
|
279 sessionId = sessId; |
|
280 return sessionId; |
|
281 } |
|
282 |
|
283 void CLpdRequestorProcessor::SetSessionId( TInt64 aSessionId ) |
|
284 { |
|
285 iSessionId = aSessionId; |
|
286 } |
|
287 |
|
288 TInt64 CLpdRequestorProcessor::GetSessionId() |
|
289 { |
|
290 return iSessionId; |
|
291 } |
|
292 |
|
293 // end of file |
|