1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmdevicefw/mdf/src/codecapi/codecapiresolverdata.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,295 @@
1.4 +// Copyright (c) 2005-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 +//
1.18 +
1.19 +#include <s32mem.h>
1.20 +#include <mdf/codecapiresolverdata.h>
1.21 +// The biggest descriptor that will be built when internalizing the object
1.22 +const TInt KMaxDescriptorLength = 128;
1.23 +
1.24 +/**
1.25 + Default constructor.
1.26 + */
1.27 +CCodecApiResolverData::CCodecApiResolverData()
1.28 + {
1.29 + }
1.30 +
1.31 +
1.32 +/**
1.33 + Destructor.
1.34 + */
1.35 +CCodecApiResolverData::~CCodecApiResolverData()
1.36 + {
1.37 + delete iInputDataFormat;
1.38 + delete iOutputDataFormat;
1.39 + }
1.40 +
1.41 +
1.42 +/**
1.43 + Creates a new CodedApiResolverStandard object.
1.44 + @return A pointer to the newly constructed object.
1.45 + */
1.46 +EXPORT_C CCodecApiResolverData* CCodecApiResolverData::NewL()
1.47 + {
1.48 + CCodecApiResolverData* self = new(ELeave) CCodecApiResolverData;
1.49 + return self;
1.50 + }
1.51 +
1.52 +
1.53 +/**
1.54 + Creates a new CodedApiResolverStandard object.
1.55 + @param aPackage
1.56 + A reference to a descriptor created using <code>PackL()</code>
1.57 + used to initialize the object.
1.58 + @return A pointer to the newly constructed object.
1.59 + */
1.60 +EXPORT_C CCodecApiResolverData* CCodecApiResolverData::NewL(const TDesC8& aPackage)
1.61 + {
1.62 + CCodecApiResolverData* self = CCodecApiResolverData::NewLC(aPackage);
1.63 + CleanupStack::Pop(self);
1.64 + return self;
1.65 + }
1.66 +
1.67 +
1.68 +/**
1.69 + Creates a new CodedApiResolverStandard object and leaves a pointer to it on the cleanup stack.
1.70 + @return A pointer to the newly constructed object.
1.71 + */
1.72 +EXPORT_C CCodecApiResolverData* CCodecApiResolverData::NewLC()
1.73 + {
1.74 + CCodecApiResolverData* self = CCodecApiResolverData::NewL();
1.75 + CleanupStack::PushL(self);
1.76 + return self;
1.77 + }
1.78 +
1.79 +
1.80 +/**
1.81 + Creates a new CodedApiResolverStandard object and leaves a pointer to it on the cleanup stack.
1.82 + @param aPackage
1.83 + A reference to a descriptor created using <code>PackL()</code>
1.84 + used to initialize the object.
1.85 + @return A pointer to the newly constructed match data object.
1.86 + */
1.87 +EXPORT_C CCodecApiResolverData* CCodecApiResolverData::NewLC(const TDesC8& aPackage)
1.88 + {
1.89 + CCodecApiResolverData* self = new(ELeave) CCodecApiResolverData;
1.90 + CleanupStack::PushL(self);
1.91 + self->ConstructL(aPackage);
1.92 + return self;
1.93 + }
1.94 +
1.95 +
1.96 +/**
1.97 + Sets up the data inside the class by calling <code>UnPackL()</code>.
1.98 + @param aPackage
1.99 + A reference to the data that will be contained by this class.
1.100 + */
1.101 +void CCodecApiResolverData::ConstructL(const TDesC8& aPackage)
1.102 + {
1.103 + UnPackL(aPackage);
1.104 + }
1.105 +
1.106 +
1.107 +/**
1.108 + Externalizes the object to a stream.
1.109 + All the member variables will be written to the stream.
1.110 + @param aStream
1.111 + A reference to the stream to which the member variables will
1.112 + be written.
1.113 + */
1.114 + void CCodecApiResolverData::ExternalizeL(RWriteStream& aStream) const
1.115 + {
1.116 + aStream.WriteInt32L(iMatchType);
1.117 + aStream.WriteInt32L(iImplementationType.iUid);
1.118 +
1.119 + aStream << InputDataFormat();
1.120 + aStream << OutputDataFormat();
1.121 + }
1.122 +
1.123 +
1.124 +/**
1.125 + Internalizes the object from a stream.
1.126 + All the member variables will be read from the streamed.
1.127 + @param aStream
1.128 + A reference to the stream from which data will be read to
1.129 + setup the member variables.
1.130 + */
1.131 +void CCodecApiResolverData::InternalizeL(RReadStream& aStream)
1.132 + {
1.133 + iMatchType = static_cast<TCodecApiResolverMatchType>(aStream.ReadInt32L());
1.134 + iImplementationType.iUid = aStream.ReadInt32L();
1.135 +
1.136 + delete iInputDataFormat;
1.137 + iInputDataFormat = NULL;
1.138 + iInputDataFormat = HBufC8::NewL(aStream,KMaxDescriptorLength); //KErrOverflow
1.139 +
1.140 + delete iOutputDataFormat;
1.141 + iOutputDataFormat = NULL;
1.142 + iOutputDataFormat = HBufC8::NewL(aStream,KMaxDescriptorLength); //KErrOverflow
1.143 + }
1.144 +
1.145 +
1.146 +/**
1.147 + Sets the match type to match against.
1.148 + @param aMatchType
1.149 + The type of match requested.
1.150 + */
1.151 +EXPORT_C void CCodecApiResolverData::SetMatchType(const TCodecApiResolverMatchType& aMatchType)
1.152 + {
1.153 + iMatchType = aMatchType;
1.154 + }
1.155 +
1.156 +
1.157 +/**
1.158 + Sets the implementation type to match against.
1.159 + @param aImplementationType
1.160 + The implementation uid of a specific codec to match against.
1.161 + */
1.162 +EXPORT_C void CCodecApiResolverData::SetImplementationType(const TUid& aImplementationType)
1.163 + {
1.164 + iImplementationType = aImplementationType;
1.165 + }
1.166 +
1.167 +
1.168 +/**
1.169 + Sets the input data type to match against.
1.170 + @param aDataType
1.171 + The input data type of a codec to match against.
1.172 + */
1.173 +EXPORT_C void CCodecApiResolverData::SetInputDataL(const TDesC8& aDataType)
1.174 + {
1.175 + delete iInputDataFormat;
1.176 + iInputDataFormat = NULL;
1.177 + iInputDataFormat = aDataType.AllocL();
1.178 + }
1.179 +
1.180 +
1.181 +/**
1.182 + Sets the output data type to match against.
1.183 + @param aDataType
1.184 + The output data type of a codec to match against.
1.185 + */
1.186 +EXPORT_C void CCodecApiResolverData::SetOutputDataL(const TDesC8& aDataType)
1.187 + {
1.188 + delete iOutputDataFormat;
1.189 + iOutputDataFormat = NULL;
1.190 + iOutputDataFormat = aDataType.AllocL();
1.191 + }
1.192 +
1.193 +
1.194 +/**
1.195 + Retrieves the match type to match against.
1.196 + @return The type of match requested.
1.197 + */
1.198 +EXPORT_C TCodecApiResolverMatchType CCodecApiResolverData::MatchType() const
1.199 + {
1.200 + return iMatchType;
1.201 + }
1.202 +
1.203 +
1.204 +/**
1.205 + Retrieves the implementation type to match against.
1.206 + @return The implementation of a specific codec to match against.
1.207 + */
1.208 +EXPORT_C TUid CCodecApiResolverData::ImplementationType() const
1.209 + {
1.210 + return iImplementationType;
1.211 + }
1.212 +
1.213 +
1.214 +
1.215 +/**
1.216 + Retrieves the input data format string to match against. If no string is set
1.217 + a null descriptor is returned.
1.218 + @return The string to match against.
1.219 + */
1.220 +EXPORT_C const TPtrC8 CCodecApiResolverData::InputDataFormat() const
1.221 + {
1.222 + TPtrC8 result;
1.223 + if(iInputDataFormat)
1.224 + {
1.225 + result.Set(*iInputDataFormat);
1.226 + }
1.227 + else
1.228 + {
1.229 + result.Set(KNullDesC8);
1.230 + }
1.231 + return result;
1.232 + }
1.233 +
1.234 +
1.235 +/**
1.236 + Retrieves the output data format string to match against. If no string is set
1.237 + a null descriptor is returned.
1.238 + @return The string to match against.
1.239 + */
1.240 +EXPORT_C const TPtrC8 CCodecApiResolverData::OutputDataFormat() const
1.241 + {
1.242 + TPtrC8 result;
1.243 + if(iOutputDataFormat)
1.244 + {
1.245 + result.Set(*iOutputDataFormat);
1.246 + }
1.247 + else
1.248 + {
1.249 + result.Set(KNullDesC8);
1.250 + }
1.251 + return result;
1.252 + }
1.253 +
1.254 +
1.255 +
1.256 +
1.257 +/**
1.258 + Packages the object up into a descriptor.
1.259 + @return A pointer to a desctriptor with the object packed in it.
1.260 + */
1.261 +EXPORT_C HBufC8* CCodecApiResolverData::NewPackLC() const
1.262 + {
1.263 + //Calculate the size necessary size for the descriptor to pack the object
1.264 + TInt size = 0;
1.265 + size = sizeof(iMatchType) + sizeof(iImplementationType.iUid) + 2*sizeof(TInt32);
1.266 + // the operator << write first the length of the string so we need to add it to the total size
1.267 + if(iInputDataFormat)
1.268 + {
1.269 + size += iInputDataFormat->Size();
1.270 + }
1.271 + if(iOutputDataFormat)
1.272 + {
1.273 + size += iOutputDataFormat->Size();
1.274 + }
1.275 +
1.276 + HBufC8* package = HBufC8::NewLC(size);
1.277 + TPtr8 packageDes = package->Des();
1.278 + RDesWriteStream stream(packageDes);
1.279 + CleanupClosePushL(stream);
1.280 + ExternalizeL(stream);
1.281 + CleanupStack::PopAndDestroy(&stream);
1.282 + return package;
1.283 + }
1.284 +
1.285 +
1.286 +
1.287 +/**
1.288 + Unpacks a packed descriptor.
1.289 + @param aPackage
1.290 + A reference to a desctriptor created.
1.291 + */
1.292 +EXPORT_C void CCodecApiResolverData::UnPackL(const TDesC8& aPackage)
1.293 + {
1.294 + RDesReadStream stream(aPackage);
1.295 + CleanupClosePushL(stream);
1.296 + InternalizeL(stream);
1.297 + CleanupStack::PopAndDestroy(&stream);
1.298 + }