|
1 /* |
|
2 * Copyright (c) 2006 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: Class CCatalogsClientAccessPointData declation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "catalogsclientaccesspointdata.h" |
|
20 #include "catalogsaccesspoint.h" |
|
21 #include "catalogsaccesspointmap.h" |
|
22 #include "catalogsdebug.h" |
|
23 #include "ncdnodeidentifier.h" |
|
24 #include "ncdnodeidentifiereditor.h" |
|
25 |
|
26 CCatalogsClientAccessPointData* CCatalogsClientAccessPointData::NewL() |
|
27 { |
|
28 CCatalogsClientAccessPointData* self = NewLC(); |
|
29 CleanupStack::Pop(); |
|
30 return self; |
|
31 } |
|
32 |
|
33 CCatalogsClientAccessPointData* CCatalogsClientAccessPointData::NewLC() |
|
34 { |
|
35 CCatalogsClientAccessPointData* self = |
|
36 new (ELeave) CCatalogsClientAccessPointData(); |
|
37 CleanupStack::PushL(self); |
|
38 return self; |
|
39 } |
|
40 |
|
41 CCatalogsClientAccessPointData::~CCatalogsClientAccessPointData() |
|
42 { |
|
43 iAccessPoints.ResetAndDestroy(); |
|
44 iAccessPointMaps.ResetAndDestroy(); |
|
45 } |
|
46 |
|
47 void CCatalogsClientAccessPointData::AddAccessPointL(CCatalogsAccessPoint* aAccessPoint) |
|
48 { |
|
49 iAccessPoints.AppendL(aAccessPoint); |
|
50 } |
|
51 |
|
52 void CCatalogsClientAccessPointData::MapAccessPointL( |
|
53 const TDesC& aNameSpace, |
|
54 const MCatalogsAccessPointManager::TAction& aAction, |
|
55 const TDesC& aApId) |
|
56 { |
|
57 // check if some access point is mapped already |
|
58 TInt mapCount = iAccessPointMaps.Count(); |
|
59 for (TInt i = 0; i < mapCount; i++) |
|
60 { |
|
61 CCatalogsAccessPointMap* map = iAccessPointMaps[i]; |
|
62 if (map->NameSpace() == aNameSpace && map->Action() == aAction) |
|
63 { |
|
64 // access point map found, delete it |
|
65 iAccessPointMaps.Remove(i); |
|
66 break; |
|
67 } |
|
68 } |
|
69 |
|
70 // create new map |
|
71 CCatalogsAccessPointMap* map = CCatalogsAccessPointMap::NewLC( |
|
72 aNameSpace, aAction, aApId); |
|
73 iAccessPointMaps.AppendL(map); |
|
74 CleanupStack::Pop(map); |
|
75 iAccessPointMaps.Compress(); |
|
76 } |
|
77 |
|
78 void CCatalogsClientAccessPointData::MapAccessPointL( |
|
79 const TDesC& aNameSpace, |
|
80 const TDesC& aCatalogId, |
|
81 const MCatalogsAccessPointManager::TAction& aAction, |
|
82 const TDesC& aApId) |
|
83 { |
|
84 // check if some access point is mapped already |
|
85 TInt mapCount = iAccessPointMaps.Count(); |
|
86 for (TInt i = 0; i < mapCount; i++) |
|
87 { |
|
88 CCatalogsAccessPointMap* map = iAccessPointMaps[i]; |
|
89 if (map->NameSpace() == aNameSpace && map->HasCatalogId() && |
|
90 map->CatalogId() == aCatalogId && map->Action() == aAction) |
|
91 { |
|
92 // access point map found, delete it |
|
93 iAccessPointMaps.Remove(i); |
|
94 break; |
|
95 } |
|
96 } |
|
97 |
|
98 // create new map |
|
99 CCatalogsAccessPointMap* map = CCatalogsAccessPointMap::NewLC( |
|
100 aNameSpace, aCatalogId, aAction, aApId); |
|
101 iAccessPointMaps.AppendL(map); |
|
102 CleanupStack::Pop(map); |
|
103 iAccessPointMaps.Compress(); |
|
104 } |
|
105 |
|
106 CCatalogsAccessPoint* CCatalogsClientAccessPointData::AccessPoint( |
|
107 const TDesC& aNameSpace, |
|
108 const MCatalogsAccessPointManager::TAction& aAction) const |
|
109 { |
|
110 const TDesC* apId = NULL; |
|
111 |
|
112 // find the access point id |
|
113 // find the map |
|
114 TInt mapCount = iAccessPointMaps.Count(); |
|
115 for (TInt i = 0; i < mapCount; i++) |
|
116 { |
|
117 CCatalogsAccessPointMap* map = iAccessPointMaps[i]; |
|
118 if (map->NameSpace() == aNameSpace && map->Action() == aAction && !map->HasCatalogId()) |
|
119 { |
|
120 // id found |
|
121 apId = &map->AccessPointId(); |
|
122 break; |
|
123 } |
|
124 } |
|
125 |
|
126 if (!apId) |
|
127 { |
|
128 return NULL; |
|
129 } |
|
130 |
|
131 return AccessPointById(*apId); |
|
132 } |
|
133 |
|
134 CCatalogsAccessPoint* CCatalogsClientAccessPointData::AccessPointL( |
|
135 const TDesC& aNameSpace, |
|
136 const TDesC& aCatalogId, |
|
137 const MCatalogsAccessPointManager::TAction& aAction) const |
|
138 { |
|
139 const TDesC* apId = NULL; |
|
140 |
|
141 // Create metadata identifier and search the access point using it. |
|
142 // Fake clientUid can be used, we are only interested in namespace and id |
|
143 // at this point. |
|
144 CNcdNodeIdentifier* nodeId = |
|
145 CNcdNodeIdentifier::NewLC( aNameSpace, aCatalogId, TUid::Uid( 1 ) ); |
|
146 CNcdNodeIdentifier* metaDataId = |
|
147 NcdNodeIdentifierEditor::CreateMetaDataIdentifierL( *nodeId ); |
|
148 CleanupStack::PopAndDestroy( nodeId ); |
|
149 |
|
150 // find the access point id |
|
151 // find the map |
|
152 TInt mapCount = iAccessPointMaps.Count(); |
|
153 for (TInt i = 0; i < mapCount; i++) |
|
154 { |
|
155 CCatalogsAccessPointMap* map = iAccessPointMaps[i]; |
|
156 if (map->NameSpace() == metaDataId->NodeNameSpace() && map->HasCatalogId() && |
|
157 map->CatalogId() == metaDataId->NodeId() && map->Action() == aAction) |
|
158 { |
|
159 // id found |
|
160 apId = &map->AccessPointId(); |
|
161 break; |
|
162 } |
|
163 } |
|
164 |
|
165 delete metaDataId; |
|
166 metaDataId = NULL; |
|
167 |
|
168 if (!apId) |
|
169 { |
|
170 return NULL; |
|
171 } |
|
172 |
|
173 return AccessPointById(*apId); |
|
174 } |
|
175 |
|
176 TInt CCatalogsClientAccessPointData::AccessPointCount() const |
|
177 { |
|
178 return iAccessPoints.Count(); |
|
179 } |
|
180 |
|
181 CCatalogsAccessPoint& CCatalogsClientAccessPointData::AccessPoint(const TInt& aIndex) |
|
182 { |
|
183 return *iAccessPoints[aIndex]; |
|
184 } |
|
185 |
|
186 |
|
187 void CCatalogsClientAccessPointData::ExternalizeL(RWriteStream& aStream) |
|
188 { |
|
189 DLTRACEIN(("")); |
|
190 |
|
191 TInt apCount = iAccessPoints.Count(); |
|
192 |
|
193 // write access points |
|
194 aStream.WriteInt32L(apCount); |
|
195 for (TInt i = 0; i < apCount; i++) |
|
196 { |
|
197 iAccessPoints[i]->ExternalizeL(aStream); |
|
198 } |
|
199 |
|
200 TInt mapCount = iAccessPointMaps.Count(); |
|
201 aStream.WriteInt32L(mapCount); |
|
202 |
|
203 // write access point maps |
|
204 for (TInt i = 0; i < mapCount; i++) |
|
205 { |
|
206 iAccessPointMaps[i]->ExternalizeL(aStream); |
|
207 } |
|
208 DLTRACEOUT(("")); |
|
209 } |
|
210 |
|
211 void CCatalogsClientAccessPointData::InternalizeL(RReadStream& aStream) |
|
212 { |
|
213 DLTRACEIN(("")); |
|
214 TInt apCount = aStream.ReadInt32L(); |
|
215 for (TInt i = 0; i < apCount; i++) |
|
216 { |
|
217 CCatalogsAccessPoint* ap = CCatalogsAccessPoint::NewLC(aStream); |
|
218 iAccessPoints.AppendL(ap); |
|
219 CleanupStack::Pop(); // ap |
|
220 } |
|
221 |
|
222 TInt mapCount = aStream.ReadInt32L(); |
|
223 for (TInt i = 0; i < mapCount; i++) |
|
224 { |
|
225 CCatalogsAccessPointMap* apMap = CCatalogsAccessPointMap::NewLC(aStream); |
|
226 iAccessPointMaps.AppendL(apMap); |
|
227 CleanupStack::Pop(); // apMap |
|
228 } |
|
229 } |
|
230 |
|
231 |
|
232 CCatalogsClientAccessPointData::CCatalogsClientAccessPointData() |
|
233 { |
|
234 } |
|
235 |
|
236 CCatalogsAccessPoint* CCatalogsClientAccessPointData::AccessPointById( |
|
237 const TDesC& apId) const |
|
238 { |
|
239 TInt apCount = iAccessPoints.Count(); |
|
240 for (TInt i = 0; i < apCount; i++) |
|
241 { |
|
242 if (iAccessPoints[i]->NcdAccessPointId() == apId) |
|
243 { |
|
244 return iAccessPoints[i]; |
|
245 } |
|
246 } |
|
247 |
|
248 return NULL; |
|
249 } |
|
250 |