lowlevellibsandfws/pluginfw/Framework/frame/DriveInfo.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     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 // Implementation for CEComCachedDriveInfo class
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22 
       
    23 #include <e32const.h>
       
    24 #include <f32file.h>
       
    25 #include <bsul/bsul.h>
       
    26 #include <ecom/ecomerrorcodes.h>
       
    27 #include "DriveInfo.h"
       
    28 #include "EComPatchDataConstantv2.h"
       
    29 #include "EComInternalErrorCodes.h"
       
    30 const TInt KInvalidIndex = -1;
       
    31 const TInt32 KInvalidDrvNumber = -1;
       
    32 
       
    33 /** static member of CEComCachedDriveInfo */
       
    34 TFixedArray<TEComDrvFlags, KMaxDrives> CEComCachedDriveInfo::iDriveAttr;
       
    35 
       
    36 /** static member of CEComCachedDriveInfo */
       
    37 TInt CEComCachedDriveInfo::iLastIndex = KInvalidIndex;
       
    38 
       
    39 /** static member of CEComCachedDriveInfo */
       
    40 TBool CEComCachedDriveInfo::iInitialized = EFalse;
       
    41 
       
    42 
       
    43 /** Standard factory method to instantiate CEComCachedDriveInfo instances.
       
    44 */
       
    45 CEComCachedDriveInfo* CEComCachedDriveInfo::NewL(RFs& aFs)
       
    46 	{
       
    47 	CEComCachedDriveInfo* self = new (ELeave) CEComCachedDriveInfo;
       
    48 	CleanupStack::PushL(self);
       
    49 	self->ConstructL(aFs, KDiscoveryDisabledDriveList);
       
    50 	CleanupStack::Pop(self);
       
    51 	return self;
       
    52 	}
       
    53 
       
    54 /** Constructor of CEComCachedDriveInfo. Nothing to do. */
       
    55 CEComCachedDriveInfo::CEComCachedDriveInfo()
       
    56 	{
       
    57 	}
       
    58 
       
    59 /** Standard two-phase construction to complete construction
       
    60 of CEComCachedDriveInfo.
       
    61 
       
    62 @param aFs reference to a connected RFs session.
       
    63 @param aDiscoveryDisabledMask bits set indicate the drives contain no plug-ins
       
    64 	and need not be scanned. There is a mechanism to allow licensees to
       
    65 	specify this mask at ROM build time.
       
    66 @leave KErrNoMemory if out of memory, or any of the other system wide errors.
       
    67 */
       
    68 void CEComCachedDriveInfo::ConstructL(RFs& aFs, TUint32 aDiscoveryDisabledMask)
       
    69 	{
       
    70 	if (iInitialized)
       
    71 		{
       
    72 		return;
       
    73 		}
       
    74 
       
    75 	iLastIndex = KInvalidIndex;
       
    76 
       
    77 	// Get list of installed drives. This info is not available from
       
    78 	// BSUL::CCachedDriveInfo API's.
       
    79 	TDriveList drvList;
       
    80 	User::LeaveIfError( aFs.DriveList(drvList) );
       
    81 
       
    82 	BSUL::CCachedDriveInfo* cachedDrvInfo = BSUL::CCachedDriveInfo::NewL(aFs);
       
    83 	CleanupStack::PushL(cachedDrvInfo);
       
    84 
       
    85 	// determine attributes of valid drives
       
    86 	for (TInt i = EDriveA; i <= EDriveZ; i++)
       
    87 		{
       
    88 		if (drvList[i])
       
    89 			{
       
    90 			// drive exist
       
    91 			TInt j = ++iLastIndex;
       
    92 
       
    93 			iDriveAttr[j].iDrvNumber = i; 
       
    94 
       
    95 			TDriveUnit drvUnit(i);
       
    96 			if (cachedDrvInfo->IsReadOnlyInternalL(drvUnit))
       
    97 				{
       
    98 				iDriveAttr[j].iFlags = EEComDrvAttrReadOnlyInternal;
       
    99 				// RO internal drive does not have any other attributes
       
   100 				continue;
       
   101 				}
       
   102 
       
   103 			iDriveAttr[j].iFlags = 0; 
       
   104 
       
   105 			// Check if drive is removable
       
   106 			if (cachedDrvInfo->IsFlagSetOnDriveL(drvUnit, KDriveAttRemovable))
       
   107 				{
       
   108 				iDriveAttr[j].iFlags |= EEComDrvAttrRemovable;
       
   109 				}
       
   110 
       
   111 			// Check if drive is on ReadWrite drive
       
   112 			if (! cachedDrvInfo->IsFlagSetOnDriveL(drvUnit, KDriveAttRom))
       
   113 				{
       
   114 				iDriveAttr[j].iFlags |= EEComDrvAttrWritable;
       
   115 				}
       
   116 
       
   117 			TUint32 drvBitMask = 1;
       
   118 			drvBitMask <<= i;
       
   119 			// Three conditions for discovery disable: disabled by licensees,
       
   120 			// remote drives and substituted drives
       
   121 			if ( (drvBitMask & aDiscoveryDisabledMask) ||
       
   122 				 cachedDrvInfo->IsFlagSetOnDriveL(drvUnit, KDriveAttSubsted) ||
       
   123 				 cachedDrvInfo->IsFlagSetOnDriveL(drvUnit, KDriveAttRemote) )
       
   124 				{
       
   125 				iDriveAttr[j].iFlags |= EEComDrvAttrNoDiscovery;
       
   126 				}
       
   127 			} // if drvList[i]
       
   128 		} // for
       
   129 
       
   130 	CleanupStack::PopAndDestroy(cachedDrvInfo);
       
   131 	__ASSERT_DEBUG(iLastIndex >= 0, User::Invariant());
       
   132 
       
   133 	for (TInt i = iLastIndex + 1; i < KMaxDrives; i++)
       
   134 		{
       
   135 		iDriveAttr[i].iDrvNumber = KInvalidDrvNumber; 
       
   136 		}
       
   137 
       
   138 	iInitialized = ETrue;
       
   139 	}
       
   140 
       
   141 /** Is EEComDrvAttrReadOnlyInternal attribute set on the given drive?
       
   142 @param aDrive the drive number
       
   143 @return ETrue if drive is RO internal. EFalse means either no such drive or
       
   144 	not RO internal.
       
   145 @leave KEComErrDriveNotFound if aDrive is not supposed to be scanned,
       
   146 	i.e. drive absent or disabled by licensees or subst or remote.
       
   147     Use TEComCachedDriveInfoIterator::SetPos instead if want to test drive
       
   148 	attribute.
       
   149 */
       
   150 TBool CEComCachedDriveInfo::DriveIsReadOnlyInternalL(const TInt aDrive) const
       
   151 	{
       
   152 	TEComCachedDriveInfoIterator iter(*this);
       
   153 
       
   154 	if (! iter.SetPos(aDrive))
       
   155 		{
       
   156 		// This method is intended to be used on drives that are known
       
   157 		// to be valid, e.g. drive extracted from the path of a discovered
       
   158 		// DLL.
       
   159 		User::Leave(KEComErrDriveNotFound);
       
   160 		}
       
   161 	return iter.DriveIsReadOnlyInternal();
       
   162 	}
       
   163 
       
   164 /** Test if the EEComDrvAttrRemovable attribute for the given drive is set.
       
   165 @param aDrive the drive number
       
   166 @return ETrue if drive is removable. EFalse means either no such drive or
       
   167 	not removable.
       
   168 @leave KEComErrDriveNotFound if aDrive is not supposed to be scanned,
       
   169 	i.e. drive absent or disabled by licensees or subst or remote.
       
   170     Use TEComCachedDriveInfoIterator::SetPos instead if want to test drive
       
   171 	is removable.
       
   172 */
       
   173 TBool CEComCachedDriveInfo::DriveIsRemovableL(const TInt aDrive) const
       
   174 	{
       
   175 	TEComCachedDriveInfoIterator iter(*this);
       
   176 
       
   177 	if (! iter.SetPos(aDrive))
       
   178 		{
       
   179 		// This method is intended to be used on drives that are known
       
   180 		// to be valid, e.g. drive extracted from the path of a discovered
       
   181 		// DLL.
       
   182 		User::Leave(KEComErrDriveNotFound);
       
   183 		}
       
   184 	return iter.DriveIsRemovable();
       
   185 	}
       
   186 
       
   187 /** Test if the EEComDrvAttrWritable attribute for the given drive is set.
       
   188 @param aDrive the drive number
       
   189 @return ETrue if drive is writable. EFalse means either no such drive or
       
   190 	drive not writable.
       
   191 @leave KEComErrDriveNotFound if aDrive is not supposed to be scanned,
       
   192 	i.e. drive absent or disabled by licensees or subst or remote.
       
   193     Use TEComCachedDriveInfoIterator::SetPos instead if want to test drive
       
   194 	is removable.
       
   195 */
       
   196 TBool CEComCachedDriveInfo::DriveIsWritableL(const TInt aDrive) const
       
   197 	{
       
   198 	TEComCachedDriveInfoIterator iter(*this);
       
   199 
       
   200 	if (! iter.SetPos(aDrive))
       
   201 		{
       
   202 		// This method is intended to be used on drives that are known
       
   203 		// to be valid, e.g. drive extracted from the path of a discovered
       
   204 		// DLL.
       
   205 		User::Leave(KEComErrDriveNotFound);
       
   206 		}
       
   207 	return iter.DriveIsWritable();
       
   208 	}
       
   209 
       
   210 // Implementation for TEComCachedDriveInfoIterator class
       
   211 
       
   212 /** TEComCachedDriveInfoIterator Constructor
       
   213 Note that the object is not yet in valid state. User must first call
       
   214 First() or Last().
       
   215 */
       
   216 TEComCachedDriveInfoIterator::TEComCachedDriveInfoIterator(const CEComCachedDriveInfo& aCachedDriveInfo)
       
   217 	: iDriveAttr(aCachedDriveInfo.iDriveAttr)
       
   218 	{
       
   219 	iIndex = KInvalidIndex;
       
   220 	}
       
   221 
       
   222 /** Check if the drive is enabled for scanning and move index there if true.
       
   223 @param aDrive the drive number of the drive to check.
       
   224 @return ETrue the drive is enabled for scanning. Index is moved to that location.
       
   225 	If drive not to be scanned, index is moved out of bound.
       
   226 */
       
   227 TBool TEComCachedDriveInfoIterator::SetPos(const TInt aDrive)
       
   228 	{
       
   229 	for (iIndex = CEComCachedDriveInfo::iLastIndex; iIndex >= 0; iIndex--)
       
   230 		{
       
   231 		if (iDriveAttr[iIndex].iDrvNumber == aDrive)
       
   232 			{
       
   233 		    if (0 == (iDriveAttr[iIndex].iFlags & EEComDrvAttrNoDiscovery))
       
   234 				{
       
   235 				return ETrue;
       
   236 				}
       
   237 			iIndex = KInvalidIndex;
       
   238 			break;
       
   239 			}
       
   240 		}
       
   241 	return EFalse;
       
   242 	}
       
   243 
       
   244 /** Position iterator at first valid drive so as to
       
   245 iterate the drive list in increasing drive number order. */
       
   246 void TEComCachedDriveInfoIterator::First(void)
       
   247 	{
       
   248 	for (iIndex = 0; iIndex <= CEComCachedDriveInfo::iLastIndex; iIndex++)
       
   249 		{
       
   250 		if (0 == (iDriveAttr[iIndex].iFlags & EEComDrvAttrNoDiscovery))
       
   251 			{
       
   252 			return;
       
   253 			}
       
   254 		}
       
   255 	}
       
   256 
       
   257 /** Position iterator at last valid drive so as to
       
   258 iterate the drive list in decreasing drive number order. */
       
   259 void TEComCachedDriveInfoIterator::Last(void)
       
   260 	{
       
   261 	for (iIndex = CEComCachedDriveInfo::iLastIndex; iIndex >=0; iIndex--)
       
   262 		{
       
   263 		if (0 == (iDriveAttr[iIndex].iFlags & EEComDrvAttrNoDiscovery))
       
   264 			{
       
   265 			return;
       
   266 			}
       
   267 		}
       
   268 	}
       
   269 
       
   270 /** To be used in for and while loops to check if iterator
       
   271 has stepped through all posible drives. */
       
   272 TBool TEComCachedDriveInfoIterator::InRange(void) const
       
   273 	{
       
   274 	return (iIndex >= 0 && iIndex <= CEComCachedDriveInfo::iLastIndex);
       
   275 	}
       
   276 
       
   277 /** Increment iterator to next valid drive. */
       
   278 void TEComCachedDriveInfoIterator::Next(void)
       
   279 	{
       
   280 	if (InRange())
       
   281 		{
       
   282 		for (++iIndex; iIndex <= CEComCachedDriveInfo::iLastIndex; iIndex++)
       
   283 			{
       
   284 			if (0 == (iDriveAttr[iIndex].iFlags & EEComDrvAttrNoDiscovery))
       
   285 				{
       
   286 				return;
       
   287 				}
       
   288 			}
       
   289 		}
       
   290 	}
       
   291 
       
   292 /** Decrement iterator to next valid drive. */
       
   293 void TEComCachedDriveInfoIterator::Prev(void)
       
   294 	{
       
   295 	if (InRange())
       
   296 		{
       
   297 		for (--iIndex; iIndex >= 0; iIndex--)
       
   298 			{
       
   299 			if (0 == (iDriveAttr[iIndex].iFlags & EEComDrvAttrNoDiscovery))
       
   300 				{
       
   301 				return;
       
   302 				}
       
   303 			}
       
   304 		}
       
   305 	}
       
   306 
       
   307 /**
       
   308 @panic USER:133 from TFixedArray if iterator is out of bound.
       
   309 */
       
   310 TDriveNumber TEComCachedDriveInfoIterator::DriveNumber(void) const
       
   311 	{
       
   312 	return static_cast<TDriveNumber>( iDriveAttr.At(iIndex).iDrvNumber );
       
   313 	}
       
   314 
       
   315 /**
       
   316 @panic USER:133 from TFixedArray if iterator is out of bound.
       
   317 */
       
   318 TDriveUnit TEComCachedDriveInfoIterator::DriveUnit(void) const
       
   319 	{
       
   320 	return TDriveUnit( DriveNumber() );
       
   321 	}
       
   322 
       
   323 /** Test if the EEComDrvAttrReadOnlyInternal attribute for the current
       
   324 drive is set.
       
   325 @panic USER:133 from TFixedArray if iterator is out of bound.
       
   326 */
       
   327 TBool TEComCachedDriveInfoIterator::DriveIsReadOnlyInternal(void) const
       
   328 	{
       
   329 	if (EEComDrvAttrReadOnlyInternal & iDriveAttr.At(iIndex).iFlags)
       
   330 		{
       
   331 		return ETrue;
       
   332 		}
       
   333 	return EFalse;
       
   334 	}
       
   335 
       
   336 /** Test if the EEComDrvAttrRemovable attribute for the current
       
   337 drive is set.
       
   338 @panic USER:133 from TFixedArray if iterator is out of bound.
       
   339 */
       
   340 TBool TEComCachedDriveInfoIterator::DriveIsRemovable(void) const
       
   341 	{
       
   342 	if (EEComDrvAttrRemovable & iDriveAttr.At(iIndex).iFlags)
       
   343 		{
       
   344 		return ETrue;
       
   345 		}
       
   346 	return EFalse;
       
   347 	}
       
   348 
       
   349 /** Test if the EEComDrvAttrWritable attribute for the current drive is set.
       
   350 @return ETrue if drive is writable. EFalse means drive is not writable.
       
   351 @panic USER:133 from TFixedArray if iterator is out of bound.
       
   352 */
       
   353 TBool TEComCachedDriveInfoIterator::DriveIsWritable(void) const
       
   354 	{
       
   355 	if (EEComDrvAttrWritable & iDriveAttr.At(iIndex).iFlags)
       
   356 		{
       
   357 		return ETrue;
       
   358 		}
       
   359 	return EFalse;
       
   360 	}