|
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: Base class for API implementations. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "presenceeventcodec.h" |
|
19 //#include "ximprequestcompleteeventimp.h" |
|
20 //#include "ximpcontextstateeventimp.h" |
|
21 #include "presentitygrouplisteventimp.h" |
|
22 #include "ownpresenceeventimp.h" |
|
23 #include "presentitypresenceeventimp.h" |
|
24 #include "presentitygroupcontenteventimp.h" |
|
25 #include "presencewatcherlisteventimp.h" |
|
26 #include "presencegrantrequestlisteventimp.h" |
|
27 #include "presenceblocklisteventimp.h" |
|
28 |
|
29 #include "ximpapieventbase.h" |
|
30 #include <s32strm.h> |
|
31 #include <s32mem.h> |
|
32 |
|
33 //DATA TYPES |
|
34 |
|
35 |
|
36 /** |
|
37 * Type definition for exact API event constructor signature. |
|
38 */ |
|
39 typedef CXIMPApiEventBase* (*TApiEventConstructor)( RReadStream& ); |
|
40 |
|
41 |
|
42 |
|
43 /** |
|
44 * Structure for mapping event interface IDs to |
|
45 * to corect API event constructors. |
|
46 */ |
|
47 struct SApiEventConstructorMap |
|
48 { |
|
49 //Interface id |
|
50 TInt32 iInterfaceId; |
|
51 |
|
52 //Function pointer to event interface implementation |
|
53 TApiEventConstructor iConstructorPtr; |
|
54 } ; |
|
55 |
|
56 |
|
57 |
|
58 /** |
|
59 * Helper macro to initialise KApiEventConstructorTable members. |
|
60 * |
|
61 * Macro forces that each event implementation class to have static |
|
62 * NewFromStreamLC() memeber function to instantiate the object. |
|
63 * |
|
64 * See TApiEventConstructor type definition for exact constructor |
|
65 * signature. |
|
66 */ |
|
67 #define CONSTRUCTOR_ENTRY( TheImplementedIf, TheClass ) \ |
|
68 { TheImplementedIf::KInterfaceId, TheClass::NewFromStreamLC } \ |
|
69 |
|
70 |
|
71 |
|
72 /** |
|
73 * Constructor function mapping for event interface implementations. |
|
74 * |
|
75 * When new event types are implemented, add them here. |
|
76 */ |
|
77 const SApiEventConstructorMap KApiEventConstructorTable[] = |
|
78 { |
|
79 // CONSTRUCTOR_ENTRY( MXIMPRequestCompleteEvent, CXIMPRequestCompleteEventImp ), |
|
80 // CONSTRUCTOR_ENTRY( MXIMPContextStateEvent, CXIMPContextStateEventImp ), |
|
81 CONSTRUCTOR_ENTRY( MPresentityGroupListEvent, CPresentityGroupListEventImp ), |
|
82 CONSTRUCTOR_ENTRY( MOwnPresenceEvent, COwnPresenceEventImp ), |
|
83 CONSTRUCTOR_ENTRY( MPresentityPresenceEvent, CPresentityPresenceEventImp ), |
|
84 CONSTRUCTOR_ENTRY( MPresentityGroupContentEvent, CPresentityGroupContentEventImp ), |
|
85 CONSTRUCTOR_ENTRY( MPresenceWatcherListEvent, CPresenceWatcherListEventImp ), |
|
86 CONSTRUCTOR_ENTRY( MPresenceGrantRequestListEvent, CPresenceGrantRequestListEventImp ), |
|
87 CONSTRUCTOR_ENTRY( MPresenceBlockListEvent, CPresenceBlockListEventImp ) |
|
88 }; |
|
89 |
|
90 |
|
91 /** |
|
92 * Count of constructor mappings. |
|
93 */ |
|
94 const TInt KApiEventConstructorCount = sizeof( KApiEventConstructorTable ) |
|
95 / sizeof( SApiEventConstructorMap ); |
|
96 |
|
97 |
|
98 |
|
99 // ============================ HELPER FUNCTIONS ============================= |
|
100 |
|
101 |
|
102 /** |
|
103 * Helper function to locate constructor function for |
|
104 * event interface ID. |
|
105 * |
|
106 * @param aEventInterfaceId The event interface ID. |
|
107 * @return Event object constructor function. |
|
108 */ |
|
109 TApiEventConstructor ConstructorForInterface( TInt32 aEventInterfaceId ) |
|
110 { |
|
111 //Locate correct constructor |
|
112 for( TInt ix = 0; ix < KApiEventConstructorCount; ix++ ) |
|
113 { |
|
114 const SApiEventConstructorMap map = KApiEventConstructorTable[ ix ]; |
|
115 if( map.iInterfaceId == aEventInterfaceId ) |
|
116 { |
|
117 return map.iConstructorPtr; |
|
118 } |
|
119 } |
|
120 |
|
121 |
|
122 //If assertion below fails, check that event implementation |
|
123 //class implementing requested event interface (aEventInterfaceId) |
|
124 //is registered to KApiEventConstructorTable |
|
125 // __ASSERT_DEBUG( EFalse, |
|
126 // User::Panic( _L("PresenceEventCodec"), KErrUnknown ) ); |
|
127 |
|
128 return NULL; |
|
129 } |
|
130 |
|
131 |
|
132 /** |
|
133 * Helper function to instantiate new event object |
|
134 * of requested type and construct it from the stream. |
|
135 * |
|
136 * @param aEventInterfaceId |
|
137 * @return Event object constructor function. |
|
138 */ |
|
139 CXIMPApiEventBase* NewEventObjectFromStreamLC( TInt32 aEventInterfaceId, |
|
140 RReadStream& aStream ) |
|
141 { |
|
142 TApiEventConstructor newFromStreamLC = NULL; |
|
143 |
|
144 //Locate correct constructor for interface ID |
|
145 newFromStreamLC = ConstructorForInterface( aEventInterfaceId ); |
|
146 if( ! newFromStreamLC ) |
|
147 { |
|
148 return NULL; |
|
149 } |
|
150 //Instantiate the object |
|
151 CXIMPApiEventBase* eventObject = newFromStreamLC( aStream ); |
|
152 |
|
153 |
|
154 return eventObject; |
|
155 } |
|
156 |
|
157 |
|
158 |
|
159 // ============================ MEMBER FUNCTIONS ============================= |
|
160 |
|
161 |
|
162 // --------------------------------------------------------------------------- |
|
163 // CPresenceEventCodec::NewL() |
|
164 // --------------------------------------------------------------------------- |
|
165 // |
|
166 CPresenceEventCodec* CPresenceEventCodec::NewL() |
|
167 { |
|
168 CPresenceEventCodec* self = new( ELeave ) CPresenceEventCodec() ; |
|
169 CleanupStack::PushL( self ); |
|
170 self->ConstructL(); |
|
171 CleanupStack::Pop(); |
|
172 return self; |
|
173 } |
|
174 |
|
175 |
|
176 // --------------------------------------------------------------------------- |
|
177 // CPresenceEventCodec::ConstructL() |
|
178 // --------------------------------------------------------------------------- |
|
179 // |
|
180 void CPresenceEventCodec::ConstructL() |
|
181 { |
|
182 } |
|
183 |
|
184 |
|
185 // --------------------------------------------------------------------------- |
|
186 // CPresenceEventCodec::CPresenceEventCodec() |
|
187 // --------------------------------------------------------------------------- |
|
188 // |
|
189 CPresenceEventCodec::CPresenceEventCodec() |
|
190 { |
|
191 } |
|
192 |
|
193 // --------------------------------------------------------------------------- |
|
194 // CPresenceEventCodec::~CPresenceEventCodec() |
|
195 // --------------------------------------------------------------------------- |
|
196 // |
|
197 CPresenceEventCodec::~CPresenceEventCodec() |
|
198 { |
|
199 } |
|
200 |
|
201 // --------------------------------------------------------------------------- |
|
202 // CPresenceEventCodec::PackL() |
|
203 // --------------------------------------------------------------------------- |
|
204 // |
|
205 HBufC8* CPresenceEventCodec::PackL( CXIMPApiEventBase& aEventObj, |
|
206 TInt32& aTypeOfEvent ) |
|
207 { |
|
208 CBufFlat* buffer = CBufFlat::NewL( 10 ); // initial granularity to 10 |
|
209 CleanupStack::PushL( buffer ); |
|
210 |
|
211 RBufWriteStream ws; |
|
212 CleanupClosePushL( ws ); |
|
213 ws.Open( *buffer ); // CSI: 65 # |
|
214 |
|
215 //Ask real event type through the event base interface |
|
216 TInt32 eventIfId = aEventObj.Base().GetInterfaceId(); |
|
217 |
|
218 //And write both event type and data |
|
219 ws.WriteInt32L( eventIfId ); |
|
220 aEventObj.ExternalizeL( ws ); |
|
221 ws.CommitL(); |
|
222 CleanupStack::PopAndDestroy(); //ws |
|
223 |
|
224 HBufC8* heapBuf = buffer->Ptr( 0 ).AllocL(); |
|
225 |
|
226 CleanupStack::PopAndDestroy( buffer ); |
|
227 |
|
228 |
|
229 aTypeOfEvent = eventIfId; |
|
230 return heapBuf; |
|
231 } |
|
232 |
|
233 |
|
234 // --------------------------------------------------------------------------- |
|
235 // CPresenceEventCodec::PackL() |
|
236 // --------------------------------------------------------------------------- |
|
237 // |
|
238 void CPresenceEventCodec::PackL( CXIMPApiEventBase& aEventObj, |
|
239 TInt32& aTypeOfEvent, |
|
240 CBufFlat* aBuffer ) |
|
241 { |
|
242 RBufWriteStream ws; |
|
243 CleanupClosePushL( ws ); |
|
244 ws.Open( *aBuffer ); // CSI: 65 # |
|
245 |
|
246 //Ask real event type through the event base interface |
|
247 TInt32 eventIfId = aEventObj.Base().GetInterfaceId(); |
|
248 |
|
249 //And write both event type and data |
|
250 ws.WriteInt32L( eventIfId ); |
|
251 aEventObj.ExternalizeL( ws ); |
|
252 ws.CommitL(); |
|
253 CleanupStack::PopAndDestroy(); //ws |
|
254 |
|
255 aTypeOfEvent = eventIfId; |
|
256 } |
|
257 |
|
258 |
|
259 // --------------------------------------------------------------------------- |
|
260 // CPresenceEventCodec::UnPackL() |
|
261 // --------------------------------------------------------------------------- |
|
262 // |
|
263 CXIMPApiEventBase* CPresenceEventCodec::UnPackL( const TDesC8& aEventData, |
|
264 TInt32& aTypeOfEvent ) |
|
265 { |
|
266 RDesReadStream rs; |
|
267 rs.Open( aEventData ); // CSI: 65 # |
|
268 CleanupClosePushL( rs ); |
|
269 |
|
270 TInt32 eventIfId = rs.ReadInt32L(); |
|
271 CXIMPApiEventBase* eventObject = NewEventObjectFromStreamLC( eventIfId, rs ); |
|
272 if(eventObject) |
|
273 { |
|
274 CleanupStack::Pop(); //eventObject |
|
275 } |
|
276 CleanupStack::PopAndDestroy(); // rs |
|
277 |
|
278 |
|
279 aTypeOfEvent = eventIfId; |
|
280 return eventObject; |
|
281 } |
|
282 |
|
283 |
|
284 // End of file |
|
285 |