|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
16 #include <tzusernames.h> |
|
17 #include <tzuserdefineddata.h> |
|
18 #endif |
|
19 #include "tzuserdatacache.h" |
|
20 |
|
21 /** |
|
22 When the data of a user defined rules, names and IDs are sent from the server |
|
23 to the client, the size of the data is requested first and then, the client can |
|
24 create a data buffer and send it to the server to fill the data. |
|
25 |
|
26 Therefore, some client-server calls (e.g. CTzUserData::ReadRulesL(), |
|
27 CTzUserData::ReadNamesL(), CTzUserData::GetTzIdsL() must be carried out in two |
|
28 steps: |
|
29 |
|
30 - Get the size of the data to allow client to create data buffer |
|
31 - Get the data using this buffer |
|
32 |
|
33 The class CTzUserDataCache is for: |
|
34 |
|
35 - Find the data size |
|
36 - Cache the data |
|
37 - Retrieve cached data |
|
38 */ |
|
39 |
|
40 CTzUserDataCache::CTzUserDataCache() |
|
41 :iNames(NULL) |
|
42 { |
|
43 } |
|
44 |
|
45 CTzUserDataCache* CTzUserDataCache::NewL() |
|
46 { |
|
47 CTzUserDataCache* self = new (ELeave) CTzUserDataCache(); |
|
48 return self; |
|
49 } |
|
50 |
|
51 CTzUserDataCache::~CTzUserDataCache() |
|
52 { |
|
53 Reset(); |
|
54 iIds.Close(); |
|
55 } |
|
56 |
|
57 void CTzUserDataCache::SetNames(CTzUserNames* aNames) |
|
58 { |
|
59 delete iNames; |
|
60 iNames = aNames; |
|
61 } |
|
62 |
|
63 void CTzUserDataCache::SetIdsL(const RArray<TUint32>& aIds) |
|
64 { |
|
65 iIds.Reset(); |
|
66 for(TInt ii=0;ii<aIds.Count();++ii) |
|
67 { |
|
68 iIds.AppendL((aIds)[ii]); |
|
69 } |
|
70 } |
|
71 |
|
72 TInt CTzUserDataCache::SizeOfNames() const |
|
73 { |
|
74 __ASSERT_DEBUG(iNames, User::Invariant()); |
|
75 if(iNames) |
|
76 { |
|
77 return iNames->SizeOfObject(); |
|
78 } |
|
79 return 0; |
|
80 } |
|
81 |
|
82 const CTzUserNames& CTzUserDataCache::GetNames() const |
|
83 { |
|
84 __ASSERT_DEBUG(iNames, User::Invariant()); |
|
85 return *iNames; |
|
86 } |
|
87 |
|
88 const TArray<TUint32> CTzUserDataCache::GetIds() const |
|
89 { |
|
90 return iIds.Array(); |
|
91 } |
|
92 |
|
93 TInt CTzUserDataCache::SizeOfIds() const |
|
94 { |
|
95 return (iIds.Count()+1) * sizeof (TInt); |
|
96 } |
|
97 |
|
98 void CTzUserDataCache::Reset() |
|
99 { |
|
100 delete iNames; |
|
101 iNames = NULL; |
|
102 iIds.Reset(); |
|
103 } |
|
104 |