|
1 /* |
|
2 * Copyright (c) 2007 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: Inline methods for codec to pack and unpack data objects. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32base.h> |
|
20 |
|
21 #include "imtypehelpers.h" |
|
22 #include "imobjectfactory.h" |
|
23 #include "ximpapidataobjbase.h" |
|
24 #include "imconversationinfoimp.h" |
|
25 |
|
26 |
|
27 //DATA TYPES |
|
28 |
|
29 |
|
30 // ============================ MEMBER FUNCTIONS ============================= |
|
31 |
|
32 /** |
|
33 * Type definition for exact API data object constructor signature. |
|
34 */ |
|
35 typedef CXIMPApiDataObjBase* (*TApiDataObjConstructor)( RReadStream& ); |
|
36 |
|
37 |
|
38 |
|
39 /** |
|
40 * Structure for mapping data object interface IDs to |
|
41 * to corect API data object constructors. |
|
42 */ |
|
43 struct SApiDataObjConstructorMap |
|
44 { |
|
45 //Interface id |
|
46 TInt32 iInterfaceId; |
|
47 |
|
48 //Function pointer to data object interface implementation |
|
49 TApiDataObjConstructor iConstructorPtr; |
|
50 } ; |
|
51 |
|
52 |
|
53 |
|
54 /** |
|
55 * Helper macro to initialise KApiDataObjConstructorTable members. |
|
56 * |
|
57 * Macro forces that each data object implementation class to have static |
|
58 * NewFromStreamLC() member function to instantiate the object. |
|
59 * |
|
60 * See TApiDataObjConstructor type definition for exact constructor |
|
61 * signature. |
|
62 */ |
|
63 #define CONSTRUCTOR_ENTRY( TheImplementedIf, TheClass ) \ |
|
64 { TheImplementedIf::KInterfaceId, TheClass::NewFromStreamLC } \ |
|
65 |
|
66 /** |
|
67 * Constructor function mapping for data object interface implementations. |
|
68 * |
|
69 * When new data object types are implemented, add them here. |
|
70 */ |
|
71 |
|
72 const SApiDataObjConstructorMap KApiDataObjConstructorTable[] = |
|
73 { |
|
74 CONSTRUCTOR_ENTRY( MImConversationInfo, CImConversationInfoImp ), |
|
75 }; |
|
76 |
|
77 |
|
78 /** |
|
79 * Count of constructor mappings. |
|
80 */ |
|
81 const TInt KApiDataObjConstructorCount = sizeof( KApiDataObjConstructorTable ) |
|
82 / sizeof( SApiDataObjConstructorMap ); |
|
83 |
|
84 |
|
85 |
|
86 // ============================ HELPER FUNCTIONS ============================= |
|
87 |
|
88 |
|
89 namespace { |
|
90 |
|
91 /** |
|
92 * Helper function to locate constructor function for |
|
93 * data object interface ID. |
|
94 * |
|
95 * @param aDataObjInterfaceId The data object interface ID. |
|
96 * @return Data object constructor function. |
|
97 */ |
|
98 TApiDataObjConstructor ConstructorForInterface( TInt32 aDataObjInterfaceId ) |
|
99 { |
|
100 //Locate correct constructor |
|
101 for( TInt ix = 0; ix < KApiDataObjConstructorCount; ix++ ) |
|
102 { |
|
103 const SApiDataObjConstructorMap map = KApiDataObjConstructorTable[ ix ]; |
|
104 if( map.iInterfaceId == aDataObjInterfaceId ) |
|
105 { |
|
106 return map.iConstructorPtr; |
|
107 } |
|
108 } |
|
109 |
|
110 |
|
111 //If assertion below fails, check that data object implementation |
|
112 //class implementing requested data object interface (aDataObjInterfaceId) |
|
113 //is registered to KApiDataObjConstructorTable |
|
114 __ASSERT_DEBUG( EFalse, |
|
115 User::Panic( _L("ImObjectFactory"), KErrUnknown ) ); |
|
116 |
|
117 return NULL; |
|
118 } |
|
119 |
|
120 /** |
|
121 * Helper function to instantiate new data object object |
|
122 * of requested type and construct it from the stream. |
|
123 * |
|
124 * @param aDataObjInterfaceId |
|
125 * @return Data object constructor function. |
|
126 */ |
|
127 CXIMPApiDataObjBase* NewDataObjectFromStreamLC( TInt32 aDataObjInterfaceId, |
|
128 RReadStream& aStream ) |
|
129 { |
|
130 TApiDataObjConstructor newFromStreamLC = NULL; |
|
131 |
|
132 //Locate correct constructor for interface ID |
|
133 newFromStreamLC = ConstructorForInterface( aDataObjInterfaceId ); |
|
134 |
|
135 //Instantiate the object |
|
136 CXIMPApiDataObjBase* dataObject = newFromStreamLC( aStream ); |
|
137 |
|
138 return dataObject; |
|
139 } |
|
140 |
|
141 } // namespace |
|
142 |
|
143 // --------------------------------------------------------------------------- |
|
144 // ImApiDataObjFactory::InternalizeL |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 template< class INFOIMP > |
|
148 inline void CImApiDataObjFactory::InternalizeL( |
|
149 RReadStream& aStream, |
|
150 RPointerArray<INFOIMP>& aArray ) |
|
151 { |
|
152 TInt32 arrLen = aStream.ReadInt32L(); |
|
153 |
|
154 for ( TInt i = 0; i < arrLen; i++ ) |
|
155 { |
|
156 TInt paramType = aStream.ReadInt32L(); |
|
157 INFOIMP* infoObj = ( INFOIMP* ) NewDataObjectFromStreamLC( paramType, aStream ); |
|
158 aArray.AppendL( infoObj ); |
|
159 CleanupStack::Pop( infoObj ); |
|
160 } |
|
161 } |
|
162 |
|
163 // --------------------------------------------------------------------------- |
|
164 // ImApiDataObjFactory::ExternalizeL |
|
165 // --------------------------------------------------------------------------- |
|
166 // |
|
167 template <class INFOIMP> |
|
168 inline void CImApiDataObjFactory::ExternalizeL( |
|
169 RWriteStream& aWs, |
|
170 const RPointerArray<INFOIMP>& aArray ) |
|
171 { |
|
172 aWs.WriteInt32L( aArray.Count() ); // array length |
|
173 |
|
174 for ( TInt i = 0; i < aArray.Count(); i++ ) |
|
175 { |
|
176 INFOIMP* infoField = aArray[ i ]; |
|
177 |
|
178 // write the type |
|
179 aWs.WriteInt32L( infoField->Base().GetInterfaceId() ); |
|
180 |
|
181 // write the actual object |
|
182 infoField->ExternalizeL( aWs ); |
|
183 } |
|
184 |
|
185 aWs.CommitL(); |
|
186 } |
|
187 |