Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // source\mmf\server\baseclasses\mmfdatabuffer.cpp
18 #include <mmf/server/mmfdatabuffer.h>
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.
28 @return A pointer to a new CMMFDescriptorBuffer.
30 EXPORT_C CMMFDataBuffer* CMMFDataBuffer::NewL()
32 return CMMFDescriptorBuffer::NewL();
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
42 The size in bytes of the descriptor buffer to be created.
44 @return A pointer to a new CMMFDescriptorBuffer.
46 EXPORT_C CMMFDataBuffer* CMMFDataBuffer::NewL(TInt aMaxBufferSize)
48 return CMMFDescriptorBuffer::NewL(aMaxBufferSize);
53 Method to instantiate a CMMFDescriptorBuffer.
55 Defaults to a CMMFDescriptorBuffer automatically. This NewL creates a CMMFDescriptorBuffer with a
56 default size of 32 bytes.
58 @return A pointer to a new CMMFDescriptorBuffer.
60 EXPORT_C CMMFDescriptorBuffer* CMMFDescriptorBuffer::NewL()
62 CMMFDescriptorBuffer* self = new(ELeave) CMMFDescriptorBuffer;
63 CleanupStack::PushL(self);
64 self->ConstructL(KMMFDataBufferDefaultBufferSize);
65 CleanupStack::Pop(); // self
71 Method to instantiate a CMMFDescriptorBuffer.
72 This NewL creates a CMMFDescriptorBuffer with a size of aMaxBufferSize bytes.
75 The size in bytes of the descriptor buffer to be created.
77 @return A pointer to a new CMMFDescriptorBuffer.
79 EXPORT_C CMMFDescriptorBuffer* CMMFDescriptorBuffer::NewL(TInt aMaxBufferSize)
81 CMMFDescriptorBuffer* self = new(ELeave) CMMFDescriptorBuffer;
82 CleanupStack::PushL(self);
83 self->ConstructL(aMaxBufferSize);
84 CleanupStack::Pop(); // self
94 The size in bytes of the descriptor buffer to be created.
96 void CMMFDescriptorBuffer::ConstructL(TInt aMaxBufferSize)
98 iData = new(ELeave) TUint8[aMaxBufferSize];
99 iPtr.Set(iData, 0, aMaxBufferSize);
105 Destructor also deletes the buffer contained in the CMMFDescriptorBuffer.
107 EXPORT_C CMMFDescriptorBuffer::~CMMFDescriptorBuffer()
113 Reallocates the max size in bytes of a CMMFDescriptorBuffer.
115 @param aMaxBufferSize
116 The new size in bytes of the descriptor buffer.
118 EXPORT_C void CMMFDescriptorBuffer::ReAllocBufferL(TInt aMaxBufferSize)
120 TUint8* tmp = new(ELeave) TUint8[aMaxBufferSize];
123 iPtr.Set(iData, 0, aMaxBufferSize);
127 Returns a descriptor to the data contained in the CMMFDescriptorBuffer.
129 @return A reference to a TPtr containing the CMMFDescriptorBuffer data.
131 TDes8& CMMFDescriptorBuffer::Data()
137 Returns a descriptor to the data contained in the CMMFDescriptorBuffer.
139 @return A const reference to a TPtr containing the CMMFDescriptorBuffer data.
141 const TDesC8& CMMFDescriptorBuffer::Data() const
147 Returns the actual data size (ie. not the maximum length) of the
148 data contained in the CMMFDescriptorBuffer.
150 @return The size in bytes of the data contained in the CMMFDescriptorBuffer.
152 TUint CMMFDescriptorBuffer::BufferSize() const
154 return iPtr.Length();
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.
167 void CMMFDescriptorBuffer::SetPosition (TUint aPosition)
168 {//used for repositioning
169 if (aPosition <= (TUint)iPtr.Length())
170 iPosition = aPosition;
172 iPosition = (TUint)iPtr.Length();//tried to position beyond end of data
176 Sets the request size.
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.
187 void CMMFDescriptorBuffer::SetRequestSizeL(TInt aSize)
190 User::Leave(KErrUnderflow);
191 else if (aSize > iPtr.MaxLength())
192 User::Leave(KErrOverflow);
194 iRequestSize = aSize;
199 Overriden method to set the status and resets the data size to 0 when the buffer becomes available.
202 The buffer status. See TBufferStatus for possible options.
204 void CMMFDescriptorBuffer::SetStatus(TBufferStatus aStatus)
206 CMMFBuffer::SetStatus(aStatus);
207 if ((iStatus == EAvailable)&&iData)
208 {//need to set size to 0
215 This function is not supported under EKA2.
217 Method to instantiate a CMMFTransferBuffer. This NewL creates a CMMFTransferBuffer.
219 @param aTransferWindow
220 This is a valid RTransferWindow that has an RTransferBuffer mapped in.
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
226 @return A pointer to a new CMMFTransferBuffer.
229 EXPORT_C CMMFTransferBuffer* CMMFTransferBuffer::NewL(RTransferWindow& aTransferWindow, TUint aDataLength)
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
241 This method is not supported under EKA2.
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
249 @param aTransferWindow
250 This is a reference to a valid RTransferWindow that has an RTransferBuffer mapped in.
252 The length of the data.
254 void CMMFTransferBuffer::ConstructL(RTransferWindow& aTransferWindow, TUint aDataLength)
256 //this method is not supported under EKA2
257 aTransferWindow = aTransferWindow; //suppressed unused argument warnings
258 aDataLength = aDataLength; //suppressed unused argument warnings
263 CMMFTransferBuffer destructor
265 Destructor maps out RTransferBuffer and closes RTransferWindow.
267 EXPORT_C CMMFTransferBuffer::~CMMFTransferBuffer()
272 Returns a descriptor to the data contained in the CMMFTransferBuffer.
274 @return A reference to a TPtr containing the CMMFTransferBuffer data.
276 TDes8& CMMFTransferBuffer::Data()
282 Returns a descriptor to the data contained in the CMMFTransferBuffer.
284 @return A const reference to a TPtr containing the CMMFTransferBuffer data.
286 const TDesC8& CMMFTransferBuffer::Data() const
292 Returns the actual data size (ie. not the max length) of the
293 data contained in the CMMFTransferBuffer.
295 @return The size in bytes of the data contained in the CMMFTransferBuffer.
297 TUint CMMFTransferBuffer::BufferSize() const
299 return iPtr.Length();
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.
309 Note: The position cannot exceed the size of the actual data not the max length.
314 void CMMFTransferBuffer::SetPosition (TUint aPosition)
315 {//used for repositioning
316 aPosition = aPosition; //suppress compiler warning
320 Sets the request size.
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.
331 void CMMFTransferBuffer::SetRequestSizeL(TInt aSize)
333 aSize = aSize; //suppress compiler warning
338 This function is not supported under EKA2.
340 Returns a reference to the transfer window currently used
341 by the CMMFtransferBuffer.
343 @return A reference to the current RTransferWindow.
345 EXPORT_C RTransferWindow& CMMFTransferBuffer::TransferWindow()
347 return iTransferWindow;
352 This method is not supported under EKA2.
354 Modifies the CMMFTransferBuffer by updating the RTransferWindow.
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.
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.
365 @param aTransferWindow
366 The RTransferWindow to update - can be a new RTransferWindow
367 or the same RTransferWindow with a new RTransferBuffer mapped in.
369 The length of the data.
371 @return An error code indicating if the function call was successful. KErrNone on success, otherwise
372 another of the system-wide error codes.
374 EXPORT_C TInt CMMFTransferBuffer::UpdateTransferWindow(RTransferWindow& aTransferWindow, TUint aDataLength)
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;
383 Maps the buffer out of the transfer window.
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
390 EXPORT_C void CMMFTransferBuffer::MapOutBuffer()
397 Function to instantiate a CMMFPtrBuffer.
398 This NewL creates an unititalised CMMFPtrBuffer.
400 @return A pointer to a new CMMFPtrBuffer.
402 EXPORT_C CMMFPtrBuffer* CMMFPtrBuffer::NewL()
404 CMMFPtrBuffer* self = new(ELeave) CMMFPtrBuffer;
411 Function to instantiate a CMMFPtrBuffer.
412 This NewL creates a CMMFPtrBuffer which owns a TPtr8.
415 A reference to a TPtr containing the CMMFPtrBuffer data.
417 @return A pointer to a new CMMFPtrBuffer.
419 EXPORT_C CMMFPtrBuffer* CMMFPtrBuffer::NewL(const TPtr8& aPtr)
421 CMMFPtrBuffer* self = new(ELeave) CMMFPtrBuffer;
422 CleanupStack::PushL(self);
423 self->ConstructL(aPtr);
424 CleanupStack::Pop(self); // self
431 * Internal ConstructL
432 * @internalTechnology
434 * Reference to a TPtr containing the CMMFPtrBuffer data
436 void CMMFPtrBuffer::ConstructL(const TPtr8& aPtr)
444 Destructor does no deletion, as this buffer class does not own the memory.
446 EXPORT_C CMMFPtrBuffer::~CMMFPtrBuffer()
452 Returns a descriptor to the data contained in the CMMFPtrBuffer.
454 @return A reference to a TPtr containing the CMMFPtrBuffer data.
456 TDes8& CMMFPtrBuffer::Data()
462 Returns a descriptor to the data contained in the CMMFPtrBuffer.
464 @return A const reference to a TPtr containing the CMMFPtrBuffer data.
466 const TDesC8& CMMFPtrBuffer::Data() const
472 Returns the actual data size (ie. not the max length) of the
473 data contained in the CMMFPtrBuffer.
475 @return The size in bytes of the data contained in the CMMFPtrBuffer.
477 TUint CMMFPtrBuffer::BufferSize() const
479 return iPtr.Length();
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.
488 Note: The position cannot exceed the size of the actual data not the maximum length.
493 void CMMFPtrBuffer::SetPosition (TUint aPosition)
494 {//used for repositioning
495 if (aPosition <= (TUint)iPtr.Length())
496 iPosition = aPosition;
498 iPosition = (TUint)iPtr.Length();//tried to position beyond end of data
502 Sets the request size.
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.
513 void CMMFPtrBuffer::SetRequestSizeL(TInt aSize)
516 User::Leave(KErrUnderflow);
517 else if (aSize > iPtr.MaxLength())
518 User::Leave(KErrOverflow);
520 iRequestSize = aSize;
525 Overriden method to set the status.
526 Resets the data size to 0 when the buffer becomes available.
529 The buffer status. See enum TBufferStatus.
531 void CMMFPtrBuffer::SetStatus(TBufferStatus aStatus)
533 CMMFBuffer::SetStatus(aStatus);
534 if (iStatus == EAvailable)
535 {//need to set size to 0
542 Takes a TPtr8 to pre-allocated memory.
545 The pointer refernce.
547 EXPORT_C void CMMFPtrBuffer::SetPtr(const TPtr8& aPtr)
553 //This functions needs updating
554 //should more CMMFDataBuffers be supported in future
556 Static method which returns ETrue if the buffer UID is a supported
560 If the buffer is not a CMMFDataBuffer this method should
564 The UID of the CMMFBuffer to be checked for support.
565 @return The buffer size.
567 EXPORT_C TBool CMMFBuffer::IsSupportedDataBuffer(TUid aUid)
569 return((aUid == KUidMmfDescriptorBuffer)
570 || (aUid == KUidMmfTransferBuffer)
571 || (aUid == KUidMmfPtrBuffer));
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
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.
586 The UID of the CMMFBuffer to be checked for support.
588 @return The buffer size.
590 EXPORT_C TBool CMMFBuffer::IsFileServerSafe(TUid aUid)
592 TBool isFileServerSafe = EFalse;
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
599 return isFileServerSafe;