messagingfw/msgsrvnstore/server/src/msvpreferreddrivelist.cpp
changeset 0 8e480a14352b
child 22 d2c4c66342f3
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 // MSVPREFERREDDRIVELIST.CPP
       
     2 
       
     3 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 // All rights reserved.
       
     5 // This component and the accompanying materials are made available
       
     6 // under the terms of "Eclipse Public License v1.0"
       
     7 // which accompanies this distribution, and is available
       
     8 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     9 //
       
    10 // Initial Contributors:
       
    11 // Nokia Corporation - initial contribution.
       
    12 //
       
    13 // Contributors:
       
    14 //
       
    15 // Description:
       
    16 // USER INCLUDES
       
    17 // 
       
    18 //
       
    19 
       
    20 #include "msvpreferreddrivelist.h"
       
    21 #include "MSVPANIC.H"
       
    22 #ifdef _DEBUG
       
    23 #include <flogger.h>
       
    24 #endif
       
    25 
       
    26 CMsvPreferredDriveList* CMsvPreferredDriveList::iMsvPreferredDriveList = NULL;
       
    27 
       
    28 
       
    29 /**
       
    30  * FUNCTION DEFINITIONS
       
    31  */
       
    32 
       
    33 
       
    34 /**
       
    35  * CreateL()
       
    36  * @return CMsvPreferredDriveList*: The newly created CMsvPreferredDriveList object.
       
    37  * 
       
    38  * Function added as part of PREQ 557.
       
    39  * It returns an instance of CMsvPreferredDriveList class. 
       
    40  */
       
    41 CMsvPreferredDriveList* CMsvPreferredDriveList::CreateL()
       
    42 	{
       
    43 	CMsvPreferredDriveList* self = new(ELeave)CMsvPreferredDriveList;
       
    44 	CleanupStack::PushL(self);
       
    45 	
       
    46 	self->ConstructL();
       
    47 	iMsvPreferredDriveList = self;
       
    48 	
       
    49 	CleanupStack::Pop(self);
       
    50 	return self;
       
    51 	}
       
    52 
       
    53 
       
    54 
       
    55 /**
       
    56  * GetDriveList()
       
    57  */
       
    58 CMsvPreferredDriveList* CMsvPreferredDriveList::GetDriveList()
       
    59 	{
       
    60 	__ASSERT_DEBUG(iMsvPreferredDriveList!=NULL, PanicServer(EMsvPreferredDriveListNotCreated));
       
    61 	return iMsvPreferredDriveList;
       
    62 	}
       
    63 	
       
    64 
       
    65 	
       
    66 /**
       
    67  * CMsvPreferredDriveList()
       
    68  *
       
    69  * Default constructor.
       
    70  */
       
    71 CMsvPreferredDriveList::CMsvPreferredDriveList()
       
    72 	{
       
    73 	
       
    74 	}
       
    75 
       
    76 
       
    77 
       
    78 /**
       
    79  * ~CMsvPreferredDriveList()
       
    80  *
       
    81  * Destructor.
       
    82  */
       
    83 CMsvPreferredDriveList::~CMsvPreferredDriveList()
       
    84 	{
       
    85 	iDrives->Close();
       
    86 	delete iDrives;
       
    87 	iDrives = NULL;
       
    88 	
       
    89 	iMsvPreferredDriveList = NULL;
       
    90 	}
       
    91 	
       
    92 	
       
    93 	
       
    94 /**
       
    95  * ConstructL()
       
    96  * @param None.
       
    97  * @return None.
       
    98  *
       
    99  * Second phase constructor.
       
   100  */
       
   101 void CMsvPreferredDriveList::ConstructL()
       
   102 	{
       
   103 	iDrives = new(ELeave)RArray<TMsvPreferredDrive>;
       
   104 	}
       
   105 	
       
   106 
       
   107 
       
   108 /**
       
   109  * GetDriveNumber()
       
   110  * @param TUint: Drive Id of the drive.
       
   111  * @return TInt: Drive number of the drive in the preferred drive list.
       
   112  *				 KErrNotFound if drive does not exist.
       
   113  *
       
   114  * Gets the drive number of the drive in the preferred drive list.
       
   115  */
       
   116 TInt CMsvPreferredDriveList::GetDriveNumber(TUint aDriveId, TDriveNumber& aDriveNum)
       
   117 	{
       
   118 	if(0 == aDriveId)
       
   119 		{
       
   120 		aDriveNum = (*iDrives)[iCurDriveIndex].driveNum;
       
   121 		return KErrNone;
       
   122 		}
       
   123 	
       
   124 	TInt driveCount = iDrives->Count();
       
   125 	for(TInt index = 0; index < driveCount; ++index)
       
   126 		{
       
   127 		if(aDriveId == (*iDrives)[index].driveId)
       
   128 			{
       
   129 			aDriveNum = (*iDrives)[index].driveNum;
       
   130 			return KErrNone;
       
   131 			}
       
   132 		}
       
   133 	return KErrNotFound;
       
   134 	}
       
   135 
       
   136 
       
   137 
       
   138 /**
       
   139  * Insert()
       
   140  * @param TMsvPreferredDrive: The drive to be inserted into the preferred
       
   141  *							  drive list.
       
   142  * @param TInt: Position of the drive in the preferred drive list.
       
   143  * @return None.
       
   144  *
       
   145  * Inserts a drive at the specified position in the preferred drive list.
       
   146  */
       
   147 void CMsvPreferredDriveList::Insert(TMsvPreferredDrive aDrive, TInt aIndex)
       
   148 	{
       
   149 	if(aIndex <= iCurDriveIndex)
       
   150 		{
       
   151 		++iCurDriveIndex;
       
   152 		}
       
   153 	iDrives->Insert(aDrive, aIndex);
       
   154 	}
       
   155 	
       
   156 	
       
   157 	
       
   158 /**
       
   159  * Remove()
       
   160  * @param TInt: Position of the drive in the preferred drive list.
       
   161  * @return None.
       
   162  *
       
   163  * Removes a drive from a specified position in the preferred drive list.
       
   164  */
       
   165 void CMsvPreferredDriveList::Remove(TInt aIndex)
       
   166 	{
       
   167 	if(aIndex <= iCurDriveIndex && 0 < iCurDriveIndex)
       
   168 		{
       
   169 		--iCurDriveIndex;
       
   170 		}
       
   171 	iDrives->Remove(aIndex);
       
   172 	}
       
   173 
       
   174 
       
   175 
       
   176 /**
       
   177  * DriveInfoL()
       
   178  * @param TUint: Index of the drive in the preferred drive list.
       
   179  * @param TMsvPreferredDrive&: Output parameter for drive info object.
       
   180  * @return None.
       
   181  */
       
   182 void CMsvPreferredDriveList::DriveInfoL(TUint aIndex, TMsvPreferredDrive& aDriveInfo) const
       
   183 	{
       
   184 	if(aIndex >= iDrives->Count())
       
   185 		{
       
   186 		User::Leave(KErrNotFound);
       
   187 		}
       
   188 	aDriveInfo = (*iDrives)[aIndex];	
       
   189 	}
       
   190 	
       
   191 
       
   192 
       
   193 /**
       
   194  * UpdateDriveId()
       
   195  * @param TUint: Index of the drive in the preferred drive list.
       
   196  * @param TUint: New drive Id.
       
   197  * @return TInt: KErrNotFound, if drive entry does not exist.
       
   198  */	
       
   199 void CMsvPreferredDriveList::UpdateDriveIdL(TUint aIndex, TUint aDriveId)
       
   200 	{
       
   201 	if(aIndex >= iDrives->Count())
       
   202 		{
       
   203 		User::Leave(KErrNotFound);
       
   204 		}
       
   205 	(*iDrives)[aIndex].driveId = aDriveId;
       
   206 	}
       
   207 	
       
   208 	
       
   209 
       
   210 /**
       
   211  * UpdateDriveStatus()
       
   212  * @param TUint: Index of the drive in the preferred drive list.
       
   213  * @param TUint: New drive status.
       
   214  * @return TInt: KErrNotFound, if drive entry does not exist.
       
   215  */	
       
   216 void CMsvPreferredDriveList::UpdateDriveStatusL(TUint aIndex, TDriveState aStatus)
       
   217 	{
       
   218 	if(aIndex >= iDrives->Count())
       
   219 		{
       
   220 		User::Leave(KErrNotFound);
       
   221 		}
       
   222 	(*iDrives)[aIndex].status = aStatus;
       
   223 	}
       
   224 
       
   225 
       
   226 
       
   227 // Returns index of the drive in the drive list. For test purpose only.
       
   228 TInt CMsvPreferredDriveList::GetDriveIndex(const TDriveNumber aDriveNum, TUint& aDriveIndex)
       
   229 	{
       
   230 	TInt count = Count();
       
   231 	for(TInt index = 0; index < count; ++index)
       
   232 		{
       
   233 		if(aDriveNum == (*iDrives)[index].driveNum)
       
   234 			{
       
   235 			aDriveIndex = index;
       
   236 			return KErrNone;
       
   237 			}
       
   238 		}
       
   239 	return KErrNotFound;
       
   240 	}
       
   241 	
       
   242 
       
   243 #if (defined SYMBIAN_MESSAGESTORE_UNIT_TESTCODE)
       
   244 #ifdef _DEBUG
       
   245 // Destroys the preferred drive list.
       
   246 void CMsvPreferredDriveList::Destroy(CMsvPreferredDriveList*& aDriveList)
       
   247 	{
       
   248 	if(NULL != aDriveList)
       
   249 		{
       
   250 		delete aDriveList;
       
   251 		aDriveList = NULL;
       
   252 		}
       
   253 	}
       
   254 void CMsvPreferredDriveList::Print()
       
   255 	{
       
   256 	_LIT8(KLtBracket, "[");
       
   257 	_LIT8(KRtBracket, "]: DRIVE-NUM: ");
       
   258 	_LIT8(KDriveId, " DRIVE-ID: ");
       
   259 	_LIT8(KStatus, " STATUS: ");
       
   260 	_LIT8(KAvailable, "EMsvMessageStoreAvailableStatus");
       
   261 	_LIT8(KUnavailable, "EMsvMessageStoreUnavailableStatus");
       
   262 	_LIT8(KNotSupported, "EMsvMessageStoreNotSupportedStatus");
       
   263 	_LIT8(KDiskNotAvailable, "EMsvDriveDiskNotAvailableStatus");
       
   264 	_LIT8(KCorruptStore, "EMsvMessageStoreCorruptStatus");
       
   265 	_LIT8(KInvalid, "EMsvInvalidDriveStatus");
       
   266 		
       
   267 	RFileLogger logger;
       
   268 	if (logger.Connect() == KErrNone)
       
   269 		{
       
   270 		logger.CreateLog(_L("msgs"), _L("DriveList.txt"), EFileLoggingModeAppend);
       
   271 		logger.SetDateAndTime(EFalse, EFalse);
       
   272 		logger.Write(_L(" Preferred Drive List:"));
       
   273 		logger.Write(_L("--------------------------------"));
       
   274 		logger.Write(_L(""));
       
   275 		}
       
   276 	
       
   277 	TInt count = Count();
       
   278 	for(TInt index = 0; index < count; ++index)
       
   279 		{		
       
   280 		RBuf8 text;
       
   281 		text.Create(100);
       
   282 		text.Append(KLtBracket);
       
   283 		text.AppendNum(index);
       
   284 		text.Append(KRtBracket);
       
   285 		text.AppendNum((*iDrives)[index].driveNum);
       
   286 		text.Append(KDriveId);
       
   287 		text.AppendNum((*iDrives)[index].driveId);
       
   288 		text.Append(KStatus);
       
   289 		switch((*iDrives)[index].status)
       
   290 			{	
       
   291 			case EMsvMessageStoreAvailableStatus:
       
   292 				text.Append(KAvailable);
       
   293 				break;
       
   294 			case EMsvMessageStoreUnavailableStatus:
       
   295 				text.Append(KUnavailable);
       
   296 				break;
       
   297 			case EMsvMessageStoreNotSupportedStatus:
       
   298 				text.Append(KNotSupported);
       
   299 				break;
       
   300 			case EMsvDriveDiskNotAvailableStatus:
       
   301 				text.Append(KDiskNotAvailable);
       
   302 				break;
       
   303 			case EMsvMessageStoreCorruptStatus:
       
   304 				text.Append(KCorruptStore);
       
   305 				break;
       
   306 			case EMsvInvalidDriveStatus:
       
   307 				text.Append(KInvalid);
       
   308 				break;
       
   309 			}
       
   310 				
       
   311 		logger.Write(text);
       
   312 		text.Close();		
       
   313 		logger.Write(_L(""));
       
   314 		}
       
   315 	logger.CloseLog();
       
   316 	logger.Close();
       
   317 	}
       
   318 	
       
   319 	
       
   320 #endif
       
   321 #endif