|
1 // Copyright (c) 2003-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 // source\mmf\server\baseclasses\mmfdatabuffer.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include <mmf/server/mmfdatabuffer.h> |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 /** |
|
24 Method to instantiate a CMMFDataBuffer defaults to a CMMFDescriptorBuffer |
|
25 to maintain buffer compatiblity with MFAD ie. instantiating a CMMFDataBuffer defaults to creating |
|
26 a CMMFDescriptorBuffer. This NewL creates a CMMFDescriptorBuffer with a default size of 32 bytes. |
|
27 |
|
28 @return A pointer to a new CMMFDescriptorBuffer. |
|
29 */ |
|
30 EXPORT_C CMMFDataBuffer* CMMFDataBuffer::NewL() |
|
31 { |
|
32 return CMMFDescriptorBuffer::NewL(); |
|
33 } |
|
34 |
|
35 /** |
|
36 Method to instantiate a CMMFDataBuffer defaults to a CMMFDescriptorBuffer by default |
|
37 to maintain buffer compatiblity with MFAD ie. instantiating a CMMFDataBuffer defaults to |
|
38 creating a CMMFDescriptorBuffer. This NewL creates a CMMFDescriptorBuffer with a size of |
|
39 aMaxBufferSize bytes. |
|
40 |
|
41 @param aMaxBufferSize |
|
42 The size in bytes of the descriptor buffer to be created. |
|
43 |
|
44 @return A pointer to a new CMMFDescriptorBuffer. |
|
45 */ |
|
46 EXPORT_C CMMFDataBuffer* CMMFDataBuffer::NewL(TInt aMaxBufferSize) |
|
47 { |
|
48 return CMMFDescriptorBuffer::NewL(aMaxBufferSize); |
|
49 } |
|
50 |
|
51 |
|
52 /** |
|
53 Method to instantiate a CMMFDescriptorBuffer. |
|
54 |
|
55 Defaults to a CMMFDescriptorBuffer automatically. This NewL creates a CMMFDescriptorBuffer with a |
|
56 default size of 32 bytes. |
|
57 |
|
58 @return A pointer to a new CMMFDescriptorBuffer. |
|
59 */ |
|
60 EXPORT_C CMMFDescriptorBuffer* CMMFDescriptorBuffer::NewL() |
|
61 { |
|
62 CMMFDescriptorBuffer* self = new(ELeave) CMMFDescriptorBuffer; |
|
63 CleanupStack::PushL(self); |
|
64 self->ConstructL(KMMFDataBufferDefaultBufferSize); |
|
65 CleanupStack::Pop(); // self |
|
66 return self; |
|
67 } |
|
68 |
|
69 |
|
70 /** |
|
71 Method to instantiate a CMMFDescriptorBuffer. |
|
72 This NewL creates a CMMFDescriptorBuffer with a size of aMaxBufferSize bytes. |
|
73 |
|
74 @param aMaxBufferSize |
|
75 The size in bytes of the descriptor buffer to be created. |
|
76 |
|
77 @return A pointer to a new CMMFDescriptorBuffer. |
|
78 */ |
|
79 EXPORT_C CMMFDescriptorBuffer* CMMFDescriptorBuffer::NewL(TInt aMaxBufferSize) |
|
80 { |
|
81 CMMFDescriptorBuffer* self = new(ELeave) CMMFDescriptorBuffer; |
|
82 CleanupStack::PushL(self); |
|
83 self->ConstructL(aMaxBufferSize); |
|
84 CleanupStack::Pop(); // self |
|
85 return self; |
|
86 } |
|
87 |
|
88 /** |
|
89 @internalTechnology |
|
90 |
|
91 Internal. |
|
92 |
|
93 @param aMaxBufferSize |
|
94 The size in bytes of the descriptor buffer to be created. |
|
95 */ |
|
96 void CMMFDescriptorBuffer::ConstructL(TInt aMaxBufferSize) |
|
97 { |
|
98 iData = new(ELeave) TUint8[aMaxBufferSize]; |
|
99 iPtr.Set(iData, 0, aMaxBufferSize); |
|
100 } |
|
101 |
|
102 /** |
|
103 Destructor. |
|
104 |
|
105 Destructor also deletes the buffer contained in the CMMFDescriptorBuffer. |
|
106 */ |
|
107 EXPORT_C CMMFDescriptorBuffer::~CMMFDescriptorBuffer() |
|
108 { |
|
109 delete[] iData; |
|
110 } |
|
111 |
|
112 /** |
|
113 Reallocates the max size in bytes of a CMMFDescriptorBuffer. |
|
114 |
|
115 @param aMaxBufferSize |
|
116 The new size in bytes of the descriptor buffer. |
|
117 */ |
|
118 EXPORT_C void CMMFDescriptorBuffer::ReAllocBufferL(TInt aMaxBufferSize) |
|
119 { |
|
120 TUint8* tmp = new(ELeave) TUint8[aMaxBufferSize]; |
|
121 delete[] iData; |
|
122 iData = tmp; |
|
123 iPtr.Set(iData, 0, aMaxBufferSize); |
|
124 } |
|
125 |
|
126 /** |
|
127 Returns a descriptor to the data contained in the CMMFDescriptorBuffer. |
|
128 |
|
129 @return A reference to a TPtr containing the CMMFDescriptorBuffer data. |
|
130 */ |
|
131 TDes8& CMMFDescriptorBuffer::Data() |
|
132 { |
|
133 return iPtr; |
|
134 } |
|
135 |
|
136 /** |
|
137 Returns a descriptor to the data contained in the CMMFDescriptorBuffer. |
|
138 |
|
139 @return A const reference to a TPtr containing the CMMFDescriptorBuffer data. |
|
140 */ |
|
141 const TDesC8& CMMFDescriptorBuffer::Data() const |
|
142 { |
|
143 return iPtr; |
|
144 } |
|
145 |
|
146 /** |
|
147 Returns the actual data size (ie. not the maximum length) of the |
|
148 data contained in the CMMFDescriptorBuffer. |
|
149 |
|
150 @return The size in bytes of the data contained in the CMMFDescriptorBuffer. |
|
151 */ |
|
152 TUint CMMFDescriptorBuffer::BufferSize() const |
|
153 { |
|
154 return iPtr.Length(); |
|
155 } |
|
156 |
|
157 /** |
|
158 Sets the position. |
|
159 |
|
160 This method is used by components (eg codecs) which read data from a buffer |
|
161 and wish to store a read position marker for further reads. |
|
162 Note: The position cannot exceed the size of the actual data not the max length. |
|
163 |
|
164 @param aPosition |
|
165 The position. |
|
166 */ |
|
167 void CMMFDescriptorBuffer::SetPosition (TUint aPosition) |
|
168 {//used for repositioning |
|
169 if (aPosition <= (TUint)iPtr.Length()) |
|
170 iPosition = aPosition; |
|
171 else |
|
172 iPosition = (TUint)iPtr.Length();//tried to position beyond end of data |
|
173 } |
|
174 |
|
175 /** |
|
176 Sets the request size. |
|
177 |
|
178 This function is used in cases where a component (eg a data source) may not be able |
|
179 or be desirable to write to the entire max length of the buffer (eg variable bit rate codecs). |
|
180 In which case the SetRequestSizeL() can be set which can be read by the RequestSize() |
|
181 function in the component so that it knows to only write data upto the request size |
|
182 and not fill the buffer up to its max length. |
|
183 |
|
184 @param aSize |
|
185 The request size. |
|
186 */ |
|
187 void CMMFDescriptorBuffer::SetRequestSizeL(TInt aSize) |
|
188 { |
|
189 if (aSize < 0) |
|
190 User::Leave(KErrUnderflow); |
|
191 else if (aSize > iPtr.MaxLength()) |
|
192 User::Leave(KErrOverflow); |
|
193 else |
|
194 iRequestSize = aSize; |
|
195 } |
|
196 |
|
197 |
|
198 /** |
|
199 Overriden method to set the status and resets the data size to 0 when the buffer becomes available. |
|
200 |
|
201 @param aStatus |
|
202 The buffer status. See TBufferStatus for possible options. |
|
203 */ |
|
204 void CMMFDescriptorBuffer::SetStatus(TBufferStatus aStatus) |
|
205 { |
|
206 CMMFBuffer::SetStatus(aStatus); |
|
207 if ((iStatus == EAvailable)&&iData) |
|
208 {//need to set size to 0 |
|
209 iPtr.Zero(); |
|
210 } |
|
211 } |
|
212 |
|
213 |
|
214 /** |
|
215 This function is not supported under EKA2. |
|
216 |
|
217 Method to instantiate a CMMFTransferBuffer. This NewL creates a CMMFTransferBuffer. |
|
218 |
|
219 @param aTransferWindow |
|
220 This is a valid RTransferWindow that has an RTransferBuffer mapped in. |
|
221 @param aDataLength |
|
222 This parameter sets the length of the actual data present in the transferbuffer. |
|
223 This is because the length of actual data may be less than the length of the mapped in |
|
224 transfer buffer. |
|
225 |
|
226 @return A pointer to a new CMMFTransferBuffer. |
|
227 */ |
|
228 |
|
229 EXPORT_C CMMFTransferBuffer* CMMFTransferBuffer::NewL(RTransferWindow& aTransferWindow, TUint aDataLength) |
|
230 { |
|
231 //this method is not supported under EKA2 |
|
232 User::Panic(_L("Not supported!"), KErrNotSupported); |
|
233 aTransferWindow = aTransferWindow; //suppressed unused argument warnings |
|
234 aDataLength = aDataLength; //suppressed unused argument warnings |
|
235 return NULL; //can't construct anything useful |
|
236 } |
|
237 |
|
238 /** |
|
239 @internalTechnology |
|
240 |
|
241 This method is not supported under EKA2. |
|
242 |
|
243 Internal ConstructL. |
|
244 |
|
245 Note this method checks if a transfer buffer has been mapped in and |
|
246 will leave with KErrNotReady if the RTransferWindow does not have a mapped |
|
247 in RTransferBuffer. |
|
248 |
|
249 @param aTransferWindow |
|
250 This is a reference to a valid RTransferWindow that has an RTransferBuffer mapped in. |
|
251 @param aDataLength |
|
252 The length of the data. |
|
253 */ |
|
254 void CMMFTransferBuffer::ConstructL(RTransferWindow& aTransferWindow, TUint aDataLength) |
|
255 { |
|
256 //this method is not supported under EKA2 |
|
257 aTransferWindow = aTransferWindow; //suppressed unused argument warnings |
|
258 aDataLength = aDataLength; //suppressed unused argument warnings |
|
259 } |
|
260 |
|
261 |
|
262 /** |
|
263 CMMFTransferBuffer destructor |
|
264 |
|
265 Destructor maps out RTransferBuffer and closes RTransferWindow. |
|
266 */ |
|
267 EXPORT_C CMMFTransferBuffer::~CMMFTransferBuffer() |
|
268 { |
|
269 } |
|
270 |
|
271 /** |
|
272 Returns a descriptor to the data contained in the CMMFTransferBuffer. |
|
273 |
|
274 @return A reference to a TPtr containing the CMMFTransferBuffer data. |
|
275 */ |
|
276 TDes8& CMMFTransferBuffer::Data() |
|
277 { |
|
278 return iPtr; |
|
279 } |
|
280 |
|
281 /** |
|
282 Returns a descriptor to the data contained in the CMMFTransferBuffer. |
|
283 |
|
284 @return A const reference to a TPtr containing the CMMFTransferBuffer data. |
|
285 */ |
|
286 const TDesC8& CMMFTransferBuffer::Data() const |
|
287 { |
|
288 return iPtr; |
|
289 } |
|
290 |
|
291 /** |
|
292 Returns the actual data size (ie. not the max length) of the |
|
293 data contained in the CMMFTransferBuffer. |
|
294 |
|
295 @return The size in bytes of the data contained in the CMMFTransferBuffer. |
|
296 */ |
|
297 TUint CMMFTransferBuffer::BufferSize() const |
|
298 { |
|
299 return iPtr.Length(); |
|
300 } |
|
301 |
|
302 |
|
303 /** |
|
304 Sets the position. |
|
305 |
|
306 This method is used by components (eg codecs) which read data from a buffer |
|
307 and wish to store a read position marker for further reads. |
|
308 |
|
309 Note: The position cannot exceed the size of the actual data not the max length. |
|
310 |
|
311 @param aPosition |
|
312 The position. |
|
313 */ |
|
314 void CMMFTransferBuffer::SetPosition (TUint aPosition) |
|
315 {//used for repositioning |
|
316 aPosition = aPosition; //suppress compiler warning |
|
317 } |
|
318 |
|
319 /** |
|
320 Sets the request size. |
|
321 |
|
322 This function is used in cases where a component (eg. a data source) may not be able |
|
323 or be desirable to write to the entire max length of the buffer (eg. variable bit rate codecs). |
|
324 In this case, the SetRequestSizeL can be set which can be read by the RequestSize() |
|
325 function in the component so that it knows to only write data upto the request size |
|
326 and not fill the buffer up to its max length. |
|
327 |
|
328 @param aSize |
|
329 The request size. |
|
330 */ |
|
331 void CMMFTransferBuffer::SetRequestSizeL(TInt aSize) |
|
332 { |
|
333 aSize = aSize; //suppress compiler warning |
|
334 } |
|
335 |
|
336 |
|
337 /** |
|
338 This function is not supported under EKA2. |
|
339 |
|
340 Returns a reference to the transfer window currently used |
|
341 by the CMMFtransferBuffer. |
|
342 |
|
343 @return A reference to the current RTransferWindow. |
|
344 */ |
|
345 EXPORT_C RTransferWindow& CMMFTransferBuffer::TransferWindow() |
|
346 { |
|
347 return iTransferWindow; |
|
348 } |
|
349 |
|
350 |
|
351 /** |
|
352 This method is not supported under EKA2. |
|
353 |
|
354 Modifies the CMMFTransferBuffer by updating the RTransferWindow. |
|
355 |
|
356 This method is used if the same CMMFTransferBuffer is used throughout |
|
357 eg. if a single CMMFTransferBuffer is created upfront but a different |
|
358 transfer window (or the same transfer window with a different buffer mapped in |
|
359 is used). That is the same CMMFTransferBuffer but the actrual buffer may be different. |
|
360 |
|
361 Note: If the updated RTransferWindow is new, then the old buffer must |
|
362 be mapped out first by a call to CMMFTransferBuffer::MapOutBuffer() and the |
|
363 RtransferWindow handle closed outside the CMMFTransferBuffer. |
|
364 |
|
365 @param aTransferWindow |
|
366 The RTransferWindow to update - can be a new RTransferWindow |
|
367 or the same RTransferWindow with a new RTransferBuffer mapped in. |
|
368 @param aDataLength |
|
369 The length of the data. |
|
370 |
|
371 @return An error code indicating if the function call was successful. KErrNone on success, otherwise |
|
372 another of the system-wide error codes. |
|
373 */ |
|
374 EXPORT_C TInt CMMFTransferBuffer::UpdateTransferWindow(RTransferWindow& aTransferWindow, TUint aDataLength) |
|
375 { |
|
376 //this method is not supported under EKA2 |
|
377 aTransferWindow = aTransferWindow; //suppressed unused argument warnings |
|
378 aDataLength = aDataLength; //suppressed unused argument warnings |
|
379 return KErrNotSupported; |
|
380 } |
|
381 |
|
382 /** |
|
383 Maps the buffer out of the transfer window. |
|
384 |
|
385 This method should be called in preference to |
|
386 calling MapOutBuffer directly on the RtransferWindow |
|
387 so that the CMMFTransferBuffer knows that it is no longer |
|
388 available. |
|
389 */ |
|
390 EXPORT_C void CMMFTransferBuffer::MapOutBuffer() |
|
391 { |
|
392 } |
|
393 |
|
394 |
|
395 |
|
396 /** |
|
397 Function to instantiate a CMMFPtrBuffer. |
|
398 This NewL creates an unititalised CMMFPtrBuffer. |
|
399 |
|
400 @return A pointer to a new CMMFPtrBuffer. |
|
401 */ |
|
402 EXPORT_C CMMFPtrBuffer* CMMFPtrBuffer::NewL() |
|
403 { |
|
404 CMMFPtrBuffer* self = new(ELeave) CMMFPtrBuffer; |
|
405 |
|
406 return self; |
|
407 } |
|
408 |
|
409 |
|
410 /** |
|
411 Function to instantiate a CMMFPtrBuffer. |
|
412 This NewL creates a CMMFPtrBuffer which owns a TPtr8. |
|
413 |
|
414 @param aPtr |
|
415 A reference to a TPtr containing the CMMFPtrBuffer data. |
|
416 |
|
417 @return A pointer to a new CMMFPtrBuffer. |
|
418 */ |
|
419 EXPORT_C CMMFPtrBuffer* CMMFPtrBuffer::NewL(const TPtr8& aPtr) |
|
420 { |
|
421 CMMFPtrBuffer* self = new(ELeave) CMMFPtrBuffer; |
|
422 CleanupStack::PushL(self); |
|
423 self->ConstructL(aPtr); |
|
424 CleanupStack::Pop(self); // self |
|
425 return self; |
|
426 } |
|
427 |
|
428 /** |
|
429 * ConstructL |
|
430 * |
|
431 * Internal ConstructL |
|
432 * @internalTechnology |
|
433 * @param "aPtr" |
|
434 * Reference to a TPtr containing the CMMFPtrBuffer data |
|
435 */ |
|
436 void CMMFPtrBuffer::ConstructL(const TPtr8& aPtr) |
|
437 { |
|
438 iPtr.Set(aPtr); |
|
439 } |
|
440 |
|
441 /** |
|
442 Destructor. |
|
443 |
|
444 Destructor does no deletion, as this buffer class does not own the memory. |
|
445 */ |
|
446 EXPORT_C CMMFPtrBuffer::~CMMFPtrBuffer() |
|
447 { |
|
448 |
|
449 } |
|
450 |
|
451 /** |
|
452 Returns a descriptor to the data contained in the CMMFPtrBuffer. |
|
453 |
|
454 @return A reference to a TPtr containing the CMMFPtrBuffer data. |
|
455 */ |
|
456 TDes8& CMMFPtrBuffer::Data() |
|
457 { |
|
458 return iPtr; |
|
459 } |
|
460 |
|
461 /** |
|
462 Returns a descriptor to the data contained in the CMMFPtrBuffer. |
|
463 |
|
464 @return A const reference to a TPtr containing the CMMFPtrBuffer data. |
|
465 */ |
|
466 const TDesC8& CMMFPtrBuffer::Data() const |
|
467 { |
|
468 return iPtr; |
|
469 } |
|
470 |
|
471 /** |
|
472 Returns the actual data size (ie. not the max length) of the |
|
473 data contained in the CMMFPtrBuffer. |
|
474 |
|
475 @return The size in bytes of the data contained in the CMMFPtrBuffer. |
|
476 */ |
|
477 TUint CMMFPtrBuffer::BufferSize() const |
|
478 { |
|
479 return iPtr.Length(); |
|
480 } |
|
481 |
|
482 /** |
|
483 Sets the position. |
|
484 |
|
485 This function is used by components (eg. codecs) which read data from a buffer |
|
486 and wish to store a read position marker for further reads. |
|
487 |
|
488 Note: The position cannot exceed the size of the actual data not the maximum length. |
|
489 |
|
490 @param aPosition |
|
491 The position. |
|
492 */ |
|
493 void CMMFPtrBuffer::SetPosition (TUint aPosition) |
|
494 {//used for repositioning |
|
495 if (aPosition <= (TUint)iPtr.Length()) |
|
496 iPosition = aPosition; |
|
497 else |
|
498 iPosition = (TUint)iPtr.Length();//tried to position beyond end of data |
|
499 } |
|
500 |
|
501 /** |
|
502 Sets the request size. |
|
503 |
|
504 This method is used in cases where a component (eg. a data source) may not be able |
|
505 or be desirable to write to the entire max length of the buffer (eg. variable bit rate codecs). |
|
506 In this case, the SetRequestSizeL() can be set which can be read by the RequestSize() |
|
507 function in the component so that it knows to only write data upto the requested size |
|
508 and not fill the buffer up to its maximum length. |
|
509 |
|
510 @param aSize |
|
511 The request size. |
|
512 */ |
|
513 void CMMFPtrBuffer::SetRequestSizeL(TInt aSize) |
|
514 { |
|
515 if (aSize < 0) |
|
516 User::Leave(KErrUnderflow); |
|
517 else if (aSize > iPtr.MaxLength()) |
|
518 User::Leave(KErrOverflow); |
|
519 else |
|
520 iRequestSize = aSize; |
|
521 } |
|
522 |
|
523 |
|
524 /** |
|
525 Overriden method to set the status. |
|
526 Resets the data size to 0 when the buffer becomes available. |
|
527 |
|
528 @param aStatus |
|
529 The buffer status. See enum TBufferStatus. |
|
530 */ |
|
531 void CMMFPtrBuffer::SetStatus(TBufferStatus aStatus) |
|
532 { |
|
533 CMMFBuffer::SetStatus(aStatus); |
|
534 if (iStatus == EAvailable) |
|
535 {//need to set size to 0 |
|
536 iPtr.Zero(); |
|
537 } |
|
538 } |
|
539 |
|
540 |
|
541 /** |
|
542 Takes a TPtr8 to pre-allocated memory. |
|
543 |
|
544 @param aPtr |
|
545 The pointer refernce. |
|
546 */ |
|
547 EXPORT_C void CMMFPtrBuffer::SetPtr(const TPtr8& aPtr) |
|
548 { |
|
549 iPtr.Set(aPtr); |
|
550 } |
|
551 |
|
552 |
|
553 //This functions needs updating |
|
554 //should more CMMFDataBuffers be supported in future |
|
555 /** |
|
556 Static method which returns ETrue if the buffer UID is a supported |
|
557 CMMFDataBuffer type. |
|
558 |
|
559 Note: |
|
560 If the buffer is not a CMMFDataBuffer this method should |
|
561 return EFalse. |
|
562 |
|
563 @param aUid |
|
564 The UID of the CMMFBuffer to be checked for support. |
|
565 @return The buffer size. |
|
566 */ |
|
567 EXPORT_C TBool CMMFBuffer::IsSupportedDataBuffer(TUid aUid) |
|
568 { |
|
569 return((aUid == KUidMmfDescriptorBuffer) |
|
570 || (aUid == KUidMmfTransferBuffer) |
|
571 || (aUid == KUidMmfPtrBuffer)); |
|
572 } |
|
573 |
|
574 |
|
575 /** |
|
576 Static method which returns ETrue if the buffer UID is a buffer |
|
577 that is safe to be used with the file server. If the buffer type |
|
578 is not safe to be used with the file server, then the client would |
|
579 need to copy the contents of the buffer, prior to passing it onto |
|
580 the file server. |
|
581 |
|
582 This implementation assumes the CMMFPtrBuffer is safe for file server copy. If this is not the case |
|
583 then remove the PtrBuffer set to ETrue. |
|
584 |
|
585 @param aUid |
|
586 The UID of the CMMFBuffer to be checked for support. |
|
587 |
|
588 @return The buffer size. |
|
589 */ |
|
590 EXPORT_C TBool CMMFBuffer::IsFileServerSafe(TUid aUid) |
|
591 { |
|
592 TBool isFileServerSafe = EFalse; |
|
593 |
|
594 if (aUid == KUidMmfDescriptorBuffer) |
|
595 isFileServerSafe = ETrue; |
|
596 if (aUid == KUidMmfPtrBuffer) //remove this if target CMMFPtrBuffers |
|
597 isFileServerSafe = ETrue; //are not safe for file server copy |
|
598 |
|
599 return isFileServerSafe; |
|
600 } |