|
1 // Copyright (c) 2006-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 |
|
16 /** |
|
17 @file |
|
18 @internalTechnology |
|
19 */ |
|
20 |
|
21 #include "connectionqueryset.h" |
|
22 #include <commsdat.h> |
|
23 #include <comms-infras/ss_commsdataobject.h> |
|
24 |
|
25 |
|
26 #ifdef _DEBUG |
|
27 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module |
|
28 // (if it could happen through user error then you should give it an explicit, documented, category + code) |
|
29 _LIT(KSpecAssert_ESockCommDatObjc, "ESockCommDatObjc"); |
|
30 #endif |
|
31 |
|
32 using namespace Meta; |
|
33 using namespace ESock; |
|
34 |
|
35 |
|
36 // -------- Connection Settings Query Set -------- |
|
37 |
|
38 EXPORT_START_ATTRIBUTE_TABLE_AND_FN(XConnectionQuerySet, CCommsDataObjectFactory::iUid, XConnectionQuerySet::iUid) |
|
39 REGISTER_ATTRIBUTE(XConnectionQuerySet, iQueries, TMetaObject<XConnectionQuerySet::RMetaDataQueryContainer>) |
|
40 END_ATTRIBUTE_TABLE() |
|
41 |
|
42 |
|
43 EXPORT_C XConnectionQueryBase* XConnectionQuerySet::FindQuery(const XConnectionQueryBase& aQuery) const |
|
44 { |
|
45 XConnectionQueryBase* query = NULL; |
|
46 TConnectionQueryIter iter(GetQueryIter(XConnectionQueryBase::ENotAnswered | XConnectionQueryBase::EAnswered)); |
|
47 query = iter++; |
|
48 while (query) |
|
49 { |
|
50 if (query->Match(aQuery)) |
|
51 { |
|
52 return query; |
|
53 } |
|
54 |
|
55 query = iter++; |
|
56 } |
|
57 |
|
58 return NULL; |
|
59 } |
|
60 |
|
61 |
|
62 EXPORT_C XCommsDataObject::TProgressAction XConnectionQuerySet::DispatchL(TAny *aItfPtr, ESock::MPlatsecApiExt* aPlatsecItf) |
|
63 { |
|
64 MQueryConnSettingsApiExt* interface = reinterpret_cast<MQueryConnSettingsApiExt*>(aItfPtr); |
|
65 |
|
66 TConnectionQueryIter iter = GetQueryIter(XConnectionQueryBase::ENotAnswered); |
|
67 XConnectionQueryBase* query = iter++; |
|
68 TInt queriesRemaining(0); |
|
69 while (query) |
|
70 { |
|
71 queriesRemaining++; |
|
72 query->GetSetting(interface, aPlatsecItf); |
|
73 if (query->IsQueryAnswered()) |
|
74 { |
|
75 queriesRemaining--; |
|
76 } |
|
77 query = iter++; |
|
78 } |
|
79 |
|
80 return (queriesRemaining > 0) ? XCommsDataObject::EContinue : XCommsDataObject::EComplete; |
|
81 } |
|
82 |
|
83 EXPORT_C void XConnectionQuerySet::XNullQuery::GetSetting(MQueryConnSettingsApiExt* /*aItfPtr*/, MPlatsecApiExt* /*aPlatsecItf*/) |
|
84 { |
|
85 // Null Query has no value to get - impl here to satisfy abstract base class |
|
86 |
|
87 #ifdef __X86GCC__ |
|
88 // Ugly hack: GCC3.4 needs extra persuasion to unroll enough of the template; without this it won't link with a missing vtbl |
|
89 RMetaDataContainer<ESock::XConnectionQueryBase> unused; |
|
90 (void) unused; |
|
91 #endif |
|
92 } |
|
93 |
|
94 |
|
95 |
|
96 // -------- Individual Connection Queries -------- |
|
97 |
|
98 EXPORT_START_ATTRIBUTE_TABLE_AND_FN(XConnectionQueryBase, XConnectionQuerySet::iUid, XConnectionQueryBase::ENull) |
|
99 REGISTER_ATTRIBUTE(XConnectionQueryBase, iQueryFlags, TMeta<TUint32>) |
|
100 REGISTER_ATTRIBUTE(XConnectionQueryBase, iError, TMetaNumber) |
|
101 REGISTER_ATTRIBUTE(XConnectionQueryBase, iElementId, TMeta<CommsDat::TMDBElementId>) |
|
102 REGISTER_ATTRIBUTE(XConnectionQueryBase, iType, TMeta<CommsDat::TCDFieldValueTypes>) |
|
103 END_ATTRIBUTE_TABLE() |
|
104 |
|
105 |
|
106 EXPORT_START_ATTRIBUTE_TABLE_AND_FN(XConnectionQuerySet::XNullQuery, CConnectionQueryFactory::iUid, XConnectionQueryBase::ENull) |
|
107 END_ATTRIBUTE_TABLE_BASE(XConnectionQueryBase, 0) |
|
108 |
|
109 EXPORT_START_ATTRIBUTE_TABLE_AND_FN(XBoolQuery, CConnectionQueryFactory::iUid, XConnectionQueryBase::EBool) |
|
110 REGISTER_ATTRIBUTE(XBoolQuery, iData, TMeta<TBool>) |
|
111 END_ATTRIBUTE_TABLE_BASE(XConnectionQueryBase, 0) |
|
112 |
|
113 EXPORT_START_ATTRIBUTE_TABLE_AND_FN(XUintQuery, CConnectionQueryFactory::iUid, XConnectionQueryBase::EUint) |
|
114 REGISTER_ATTRIBUTE(XUintQuery, iData, TMeta<TUint32>) |
|
115 END_ATTRIBUTE_TABLE_BASE(XConnectionQueryBase, 0) |
|
116 |
|
117 EXPORT_START_ATTRIBUTE_TABLE_AND_FN(XIntQuery, CConnectionQueryFactory::iUid, XConnectionQueryBase::EInt) |
|
118 REGISTER_ATTRIBUTE(XIntQuery, iData, TMeta<TInt>) |
|
119 END_ATTRIBUTE_TABLE_BASE(XConnectionQueryBase, 0) |
|
120 |
|
121 EXPORT_START_ATTRIBUTE_TABLE_AND_FN(XText8Query, CConnectionQueryFactory::iUid, XConnectionQueryBase::EText8) |
|
122 REGISTER_ATTRIBUTE(XText8Query, iData, TMetaBuf8) |
|
123 END_ATTRIBUTE_TABLE_BASE(XConnectionQueryBase, 0) |
|
124 |
|
125 EXPORT_START_ATTRIBUTE_TABLE_AND_FN(XText16Query, CConnectionQueryFactory::iUid, XConnectionQueryBase::EText16) |
|
126 REGISTER_ATTRIBUTE(XText16Query, iData, TMetaBuf16) |
|
127 END_ATTRIBUTE_TABLE_BASE(XConnectionQueryBase, 0) |
|
128 |
|
129 |
|
130 |
|
131 EXPORT_C XConnectionQueryBase* XConnectionQueryBase::LoadL(TPtrC8& aDes) |
|
132 { |
|
133 // LoadL methods are expected to strip the type Id from the buffer |
|
134 STypeId typeId = STypeId::CreateSTypeId(aDes); // This STypeId c'tor overload will adjust aDes |
|
135 __ASSERT_DEBUG(typeId.iUid.iUid == CConnectionQueryFactory::iUid && typeId.iType != XConnectionQueryBase::ENull, User::Panic(KSpecAssert_ESockCommDatObjc, 1)); |
|
136 |
|
137 XConnectionQueryBase* query = NULL; |
|
138 switch (typeId.iType) |
|
139 { |
|
140 case XConnectionQueryBase::EBool: |
|
141 query = new (ELeave)XBoolQuery(); |
|
142 break; |
|
143 |
|
144 case XConnectionQueryBase::EInt: |
|
145 query = new (ELeave)XIntQuery(); |
|
146 break; |
|
147 |
|
148 case XConnectionQueryBase::EUint: |
|
149 query = new (ELeave)XUintQuery(); |
|
150 break; |
|
151 |
|
152 case XConnectionQueryBase::EText8: |
|
153 query = new (ELeave)XText8Query(); |
|
154 break; |
|
155 |
|
156 case XConnectionQueryBase::EText16: |
|
157 query = new (ELeave)XText16Query(); |
|
158 break; |
|
159 |
|
160 default: |
|
161 // Some unknown type in the descriptor |
|
162 User::Leave(KErrCorrupt); |
|
163 } |
|
164 |
|
165 CleanupStack::PushL(query); |
|
166 TInt err = query->Load(aDes); |
|
167 User::LeaveIfError(err); |
|
168 CleanupStack::Pop(query); |
|
169 return query; |
|
170 } |
|
171 |
|
172 |
|
173 |
|
174 EXPORT_C void XConnectionQueryBase::SetQueryAnswered() |
|
175 { |
|
176 SetFlags(EAnswered); |
|
177 ClearFlags(ENotAttempted); |
|
178 } |
|
179 |
|
180 |
|
181 EXPORT_C void XConnectionQueryBase::SetFlags(TUint32 aFlags) |
|
182 { |
|
183 const TUint answeredFlags = ENotAnswered | EAnswered; |
|
184 |
|
185 // Can't be answered and not answered |
|
186 __ASSERT_DEBUG((aFlags & answeredFlags) != answeredFlags, User::Panic(KSpecAssert_ESockCommDatObjc, 2)); |
|
187 |
|
188 if (aFlags & EAnswered) |
|
189 { |
|
190 iQueryFlags &= ~ENotAnswered; // Clear ENotAnswered |
|
191 iQueryFlags |= EAnswered; // Set EAnswered |
|
192 } |
|
193 else if (aFlags & ENotAnswered) |
|
194 { |
|
195 iQueryFlags &= ~ EAnswered; // Clear EAnswered |
|
196 iQueryFlags |= ENotAnswered; // Set ENotAnswered |
|
197 } |
|
198 |
|
199 // Set flags except for EAnswered or ENotAnswered |
|
200 iQueryFlags |= (aFlags & ~answeredFlags); |
|
201 } |
|
202 |
|
203 |
|
204 EXPORT_C void XConnectionQueryBase::ClearFlags(TUint32 aFlags) |
|
205 { |
|
206 const TUint answeredFlags = ENotAnswered | EAnswered; |
|
207 |
|
208 // Can't be answered and not answered |
|
209 __ASSERT_DEBUG((aFlags & answeredFlags) != answeredFlags, User::Panic(KSpecAssert_ESockCommDatObjc, 3)); |
|
210 |
|
211 if (aFlags & EAnswered) |
|
212 { |
|
213 iQueryFlags &= ~EAnswered; // Clear EAnswered |
|
214 iQueryFlags |= ENotAnswered; // Set ENotAnswered |
|
215 } |
|
216 else if (aFlags & ENotAnswered) |
|
217 { |
|
218 iQueryFlags &= ~ENotAnswered; // Clear ENotAnswered |
|
219 iQueryFlags |= EAnswered; // Set EAnswered |
|
220 } |
|
221 |
|
222 // Clear flags except for EAnswered or ENotAnswered |
|
223 iQueryFlags &= (~aFlags | answeredFlags); |
|
224 } |
|
225 |
|
226 |
|
227 EXPORT_C void XConnectionQueryBase::SetError(TInt aError) |
|
228 { |
|
229 iError = aError; |
|
230 if (aError == KErrNone) |
|
231 { |
|
232 ClearFlags(EFailed|ENotAttempted); |
|
233 } |
|
234 else |
|
235 { |
|
236 ClearFlags(ENotAttempted); |
|
237 SetFlags(EFailed); |
|
238 } |
|
239 } |
|
240 |
|
241 |
|
242 EXPORT_C XConnectionQuerySet::~XConnectionQuerySet() |
|
243 { |
|
244 iQueries.ResetAndDestroy(); |
|
245 iQueries.Close(); |
|
246 } |
|
247 |
|
248 |
|
249 |
|
250 EXPORT_C XBoolQuery::~XBoolQuery() |
|
251 { |
|
252 } |
|
253 |
|
254 EXPORT_C void XBoolQuery::GetSetting(MQueryConnSettingsApiExt* aItfPtr, MPlatsecApiExt* aPlatsecItf) |
|
255 { |
|
256 TInt err = aItfPtr->GetBool(ElementId(), iData, aPlatsecItf); |
|
257 if (err == KErrNone) |
|
258 { |
|
259 SetQueryAnswered(); |
|
260 } |
|
261 SetError(err); |
|
262 } |
|
263 |
|
264 |
|
265 EXPORT_C XUintQuery::~XUintQuery() |
|
266 { |
|
267 } |
|
268 |
|
269 EXPORT_C void XUintQuery::GetSetting(MQueryConnSettingsApiExt* aItfPtr, MPlatsecApiExt* aPlatsecItf) |
|
270 { |
|
271 TInt err = aItfPtr->GetInt(ElementId(), iData, aPlatsecItf); |
|
272 if (err == KErrNone) |
|
273 { |
|
274 SetQueryAnswered(); |
|
275 } |
|
276 SetError(err); |
|
277 } |
|
278 |
|
279 |
|
280 EXPORT_C XIntQuery::~XIntQuery() |
|
281 { |
|
282 } |
|
283 |
|
284 EXPORT_C void XIntQuery::GetSetting(MQueryConnSettingsApiExt* aItfPtr, MPlatsecApiExt* aPlatsecItf) |
|
285 { |
|
286 TInt err = aItfPtr->GetInt(ElementId(), iData, aPlatsecItf); |
|
287 if (err == KErrNone) |
|
288 { |
|
289 SetQueryAnswered(); |
|
290 } |
|
291 SetError(err); |
|
292 } |
|
293 |
|
294 |
|
295 EXPORT_C XText8Query::~XText8Query() |
|
296 { |
|
297 iData.Close(); |
|
298 } |
|
299 |
|
300 EXPORT_C void XText8Query::GetSetting(MQueryConnSettingsApiExt* aItfPtr, MPlatsecApiExt* aPlatsecItf) |
|
301 { |
|
302 HBufC8* data = NULL; |
|
303 TInt err = aItfPtr->GetText(ElementId(), data, aPlatsecItf); |
|
304 if (err == KErrNone) |
|
305 { |
|
306 iData.Close(); |
|
307 iData.Create(data->Des()); |
|
308 |
|
309 SetQueryAnswered(); |
|
310 } |
|
311 delete data; |
|
312 SetError(err); |
|
313 } |
|
314 |
|
315 |
|
316 EXPORT_C XText16Query::~XText16Query() |
|
317 { |
|
318 iData.Close(); |
|
319 } |
|
320 |
|
321 EXPORT_C void XText16Query::GetSetting(MQueryConnSettingsApiExt* aItfPtr, MPlatsecApiExt* aPlatsecItf) |
|
322 { |
|
323 HBufC16* data = NULL; |
|
324 TInt err = aItfPtr->GetText(ElementId(), data, aPlatsecItf); |
|
325 if (err == KErrNone) |
|
326 { |
|
327 iData.Close(); |
|
328 iData.Create(data->Des()); |
|
329 |
|
330 SetQueryAnswered(); |
|
331 } |
|
332 delete data; |
|
333 SetError(err); |
|
334 } |
|
335 |