|
1 // Copyright (c) 2005-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 #include <s32mem.h> |
|
17 #include <mdf/codecapiresolverdata.h> |
|
18 // The biggest descriptor that will be built when internalizing the object |
|
19 const TInt KMaxDescriptorLength = 128; |
|
20 |
|
21 /** |
|
22 Default constructor. |
|
23 */ |
|
24 CCodecApiResolverData::CCodecApiResolverData() |
|
25 { |
|
26 } |
|
27 |
|
28 |
|
29 /** |
|
30 Destructor. |
|
31 */ |
|
32 CCodecApiResolverData::~CCodecApiResolverData() |
|
33 { |
|
34 delete iInputDataFormat; |
|
35 delete iOutputDataFormat; |
|
36 } |
|
37 |
|
38 |
|
39 /** |
|
40 Creates a new CodedApiResolverStandard object. |
|
41 @return A pointer to the newly constructed object. |
|
42 */ |
|
43 EXPORT_C CCodecApiResolverData* CCodecApiResolverData::NewL() |
|
44 { |
|
45 CCodecApiResolverData* self = new(ELeave) CCodecApiResolverData; |
|
46 return self; |
|
47 } |
|
48 |
|
49 |
|
50 /** |
|
51 Creates a new CodedApiResolverStandard object. |
|
52 @param aPackage |
|
53 A reference to a descriptor created using <code>PackL()</code> |
|
54 used to initialize the object. |
|
55 @return A pointer to the newly constructed object. |
|
56 */ |
|
57 EXPORT_C CCodecApiResolverData* CCodecApiResolverData::NewL(const TDesC8& aPackage) |
|
58 { |
|
59 CCodecApiResolverData* self = CCodecApiResolverData::NewLC(aPackage); |
|
60 CleanupStack::Pop(self); |
|
61 return self; |
|
62 } |
|
63 |
|
64 |
|
65 /** |
|
66 Creates a new CodedApiResolverStandard object and leaves a pointer to it on the cleanup stack. |
|
67 @return A pointer to the newly constructed object. |
|
68 */ |
|
69 EXPORT_C CCodecApiResolverData* CCodecApiResolverData::NewLC() |
|
70 { |
|
71 CCodecApiResolverData* self = CCodecApiResolverData::NewL(); |
|
72 CleanupStack::PushL(self); |
|
73 return self; |
|
74 } |
|
75 |
|
76 |
|
77 /** |
|
78 Creates a new CodedApiResolverStandard object and leaves a pointer to it on the cleanup stack. |
|
79 @param aPackage |
|
80 A reference to a descriptor created using <code>PackL()</code> |
|
81 used to initialize the object. |
|
82 @return A pointer to the newly constructed match data object. |
|
83 */ |
|
84 EXPORT_C CCodecApiResolverData* CCodecApiResolverData::NewLC(const TDesC8& aPackage) |
|
85 { |
|
86 CCodecApiResolverData* self = new(ELeave) CCodecApiResolverData; |
|
87 CleanupStack::PushL(self); |
|
88 self->ConstructL(aPackage); |
|
89 return self; |
|
90 } |
|
91 |
|
92 |
|
93 /** |
|
94 Sets up the data inside the class by calling <code>UnPackL()</code>. |
|
95 @param aPackage |
|
96 A reference to the data that will be contained by this class. |
|
97 */ |
|
98 void CCodecApiResolverData::ConstructL(const TDesC8& aPackage) |
|
99 { |
|
100 UnPackL(aPackage); |
|
101 } |
|
102 |
|
103 |
|
104 /** |
|
105 Externalizes the object to a stream. |
|
106 All the member variables will be written to the stream. |
|
107 @param aStream |
|
108 A reference to the stream to which the member variables will |
|
109 be written. |
|
110 */ |
|
111 void CCodecApiResolverData::ExternalizeL(RWriteStream& aStream) const |
|
112 { |
|
113 aStream.WriteInt32L(iMatchType); |
|
114 aStream.WriteInt32L(iImplementationType.iUid); |
|
115 |
|
116 aStream << InputDataFormat(); |
|
117 aStream << OutputDataFormat(); |
|
118 } |
|
119 |
|
120 |
|
121 /** |
|
122 Internalizes the object from a stream. |
|
123 All the member variables will be read from the streamed. |
|
124 @param aStream |
|
125 A reference to the stream from which data will be read to |
|
126 setup the member variables. |
|
127 */ |
|
128 void CCodecApiResolverData::InternalizeL(RReadStream& aStream) |
|
129 { |
|
130 iMatchType = static_cast<TCodecApiResolverMatchType>(aStream.ReadInt32L()); |
|
131 iImplementationType.iUid = aStream.ReadInt32L(); |
|
132 |
|
133 delete iInputDataFormat; |
|
134 iInputDataFormat = NULL; |
|
135 iInputDataFormat = HBufC8::NewL(aStream,KMaxDescriptorLength); //KErrOverflow |
|
136 |
|
137 delete iOutputDataFormat; |
|
138 iOutputDataFormat = NULL; |
|
139 iOutputDataFormat = HBufC8::NewL(aStream,KMaxDescriptorLength); //KErrOverflow |
|
140 } |
|
141 |
|
142 |
|
143 /** |
|
144 Sets the match type to match against. |
|
145 @param aMatchType |
|
146 The type of match requested. |
|
147 */ |
|
148 EXPORT_C void CCodecApiResolverData::SetMatchType(const TCodecApiResolverMatchType& aMatchType) |
|
149 { |
|
150 iMatchType = aMatchType; |
|
151 } |
|
152 |
|
153 |
|
154 /** |
|
155 Sets the implementation type to match against. |
|
156 @param aImplementationType |
|
157 The implementation uid of a specific codec to match against. |
|
158 */ |
|
159 EXPORT_C void CCodecApiResolverData::SetImplementationType(const TUid& aImplementationType) |
|
160 { |
|
161 iImplementationType = aImplementationType; |
|
162 } |
|
163 |
|
164 |
|
165 /** |
|
166 Sets the input data type to match against. |
|
167 @param aDataType |
|
168 The input data type of a codec to match against. |
|
169 */ |
|
170 EXPORT_C void CCodecApiResolverData::SetInputDataL(const TDesC8& aDataType) |
|
171 { |
|
172 delete iInputDataFormat; |
|
173 iInputDataFormat = NULL; |
|
174 iInputDataFormat = aDataType.AllocL(); |
|
175 } |
|
176 |
|
177 |
|
178 /** |
|
179 Sets the output data type to match against. |
|
180 @param aDataType |
|
181 The output data type of a codec to match against. |
|
182 */ |
|
183 EXPORT_C void CCodecApiResolverData::SetOutputDataL(const TDesC8& aDataType) |
|
184 { |
|
185 delete iOutputDataFormat; |
|
186 iOutputDataFormat = NULL; |
|
187 iOutputDataFormat = aDataType.AllocL(); |
|
188 } |
|
189 |
|
190 |
|
191 /** |
|
192 Retrieves the match type to match against. |
|
193 @return The type of match requested. |
|
194 */ |
|
195 EXPORT_C TCodecApiResolverMatchType CCodecApiResolverData::MatchType() const |
|
196 { |
|
197 return iMatchType; |
|
198 } |
|
199 |
|
200 |
|
201 /** |
|
202 Retrieves the implementation type to match against. |
|
203 @return The implementation of a specific codec to match against. |
|
204 */ |
|
205 EXPORT_C TUid CCodecApiResolverData::ImplementationType() const |
|
206 { |
|
207 return iImplementationType; |
|
208 } |
|
209 |
|
210 |
|
211 |
|
212 /** |
|
213 Retrieves the input data format string to match against. If no string is set |
|
214 a null descriptor is returned. |
|
215 @return The string to match against. |
|
216 */ |
|
217 EXPORT_C const TPtrC8 CCodecApiResolverData::InputDataFormat() const |
|
218 { |
|
219 TPtrC8 result; |
|
220 if(iInputDataFormat) |
|
221 { |
|
222 result.Set(*iInputDataFormat); |
|
223 } |
|
224 else |
|
225 { |
|
226 result.Set(KNullDesC8); |
|
227 } |
|
228 return result; |
|
229 } |
|
230 |
|
231 |
|
232 /** |
|
233 Retrieves the output data format string to match against. If no string is set |
|
234 a null descriptor is returned. |
|
235 @return The string to match against. |
|
236 */ |
|
237 EXPORT_C const TPtrC8 CCodecApiResolverData::OutputDataFormat() const |
|
238 { |
|
239 TPtrC8 result; |
|
240 if(iOutputDataFormat) |
|
241 { |
|
242 result.Set(*iOutputDataFormat); |
|
243 } |
|
244 else |
|
245 { |
|
246 result.Set(KNullDesC8); |
|
247 } |
|
248 return result; |
|
249 } |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 /** |
|
255 Packages the object up into a descriptor. |
|
256 @return A pointer to a desctriptor with the object packed in it. |
|
257 */ |
|
258 EXPORT_C HBufC8* CCodecApiResolverData::NewPackLC() const |
|
259 { |
|
260 //Calculate the size necessary size for the descriptor to pack the object |
|
261 TInt size = 0; |
|
262 size = sizeof(iMatchType) + sizeof(iImplementationType.iUid) + 2*sizeof(TInt32); |
|
263 // the operator << write first the length of the string so we need to add it to the total size |
|
264 if(iInputDataFormat) |
|
265 { |
|
266 size += iInputDataFormat->Size(); |
|
267 } |
|
268 if(iOutputDataFormat) |
|
269 { |
|
270 size += iOutputDataFormat->Size(); |
|
271 } |
|
272 |
|
273 HBufC8* package = HBufC8::NewLC(size); |
|
274 TPtr8 packageDes = package->Des(); |
|
275 RDesWriteStream stream(packageDes); |
|
276 CleanupClosePushL(stream); |
|
277 ExternalizeL(stream); |
|
278 CleanupStack::PopAndDestroy(&stream); |
|
279 return package; |
|
280 } |
|
281 |
|
282 |
|
283 |
|
284 /** |
|
285 Unpacks a packed descriptor. |
|
286 @param aPackage |
|
287 A reference to a desctriptor created. |
|
288 */ |
|
289 EXPORT_C void CCodecApiResolverData::UnPackL(const TDesC8& aPackage) |
|
290 { |
|
291 RDesReadStream stream(aPackage); |
|
292 CleanupClosePushL(stream); |
|
293 InternalizeL(stream); |
|
294 CleanupStack::PopAndDestroy(&stream); |
|
295 } |