14
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 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:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include "cserviceinfo.h"
|
|
20 |
|
|
21 |
const TUint KCacheRecords = 4;
|
|
22 |
const TUint KGranularity = 2;
|
|
23 |
const TUint KDefaultTtl = 4500;
|
|
24 |
const TUint KQueryFactor = 0.2;
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
CServiceInfo* CServiceInfo::NewL()
|
|
29 |
{
|
|
30 |
CServiceInfo* self = CServiceInfo::NewLC();
|
|
31 |
CleanupStack::Pop(self);
|
|
32 |
return self;
|
|
33 |
}
|
|
34 |
|
|
35 |
CServiceInfo* CServiceInfo::NewLC()
|
|
36 |
{
|
|
37 |
CServiceInfo* self = new (ELeave)CServiceInfo();
|
|
38 |
CleanupStack::PushL(self);
|
|
39 |
self->ConstructL();
|
|
40 |
return self;
|
|
41 |
}
|
|
42 |
|
|
43 |
CServiceInfo::CServiceInfo():iEntryTime(KCacheRecords),iExpiryTime(KCacheRecords),iAddressRecord(NULL),iServiceRecord(NULL),iPtrRecord(NULL),iTxtRecord(NULL)
|
|
44 |
{
|
|
45 |
iEntryExpired = EFalse;
|
|
46 |
}
|
|
47 |
|
|
48 |
CServiceInfo::~CServiceInfo()
|
|
49 |
{
|
|
50 |
delete iAddressRecord;
|
|
51 |
delete iServiceRecord;
|
|
52 |
delete iPtrRecord;
|
|
53 |
delete iTxtRecord;
|
|
54 |
iEntryTime.Close();
|
|
55 |
iExpiryTime.Close();
|
|
56 |
iKey.Close();
|
|
57 |
|
|
58 |
}
|
|
59 |
|
|
60 |
void CServiceInfo::ConstructL()
|
|
61 |
{
|
|
62 |
TTime currentTime;
|
|
63 |
currentTime.UniversalTime();
|
|
64 |
TTimeIntervalSeconds ttl = KDefaultTtl;
|
|
65 |
|
|
66 |
//Set default Entry time
|
|
67 |
for(TInt count=0;count<KCacheRecords;count++ )
|
|
68 |
{
|
|
69 |
iEntryTime.AppendL(currentTime);
|
|
70 |
}
|
|
71 |
|
|
72 |
|
|
73 |
//Set default Expiry time
|
|
74 |
for(TInt count=0;count<KCacheRecords;count++ )
|
|
75 |
{
|
|
76 |
iExpiryTime.AppendL(currentTime + ttl);
|
|
77 |
}
|
|
78 |
|
|
79 |
}
|
|
80 |
|
|
81 |
TBool CServiceInfo::IsAuthoritative()const
|
|
82 |
{
|
|
83 |
return iAuthoritative;
|
|
84 |
}
|
|
85 |
|
|
86 |
void CServiceInfo::SetAuthoritative(TBool aAuthoritative)
|
|
87 |
{
|
|
88 |
iAuthoritative = aAuthoritative;
|
|
89 |
}
|
|
90 |
|
|
91 |
const TTime& CServiceInfo::LastAccessTime()const
|
|
92 |
{
|
|
93 |
return iLastAccessTime;
|
|
94 |
}
|
|
95 |
|
|
96 |
void CServiceInfo::SetAccessTime(TTime aTime)
|
|
97 |
{
|
|
98 |
iLastAccessTime = aTime;
|
|
99 |
}
|
|
100 |
|
|
101 |
TUint32 CServiceInfo::SessionId()const
|
|
102 |
{
|
|
103 |
return iSessionId;
|
|
104 |
}
|
|
105 |
|
|
106 |
void CServiceInfo::SetSessionId(TUint32 aSessionId)
|
|
107 |
{
|
|
108 |
iSessionId = aSessionId;
|
|
109 |
}
|
|
110 |
|
|
111 |
void CServiceInfo::SetAddressRecord(CRdTypeA* aAddressRecord)
|
|
112 |
{
|
|
113 |
|
|
114 |
SetEntryTime(ECacheEntryAddr);
|
|
115 |
iAddressRecord = aAddressRecord;
|
|
116 |
SetExpiryTime(ECacheEntryAddr);
|
|
117 |
|
|
118 |
}
|
|
119 |
|
|
120 |
void CServiceInfo::SetServiceRecord(CRdTypeSrv* aServiceRecord)
|
|
121 |
{
|
|
122 |
|
|
123 |
SetEntryTime(ECacheEntrySrv);
|
|
124 |
iServiceRecord = aServiceRecord;
|
|
125 |
SetExpiryTime(ECacheEntrySrv);
|
|
126 |
|
|
127 |
}
|
|
128 |
|
|
129 |
void CServiceInfo::SetPtrRecord(CRdTypePtr* aPtrRecord)
|
|
130 |
{
|
|
131 |
|
|
132 |
SetEntryTime(ECacheEntryPtr);
|
|
133 |
iPtrRecord = aPtrRecord;
|
|
134 |
SetExpiryTime(ECacheEntryPtr);
|
|
135 |
|
|
136 |
}
|
|
137 |
|
|
138 |
void CServiceInfo::SetTxtRecord(CRdTypeTxt* aTxtRecord)
|
|
139 |
{
|
|
140 |
|
|
141 |
SetEntryTime(ECacheEntryTxt);
|
|
142 |
iTxtRecord = aTxtRecord;
|
|
143 |
SetExpiryTime(ECacheEntryTxt);
|
|
144 |
|
|
145 |
}
|
|
146 |
|
|
147 |
|
|
148 |
CRdTypeA* CServiceInfo::AddressRecord()const
|
|
149 |
{
|
|
150 |
return iAddressRecord;
|
|
151 |
}
|
|
152 |
|
|
153 |
CRdTypeSrv* CServiceInfo::ServiceRecord()const
|
|
154 |
{
|
|
155 |
return iServiceRecord;
|
|
156 |
}
|
|
157 |
|
|
158 |
CRdTypePtr* CServiceInfo::PtrRecord()const
|
|
159 |
{
|
|
160 |
return iPtrRecord;
|
|
161 |
}
|
|
162 |
|
|
163 |
CRdTypeTxt* CServiceInfo::TxtRecord()const
|
|
164 |
{
|
|
165 |
return iTxtRecord;
|
|
166 |
}
|
|
167 |
|
|
168 |
void CServiceInfo::SetKeyL(const TDesC8& aKey)
|
|
169 |
{
|
|
170 |
iKey.Close();
|
|
171 |
iKey.CreateL(aKey);
|
|
172 |
iKey.LowerCase();
|
|
173 |
}
|
|
174 |
|
|
175 |
const TDesC8& CServiceInfo::Key()const
|
|
176 |
{
|
|
177 |
return iKey;
|
|
178 |
}
|
|
179 |
|
|
180 |
void CServiceInfo::SetEntryTime(TCacheEntryType aType)
|
|
181 |
{
|
|
182 |
TTime currentTime;
|
|
183 |
currentTime.UniversalTime();
|
|
184 |
|
|
185 |
//Set the Entry Time when the record data is obtained for
|
|
186 |
//the first time
|
|
187 |
|
|
188 |
switch(aType)
|
|
189 |
{
|
|
190 |
case ECacheEntryAddr:
|
|
191 |
//if(!AddressRecord())
|
|
192 |
{
|
|
193 |
iEntryTime.Insert(currentTime,ECacheEntryAddr);
|
|
194 |
}
|
|
195 |
break;
|
|
196 |
|
|
197 |
|
|
198 |
case ECacheEntryPtr:
|
|
199 |
//if(!PtrRecord())
|
|
200 |
{
|
|
201 |
iEntryTime.Insert(currentTime,ECacheEntryPtr);
|
|
202 |
}
|
|
203 |
break;
|
|
204 |
|
|
205 |
|
|
206 |
case ECacheEntrySrv:
|
|
207 |
//if(!ServiceRecord())
|
|
208 |
{
|
|
209 |
iEntryTime.Insert(currentTime,ECacheEntrySrv);
|
|
210 |
}
|
|
211 |
break;
|
|
212 |
|
|
213 |
case ECacheEntryTxt:
|
|
214 |
//if(!TxtRecord())
|
|
215 |
{
|
|
216 |
iEntryTime.Insert(currentTime,ECacheEntryTxt);
|
|
217 |
}
|
|
218 |
break;
|
|
219 |
}
|
|
220 |
|
|
221 |
}
|
|
222 |
|
|
223 |
|
|
224 |
void CServiceInfo::SetExpiryTime(TCacheEntryType aType)
|
|
225 |
{
|
|
226 |
TTimeIntervalSeconds ttl;
|
|
227 |
|
|
228 |
//Set/Update the Expiry time
|
|
229 |
switch(aType)
|
|
230 |
{
|
|
231 |
case ECacheEntryAddr:
|
|
232 |
ttl = AddressRecord()->Ttl();
|
|
233 |
break;
|
|
234 |
|
|
235 |
|
|
236 |
case ECacheEntryPtr:
|
|
237 |
ttl = PtrRecord()->Ttl();
|
|
238 |
break;
|
|
239 |
|
|
240 |
|
|
241 |
case ECacheEntrySrv:
|
|
242 |
ttl = ServiceRecord()->Ttl();
|
|
243 |
break;
|
|
244 |
|
|
245 |
case ECacheEntryTxt:
|
|
246 |
ttl = TxtRecord()->Ttl();
|
|
247 |
break;
|
|
248 |
}
|
|
249 |
|
|
250 |
//Set the Expiry Time
|
|
251 |
TTime expiryTime = iEntryTime[aType] + ttl;
|
|
252 |
iExpiryTime.Insert(expiryTime,aType);
|
|
253 |
}
|
|
254 |
|
|
255 |
|
|
256 |
TBool CServiceInfo::EntryExpired()
|
|
257 |
{
|
|
258 |
TTime currentTime;
|
|
259 |
currentTime.UniversalTime();
|
|
260 |
|
|
261 |
if(AddressRecord())
|
|
262 |
{
|
|
263 |
if(iExpiryTime[ECacheEntryAddr] <= currentTime)
|
|
264 |
{
|
|
265 |
iEntryExpired = ETrue;
|
|
266 |
return iEntryExpired;
|
|
267 |
}
|
|
268 |
}
|
|
269 |
|
|
270 |
if(PtrRecord())
|
|
271 |
{
|
|
272 |
if(iExpiryTime[ECacheEntryPtr] <= currentTime)
|
|
273 |
{
|
|
274 |
iEntryExpired = ETrue;
|
|
275 |
return iEntryExpired;
|
|
276 |
}
|
|
277 |
}
|
|
278 |
|
|
279 |
|
|
280 |
if(ServiceRecord())
|
|
281 |
{
|
|
282 |
if(iExpiryTime[ECacheEntrySrv] <= currentTime)
|
|
283 |
{
|
|
284 |
iEntryExpired = ETrue;
|
|
285 |
return iEntryExpired;
|
|
286 |
}
|
|
287 |
}
|
|
288 |
|
|
289 |
|
|
290 |
if(TxtRecord())
|
|
291 |
{
|
|
292 |
if(iExpiryTime[ECacheEntryTxt] <= currentTime)
|
|
293 |
{
|
|
294 |
iEntryExpired = ETrue;
|
|
295 |
return iEntryExpired;
|
|
296 |
}
|
|
297 |
}
|
|
298 |
|
|
299 |
return EFalse;
|
|
300 |
}
|
|
301 |
|
|
302 |
|
|
303 |
// This Clone funtion returns back what is necessary.
|
|
304 |
|
|
305 |
CServiceInfo* CServiceInfo::CloneL()const
|
|
306 |
{
|
|
307 |
CServiceInfo* serviceInfo = CServiceInfo::NewL();
|
|
308 |
|
|
309 |
if(iAddressRecord)
|
|
310 |
{
|
|
311 |
serviceInfo->SetAddressRecord(static_cast<CRdTypeA*>(iAddressRecord->CloneL()));
|
|
312 |
}
|
|
313 |
if(iServiceRecord)
|
|
314 |
{
|
|
315 |
serviceInfo->SetServiceRecord(static_cast<CRdTypeSrv*>(iServiceRecord->CloneL()));
|
|
316 |
}
|
|
317 |
if(iPtrRecord)
|
|
318 |
{
|
|
319 |
serviceInfo->SetPtrRecord(static_cast<CRdTypePtr*>(iPtrRecord->CloneL()));
|
|
320 |
}
|
|
321 |
if(iTxtRecord)
|
|
322 |
{
|
|
323 |
serviceInfo->SetTxtRecord(static_cast<CRdTypeTxt*>(iTxtRecord->CloneL()));
|
|
324 |
}
|
|
325 |
|
|
326 |
serviceInfo->SetKeyL(iKey);
|
|
327 |
serviceInfo->SetSessionId(iSessionId);
|
|
328 |
|
|
329 |
return serviceInfo;
|
|
330 |
}
|
|
331 |
|
|
332 |
TBool CServiceInfo::EntryToBeQueried()
|
|
333 |
{
|
|
334 |
//Check if any record in the entry has exceeded 80% ttl, if yes, Query!
|
|
335 |
|
|
336 |
TTime currentTime;
|
|
337 |
currentTime.UniversalTime();
|
|
338 |
|
|
339 |
|
|
340 |
if(AddressRecord())
|
|
341 |
{
|
|
342 |
TInt64 addExpiryTime = iExpiryTime[ECacheEntryAddr].Int64();
|
|
343 |
TInt64 current = currentTime.Int64();
|
|
344 |
//Converted to seconds
|
|
345 |
TUint64 addExpiryFactor = (addExpiryTime - current) / 1000000;
|
|
346 |
if( addExpiryFactor < (0.2)*(AddressRecord()->Ttl()))
|
|
347 |
{
|
|
348 |
return ETrue;
|
|
349 |
}
|
|
350 |
}
|
|
351 |
|
|
352 |
if(PtrRecord())
|
|
353 |
{
|
|
354 |
TInt64 ptrExpiryTime = iExpiryTime[ECacheEntryPtr].Int64();
|
|
355 |
TInt64 current = currentTime.Int64();
|
|
356 |
//Converted to seconds
|
|
357 |
TUint64 ptrExpiryFactor = (ptrExpiryTime - current) / 1000000;
|
|
358 |
if( ptrExpiryFactor < (0.2)*(PtrRecord()->Ttl()))
|
|
359 |
{
|
|
360 |
return ETrue;
|
|
361 |
}
|
|
362 |
}
|
|
363 |
|
|
364 |
|
|
365 |
if(ServiceRecord())
|
|
366 |
{
|
|
367 |
TInt64 srvExpiryTime = iExpiryTime[ECacheEntrySrv].Int64();
|
|
368 |
TInt64 current = currentTime.Int64();
|
|
369 |
//Converted to seconds
|
|
370 |
TUint64 srvExpiryFactor = (srvExpiryTime - current) / 1000000;
|
|
371 |
if( srvExpiryFactor < (0.2)*(ServiceRecord()->Ttl()))
|
|
372 |
{
|
|
373 |
return ETrue;
|
|
374 |
}
|
|
375 |
}
|
|
376 |
|
|
377 |
|
|
378 |
if(TxtRecord())
|
|
379 |
{
|
|
380 |
TInt64 txtExpiryTime = iExpiryTime[ECacheEntryTxt].Int64();
|
|
381 |
TInt64 current = currentTime.Int64();
|
|
382 |
//Converted to seconds
|
|
383 |
TUint64 txtExpiryFactor = (txtExpiryTime - current) / 1000000;
|
|
384 |
if( txtExpiryFactor < (0.2)*(TxtRecord()->Ttl()))
|
|
385 |
{
|
|
386 |
return ETrue;
|
|
387 |
}
|
|
388 |
}
|
|
389 |
|
|
390 |
return EFalse;
|
|
391 |
}
|
|
392 |
|
|
393 |
|
|
394 |
TBool CServiceInfo::StaleEntry()
|
|
395 |
{
|
|
396 |
return iEntryExpired;
|
|
397 |
}
|