|
1 /* |
|
2 * Copyright (c) 2002-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: CCFContextQueryImpl class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <s32strm.h> |
|
20 |
|
21 #include "CFContextQueryImpl.h" |
|
22 #include "cfserviceutils.h" |
|
23 #include "cftrace.h" |
|
24 |
|
25 // MEMBER FUNCTIONS |
|
26 |
|
27 EXPORT_C CCFContextQueryImpl* CCFContextQueryImpl::NewL( const TDesC& aSource, |
|
28 const TDesC& aType ) |
|
29 { |
|
30 FUNC_LOG; |
|
31 |
|
32 CCFContextQueryImpl* self = CCFContextQueryImpl::NewLC( aSource, aType ); |
|
33 CleanupStack::Pop( self ); |
|
34 |
|
35 return self; |
|
36 } |
|
37 |
|
38 EXPORT_C CCFContextQueryImpl* CCFContextQueryImpl::NewLC( const TDesC& aSource, |
|
39 const TDesC& aType ) |
|
40 { |
|
41 FUNC_LOG; |
|
42 |
|
43 CCFContextQueryImpl* self = new( ELeave ) CCFContextQueryImpl; |
|
44 CleanupStack::PushL( self ); |
|
45 self->ConstructL( aSource, aType ); |
|
46 |
|
47 return self; |
|
48 } |
|
49 |
|
50 CCFContextQueryImpl::~CCFContextQueryImpl() |
|
51 { |
|
52 FUNC_LOG; |
|
53 |
|
54 delete iSource; |
|
55 delete iType; |
|
56 } |
|
57 |
|
58 CCFContextQueryImpl::CCFContextQueryImpl() |
|
59 { |
|
60 FUNC_LOG; |
|
61 |
|
62 // Nothing to do |
|
63 } |
|
64 |
|
65 void CCFContextQueryImpl::ConstructL( const TDesC& aSource, |
|
66 const TDesC& aType ) |
|
67 { |
|
68 FUNC_LOG; |
|
69 |
|
70 // Initialize members |
|
71 iSource = aSource.AllocL(); |
|
72 iType = aType.AllocL(); |
|
73 } |
|
74 |
|
75 // METHODS |
|
76 |
|
77 //----------------------------------------------------------------------------- |
|
78 // CCFContextQueryImpl::SetTypeL |
|
79 //----------------------------------------------------------------------------- |
|
80 // |
|
81 void CCFContextQueryImpl::SetTypeL( const TDesC& aType ) |
|
82 { |
|
83 FUNC_LOG; |
|
84 |
|
85 CFServiceUtils::UpdateBufferL( iType, aType ); |
|
86 } |
|
87 |
|
88 //----------------------------------------------------------------------------- |
|
89 // CCFContextQueryImpl::Type |
|
90 //----------------------------------------------------------------------------- |
|
91 // |
|
92 const TDesC& CCFContextQueryImpl::Type() const |
|
93 { |
|
94 FUNC_LOG; |
|
95 |
|
96 if( iType ) |
|
97 { |
|
98 return *iType; |
|
99 } |
|
100 else |
|
101 { |
|
102 return KNullDesC; |
|
103 } |
|
104 } |
|
105 |
|
106 //----------------------------------------------------------------------------- |
|
107 // CCFContextQueryImpl::SetSourceL |
|
108 //----------------------------------------------------------------------------- |
|
109 // |
|
110 void CCFContextQueryImpl::SetSourceL( const TDesC& aSource ) |
|
111 { |
|
112 FUNC_LOG; |
|
113 |
|
114 CFServiceUtils::UpdateBufferL( iSource, aSource ); |
|
115 } |
|
116 |
|
117 //----------------------------------------------------------------------------- |
|
118 // CCFContextQueryImpl::Source |
|
119 //----------------------------------------------------------------------------- |
|
120 // |
|
121 const TDesC& CCFContextQueryImpl::Source() const |
|
122 { |
|
123 FUNC_LOG; |
|
124 |
|
125 if( iSource ) |
|
126 { |
|
127 return *iSource; |
|
128 } |
|
129 else |
|
130 { |
|
131 return KNullDesC; |
|
132 } |
|
133 } |
|
134 |
|
135 //----------------------------------------------------------------------------- |
|
136 // CCFContextQueryImpl::SubTypeMatch |
|
137 //----------------------------------------------------------------------------- |
|
138 // |
|
139 TBool CCFContextQueryImpl::SubTypeMatch() const |
|
140 { |
|
141 FUNC_LOG; |
|
142 |
|
143 return iMatchSubTypes; |
|
144 } |
|
145 |
|
146 //----------------------------------------------------------------------------- |
|
147 // CCFContextQueryImpl::SetTypeMatch |
|
148 //----------------------------------------------------------------------------- |
|
149 // |
|
150 void CCFContextQueryImpl::SetSubTypeMatch( TBool aMatchSubTypes ) |
|
151 { |
|
152 FUNC_LOG; |
|
153 |
|
154 iMatchSubTypes = aMatchSubTypes; |
|
155 } |
|
156 |
|
157 //----------------------------------------------------------------------------- |
|
158 // CCFContextQueryImpl::Matches |
|
159 //----------------------------------------------------------------------------- |
|
160 // |
|
161 EXPORT_C TBool CCFContextQueryImpl::MatchesQuery( |
|
162 const CCFContextQuery& aQuery, |
|
163 const TDesC& aContextType, |
|
164 const TDesC& aContextSource, |
|
165 TBool aMatchSubTypes ) |
|
166 { |
|
167 FUNC_LOG; |
|
168 |
|
169 // Source must be always completely the same |
|
170 if( aQuery.Source().Compare( aContextSource ) == KErrNone ) |
|
171 { |
|
172 if ( aMatchSubTypes ) |
|
173 { |
|
174 // beginning of the type must be same |
|
175 if( aQuery.Type().Compare( |
|
176 aContextType.Left( aQuery.Type().Length() ) ) == KErrNone ) |
|
177 { |
|
178 return ETrue; |
|
179 } |
|
180 } |
|
181 else |
|
182 { |
|
183 // type must be completely same |
|
184 if( aQuery.Type().Compare( aContextType ) == KErrNone ) |
|
185 { |
|
186 return ETrue; |
|
187 } |
|
188 } |
|
189 } |
|
190 return EFalse; |
|
191 } |
|
192 |
|
193 //----------------------------------------------------------------------------- |
|
194 // CCFContextQueryImpl::Matches |
|
195 //----------------------------------------------------------------------------- |
|
196 // |
|
197 EXPORT_C TBool CCFContextQueryImpl::Matches( const TDesC& aContextType, |
|
198 const TDesC& aContextSource ) const |
|
199 { |
|
200 FUNC_LOG; |
|
201 |
|
202 return MatchesQuery( *this, aContextType, aContextSource, iMatchSubTypes ); |
|
203 } |
|
204 |
|
205 |
|
206 //----------------------------------------------------------------------------- |
|
207 // CCFContextQueryImpl::IsSame |
|
208 //----------------------------------------------------------------------------- |
|
209 // |
|
210 EXPORT_C TBool CCFContextQueryImpl::IsSame( |
|
211 const CCFContextQuery& aQuery1, |
|
212 const CCFContextQuery& aQuery2) |
|
213 { |
|
214 FUNC_LOG; |
|
215 |
|
216 if( aQuery1.Type().Compare( aQuery2.Type() ) == KErrNone && |
|
217 aQuery1.Source().Compare( aQuery2.Source() ) == KErrNone ) |
|
218 { |
|
219 return ETrue; |
|
220 } |
|
221 else |
|
222 { |
|
223 return EFalse; |
|
224 } |
|
225 } |
|
226 |
|
227 //----------------------------------------------------------------------------- |
|
228 // CCFContextQueryImpl::InternalizeL |
|
229 //----------------------------------------------------------------------------- |
|
230 // |
|
231 EXPORT_C void CCFContextQueryImpl::InternalizeL( RReadStream& aStream ) |
|
232 { |
|
233 FUNC_LOG; |
|
234 |
|
235 // Source |
|
236 CFServiceUtils::ReadFromStreamL( iSource, aStream ); |
|
237 |
|
238 // Type |
|
239 CFServiceUtils::ReadFromStreamL( iType, aStream ); |
|
240 |
|
241 // Sub type match flag |
|
242 iMatchSubTypes = aStream.ReadInt16L(); |
|
243 } |
|
244 |
|
245 //----------------------------------------------------------------------------- |
|
246 // CCFContextQueryImpl::ExternalizeL |
|
247 //----------------------------------------------------------------------------- |
|
248 // |
|
249 EXPORT_C void CCFContextQueryImpl::ExternalizeL( RWriteStream& aStream ) |
|
250 { |
|
251 FUNC_LOG; |
|
252 |
|
253 // Source |
|
254 CFServiceUtils::WriteIntoStreamL( iSource, aStream ); |
|
255 |
|
256 // Type |
|
257 CFServiceUtils::WriteIntoStreamL( iType, aStream ); |
|
258 |
|
259 // Sub type match flag |
|
260 aStream.WriteInt16L( iMatchSubTypes ); |
|
261 |
|
262 // Commit stream |
|
263 aStream.CommitL(); |
|
264 } |
|
265 |
|
266 //----------------------------------------------------------------------------- |
|
267 // CCFContextQueryImpl::Size |
|
268 //----------------------------------------------------------------------------- |
|
269 // |
|
270 EXPORT_C TInt CCFContextQueryImpl::Size() const |
|
271 { |
|
272 FUNC_LOG; |
|
273 |
|
274 TInt size = 0; |
|
275 |
|
276 // Source |
|
277 size += sizeof( TInt ); |
|
278 if( iSource ) |
|
279 { |
|
280 size += ( *iSource ).Size(); |
|
281 } |
|
282 |
|
283 // Type |
|
284 size += sizeof( TInt ); |
|
285 if( iType ) |
|
286 { |
|
287 size += ( *iType ).Size(); |
|
288 } |
|
289 |
|
290 // Sub type match flag |
|
291 size += sizeof( iMatchSubTypes ); |
|
292 |
|
293 return size; |
|
294 } |