os/boardsupport/haitest/bspsvs/suite/bsp/mmc/src/T_MmcSDMediaChangeDriverData.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2005-2009 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 #include "T_MmcSDMediaChangeDriverData.h"
    19 
    20 //MMCSD Commands index
    21 /*@{*/
    22 
    23 _LIT(KEnumNull,							" ");
    24 
    25 _LIT(KCmdMediaState,					"MediaState");
    26 _LIT(KCmdForceMediaChange,				"ForceMediaChange");
    27 _LIT(KCmdReplayCount,					"ReplayCount");
    28 
    29 _LIT(KExpectedMediaState,				"expectedmediastate");
    30 _LIT(KExpectedeventcount,				"expectedeventcount");
    31 
    32 _LIT(KOpened,							"EOpened");
    33 _LIT(KClosed,							"EClosed");
    34 
    35 const CDataWrapperBase::TEnumEntryTable	CT_MMCSDMediaChangeDriverData::iEnumMediaState[] =
    36 	{
    37 //	Enum as a descriptor					Enum
    38 	KOpened,								EOpened,
    39 	KClosed,								EClosed,
    40 	KEnumNull,								-1
    41 	};
    42 
    43 /*@}*/
    44 
    45 //////////////////////////////////////////////////////////////////////
    46 // Construction/Destruction
    47 //////////////////////////////////////////////////////////////////////
    48 
    49 CT_MMCSDMediaChangeDriverData* CT_MMCSDMediaChangeDriverData::NewL()
    50 	{
    51 	CT_MMCSDMediaChangeDriverData*	ret=new (ELeave) CT_MMCSDMediaChangeDriverData();
    52 	CleanupStack::PushL(ret);
    53 	ret->ConstructL();
    54 	CleanupStack::Pop(ret);
    55 	return ret;
    56 	}
    57 
    58 
    59 CT_MMCSDMediaChangeDriverData::CT_MMCSDMediaChangeDriverData()
    60 :	CT_MmcSDDriverData()
    61 ,	iAsyncErrorIndex(0)
    62 ,	iCons(NULL)
    63 	{
    64 	}
    65 
    66 void CT_MMCSDMediaChangeDriverData::ConstructL()
    67 /**
    68  * Second phase construction
    69  *
    70  * @internalComponent
    71  *
    72  * @return	N/A
    73  *
    74  * @pre		None
    75  * @post	None
    76  *
    77  * @leave	system wide error
    78  */
    79 	{
    80 	CT_MmcSDDriverData::ConstructL();
    81 	if(!iCons)
    82 		{
    83 		iCons = GetConsoleL();
    84 		}
    85 
    86 	}
    87 
    88 CT_MMCSDMediaChangeDriverData::~CT_MMCSDMediaChangeDriverData()
    89 /**
    90  * Public destructor
    91  */
    92 	{
    93 	delete iCons;
    94 	}
    95 
    96 TBool CT_MMCSDMediaChangeDriverData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
    97 /**
    98  * Process a command read from the ini file
    99  *
   100  * @param aCommand			The command to process
   101  * @param aSection			The section in the ini containing data for the command
   102  * @param aAsyncErrorIndex	Command index for async calls to return errors to
   103  *
   104  * @return					ETrue if the command is processed
   105  *
   106  * @leave					System wide error
   107  */
   108 	{
   109 	TBool	ret=ETrue;
   110 
   111 	if ( aCommand==KCmdMediaState)
   112 		{
   113 		DoCmdMediaState(aSection);
   114 		}
   115  	else if ( aCommand==KCmdForceMediaChange)
   116 		{
   117 		DoCmdForceMediaChange();
   118 		}
   119 	else if ( aCommand==KCmdReplayCount)
   120 		{
   121 		DoCmdReplayCount(aSection);
   122 		}
   123 	else
   124 		{
   125 		ret=CT_MmcSDDriverData::DoCommandL(aCommand, aSection, aAsyncErrorIndex);
   126 		}
   127 	return ret;
   128 	}
   129 
   130 /**
   131  * Get the Media State Information
   132  *
   133  * @param aSection			The section in the ini containing data for the command
   134  *
   135  * @return					void
   136  *
   137  * @leave					System wide error
   138  */
   139 void CT_MMCSDMediaChangeDriverData::DoCmdMediaState(const TDesC& aSection)
   140 	{
   141 	TInt err;
   142 	TInt mediaState;
   143 	err= iMmcSDController->MediaStateInfo(mediaState);
   144 		if(err != KErrNone)
   145 			{
   146 			ERR_PRINTF2(_L("MMC/SD : Error in getting MediaState information, error code = %d \n"),err);
   147 			SetBlockResult(EFail);
   148 			}
   149 		else
   150 			{
   151 			switch(mediaState)
   152 				{
   153 			case EOpened:
   154 					{
   155 					INFO_PRINTF1(_L("MMC/SD Current MediaChange MediaState - Opened"));
   156 					break;
   157 					}
   158 			case EClosed:
   159 					{
   160 					INFO_PRINTF1(_L("MMC/SD Current MediaChange MediaState - Closed"));
   161 					break;
   162 					}
   163 			default:
   164 					{
   165 					ERR_PRINTF2(_L("MMC/SD : Current Media State is not supported by the platform-MediaState= %d \n"),mediaState);
   166 					SetBlockResult(EFail);
   167 					break;
   168 					}
   169 				}
   170 				TInt	expectedmediaState;
   171 				if ( GetEnumFromConfig(aSection, KExpectedMediaState(), iEnumMediaState, expectedmediaState) )
   172 					{
   173 					if(mediaState != expectedmediaState)
   174 						{
   175 						ERR_PRINTF3(_L("mediaState(%d) != expectedmediaState(%d)"), mediaState, expectedmediaState);
   176 						SetBlockResult(EFail);
   177 						}
   178 					}
   179 				else
   180 				{
   181 				SetBlockResult(EFail);
   182 				WARN_PRINTF1(_L("expectedmediaState Value Missing From INI File"));
   183 				}
   184 			}
   185 	}
   186 /**
   187  * Force Media to Change the State
   188  *
   189  * @param aSection			The section in the ini containing data for the command
   190  *
   191  * @return					void
   192  *
   193  * @leave					System wide error
   194  */
   195 void CT_MMCSDMediaChangeDriverData::DoCmdForceMediaChange()
   196 	{
   197 	TInt err;
   198 	err= iMmcSDController->ForceMediaChange();
   199 	if(err != KErrNone)
   200 			{
   201 			ERR_PRINTF2(_L("MMC/SD : Error in forcing media state, error code = %d \n"),err);
   202 			SetError(err);
   203 			}
   204 	}
   205 
   206 /**
   207  * Count of media events yet to be acknowledged.
   208  *
   209  * @param aSection			The section in the ini containing data for the command
   210  *
   211  * @return					void
   212  *
   213  * @leave					System wide error
   214  */
   215 void CT_MMCSDMediaChangeDriverData::DoCmdReplayCount(const TDesC& aSection)
   216 	{
   217 	TInt err;
   218 	TInt mediaEventCount;
   219 	err=iMmcSDController->MediaChangeCounter(mediaEventCount);
   220 	if(err != KErrNone)
   221 			{
   222 			ERR_PRINTF2(_L("MMC/SD : Error in reading media event replay count, error code = %d \n"),err);
   223 			SetBlockResult(EFail);
   224 			}
   225 		else
   226 			{
   227 			INFO_PRINTF2(_L("MMC/SD: Media Event Count    = %d \n"),mediaEventCount);
   228 			TInt	expectedmediaEventCount;
   229 			if(GetBoolFromConfig(aSection, KExpectedeventcount(), expectedmediaEventCount))
   230 				{
   231 				if(mediaEventCount != expectedmediaEventCount)
   232 					{
   233 					ERR_PRINTF3(_L("mediaEventCount(%d) != expectedchangedState(%d)"), mediaEventCount, expectedmediaEventCount);
   234 					SetBlockResult(EFail);
   235 					}
   236 				}
   237 			else
   238 				{
   239 				SetBlockResult(EFail);
   240 				WARN_PRINTF1(_L("expectedchangedState Value Missing From INI File"));
   241 				}
   242 			}
   243 	}