os/boardsupport/haitest/bspsvs/suite/bsp/mmc/src/T_MmcSDMediaChangeDriverData.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/boardsupport/haitest/bspsvs/suite/bsp/mmc/src/T_MmcSDMediaChangeDriverData.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,243 @@
1.4 +/*
1.5 +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +#include "T_MmcSDMediaChangeDriverData.h"
1.22 +
1.23 +//MMCSD Commands index
1.24 +/*@{*/
1.25 +
1.26 +_LIT(KEnumNull, " ");
1.27 +
1.28 +_LIT(KCmdMediaState, "MediaState");
1.29 +_LIT(KCmdForceMediaChange, "ForceMediaChange");
1.30 +_LIT(KCmdReplayCount, "ReplayCount");
1.31 +
1.32 +_LIT(KExpectedMediaState, "expectedmediastate");
1.33 +_LIT(KExpectedeventcount, "expectedeventcount");
1.34 +
1.35 +_LIT(KOpened, "EOpened");
1.36 +_LIT(KClosed, "EClosed");
1.37 +
1.38 +const CDataWrapperBase::TEnumEntryTable CT_MMCSDMediaChangeDriverData::iEnumMediaState[] =
1.39 + {
1.40 +// Enum as a descriptor Enum
1.41 + KOpened, EOpened,
1.42 + KClosed, EClosed,
1.43 + KEnumNull, -1
1.44 + };
1.45 +
1.46 +/*@}*/
1.47 +
1.48 +//////////////////////////////////////////////////////////////////////
1.49 +// Construction/Destruction
1.50 +//////////////////////////////////////////////////////////////////////
1.51 +
1.52 +CT_MMCSDMediaChangeDriverData* CT_MMCSDMediaChangeDriverData::NewL()
1.53 + {
1.54 + CT_MMCSDMediaChangeDriverData* ret=new (ELeave) CT_MMCSDMediaChangeDriverData();
1.55 + CleanupStack::PushL(ret);
1.56 + ret->ConstructL();
1.57 + CleanupStack::Pop(ret);
1.58 + return ret;
1.59 + }
1.60 +
1.61 +
1.62 +CT_MMCSDMediaChangeDriverData::CT_MMCSDMediaChangeDriverData()
1.63 +: CT_MmcSDDriverData()
1.64 +, iAsyncErrorIndex(0)
1.65 +, iCons(NULL)
1.66 + {
1.67 + }
1.68 +
1.69 +void CT_MMCSDMediaChangeDriverData::ConstructL()
1.70 +/**
1.71 + * Second phase construction
1.72 + *
1.73 + * @internalComponent
1.74 + *
1.75 + * @return N/A
1.76 + *
1.77 + * @pre None
1.78 + * @post None
1.79 + *
1.80 + * @leave system wide error
1.81 + */
1.82 + {
1.83 + CT_MmcSDDriverData::ConstructL();
1.84 + if(!iCons)
1.85 + {
1.86 + iCons = GetConsoleL();
1.87 + }
1.88 +
1.89 + }
1.90 +
1.91 +CT_MMCSDMediaChangeDriverData::~CT_MMCSDMediaChangeDriverData()
1.92 +/**
1.93 + * Public destructor
1.94 + */
1.95 + {
1.96 + delete iCons;
1.97 + }
1.98 +
1.99 +TBool CT_MMCSDMediaChangeDriverData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
1.100 +/**
1.101 + * Process a command read from the ini file
1.102 + *
1.103 + * @param aCommand The command to process
1.104 + * @param aSection The section in the ini containing data for the command
1.105 + * @param aAsyncErrorIndex Command index for async calls to return errors to
1.106 + *
1.107 + * @return ETrue if the command is processed
1.108 + *
1.109 + * @leave System wide error
1.110 + */
1.111 + {
1.112 + TBool ret=ETrue;
1.113 +
1.114 + if ( aCommand==KCmdMediaState)
1.115 + {
1.116 + DoCmdMediaState(aSection);
1.117 + }
1.118 + else if ( aCommand==KCmdForceMediaChange)
1.119 + {
1.120 + DoCmdForceMediaChange();
1.121 + }
1.122 + else if ( aCommand==KCmdReplayCount)
1.123 + {
1.124 + DoCmdReplayCount(aSection);
1.125 + }
1.126 + else
1.127 + {
1.128 + ret=CT_MmcSDDriverData::DoCommandL(aCommand, aSection, aAsyncErrorIndex);
1.129 + }
1.130 + return ret;
1.131 + }
1.132 +
1.133 +/**
1.134 + * Get the Media State Information
1.135 + *
1.136 + * @param aSection The section in the ini containing data for the command
1.137 + *
1.138 + * @return void
1.139 + *
1.140 + * @leave System wide error
1.141 + */
1.142 +void CT_MMCSDMediaChangeDriverData::DoCmdMediaState(const TDesC& aSection)
1.143 + {
1.144 + TInt err;
1.145 + TInt mediaState;
1.146 + err= iMmcSDController->MediaStateInfo(mediaState);
1.147 + if(err != KErrNone)
1.148 + {
1.149 + ERR_PRINTF2(_L("MMC/SD : Error in getting MediaState information, error code = %d \n"),err);
1.150 + SetBlockResult(EFail);
1.151 + }
1.152 + else
1.153 + {
1.154 + switch(mediaState)
1.155 + {
1.156 + case EOpened:
1.157 + {
1.158 + INFO_PRINTF1(_L("MMC/SD Current MediaChange MediaState - Opened"));
1.159 + break;
1.160 + }
1.161 + case EClosed:
1.162 + {
1.163 + INFO_PRINTF1(_L("MMC/SD Current MediaChange MediaState - Closed"));
1.164 + break;
1.165 + }
1.166 + default:
1.167 + {
1.168 + ERR_PRINTF2(_L("MMC/SD : Current Media State is not supported by the platform-MediaState= %d \n"),mediaState);
1.169 + SetBlockResult(EFail);
1.170 + break;
1.171 + }
1.172 + }
1.173 + TInt expectedmediaState;
1.174 + if ( GetEnumFromConfig(aSection, KExpectedMediaState(), iEnumMediaState, expectedmediaState) )
1.175 + {
1.176 + if(mediaState != expectedmediaState)
1.177 + {
1.178 + ERR_PRINTF3(_L("mediaState(%d) != expectedmediaState(%d)"), mediaState, expectedmediaState);
1.179 + SetBlockResult(EFail);
1.180 + }
1.181 + }
1.182 + else
1.183 + {
1.184 + SetBlockResult(EFail);
1.185 + WARN_PRINTF1(_L("expectedmediaState Value Missing From INI File"));
1.186 + }
1.187 + }
1.188 + }
1.189 +/**
1.190 + * Force Media to Change the State
1.191 + *
1.192 + * @param aSection The section in the ini containing data for the command
1.193 + *
1.194 + * @return void
1.195 + *
1.196 + * @leave System wide error
1.197 + */
1.198 +void CT_MMCSDMediaChangeDriverData::DoCmdForceMediaChange()
1.199 + {
1.200 + TInt err;
1.201 + err= iMmcSDController->ForceMediaChange();
1.202 + if(err != KErrNone)
1.203 + {
1.204 + ERR_PRINTF2(_L("MMC/SD : Error in forcing media state, error code = %d \n"),err);
1.205 + SetError(err);
1.206 + }
1.207 + }
1.208 +
1.209 +/**
1.210 + * Count of media events yet to be acknowledged.
1.211 + *
1.212 + * @param aSection The section in the ini containing data for the command
1.213 + *
1.214 + * @return void
1.215 + *
1.216 + * @leave System wide error
1.217 + */
1.218 +void CT_MMCSDMediaChangeDriverData::DoCmdReplayCount(const TDesC& aSection)
1.219 + {
1.220 + TInt err;
1.221 + TInt mediaEventCount;
1.222 + err=iMmcSDController->MediaChangeCounter(mediaEventCount);
1.223 + if(err != KErrNone)
1.224 + {
1.225 + ERR_PRINTF2(_L("MMC/SD : Error in reading media event replay count, error code = %d \n"),err);
1.226 + SetBlockResult(EFail);
1.227 + }
1.228 + else
1.229 + {
1.230 + INFO_PRINTF2(_L("MMC/SD: Media Event Count = %d \n"),mediaEventCount);
1.231 + TInt expectedmediaEventCount;
1.232 + if(GetBoolFromConfig(aSection, KExpectedeventcount(), expectedmediaEventCount))
1.233 + {
1.234 + if(mediaEventCount != expectedmediaEventCount)
1.235 + {
1.236 + ERR_PRINTF3(_L("mediaEventCount(%d) != expectedchangedState(%d)"), mediaEventCount, expectedmediaEventCount);
1.237 + SetBlockResult(EFail);
1.238 + }
1.239 + }
1.240 + else
1.241 + {
1.242 + SetBlockResult(EFail);
1.243 + WARN_PRINTF1(_L("expectedchangedState Value Missing From INI File"));
1.244 + }
1.245 + }
1.246 + }