|
1 // Copyright (c) 2007-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 // Implemetation of class CPluginInfo |
|
15 // |
|
16 |
|
17 |
|
18 |
|
19 /** |
|
20 @file |
|
21 @see CPluginInfo |
|
22 */ |
|
23 |
|
24 #include <e32debug.h> |
|
25 |
|
26 #include <debuglogging.h> |
|
27 #include <plugindata.h> |
|
28 |
|
29 |
|
30 /** |
|
31 Allocates and constructs a CPluginInfo object. |
|
32 |
|
33 @see CPlguinInfo::CPluginInfo |
|
34 */ |
|
35 EXPORT_C CPluginInfo* CPluginInfo::NewL(const TDesC &aName, |
|
36 const TInt aUid, |
|
37 const TUint aVersion, |
|
38 const TPluginRequest::TPluginType aType) |
|
39 { |
|
40 const TUint size = |
|
41 + sizeof( TUint32 ) // When externalized, we send the name length, so must include this |
|
42 + 2 // When externalized, the << operator writes 2 bytes for the descriptor size |
|
43 + aName.Size() // iName Size, in bytes. |
|
44 + sizeof( TInt32 ) // aUid |
|
45 + sizeof( TUint32 ) // aVersion |
|
46 + sizeof( TUint32 ) // aType |
|
47 + sizeof( TUint32 ) // aPair |
|
48 + sizeof( TUint32 ); // iSize itself |
|
49 |
|
50 |
|
51 if( size >= MaxSize() ) |
|
52 { |
|
53 LOG_MSG3( "CPluginInfo::NewL() : Descriptorized object = 0x%X bytes would exceed the maximum of 0x%X\n", |
|
54 size, MaxSize() ); |
|
55 |
|
56 User::Leave( KErrTooBig ); |
|
57 } |
|
58 |
|
59 CPluginInfo * data = new (ELeave) CPluginInfo( aUid, aVersion, aType ); |
|
60 |
|
61 CleanupStack::PushL( data ); |
|
62 |
|
63 data->ConstructL( aName ); |
|
64 |
|
65 CleanupStack::Pop(data); |
|
66 |
|
67 return (data); |
|
68 } |
|
69 |
|
70 |
|
71 /** |
|
72 Allocates and constructs a CPluginInfo object from a descriptor. |
|
73 The descriptor contains an externalised version of a CPluginInfo object. |
|
74 This method is typically used to obtain a CPluginInfo object from a |
|
75 descriptor returned by the core dump server. |
|
76 |
|
77 @param aStreamData Descriptor with externalised/streamed object to initialize from. |
|
78 @see InternalizeL |
|
79 @see ExternalizeL |
|
80 */ |
|
81 EXPORT_C CPluginInfo* CPluginInfo::NewL( const TDesC8 & aStreamData ) |
|
82 { |
|
83 CPluginInfo* self = new (ELeave) CPluginInfo(); |
|
84 |
|
85 CleanupStack::PushL( self ); |
|
86 |
|
87 RDesReadStream stream( aStreamData ); |
|
88 |
|
89 CleanupClosePushL( stream ); |
|
90 |
|
91 self->InternalizeL( stream ); |
|
92 |
|
93 CleanupStack::PopAndDestroy( &stream ); // finished with the stream |
|
94 |
|
95 CleanupStack::Pop( self ); |
|
96 |
|
97 return ( self ); |
|
98 } |
|
99 |
|
100 |
|
101 /** |
|
102 Destructor. Deletes name if allocated. |
|
103 */ |
|
104 EXPORT_C CPluginInfo::~CPluginInfo() |
|
105 { |
|
106 |
|
107 if(iName) |
|
108 { |
|
109 delete iName; |
|
110 } |
|
111 } |
|
112 |
|
113 /** |
|
114 First phase contructor. Sets the size to 0, name to NULL. |
|
115 |
|
116 @see CPluginInfo::NewL(). |
|
117 */ |
|
118 CPluginInfo::CPluginInfo(const TInt aUid, |
|
119 const TUint aVersion, |
|
120 const TPluginRequest::TPluginType aType): |
|
121 |
|
122 iName(NULL), |
|
123 iUid(aUid ), |
|
124 iVersion(aVersion), |
|
125 iType(aType), |
|
126 iPair(KMaxTUint32), |
|
127 iSize(0) |
|
128 { |
|
129 } |
|
130 |
|
131 |
|
132 /** |
|
133 Second phase constructor initialises the name of the executable. |
|
134 @param aName Plugin name |
|
135 @see NameL() |
|
136 */ |
|
137 void CPluginInfo::ConstructL(const TDesC &aName) |
|
138 { |
|
139 NameL(aName); |
|
140 } |
|
141 |
|
142 |
|
143 /** |
|
144 Initialise this object with the contents of RReadStream aStream. |
|
145 The descriptor contains an externalised version of an object. |
|
146 This method is typically used to obtain a CPluginInfo object from |
|
147 the core dump server. |
|
148 Any modifications to this method should be synchronised with ExternalizeL(). |
|
149 Also note that the methods used from RReadStream (>> or ReadUint32L) |
|
150 can behave differently, especially for descriptors. |
|
151 @param aStream Stream with streamed object |
|
152 @see ExternalizeL |
|
153 @see RReadStream |
|
154 @pre Call Externalise to obtain the stream containing an externalised |
|
155 version of this object. |
|
156 */ |
|
157 EXPORT_C void CPluginInfo::InternalizeL( RReadStream & aStream ) |
|
158 { |
|
159 // Read the number of character elements in the name. |
|
160 TUint32 nameLength = aStream.ReadUint32L(); |
|
161 |
|
162 if( NULL != iName ) |
|
163 { |
|
164 delete iName; |
|
165 iName = NULL; |
|
166 } |
|
167 |
|
168 if ( nameLength > 0 ) |
|
169 { |
|
170 iName = HBufC::NewL( aStream, nameLength ); |
|
171 } |
|
172 else |
|
173 { |
|
174 iName = NULL; |
|
175 } |
|
176 |
|
177 iUid = static_cast<TInt>(aStream.ReadInt32L()); |
|
178 iVersion = static_cast<TUint>(aStream.ReadUint32L()); |
|
179 iType = static_cast<TPluginRequest::TPluginType>(aStream.ReadUint32L()); |
|
180 iPair = static_cast<TUint>(aStream.ReadUint32L()); |
|
181 |
|
182 iSize = aStream.ReadUint32L() ; |
|
183 } |
|
184 |
|
185 |
|
186 /** |
|
187 Make a streamed representation of this object to a RWriteStream. |
|
188 |
|
189 This method is typically by the core dump server when contructing a list of |
|
190 CPluginInfo for a client. |
|
191 Any modifications to this method should be synchronised with InternalizeL(). |
|
192 Also note that the methods used from RWriteStream (>> or WriteUint32L) can behave differently, |
|
193 especially for descriptors. |
|
194 @param aStream Stream to stream object onto |
|
195 @param buf Buffer onto the same stream, used to obtain the correct size of the externalised object |
|
196 @see InternalizeL |
|
197 @see RReadStream |
|
198 @see RWriteStream |
|
199 @post The stream contains an externalised version of this object. |
|
200 */ |
|
201 EXPORT_C void CPluginInfo::ExternalizeL( RWriteStream & aStream, CBufFlat* buf ) |
|
202 { |
|
203 |
|
204 // Take the size of the buffer before we add anything to it. |
|
205 TUint startBufSize = buf->Size(); |
|
206 |
|
207 TUint nameLength = 0; |
|
208 |
|
209 if ( ( NULL != iName ) && ( iName->Des().Length() > 0 ) ) |
|
210 { |
|
211 |
|
212 nameLength = iName->Des().Length(); |
|
213 |
|
214 if( nameLength > 0 ) |
|
215 { |
|
216 // Write the number of character elements in the name. |
|
217 aStream.WriteUint32L( nameLength ); |
|
218 aStream << iName->Des(); |
|
219 } |
|
220 } |
|
221 |
|
222 if( nameLength == 0 ) |
|
223 { |
|
224 aStream.WriteUint32L( 0 ); |
|
225 } |
|
226 |
|
227 aStream.WriteInt32L( static_cast<TInt32>(iUid) ); |
|
228 aStream.WriteUint32L( static_cast<TUint32>(iVersion) ); |
|
229 |
|
230 aStream.WriteUint32L( static_cast<TUint32>(iType) ); |
|
231 aStream.WriteUint32L( static_cast<TUint32>(iPair) ); |
|
232 |
|
233 iSize = buf->Size() - startBufSize + 4; |
|
234 |
|
235 aStream.WriteUint32L( iSize ); |
|
236 |
|
237 } |
|
238 |
|
239 /** |
|
240 */ |
|
241 EXPORT_C TInt CPluginInfo::Uid() const |
|
242 { |
|
243 return ( iUid ); |
|
244 } |
|
245 |
|
246 /** |
|
247 */ |
|
248 EXPORT_C void CPluginInfo::Uid( TInt aUid ) |
|
249 { |
|
250 iUid = aUid; |
|
251 } |
|
252 |
|
253 /** |
|
254 */ |
|
255 EXPORT_C TUint CPluginInfo::Version() const |
|
256 { |
|
257 return ( iVersion ); |
|
258 } |
|
259 |
|
260 |
|
261 /** |
|
262 */ |
|
263 EXPORT_C void CPluginInfo::Version(TUint aVersion ) |
|
264 { |
|
265 iVersion = aVersion; |
|
266 } |
|
267 |
|
268 /** |
|
269 */ |
|
270 EXPORT_C TPluginRequest::TPluginType CPluginInfo::Type() const |
|
271 { |
|
272 return ( iType ); |
|
273 } |
|
274 |
|
275 |
|
276 /** |
|
277 */ |
|
278 EXPORT_C void CPluginInfo::Type( TPluginRequest::TPluginType aType ) |
|
279 { |
|
280 iType = aType; |
|
281 } |
|
282 /** |
|
283 */ |
|
284 EXPORT_C TUint CPluginInfo::Pair() const |
|
285 { |
|
286 return ( iPair ); |
|
287 } |
|
288 |
|
289 |
|
290 /** |
|
291 */ |
|
292 EXPORT_C void CPluginInfo::Pair(TUint aIndex ) |
|
293 { |
|
294 iPair = aIndex; |
|
295 } |
|
296 |
|
297 |
|
298 /** |
|
299 Set the name of the plugin by deleting, allocating and then copying the parameter. |
|
300 @param aName Name of the executable to set to |
|
301 @see ConstructL() |
|
302 */ |
|
303 EXPORT_C void CPluginInfo::NameL(const TDesC &aName) |
|
304 { |
|
305 |
|
306 if(iName) |
|
307 { |
|
308 delete iName; //missing in all other data files - leak?!? |
|
309 } |
|
310 |
|
311 if( aName.Length() > 0 ) |
|
312 { |
|
313 TUint toCopy = aName.Length(); |
|
314 iName = HBufC::NewL( toCopy ); |
|
315 TPtr nameDes = iName->Des(); |
|
316 |
|
317 nameDes.Copy( aName.Ptr(), toCopy ); |
|
318 nameDes.SetLength( toCopy ); |
|
319 } |
|
320 else |
|
321 { |
|
322 iName = NULL; |
|
323 } |
|
324 } |
|
325 |
|
326 |
|
327 /** |
|
328 Obtain the kernel executable name. |
|
329 */ |
|
330 EXPORT_C const TDesC & CPluginInfo::Name() const |
|
331 { |
|
332 return ( *iName ); |
|
333 } |
|
334 |
|
335 |
|
336 CPluginInfo::CPluginInfo() |
|
337 { |
|
338 } |
|
339 |
|
340 |
|
341 /** |
|
342 Get the maximum size allowed for this object. This is needed as the object is passed |
|
343 across the Client Server interface. |
|
344 */ |
|
345 EXPORT_C TInt CPluginInfo::MaxSize() |
|
346 { |
|
347 const TInt maxSize = 256; |
|
348 return maxSize; |
|
349 } |
|
350 |
|
351 |
|
352 /** |
|
353 Gets the size of the object when externalized. The sizeofs used to calculate this |
|
354 must match the operators used in ExternalizeL and InternalizeL. |
|
355 Special attention must be paid to the name. If the object has not been |
|
356 externalized yet then this method returns the maximum that it could take. |
|
357 The name descriptor is compressed when externalized, so it is not its Size(). |
|
358 Furthermore the << operator adds two bytes to the stream when externalizing |
|
359 a descriptor. |
|
360 */ |
|
361 EXPORT_C TInt CPluginInfo::Size() const |
|
362 { |
|
363 |
|
364 if( iSize != 0 ) |
|
365 { |
|
366 return iSize; |
|
367 } |
|
368 |
|
369 TUint extNameSize = 0; |
|
370 if( iName ) |
|
371 { |
|
372 extNameSize = 2 // When externalized, the << operator writes 2 bytes for the descriptor size |
|
373 + iName->Size(); // iName itself, in bytes. |
|
374 } |
|
375 |
|
376 const TUint size = |
|
377 + sizeof( TUint32 ) // When externalized, we send the name length, so must include this |
|
378 + extNameSize |
|
379 + sizeof( TInt32 ) // aUid |
|
380 + sizeof( TUint32 ) // aVersion |
|
381 + sizeof( TUint32 ) // aType |
|
382 + sizeof( TUint32 ) // aPair |
|
383 + sizeof( TUint32 ); // iSize When externalized, we send the real externalized size of the buffer |
|
384 |
|
385 return size; |
|
386 } |
|
387 |
|
388 |