1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmlibs/mmfw/src/server/BaseClasses/mmfdatabuffer.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,600 @@
1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// source\mmf\server\baseclasses\mmfdatabuffer.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include <mmf/server/mmfdatabuffer.h>
1.22 +
1.23 +
1.24 +
1.25 +
1.26 +/**
1.27 +Method to instantiate a CMMFDataBuffer defaults to a CMMFDescriptorBuffer
1.28 +to maintain buffer compatiblity with MFAD ie. instantiating a CMMFDataBuffer defaults to creating
1.29 +a CMMFDescriptorBuffer. This NewL creates a CMMFDescriptorBuffer with a default size of 32 bytes.
1.30 +
1.31 +@return A pointer to a new CMMFDescriptorBuffer.
1.32 +*/
1.33 +EXPORT_C CMMFDataBuffer* CMMFDataBuffer::NewL()
1.34 + {
1.35 + return CMMFDescriptorBuffer::NewL();
1.36 + }
1.37 +
1.38 +/**
1.39 +Method to instantiate a CMMFDataBuffer defaults to a CMMFDescriptorBuffer by default
1.40 +to maintain buffer compatiblity with MFAD ie. instantiating a CMMFDataBuffer defaults to
1.41 +creating a CMMFDescriptorBuffer. This NewL creates a CMMFDescriptorBuffer with a size of
1.42 +aMaxBufferSize bytes.
1.43 +
1.44 +@param aMaxBufferSize
1.45 + The size in bytes of the descriptor buffer to be created.
1.46 +
1.47 +@return A pointer to a new CMMFDescriptorBuffer.
1.48 +*/
1.49 +EXPORT_C CMMFDataBuffer* CMMFDataBuffer::NewL(TInt aMaxBufferSize)
1.50 + {
1.51 + return CMMFDescriptorBuffer::NewL(aMaxBufferSize);
1.52 + }
1.53 +
1.54 +
1.55 +/**
1.56 +Method to instantiate a CMMFDescriptorBuffer.
1.57 +
1.58 +Defaults to a CMMFDescriptorBuffer automatically. This NewL creates a CMMFDescriptorBuffer with a
1.59 +default size of 32 bytes.
1.60 +
1.61 +@return A pointer to a new CMMFDescriptorBuffer.
1.62 +*/
1.63 +EXPORT_C CMMFDescriptorBuffer* CMMFDescriptorBuffer::NewL()
1.64 + {
1.65 + CMMFDescriptorBuffer* self = new(ELeave) CMMFDescriptorBuffer;
1.66 + CleanupStack::PushL(self);
1.67 + self->ConstructL(KMMFDataBufferDefaultBufferSize);
1.68 + CleanupStack::Pop(); // self
1.69 + return self;
1.70 + }
1.71 +
1.72 +
1.73 +/**
1.74 +Method to instantiate a CMMFDescriptorBuffer.
1.75 +This NewL creates a CMMFDescriptorBuffer with a size of aMaxBufferSize bytes.
1.76 +
1.77 +@param aMaxBufferSize
1.78 + The size in bytes of the descriptor buffer to be created.
1.79 +
1.80 +@return A pointer to a new CMMFDescriptorBuffer.
1.81 +*/
1.82 +EXPORT_C CMMFDescriptorBuffer* CMMFDescriptorBuffer::NewL(TInt aMaxBufferSize)
1.83 + {
1.84 + CMMFDescriptorBuffer* self = new(ELeave) CMMFDescriptorBuffer;
1.85 + CleanupStack::PushL(self);
1.86 + self->ConstructL(aMaxBufferSize);
1.87 + CleanupStack::Pop(); // self
1.88 + return self;
1.89 + }
1.90 +
1.91 +/**
1.92 +@internalTechnology
1.93 +
1.94 +Internal.
1.95 +
1.96 +@param aMaxBufferSize
1.97 + The size in bytes of the descriptor buffer to be created.
1.98 +*/
1.99 +void CMMFDescriptorBuffer::ConstructL(TInt aMaxBufferSize)
1.100 + {
1.101 + iData = new(ELeave) TUint8[aMaxBufferSize];
1.102 + iPtr.Set(iData, 0, aMaxBufferSize);
1.103 + }
1.104 +
1.105 +/**
1.106 +Destructor.
1.107 +
1.108 +Destructor also deletes the buffer contained in the CMMFDescriptorBuffer.
1.109 +*/
1.110 +EXPORT_C CMMFDescriptorBuffer::~CMMFDescriptorBuffer()
1.111 + {
1.112 + delete[] iData;
1.113 + }
1.114 +
1.115 +/**
1.116 +Reallocates the max size in bytes of a CMMFDescriptorBuffer.
1.117 +
1.118 +@param aMaxBufferSize
1.119 + The new size in bytes of the descriptor buffer.
1.120 +*/
1.121 +EXPORT_C void CMMFDescriptorBuffer::ReAllocBufferL(TInt aMaxBufferSize)
1.122 + {
1.123 + TUint8* tmp = new(ELeave) TUint8[aMaxBufferSize];
1.124 + delete[] iData;
1.125 + iData = tmp;
1.126 + iPtr.Set(iData, 0, aMaxBufferSize);
1.127 + }
1.128 +
1.129 +/**
1.130 +Returns a descriptor to the data contained in the CMMFDescriptorBuffer.
1.131 +
1.132 +@return A reference to a TPtr containing the CMMFDescriptorBuffer data.
1.133 +*/
1.134 +TDes8& CMMFDescriptorBuffer::Data()
1.135 + {
1.136 + return iPtr;
1.137 + }
1.138 +
1.139 +/**
1.140 +Returns a descriptor to the data contained in the CMMFDescriptorBuffer.
1.141 +
1.142 +@return A const reference to a TPtr containing the CMMFDescriptorBuffer data.
1.143 +*/
1.144 +const TDesC8& CMMFDescriptorBuffer::Data() const
1.145 + {
1.146 + return iPtr;
1.147 + }
1.148 +
1.149 +/**
1.150 +Returns the actual data size (ie. not the maximum length) of the
1.151 +data contained in the CMMFDescriptorBuffer.
1.152 +
1.153 +@return The size in bytes of the data contained in the CMMFDescriptorBuffer.
1.154 +*/
1.155 +TUint CMMFDescriptorBuffer::BufferSize() const
1.156 + {
1.157 + return iPtr.Length();
1.158 + }
1.159 +
1.160 +/**
1.161 +Sets the position.
1.162 +
1.163 +This method is used by components (eg codecs) which read data from a buffer
1.164 +and wish to store a read position marker for further reads.
1.165 +Note: The position cannot exceed the size of the actual data not the max length.
1.166 +
1.167 +@param aPosition
1.168 + The position.
1.169 +*/
1.170 +void CMMFDescriptorBuffer::SetPosition (TUint aPosition)
1.171 + {//used for repositioning
1.172 + if (aPosition <= (TUint)iPtr.Length())
1.173 + iPosition = aPosition;
1.174 + else
1.175 + iPosition = (TUint)iPtr.Length();//tried to position beyond end of data
1.176 + }
1.177 +
1.178 +/**
1.179 +Sets the request size.
1.180 +
1.181 +This function is used in cases where a component (eg a data source) may not be able
1.182 +or be desirable to write to the entire max length of the buffer (eg variable bit rate codecs).
1.183 +In which case the SetRequestSizeL() can be set which can be read by the RequestSize()
1.184 +function in the component so that it knows to only write data upto the request size
1.185 +and not fill the buffer up to its max length.
1.186 +
1.187 +@param aSize
1.188 + The request size.
1.189 +*/
1.190 +void CMMFDescriptorBuffer::SetRequestSizeL(TInt aSize)
1.191 + {
1.192 + if (aSize < 0)
1.193 + User::Leave(KErrUnderflow);
1.194 + else if (aSize > iPtr.MaxLength())
1.195 + User::Leave(KErrOverflow);
1.196 + else
1.197 + iRequestSize = aSize;
1.198 + }
1.199 +
1.200 +
1.201 +/**
1.202 +Overriden method to set the status and resets the data size to 0 when the buffer becomes available.
1.203 +
1.204 +@param aStatus
1.205 + The buffer status. See TBufferStatus for possible options.
1.206 +*/
1.207 +void CMMFDescriptorBuffer::SetStatus(TBufferStatus aStatus)
1.208 + {
1.209 + CMMFBuffer::SetStatus(aStatus);
1.210 + if ((iStatus == EAvailable)&&iData)
1.211 + {//need to set size to 0
1.212 + iPtr.Zero();
1.213 + }
1.214 + }
1.215 +
1.216 +
1.217 +/**
1.218 +This function is not supported under EKA2.
1.219 +
1.220 +Method to instantiate a CMMFTransferBuffer. This NewL creates a CMMFTransferBuffer.
1.221 +
1.222 +@param aTransferWindow
1.223 + This is a valid RTransferWindow that has an RTransferBuffer mapped in.
1.224 +@param aDataLength
1.225 + This parameter sets the length of the actual data present in the transferbuffer.
1.226 + This is because the length of actual data may be less than the length of the mapped in
1.227 + transfer buffer.
1.228 +
1.229 +@return A pointer to a new CMMFTransferBuffer.
1.230 +*/
1.231 +
1.232 +EXPORT_C CMMFTransferBuffer* CMMFTransferBuffer::NewL(RTransferWindow& aTransferWindow, TUint aDataLength)
1.233 + {
1.234 +//this method is not supported under EKA2
1.235 + User::Panic(_L("Not supported!"), KErrNotSupported);
1.236 + aTransferWindow = aTransferWindow; //suppressed unused argument warnings
1.237 + aDataLength = aDataLength; //suppressed unused argument warnings
1.238 + return NULL; //can't construct anything useful
1.239 + }
1.240 +
1.241 +/**
1.242 +@internalTechnology
1.243 +
1.244 +This method is not supported under EKA2.
1.245 +
1.246 +Internal ConstructL.
1.247 +
1.248 +Note this method checks if a transfer buffer has been mapped in and
1.249 +will leave with KErrNotReady if the RTransferWindow does not have a mapped
1.250 +in RTransferBuffer.
1.251 +
1.252 +@param aTransferWindow
1.253 + This is a reference to a valid RTransferWindow that has an RTransferBuffer mapped in.
1.254 +@param aDataLength
1.255 + The length of the data.
1.256 +*/
1.257 +void CMMFTransferBuffer::ConstructL(RTransferWindow& aTransferWindow, TUint aDataLength)
1.258 + {
1.259 +//this method is not supported under EKA2
1.260 + aTransferWindow = aTransferWindow; //suppressed unused argument warnings
1.261 + aDataLength = aDataLength; //suppressed unused argument warnings
1.262 + }
1.263 +
1.264 +
1.265 +/**
1.266 +CMMFTransferBuffer destructor
1.267 +
1.268 +Destructor maps out RTransferBuffer and closes RTransferWindow.
1.269 +*/
1.270 +EXPORT_C CMMFTransferBuffer::~CMMFTransferBuffer()
1.271 + {
1.272 + }
1.273 +
1.274 +/**
1.275 +Returns a descriptor to the data contained in the CMMFTransferBuffer.
1.276 +
1.277 +@return A reference to a TPtr containing the CMMFTransferBuffer data.
1.278 +*/
1.279 +TDes8& CMMFTransferBuffer::Data()
1.280 + {
1.281 + return iPtr;
1.282 + }
1.283 +
1.284 +/**
1.285 +Returns a descriptor to the data contained in the CMMFTransferBuffer.
1.286 +
1.287 +@return A const reference to a TPtr containing the CMMFTransferBuffer data.
1.288 +*/
1.289 +const TDesC8& CMMFTransferBuffer::Data() const
1.290 + {
1.291 + return iPtr;
1.292 + }
1.293 +
1.294 +/**
1.295 +Returns the actual data size (ie. not the max length) of the
1.296 +data contained in the CMMFTransferBuffer.
1.297 +
1.298 +@return The size in bytes of the data contained in the CMMFTransferBuffer.
1.299 +*/
1.300 +TUint CMMFTransferBuffer::BufferSize() const
1.301 + {
1.302 + return iPtr.Length();
1.303 + }
1.304 +
1.305 +
1.306 +/**
1.307 +Sets the position.
1.308 +
1.309 +This method is used by components (eg codecs) which read data from a buffer
1.310 +and wish to store a read position marker for further reads.
1.311 +
1.312 +Note: The position cannot exceed the size of the actual data not the max length.
1.313 +
1.314 +@param aPosition
1.315 + The position.
1.316 +*/
1.317 +void CMMFTransferBuffer::SetPosition (TUint aPosition)
1.318 + {//used for repositioning
1.319 + aPosition = aPosition; //suppress compiler warning
1.320 + }
1.321 +
1.322 +/**
1.323 +Sets the request size.
1.324 +
1.325 +This function is used in cases where a component (eg. a data source) may not be able
1.326 +or be desirable to write to the entire max length of the buffer (eg. variable bit rate codecs).
1.327 +In this case, the SetRequestSizeL can be set which can be read by the RequestSize()
1.328 +function in the component so that it knows to only write data upto the request size
1.329 +and not fill the buffer up to its max length.
1.330 +
1.331 +@param aSize
1.332 + The request size.
1.333 +*/
1.334 +void CMMFTransferBuffer::SetRequestSizeL(TInt aSize)
1.335 + {
1.336 + aSize = aSize; //suppress compiler warning
1.337 + }
1.338 +
1.339 +
1.340 +/**
1.341 +This function is not supported under EKA2.
1.342 +
1.343 +Returns a reference to the transfer window currently used
1.344 +by the CMMFtransferBuffer.
1.345 +
1.346 +@return A reference to the current RTransferWindow.
1.347 +*/
1.348 +EXPORT_C RTransferWindow& CMMFTransferBuffer::TransferWindow()
1.349 + {
1.350 + return iTransferWindow;
1.351 + }
1.352 +
1.353 +
1.354 +/**
1.355 +This method is not supported under EKA2.
1.356 +
1.357 +Modifies the CMMFTransferBuffer by updating the RTransferWindow.
1.358 +
1.359 +This method is used if the same CMMFTransferBuffer is used throughout
1.360 +eg. if a single CMMFTransferBuffer is created upfront but a different
1.361 +transfer window (or the same transfer window with a different buffer mapped in
1.362 +is used). That is the same CMMFTransferBuffer but the actrual buffer may be different.
1.363 +
1.364 +Note: If the updated RTransferWindow is new, then the old buffer must
1.365 +be mapped out first by a call to CMMFTransferBuffer::MapOutBuffer() and the
1.366 +RtransferWindow handle closed outside the CMMFTransferBuffer.
1.367 +
1.368 +@param aTransferWindow
1.369 + The RTransferWindow to update - can be a new RTransferWindow
1.370 + or the same RTransferWindow with a new RTransferBuffer mapped in.
1.371 +@param aDataLength
1.372 + The length of the data.
1.373 +
1.374 +@return An error code indicating if the function call was successful. KErrNone on success, otherwise
1.375 + another of the system-wide error codes.
1.376 +*/
1.377 +EXPORT_C TInt CMMFTransferBuffer::UpdateTransferWindow(RTransferWindow& aTransferWindow, TUint aDataLength)
1.378 + {
1.379 +//this method is not supported under EKA2
1.380 + aTransferWindow = aTransferWindow; //suppressed unused argument warnings
1.381 + aDataLength = aDataLength; //suppressed unused argument warnings
1.382 + return KErrNotSupported;
1.383 + }
1.384 +
1.385 +/**
1.386 +Maps the buffer out of the transfer window.
1.387 +
1.388 +This method should be called in preference to
1.389 +calling MapOutBuffer directly on the RtransferWindow
1.390 +so that the CMMFTransferBuffer knows that it is no longer
1.391 +available.
1.392 +*/
1.393 +EXPORT_C void CMMFTransferBuffer::MapOutBuffer()
1.394 + {
1.395 + }
1.396 +
1.397 +
1.398 +
1.399 +/**
1.400 +Function to instantiate a CMMFPtrBuffer.
1.401 +This NewL creates an unititalised CMMFPtrBuffer.
1.402 +
1.403 +@return A pointer to a new CMMFPtrBuffer.
1.404 +*/
1.405 +EXPORT_C CMMFPtrBuffer* CMMFPtrBuffer::NewL()
1.406 + {
1.407 + CMMFPtrBuffer* self = new(ELeave) CMMFPtrBuffer;
1.408 +
1.409 + return self;
1.410 + }
1.411 +
1.412 +
1.413 +/**
1.414 +Function to instantiate a CMMFPtrBuffer.
1.415 +This NewL creates a CMMFPtrBuffer which owns a TPtr8.
1.416 +
1.417 +@param aPtr
1.418 + A reference to a TPtr containing the CMMFPtrBuffer data.
1.419 +
1.420 +@return A pointer to a new CMMFPtrBuffer.
1.421 +*/
1.422 +EXPORT_C CMMFPtrBuffer* CMMFPtrBuffer::NewL(const TPtr8& aPtr)
1.423 + {
1.424 + CMMFPtrBuffer* self = new(ELeave) CMMFPtrBuffer;
1.425 + CleanupStack::PushL(self);
1.426 + self->ConstructL(aPtr);
1.427 + CleanupStack::Pop(self); // self
1.428 + return self;
1.429 + }
1.430 +
1.431 +/**
1.432 + * ConstructL
1.433 + *
1.434 + * Internal ConstructL
1.435 + * @internalTechnology
1.436 + * @param "aPtr"
1.437 + * Reference to a TPtr containing the CMMFPtrBuffer data
1.438 + */
1.439 +void CMMFPtrBuffer::ConstructL(const TPtr8& aPtr)
1.440 + {
1.441 + iPtr.Set(aPtr);
1.442 + }
1.443 +
1.444 +/**
1.445 +Destructor.
1.446 +
1.447 +Destructor does no deletion, as this buffer class does not own the memory.
1.448 +*/
1.449 +EXPORT_C CMMFPtrBuffer::~CMMFPtrBuffer()
1.450 + {
1.451 +
1.452 + }
1.453 +
1.454 +/**
1.455 +Returns a descriptor to the data contained in the CMMFPtrBuffer.
1.456 +
1.457 +@return A reference to a TPtr containing the CMMFPtrBuffer data.
1.458 +*/
1.459 +TDes8& CMMFPtrBuffer::Data()
1.460 + {
1.461 + return iPtr;
1.462 + }
1.463 +
1.464 +/**
1.465 +Returns a descriptor to the data contained in the CMMFPtrBuffer.
1.466 +
1.467 +@return A const reference to a TPtr containing the CMMFPtrBuffer data.
1.468 +*/
1.469 +const TDesC8& CMMFPtrBuffer::Data() const
1.470 + {
1.471 + return iPtr;
1.472 + }
1.473 +
1.474 +/**
1.475 +Returns the actual data size (ie. not the max length) of the
1.476 +data contained in the CMMFPtrBuffer.
1.477 +
1.478 +@return The size in bytes of the data contained in the CMMFPtrBuffer.
1.479 +*/
1.480 +TUint CMMFPtrBuffer::BufferSize() const
1.481 + {
1.482 + return iPtr.Length();
1.483 + }
1.484 +
1.485 +/**
1.486 +Sets the position.
1.487 +
1.488 +This function is used by components (eg. codecs) which read data from a buffer
1.489 +and wish to store a read position marker for further reads.
1.490 +
1.491 +Note: The position cannot exceed the size of the actual data not the maximum length.
1.492 +
1.493 +@param aPosition
1.494 + The position.
1.495 +*/
1.496 +void CMMFPtrBuffer::SetPosition (TUint aPosition)
1.497 + {//used for repositioning
1.498 + if (aPosition <= (TUint)iPtr.Length())
1.499 + iPosition = aPosition;
1.500 + else
1.501 + iPosition = (TUint)iPtr.Length();//tried to position beyond end of data
1.502 + }
1.503 +
1.504 +/**
1.505 +Sets the request size.
1.506 +
1.507 +This method is used in cases where a component (eg. a data source) may not be able
1.508 +or be desirable to write to the entire max length of the buffer (eg. variable bit rate codecs).
1.509 +In this case, the SetRequestSizeL() can be set which can be read by the RequestSize()
1.510 +function in the component so that it knows to only write data upto the requested size
1.511 +and not fill the buffer up to its maximum length.
1.512 +
1.513 +@param aSize
1.514 + The request size.
1.515 +*/
1.516 +void CMMFPtrBuffer::SetRequestSizeL(TInt aSize)
1.517 + {
1.518 + if (aSize < 0)
1.519 + User::Leave(KErrUnderflow);
1.520 + else if (aSize > iPtr.MaxLength())
1.521 + User::Leave(KErrOverflow);
1.522 + else
1.523 + iRequestSize = aSize;
1.524 + }
1.525 +
1.526 +
1.527 +/**
1.528 +Overriden method to set the status.
1.529 +Resets the data size to 0 when the buffer becomes available.
1.530 +
1.531 +@param aStatus
1.532 + The buffer status. See enum TBufferStatus.
1.533 +*/
1.534 +void CMMFPtrBuffer::SetStatus(TBufferStatus aStatus)
1.535 + {
1.536 + CMMFBuffer::SetStatus(aStatus);
1.537 + if (iStatus == EAvailable)
1.538 + {//need to set size to 0
1.539 + iPtr.Zero();
1.540 + }
1.541 + }
1.542 +
1.543 +
1.544 +/**
1.545 +Takes a TPtr8 to pre-allocated memory.
1.546 +
1.547 +@param aPtr
1.548 + The pointer refernce.
1.549 +*/
1.550 +EXPORT_C void CMMFPtrBuffer::SetPtr(const TPtr8& aPtr)
1.551 + {
1.552 + iPtr.Set(aPtr);
1.553 + }
1.554 +
1.555 +
1.556 +//This functions needs updating
1.557 +//should more CMMFDataBuffers be supported in future
1.558 +/**
1.559 +Static method which returns ETrue if the buffer UID is a supported
1.560 +CMMFDataBuffer type.
1.561 +
1.562 +Note:
1.563 +If the buffer is not a CMMFDataBuffer this method should
1.564 +return EFalse.
1.565 +
1.566 +@param aUid
1.567 + The UID of the CMMFBuffer to be checked for support.
1.568 +@return The buffer size.
1.569 +*/
1.570 +EXPORT_C TBool CMMFBuffer::IsSupportedDataBuffer(TUid aUid)
1.571 + {
1.572 + return((aUid == KUidMmfDescriptorBuffer)
1.573 + || (aUid == KUidMmfTransferBuffer)
1.574 + || (aUid == KUidMmfPtrBuffer));
1.575 + }
1.576 +
1.577 +
1.578 +/**
1.579 +Static method which returns ETrue if the buffer UID is a buffer
1.580 +that is safe to be used with the file server. If the buffer type
1.581 +is not safe to be used with the file server, then the client would
1.582 +need to copy the contents of the buffer, prior to passing it onto
1.583 +the file server.
1.584 +
1.585 +This implementation assumes the CMMFPtrBuffer is safe for file server copy. If this is not the case
1.586 +then remove the PtrBuffer set to ETrue.
1.587 +
1.588 +@param aUid
1.589 + The UID of the CMMFBuffer to be checked for support.
1.590 +
1.591 +@return The buffer size.
1.592 +*/
1.593 +EXPORT_C TBool CMMFBuffer::IsFileServerSafe(TUid aUid)
1.594 + {
1.595 + TBool isFileServerSafe = EFalse;
1.596 +
1.597 + if (aUid == KUidMmfDescriptorBuffer)
1.598 + isFileServerSafe = ETrue;
1.599 + if (aUid == KUidMmfPtrBuffer) //remove this if target CMMFPtrBuffers
1.600 + isFileServerSafe = ETrue; //are not safe for file server copy
1.601 +
1.602 + return isFileServerSafe;
1.603 + }