imagingandcamerafws/imagingfws/ImageDisplay/src/Resolver/ImageDisplayResolverAPI.cpp
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     1 /*
       
     2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 /**    @file
       
    19    @internalComponent */
       
    20 #include <s32mem.h>
       
    21 #include "ImageDisplayResolverAPI.h"
       
    22 
       
    23 const TInt KMaxDescriptorLength = 128;	// The biggest descriptor that will be
       
    24 										// built when internalizing the object
       
    25 
       
    26 /**
       
    27  *
       
    28  * Default constructor
       
    29  *
       
    30  */
       
    31 CCustomMatchData::CCustomMatchData()
       
    32 	{
       
    33 	}
       
    34 
       
    35 /**
       
    36  *
       
    37  * Default destructor
       
    38  *
       
    39  */
       
    40 CCustomMatchData::~CCustomMatchData()
       
    41 	{
       
    42 	delete iMatchString;
       
    43 	delete iFileSuffix;
       
    44 	}
       
    45 
       
    46 /**
       
    47  *
       
    48  * Standard, safe constructor that leaves nothing on the cleanup stack
       
    49  *
       
    50  * @return "CCustomMatchData*"
       
    51  *         A pointer to the newly constructed match data object
       
    52  *
       
    53  */
       
    54 CCustomMatchData* CCustomMatchData::NewL()
       
    55 	{
       
    56 	CCustomMatchData* self = CCustomMatchData::NewLC();
       
    57 	CleanupStack::Pop(self); 
       
    58 	return self;
       
    59 	}
       
    60 /**
       
    61  *
       
    62  * Standard, safe constructor that leaves nothing on the cleanup stack
       
    63  *
       
    64  * @param  "const TDesC8& aPackage"
       
    65  *		   A reference to a descriptor created using <code>PackL()</code>
       
    66  *         used to initialize the object.
       
    67  * @return "CCustomMatchData*"
       
    68  *         A pointer to the newly constructed match data object
       
    69  *
       
    70  */
       
    71 CCustomMatchData* CCustomMatchData::NewL(const TDesC8& aPackage)
       
    72 	{
       
    73 	CCustomMatchData* self = CCustomMatchData::NewLC(aPackage);
       
    74 	CleanupStack::Pop(self);
       
    75 	return self;
       
    76 	}
       
    77 
       
    78 /**
       
    79  *
       
    80  * Standard, safe constructor that leaves the pointer to the newly constructed
       
    81  * match data object on the cleanup stack
       
    82  *
       
    83  * @return	"CCustomMatchData*"
       
    84  *			A pointer to the newly constructed match data object
       
    85  *
       
    86  */
       
    87 CCustomMatchData* CCustomMatchData::NewLC()
       
    88 	{
       
    89 	CCustomMatchData* self = new(ELeave) CCustomMatchData;
       
    90 	CleanupStack::PushL(self);
       
    91     return self;
       
    92 	}
       
    93 
       
    94 /**
       
    95  *
       
    96  * Standard, safe constructor that leaves the pointer to the newly constructed
       
    97  * match data object on the cleanup stack
       
    98  *
       
    99  * @param	"const TDesC8& aPackage"
       
   100  *			A reference to a descriptor created using <code>PackL()</code>
       
   101  *			used to initialize the object.
       
   102  * @return	"CCustomMatchData*"
       
   103  *			A pointer to the newly constructed match data object
       
   104  *
       
   105  */
       
   106 CCustomMatchData* CCustomMatchData::NewLC(const TDesC8& aPackage)
       
   107 	{
       
   108 	CCustomMatchData* self = new(ELeave) CCustomMatchData;
       
   109 	CleanupStack::PushL(self);
       
   110 	self->ConstructL(aPackage);
       
   111     return self;
       
   112 	}
       
   113 
       
   114 void CCustomMatchData::ConstructL(const TDesC8& aPackage)
       
   115 	{
       
   116 	UnPackL(aPackage);
       
   117 	}
       
   118 
       
   119 /**
       
   120  *
       
   121  * Externalize the object to a stream.
       
   122  * All the member variables will be written to the stream, and if no MatchString
       
   123  * is provided a null descriptor is used. The stream must be able to accomodate 
       
   124  * the streaming operation or it will leave with <code>KErrOverFlow</code>.
       
   125  *
       
   126  * @param	"RWriteStream& aStream"
       
   127  *          A reference to the stream to which the member variables will
       
   128  *          be written.
       
   129  *
       
   130  */
       
   131 void CCustomMatchData::ExternalizeL(RWriteStream& aStream) const
       
   132 	{
       
   133 	aStream.WriteInt32L(iMatchType);
       
   134 	aStream.WriteInt32L(iPluginFlagsNeeded);
       
   135 	aStream.WriteInt32L(iBaseType.iUid);
       
   136 	aStream.WriteInt32L(iSubType.iUid);
       
   137 	aStream.WriteInt32L(iImplementationType.iUid);
       
   138 
       
   139 	// if Match String is not used send empty descriptor
       
   140 	if(iMatchString)
       
   141 		aStream << *iMatchString;
       
   142 	else
       
   143 		aStream << KNullDesC8;
       
   144 
       
   145 	// if File Suffix is not used send empty descriptor
       
   146 	if(iFileSuffix)
       
   147 		aStream << *iFileSuffix;
       
   148 	else
       
   149 		aStream << KNullDesC8;
       
   150 	}
       
   151 /**
       
   152  *
       
   153  * Internalize the object from a stream.
       
   154  * All the member variables will be read from the streamed.
       
   155  * If there is not enougth data in the stream or it will 
       
   156  * leave with <code>KErrEof</code>.
       
   157  *
       
   158  * @param	"RReadStream& aStream"
       
   159  *          A reference to the stream from which data will be read to
       
   160  *          setup the member variables.
       
   161  *
       
   162  */
       
   163 void CCustomMatchData::InternalizeL(RReadStream& aStream)
       
   164 	{
       
   165 	iMatchType      = static_cast<TResolverMatchType>(aStream.ReadInt32L());
       
   166 	iPluginFlagsNeeded      = static_cast<TPluginFlagsNeeded>(aStream.ReadInt32L());
       
   167 	iBaseType.iUid  = aStream.ReadInt32L();
       
   168 	iSubType.iUid   = aStream.ReadInt32L();
       
   169 	iImplementationType.iUid = aStream.ReadInt32L();
       
   170 
       
   171 	delete iMatchString; iMatchString = NULL;
       
   172 	iMatchString = HBufC8::NewL(aStream,KMaxDescriptorLength); //KErrOverflow
       
   173 
       
   174 	delete iFileSuffix; iFileSuffix = NULL;
       
   175 	iFileSuffix = HBufC::NewL(aStream,KMaxDescriptorLength); //KErrOverflow
       
   176 	}
       
   177 
       
   178 /**
       
   179  *
       
   180  * Set a string to match against.
       
   181  *
       
   182  * @param	"const TDesC8& aMIMEType"
       
   183  *          A reference to a descriptor to match against.
       
   184  *
       
   185  */
       
   186 void CCustomMatchData::SetMatchStringL(const TDesC8& aMIMEType)
       
   187 	{
       
   188 	delete iMatchString; iMatchString = NULL;
       
   189 	iMatchString = aMIMEType.AllocL();
       
   190 	}
       
   191 
       
   192 /**
       
   193  *
       
   194  * Sets the match type, base type and sub type to match against
       
   195  *
       
   196  * @param	"const TResolverMatchType& aMatchType"
       
   197  *			The type of match requested.
       
   198  * @param	"const TUid& aBaseType"
       
   199  *			The base type to match against
       
   200  * @param	"const TUid& aSubType"
       
   201  *			The sub type to match against
       
   202  *
       
   203  */
       
   204 void CCustomMatchData::SetTypes(const TResolverMatchType& aMatchType, const TUid& aBaseType, const TUid& aSubType)
       
   205 	{
       
   206 	iMatchType = aMatchType;
       
   207 	iBaseType  = aBaseType;
       
   208 	iSubType   = aSubType;
       
   209 	}
       
   210 
       
   211 /**
       
   212  *
       
   213  * Sets the match type to match against
       
   214  *
       
   215  * @param	"const TResolverMatchType& aMatchType"
       
   216  *			The type of match requested.
       
   217  *
       
   218  */
       
   219 void CCustomMatchData::SetMatchType(const TResolverMatchType& aMatchType)
       
   220 	{
       
   221 	iMatchType = aMatchType;
       
   222 	}
       
   223 
       
   224 /** set the flags that the plugin must support
       
   225  */
       
   226 void CCustomMatchData::SetPluginFlagsNeeded(const TPluginFlagsNeeded& aPluginFlags)
       
   227 	{
       
   228 	iPluginFlagsNeeded = aPluginFlags;
       
   229 	}
       
   230 
       
   231 /**
       
   232  *
       
   233  * Sets the base type to match against
       
   234  *
       
   235  * @param	"const TUid& aBaseType"
       
   236  *			The base type to match against
       
   237  *
       
   238  */
       
   239 void CCustomMatchData::SetBaseType(const TUid& aBaseType)
       
   240 	{
       
   241 	iBaseType  = aBaseType;
       
   242 	}
       
   243 
       
   244 /**
       
   245  *
       
   246  * Sets the sub type to match against
       
   247  *
       
   248  * @param	"const TUid& aSubType"
       
   249  *			The sub type to match against
       
   250  *
       
   251  */
       
   252 void CCustomMatchData::SetSubType(const TUid& aSubType)
       
   253 	{
       
   254 	iSubType   = aSubType;
       
   255 	}
       
   256 
       
   257 /**
       
   258  *
       
   259  * Sets the implementation type to match against
       
   260  *
       
   261  * @param	"const TUid& aImplementationType"
       
   262  *			The implementation uid of a specific codec to match against
       
   263  *
       
   264  */
       
   265 void CCustomMatchData::SetImplementationType(const TUid& aImplementationType)
       
   266 	{
       
   267 	iImplementationType = aImplementationType;
       
   268 	}
       
   269 /**
       
   270  *
       
   271  * Set a file extension to match against.
       
   272  *
       
   273  * @param	"const TDesC8& aFileSuffix"
       
   274  *          A reference to a file suffix to match against.
       
   275  *
       
   276  */
       
   277 void CCustomMatchData::SetFileSuffixL(const TDesC& aFileSuffix)
       
   278 	{
       
   279 	delete iFileSuffix; iFileSuffix = NULL;
       
   280 	iFileSuffix = aFileSuffix.AllocL();
       
   281 	}
       
   282 
       
   283 /**
       
   284  *
       
   285  * Retrieves the match type, base type and sub type to match against
       
   286  *
       
   287  * @param	"TResolverMatchType& aMatchType"
       
   288  *			The type of match requested.
       
   289  * @param	"TUid& aBaseType"
       
   290  *			The base type to match against
       
   291  * @param	"TUid& aSubType"
       
   292  *			The sub type to match against
       
   293  *
       
   294  */
       
   295 void CCustomMatchData::GetTypes(TResolverMatchType& aMatchType, TUid& aBaseType, TUid& aSubType) const
       
   296 	{
       
   297 	aMatchType = iMatchType;
       
   298 	aBaseType  = iBaseType;
       
   299 	aSubType   = iSubType;
       
   300 	}
       
   301 /**
       
   302  *
       
   303  * Retrieves the match type to match against
       
   304  *
       
   305  * @return	"TResolverMatchType"
       
   306  *			The type of match requested.
       
   307  *
       
   308  */
       
   309 TResolverMatchType CCustomMatchData::MatchType() const
       
   310 	{
       
   311 	return iMatchType;
       
   312 	}
       
   313 
       
   314 
       
   315 /**
       
   316  *
       
   317  * Retrieves the plugin flags that are needed
       
   318  *
       
   319  * @return	"TResolverMatchType"
       
   320  *			The type of match requested.
       
   321  *
       
   322  */
       
   323 TPluginFlagsNeeded CCustomMatchData::PluginFlagsNeeded() const
       
   324 	{
       
   325 	return iPluginFlagsNeeded;
       
   326 	}
       
   327 
       
   328 /**
       
   329  *
       
   330  * Retrieves the base type to match against
       
   331  *
       
   332  * @return	"TUid"
       
   333  *			The base type to match against
       
   334  *
       
   335  */
       
   336 TUid CCustomMatchData::BaseType() const
       
   337 	{
       
   338 	return iBaseType;
       
   339 	}
       
   340 
       
   341 /**
       
   342  *
       
   343  * Retrieves the sub type to match against
       
   344  *
       
   345  * @return	"TUid"
       
   346  *			The sub type to match against
       
   347  *
       
   348  */
       
   349 TUid CCustomMatchData::SubType() const
       
   350 	{
       
   351 	return iSubType;
       
   352 	}
       
   353 /**
       
   354  *
       
   355  * Retrieves the implementation type to match against
       
   356  *
       
   357  * @return	"TUid"
       
   358  *			The implementation of a specific codec to match against
       
   359  *
       
   360  */
       
   361 
       
   362 TUid CCustomMatchData::ImplementationType() const
       
   363 	{
       
   364 	return iImplementationType;
       
   365 	}
       
   366 
       
   367 /**
       
   368  *
       
   369  * Retrieves the string to match against. If no string is set
       
   370  * a null descriptor is returned.
       
   371  *
       
   372  * @return	"TPtrC8"
       
   373  *			The string to match against
       
   374  *
       
   375  */
       
   376 const TPtrC8 CCustomMatchData::MatchString() const
       
   377 	{
       
   378 	TPtrC8 result;
       
   379 
       
   380 	if(iMatchString)
       
   381 		result.Set(*iMatchString);
       
   382 	else
       
   383 		result.Set(KNullDesC8);
       
   384 
       
   385 	return result;
       
   386 	}
       
   387 
       
   388 /**
       
   389  *
       
   390  * Retrieves the file extension to match against. If no suffix is set
       
   391  * a null descriptor is returned.
       
   392  *
       
   393  * @return	"TPtrC8"
       
   394  *			The file suffix to match against
       
   395  *
       
   396  */
       
   397 const TPtrC CCustomMatchData::FileSuffix() const
       
   398 	{
       
   399 	TPtrC result;
       
   400 
       
   401 	if(iFileSuffix)
       
   402 		result.Set(*iFileSuffix);
       
   403 	else
       
   404 		result.Set(KNullDesC);
       
   405 
       
   406 	return result;
       
   407 	}
       
   408 
       
   409 /** Used to package up the object into a descriptor so
       
   410  * that it can be placed in the <code>DataType</code> descriptor of a
       
   411  * <code>TEComResolverParams</code> before being passed across the client
       
   412  * server boundary within ECom and handed to the custom resolver.
       
   413  *
       
   414  * @return	"const HBufC8*"
       
   415  *			A pointer to a desctriptor with the object packed in it.
       
   416  *			The object does not take responsibility for the pointer
       
   417  *			and the external code must ensure that the pointer is deleted.
       
   418  *			The pointer is left on the cleanupstack.	
       
   419  *
       
   420  */
       
   421 HBufC8* CCustomMatchData::NewPackLC() const
       
   422 	{
       
   423 
       
   424 	//Calculate the size necessary size for the descriptor to pack the object
       
   425 	TInt size = 0;
       
   426 	if(iMatchString)
       
   427 		size = iMatchString->Size();
       
   428 	if(iFileSuffix)
       
   429 		size += iFileSuffix->Size();
       
   430 
       
   431 	size += 6*sizeof(TInt32);	// The size necessary for 
       
   432 								//		iMatchType
       
   433 								//		iPluginFlagsNeeded
       
   434 								//		iBaseType
       
   435 								//		iSubType
       
   436 								//		iInterfaceUid
       
   437 								// and the size of the descriptor (Max TInt32)
       
   438 	HBufC8* package = HBufC8::NewLC(size);
       
   439 	TPtr8   packageDes = package->Des();
       
   440 
       
   441 	RDesWriteStream stream(packageDes);
       
   442 	ExternalizeL(stream);
       
   443 	stream.Close();
       
   444 
       
   445 	return package;
       
   446 	}
       
   447 
       
   448 /** Used to unpack a descriptor packed using <code>PackL()</code> and set the
       
   449  * member variables to the data contained in the descriptor. The descriptor 
       
   450  * is passed to the custom resolver by ECom and can be retrieved from the <code>DataType</code> 
       
   451  * of <code>TEComResolverParams</code>.
       
   452  *
       
   453  * @param	"const TDes8& aPackage"
       
   454  *			A reference to a desctriptor created using <code>PackL()</code> to which
       
   455  *			the member variables will be set.
       
   456  *
       
   457  */
       
   458 void CCustomMatchData::UnPackL(const TDesC8& aPackage)
       
   459 	{
       
   460 	RDesReadStream stream(aPackage);
       
   461 	InternalizeL(stream);
       
   462 	stream.Close();
       
   463 	}