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