mtpfws/mtpfw/dataproviders/devdp/src/cmtpdevicedpconfigmgr.cpp
changeset 0 d0791faffa3f
child 15 f85613f12947
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     1 // Copyright (c) 2006-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 //
       
    15 
       
    16 #include <barsc.h>
       
    17 #include <barsread.h>
       
    18 
       
    19 #include <mtp/mmtpdataproviderconfig.h>
       
    20 #include <mtp/mmtpdataproviderframework.h>
       
    21 #include <102827af.rsg>
       
    22 #include "cmtpdevicedpconfigmgr.h"
       
    23 
       
    24 enum PanicReason
       
    25 {
       
    26 CMTPDeviceDpConfigMgrPanic = -1,
       
    27 };
       
    28 #ifdef _DEBUG
       
    29 _LIT(KPanicInvalidInt, "Panic is due to invalid Integer");
       
    30 _LIT(KPanicinvalidRssConfigParam, "Panic is due to invalid RSS Config Param");
       
    31 #endif 
       
    32 
       
    33 // Class constants.
       
    34 __FLOG_STMT(_LIT8(KComponent,"DeviceDpConfigMgr");)
       
    35 
       
    36 CMTPDeviceDpConfigMgr* CMTPDeviceDpConfigMgr::NewL(MMTPDataProviderFramework& aFramework)
       
    37 	{
       
    38 	CMTPDeviceDpConfigMgr* self = new (ELeave) CMTPDeviceDpConfigMgr(aFramework);
       
    39 	CleanupStack::PushL(self);
       
    40 	self->ConstructL();
       
    41 	CleanupStack::Pop(self);
       
    42 	return self;
       
    43 	}
       
    44 	
       
    45 CMTPDeviceDpConfigMgr::CMTPDeviceDpConfigMgr(MMTPDataProviderFramework& aFramework) :
       
    46 	iFramework(aFramework)
       
    47 	{
       
    48 	}
       
    49 	
       
    50 void CMTPDeviceDpConfigMgr::ConstructL()
       
    51 	{
       
    52 	__FLOG_OPEN(KMTPSubsystem, KComponent);
       
    53     __FLOG(_L8("ConstructL - Entry"));
       
    54     
       
    55 	iResourceId = iFramework.DataProviderConfig().UintValue(MMTPDataProviderConfig::EOpaqueResource);
       
    56 	
       
    57 	RResourceFile resFile;
       
    58 	CleanupClosePushL(resFile);
       
    59 	
       
    60 	resFile.OpenL(iFramework.Fs(), iFramework.DataProviderConfig().DesCValue(MMTPDataProviderConfig::EResourceFileName));
       
    61 	HBufC8* res = resFile.AllocReadLC(iResourceId);
       
    62 	
       
    63 	TResourceReader reader;
       
    64 	reader.SetBuffer(res);
       
    65 	
       
    66 	// WORD - enumeration_iteration_length
       
    67 	iEnumItrLength = reader.ReadInt16();
       
    68 	
       
    69 	// Do not read exclusion_list to conserve memory
       
    70 	// - instead read it in dynamically when requested	
       
    71 	CleanupStack::PopAndDestroy(res);
       
    72 	CleanupStack::PopAndDestroy(&resFile);
       
    73 	
       
    74 	__FLOG(_L8("ConstructL - Exit"));
       
    75 	}
       
    76 	
       
    77 CMTPDeviceDpConfigMgr::~CMTPDeviceDpConfigMgr()
       
    78 	{
       
    79 	__FLOG_CLOSE;
       
    80 	}
       
    81 	
       
    82 #ifdef _DEBUG
       
    83 TUint CMTPDeviceDpConfigMgr::UintValueL(TParameter aParam) const
       
    84 #else
       
    85 TUint CMTPDeviceDpConfigMgr::UintValueL(TParameter /*aParam*/) const
       
    86 #endif // _DEBUG
       
    87 	{
       
    88 	__ASSERT_DEBUG(aParam == CMTPDeviceDpConfigMgr::EEnumerationIterationLength, User::Invariant());
       
    89 	return iEnumItrLength;
       
    90 	}
       
    91 	
       
    92 	
       
    93 #ifdef _DEBUG
       
    94 CDesCArray* CMTPDeviceDpConfigMgr::GetArrayValueL(TParameter aParam) const
       
    95 #else
       
    96 CDesCArray* CMTPDeviceDpConfigMgr::GetArrayValueL(TParameter /*aParam*/) const
       
    97 #endif // _DEBUG
       
    98 	{
       
    99 	__ASSERT_DEBUG(aParam == CMTPDeviceDpConfigMgr::EFolderExclusionList, User::Invariant());
       
   100 	return ReadExclusionListL();
       
   101 	}
       
   102 
       
   103 CDesCArray* CMTPDeviceDpConfigMgr::ReadExclusionListL() const
       
   104 	{
       
   105 	RResourceFile resFile;
       
   106 	CleanupClosePushL(resFile);
       
   107 	
       
   108 	resFile.OpenL(iFramework.Fs(), iFramework.DataProviderConfig().DesCValue(MMTPDataProviderConfig::EResourceFileName));
       
   109 	HBufC8* res = resFile.AllocReadLC(iResourceId);
       
   110 	
       
   111 	TResourceReader reader;
       
   112 	reader.SetBuffer(res);
       
   113 	
       
   114 	// WORD - enumeration_iteration_length, skip it
       
   115 	reader.ReadInt16();
       
   116 	
       
   117 	// ARRAY - exclusion_list
       
   118 	CDesCArrayFlat* exclusionList = reader.ReadDesCArrayL();
       
   119 	
       
   120 	CleanupStack::PopAndDestroy(res);
       
   121 	CleanupStack::PopAndDestroy(&resFile);
       
   122 	return exclusionList;
       
   123 	}
       
   124 
       
   125 void CMTPDeviceDpConfigMgr::GetDriveInfoL(TInt aDriveNo, TDes& aVolumeName, TDes& aRootDirPath)
       
   126 	{
       
   127 	__FLOG(_L8("GetDriveInfoL - Entry"));
       
   128 	RResourceFile resFile;
       
   129 	resFile.OpenL(iFramework.Fs(), iFramework.DataProviderConfig().DesCValue(MMTPDataProviderConfig::EResourceFileName));
       
   130 	CleanupClosePushL(resFile);
       
   131 	HBufC8* dataBuffer=resFile.AllocReadLC(DRIVES);
       
   132 	
       
   133 	TResourceReader reader;
       
   134 	reader.SetBuffer(dataBuffer);
       
   135 	TInt maxDrives = reader.ReadInt16();
       
   136 	__FLOG_VA((_L8("aDriveNo = %d"), aDriveNo));
       
   137 	TBool found = EFalse;
       
   138 	for(TInt driveIndex = 0; driveIndex < maxDrives; driveIndex++)
       
   139 		{
       
   140 		TInt driveNumber = reader.ReadInt16();
       
   141 		TPtrC volumeName = reader.ReadTPtrC();
       
   142 		TPtrC rootDirName = reader.ReadTPtrC();
       
   143 
       
   144 		if(driveNumber ==  aDriveNo)
       
   145 			{
       
   146 			found = ETrue;
       
   147 			__FLOG_VA((_L8("Found the drive! Drive Number = %d"), driveNumber));
       
   148 			if ((KMaxFileName > volumeName.Length()) && 
       
   149 			    (KMaxFileName > rootDirName.Length())
       
   150 			    )
       
   151 				{
       
   152 				aVolumeName = volumeName;
       
   153 				aRootDirPath = rootDirName;
       
   154 				}
       
   155 			else
       
   156 				{
       
   157 				__FLOG(_L8("VolumeName or RootDirName length is more than KMaxFileName"));
       
   158 				// volumeName and/or rootDirName specified in resource file is too lengthy.
       
   159 				User::Leave(KErrArgument);
       
   160 				}			
       
   161 			break;
       
   162 			}
       
   163 		}
       
   164 	
       
   165 	if (!found)
       
   166 		{
       
   167 		__FLOG_VA((_L8("No match in resource file for Drive Number = %d"), aDriveNo));
       
   168 		// Matching drive number was not found in resource file.
       
   169 		User::Leave(KErrNotFound);
       
   170 		}
       
   171 		
       
   172 	CleanupStack::PopAndDestroy(dataBuffer);
       
   173 	CleanupStack::PopAndDestroy(&resFile);
       
   174 	__FLOG(_L8("GetDriveInfoL - Exit"));
       
   175 	}
       
   176 
       
   177 void CMTPDeviceDpConfigMgr::GetFriendlyVolumeNameL(TInt aDriveNo, TDes& aVolumeName)
       
   178 	{
       
   179 	__FLOG(_L8("GetFriendlyVolumeNameL - Entry"));
       
   180 	RBuf rootDirPath;
       
   181 	rootDirPath.CreateL(KMaxFileName);
       
   182 	rootDirPath.CleanupClosePushL();
       
   183 	GetDriveInfoL(aDriveNo, aVolumeName, rootDirPath);
       
   184 	CleanupStack::PopAndDestroy();
       
   185 	__FLOG(_L8("GetFriendlyVolumeNameL - Exit"));
       
   186 	}
       
   187 
       
   188 void CMTPDeviceDpConfigMgr::GetRootDirPathL(TInt aDriveNo, TDes& aRootDirPath)
       
   189 	{
       
   190 	__FLOG(_L8("GetRootDirPathL - Entry"));
       
   191 	RBuf volumeName;
       
   192 	volumeName.CreateL(KMaxFileName);
       
   193 	volumeName.CleanupClosePushL();
       
   194 	GetDriveInfoL(aDriveNo, volumeName, aRootDirPath);
       
   195 	CleanupStack::PopAndDestroy();
       
   196 	__FLOG(_L8("GetRootDirPathL - Exit"));
       
   197 	}
       
   198 
       
   199 /**
       
   200   *This method is to get the ordered format from the rss file
       
   201   *
       
   202   *@param aOrderInfoArray : is an array for storing ordered formats(out param).
       
   203   * 
       
   204   */
       
   205  void CMTPDeviceDpConfigMgr::GetRssConfigInfoArrayL(RArray<TUint>& aOrderInfoArray, TDevDPConfigRSSParams aParam)
       
   206 	{
       
   207 	__FLOG(_L8("GetOrderedFormatInfo - Entry"));
       
   208 	RResourceFile resFile;
       
   209 	resFile.OpenL(iFramework.Fs(), iFramework.DataProviderConfig().DesCValue(MMTPDataProviderConfig::EResourceFileName));
       
   210 	CleanupClosePushL(resFile);
       
   211 	HBufC8* dataBuffer = NULL;
       
   212 	
       
   213 	switch(aParam)
       
   214 		{
       
   215 		case EDevDpFormats:
       
   216 			dataBuffer = resFile.AllocReadLC(FORMATS);
       
   217 		break;
       
   218 		
       
   219 		case EDevDpExtnUids:
       
   220 			dataBuffer = resFile.AllocReadLC(EXTNPLUGINUIDS);
       
   221 		break;
       
   222 
       
   223 		default:			
       
   224 			//should not come here raise panic	
       
   225 			__ASSERT_DEBUG( 0, User::Panic(KPanicinvalidRssConfigParam, CMTPDeviceDpConfigMgrPanic));				
       
   226 		break;	
       
   227 		}
       
   228 
       
   229 	TResourceReader reader;
       
   230 	reader.SetBuffer(dataBuffer);
       
   231 	TInt noOfElem = reader.ReadInt16();
       
   232 	//rewind to the begening else desc array can not read value.
       
   233 	reader.Rewind(sizeof(TInt16));
       
   234 	if(0 != noOfElem)	
       
   235 	{
       
   236 	CDesCArrayFlat* formatArray = reader.ReadDesCArrayL();
       
   237 	CleanupStack::PushL(formatArray);
       
   238 	TInt numFormats = formatArray->Count();
       
   239 	TUint formatInt;	
       
   240 	TPtrC orderedFormat;
       
   241 	TInt errorCode = KErrNotFound;	
       
   242 	for(TInt formtIndex = 0; formtIndex < numFormats; formtIndex++)
       
   243 		{
       
   244 		orderedFormat.Set(formatArray->MdcaPoint(formtIndex));
       
   245 		TLex lex(orderedFormat);
       
   246 		errorCode = lex.Val(formatInt, EHex);		
       
   247 		//panic in debug mode invalid string is provaided
       
   248 		__ASSERT_DEBUG((errorCode == KErrNone), User::Panic(KPanicInvalidInt, CMTPDeviceDpConfigMgrPanic));
       
   249 
       
   250 		if(errorCode )
       
   251 			{
       
   252 			 __FLOG(_L8("ERROR !!!Invalid entry in the config.rss file "));
       
   253 			}
       
   254 		else
       
   255 			{
       
   256 			//Ignore the duplicate value.
       
   257 			if( aOrderInfoArray.Find(formatInt) == KErrNotFound )
       
   258 				{
       
   259 				aOrderInfoArray.Append(formatInt);
       
   260 				}
       
   261 			}
       
   262 		}
       
   263 	CleanupStack::PopAndDestroy(formatArray);
       
   264 	CleanupStack::PopAndDestroy(dataBuffer);
       
   265 	CleanupStack::PopAndDestroy(&resFile);
       
   266 
       
   267 	}
       
   268 	else
       
   269 	{
       
   270 	CleanupStack::PopAndDestroy(dataBuffer);
       
   271 	CleanupStack::PopAndDestroy(&resFile);	
       
   272 	User::Leave(KErrArgument);	
       
   273 	}
       
   274 
       
   275 	__FLOG(_L8("GetOrderedFormatInfo -  Exit"));
       
   276 	}
       
   277