|
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: Presence context event filter. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "ximpcontexteventfilter.h" |
|
19 |
|
20 const TInt KXIMPEventListGranurality = 3; |
|
21 |
|
22 |
|
23 // ============================ MEMBER FUNCTIONS ============================= |
|
24 |
|
25 // --------------------------------------------------------------------------- |
|
26 // CXIMPContextEventFilter::NewLC() |
|
27 // --------------------------------------------------------------------------- |
|
28 // |
|
29 EXPORT_C CXIMPContextEventFilter* CXIMPContextEventFilter::NewLC( |
|
30 const TArray< TInt32 >* aAcceptedEvents ) |
|
31 { |
|
32 CXIMPContextEventFilter* self = |
|
33 new( ELeave ) CXIMPContextEventFilter; |
|
34 CleanupStack::PushL( self ); |
|
35 self->SetFilterL( aAcceptedEvents ); |
|
36 return self; |
|
37 } |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // CXIMPContextEventFilter::NewL() |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 EXPORT_C CXIMPContextEventFilter* CXIMPContextEventFilter::NewL( |
|
44 const TArray< TInt32 >* aAcceptedEvents ) |
|
45 { |
|
46 CXIMPContextEventFilter* self = NewLC( aAcceptedEvents ); |
|
47 CleanupStack::Pop( self ); |
|
48 return self; |
|
49 } |
|
50 |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // CXIMPContextEventFilter::NewCombinedLC() |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 EXPORT_C CXIMPContextEventFilter* |
|
57 CXIMPContextEventFilter::NewCombinedLC( |
|
58 const TArray< CXIMPContextEventFilter* >& aFilters ) |
|
59 { |
|
60 CXIMPContextEventFilter* self = |
|
61 new( ELeave ) CXIMPContextEventFilter; |
|
62 CleanupStack::PushL( self ); |
|
63 self->CombineFilterL( aFilters ); |
|
64 return self; |
|
65 } |
|
66 |
|
67 |
|
68 // --------------------------------------------------------------------------- |
|
69 // CXIMPContextEventFilter::~CXIMPContextEventFilter() |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 CXIMPContextEventFilter::~CXIMPContextEventFilter() |
|
73 { |
|
74 delete iAcceptedEvents; |
|
75 } |
|
76 |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // CXIMPContextEventFilter::CXIMPContextEventFilter() |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 CXIMPContextEventFilter::CXIMPContextEventFilter() |
|
83 { |
|
84 } |
|
85 |
|
86 |
|
87 // --------------------------------------------------------------------------- |
|
88 // CXIMPContextEventFilter::IsEventAccepted() |
|
89 // --------------------------------------------------------------------------- |
|
90 // |
|
91 EXPORT_C TBool CXIMPContextEventFilter::IsEventAccepted( |
|
92 TInt32 aEvent ) const |
|
93 { |
|
94 TBool accepted = ETrue; |
|
95 |
|
96 |
|
97 //If there isn't iAcceptedEvents list limiting accepted event types, |
|
98 //all types are accepted by default |
|
99 if( iAcceptedEvents ) |
|
100 { |
|
101 TInt pos; |
|
102 if( !FindEventPosition( aEvent, *iAcceptedEvents, pos ) ) |
|
103 { |
|
104 accepted = EFalse; |
|
105 } |
|
106 } |
|
107 |
|
108 return accepted; |
|
109 } |
|
110 |
|
111 |
|
112 // --------------------------------------------------------------------------- |
|
113 // CXIMPContextEventFilter::ExternalizeL() |
|
114 // --------------------------------------------------------------------------- |
|
115 // |
|
116 EXPORT_C void CXIMPContextEventFilter::ExternalizeL( |
|
117 RWriteStream& aStream ) const |
|
118 { |
|
119 if( !iAcceptedEvents ) |
|
120 { |
|
121 aStream.WriteInt32L( 0 ); |
|
122 } |
|
123 else |
|
124 { |
|
125 TInt count = iAcceptedEvents->Count(); |
|
126 aStream.WriteInt32L( count ); |
|
127 for( TInt ix = 0; ix < count; ++ix ) |
|
128 { |
|
129 aStream.WriteInt32L( ( *iAcceptedEvents )[ ix ] ); |
|
130 } |
|
131 } |
|
132 } |
|
133 |
|
134 |
|
135 // --------------------------------------------------------------------------- |
|
136 // CXIMPContextEventFilter::InternalizeL() |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 EXPORT_C void CXIMPContextEventFilter::InternalizeL( |
|
140 RReadStream& aStream ) |
|
141 { |
|
142 TInt count = aStream.ReadInt32L(); |
|
143 if( count ) |
|
144 { |
|
145 //We are internalizing data which we have previously externalized |
|
146 // => Internalized array can be directly set as current array |
|
147 |
|
148 CArrayFix< TInt32 >* events = |
|
149 new (ELeave) CArrayFixFlat< TInt32 >( KXIMPEventListGranurality ); |
|
150 CleanupStack::PushL( events ); |
|
151 |
|
152 for( TInt ix = 0; ix < count; ++ix ) |
|
153 { |
|
154 events->AppendL( aStream.ReadInt32L() ); |
|
155 } |
|
156 delete iAcceptedEvents; |
|
157 iAcceptedEvents = events; |
|
158 |
|
159 CleanupStack::Pop( events ); |
|
160 } |
|
161 |
|
162 else |
|
163 { |
|
164 delete iAcceptedEvents; |
|
165 iAcceptedEvents = NULL; |
|
166 } |
|
167 } |
|
168 |
|
169 |
|
170 // --------------------------------------------------------------------------- |
|
171 // CXIMPContextEventFilter::SetFilterL() |
|
172 // --------------------------------------------------------------------------- |
|
173 // |
|
174 void CXIMPContextEventFilter::SetFilterL( |
|
175 const TArray< TInt32 >* aAcceptedEvents ) |
|
176 { |
|
177 if( aAcceptedEvents ) |
|
178 { |
|
179 CArrayFix< TInt32 >* events = |
|
180 new (ELeave) CArrayFixFlat< TInt32 >( KXIMPEventListGranurality ); |
|
181 CleanupStack::PushL( events ); |
|
182 |
|
183 CopyUniqueEventsL( *aAcceptedEvents, *events ); |
|
184 |
|
185 delete iAcceptedEvents; |
|
186 iAcceptedEvents = events; |
|
187 CleanupStack::Pop( events ); |
|
188 } |
|
189 |
|
190 else |
|
191 { |
|
192 //Set all accepted |
|
193 delete iAcceptedEvents; |
|
194 iAcceptedEvents = NULL; |
|
195 } |
|
196 } |
|
197 |
|
198 |
|
199 // --------------------------------------------------------------------------- |
|
200 // CXIMPContextEventFilter::CombineFilterL() |
|
201 // --------------------------------------------------------------------------- |
|
202 // |
|
203 void CXIMPContextEventFilter::CombineFilterL( |
|
204 const TArray< CXIMPContextEventFilter* >& aFilters ) |
|
205 { |
|
206 const TInt filterCount = aFilters.Count(); |
|
207 |
|
208 CArrayFix< TInt32 >* combinedEvents = new (ELeave) CArrayFixFlat< TInt32 >( KXIMPEventListGranurality ); |
|
209 CleanupStack::PushL( combinedEvents ); |
|
210 |
|
211 for( TInt ix = 0; ix < filterCount; ix++ ) |
|
212 { |
|
213 const CXIMPContextEventFilter* sourceFilter = aFilters[ ix ]; |
|
214 if( sourceFilter->iAcceptedEvents ) |
|
215 { |
|
216 CopyUniqueEventsL( sourceFilter->iAcceptedEvents->Array(), |
|
217 *combinedEvents ); |
|
218 } |
|
219 |
|
220 else |
|
221 { |
|
222 //Set all accepted |
|
223 delete combinedEvents; |
|
224 combinedEvents = NULL; |
|
225 break; |
|
226 } |
|
227 } |
|
228 |
|
229 |
|
230 delete iAcceptedEvents; |
|
231 iAcceptedEvents = combinedEvents; |
|
232 |
|
233 CleanupStack::Pop(); //combinedEvents |
|
234 } |
|
235 |
|
236 |
|
237 // --------------------------------------------------------------------------- |
|
238 // CXIMPContextEventFilter::CopyUniqueEventsL() |
|
239 // --------------------------------------------------------------------------- |
|
240 // |
|
241 void CXIMPContextEventFilter::CopyUniqueEventsL( |
|
242 const TArray< TInt32 >& aSource, |
|
243 CArrayFix< TInt32 >& aTarget ) |
|
244 { |
|
245 |
|
246 const TInt eventCount = aSource.Count(); |
|
247 |
|
248 for( TInt ix = 0; ix < eventCount; ix++ ) |
|
249 { |
|
250 const TInt32 event = aSource[ ix ]; |
|
251 TInt pos; |
|
252 if( !FindEventPosition( event, aTarget, pos ) ) |
|
253 { |
|
254 aTarget.InsertL( pos, event ); |
|
255 } |
|
256 } |
|
257 } |
|
258 |
|
259 |
|
260 // --------------------------------------------------------------------------- |
|
261 // CXIMPContextEventFilter::FindEventPosition() |
|
262 // --------------------------------------------------------------------------- |
|
263 // |
|
264 TBool CXIMPContextEventFilter::FindEventPosition( |
|
265 const TInt32 aEvent, const CArrayFix< TInt32 >& aEvents, TInt& aPos ) const |
|
266 { |
|
267 TKeyArrayFix key( 0, ECmpTInt32 ); |
|
268 if( aEvents.FindIsq( aEvent, key, aPos ) == 0 ) |
|
269 { |
|
270 //FindIsq() returns zero, if element is found => this is mapped to ETrue |
|
271 return ETrue; |
|
272 } |
|
273 |
|
274 return EFalse; |
|
275 } |
|
276 |