telephonyserverplugins/simtsy/src/CSimBatteryCharger.cpp
branchRCL_3
changeset 20 07a122eea281
parent 19 630d2f34d719
equal deleted inserted replaced
19:630d2f34d719 20:07a122eea281
     1 // Copyright (c) 2001-2010 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    18 
    18 
    19 /**
    19 /**
    20  @file
    20  @file
    21 */
    21 */
    22 
    22 
    23 
       
    24 
       
    25 #include "OstTraceDefinitions.h"
       
    26 #ifdef OST_TRACE_COMPILER_IN_USE
       
    27 #include "CSimBatteryChargerTraces.h"
       
    28 #endif
       
    29 
       
    30 #include <testconfigfileparser.h>
    23 #include <testconfigfileparser.h>
    31 #include "CSimBatteryCharger.h"
    24 #include "CSimBatteryCharger.h"
    32 #include "CSimPhone.h"
    25 #include "CSimPhone.h"
       
    26 #include "Simlog.h"
    33 
    27 
    34 const TInt KChargerGranularity=5;		// < Granularity for Battery Charger list array
    28 const TInt KChargerGranularity=5;		// < Granularity for Battery Charger list array
    35 
    29 
    36 
    30 
    37 CSimBatteryCharger* CSimBatteryCharger::NewL(CSimPhone* aPhone)
    31 CSimBatteryCharger* CSimBatteryCharger::NewL(CSimPhone* aPhone)
    72  */
    66  */
    73 	{
    67 	{
    74 	iTimer=CSimTimer::NewL(iPhone);
    68 	iTimer=CSimTimer::NewL(iPhone);
    75 	iBatteryChargerInfo=new(ELeave) CArrayFixFlat<TBatteryChargerInfo>(KChargerGranularity);
    69 	iBatteryChargerInfo=new(ELeave) CArrayFixFlat<TBatteryChargerInfo>(KChargerGranularity);
    76 
    70 
    77 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSIMBATTERYCHARGER_CONSTRUCTL_1, "Starting to parse Battery Charger config parameters...");
    71 	LOGMISC1("Starting to parse Battery Charger config parameters...");
    78 	TInt count=CfgFile()->ItemCount(KBatteryCharger);
    72 	TInt count=CfgFile()->ItemCount(KBatteryCharger);
    79 	const CTestConfigItem* item=NULL;
    73 	const CTestConfigItem* item=NULL;
    80 	TInt ret=KErrNone;
    74 	TInt ret=KErrNone;
    81 
    75 
    82 	TInt i;
    76 	TInt i;
    89 		TInt duration, status, level, error;
    83 		TInt duration, status, level, error;
    90 
    84 
    91 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,0,duration);
    85 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,0,duration);
    92 		if(ret!=KErrNone)
    86 		if(ret!=KErrNone)
    93 			{
    87 			{
    94 			OstTraceDefExt3(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSIMBATTERYCHARGER_CONSTRUCTL_2, "WARNING - CONFIGURATION FILE PARSING - Reading element DURATION returned %d (element no. %d) from tag %s.",ret,0,KBatteryCharger);
    88 			LOGPARSERR("duration",ret,0,&KBatteryCharger);
    95 			continue;
    89 			continue;
    96 			}
    90 			}
    97 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,1,status);
    91 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,1,status);
    98 		if(ret!=KErrNone)
    92 		if(ret!=KErrNone)
    99 			{
    93 			{
   100 			OstTraceDefExt3(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSIMBATTERYCHARGER_CONSTRUCTL_3, "WARNING - CONFIGURATION FILE PARSING - Reading element STATUS returned %d (element no. %d) from tag %s.",ret,1,KBatteryCharger);
    94 			LOGPARSERR("status",ret,1,&KBatteryCharger);
   101 			continue;
    95 			continue;
   102 			}
    96 			}
   103 		
    97 		
   104 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,2,level);
    98 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,2,level);
   105 		if(ret!=KErrNone)
    99 		if(ret!=KErrNone)
   106 			{
   100 			{
   107 			OstTraceDefExt3(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSIMBATTERYCHARGER_CONSTRUCTL_4, "WARNING - CONFIGURATION FILE PARSING - Reading element LEVEL returned %d (element no. %d) from tag %s.",ret,2,KBatteryCharger);
   101 			LOGPARSERR("level",ret,2,&KBatteryCharger);
   108 			continue;
   102 			continue;
   109 			}
   103 			}
   110 
   104 
   111 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,3,error);
   105 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,3,error);
   112 		if(ret!=KErrNone)
   106 		if(ret!=KErrNone)
   118 		chargerInfo.iChargeLevel = level;
   112 		chargerInfo.iChargeLevel = level;
   119 		chargerInfo.iError = error;
   113 		chargerInfo.iError = error;
   120 		iBatteryChargerInfo->AppendL(chargerInfo);
   114 		iBatteryChargerInfo->AppendL(chargerInfo);
   121 		}
   115 		}
   122 	
   116 	
   123 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSIMBATTERYCHARGER_CONSTRUCTL_5, "Finished parsing Battery Charger config parameters...%d items found",count);
   117 	LOGMISC2("Finished parsing Battery Charger config parameters...%d items found",count);
   124 
   118 
   125 	if(iBatteryChargerInfo->Count()!=0)
   119 	if(iBatteryChargerInfo->Count()!=0)
   126 		{
   120 		{
   127 		iBatteryChargerIndex = 0;
   121 		iBatteryChargerIndex = 0;
   128 		iCurrentBatteryCharger = iBatteryChargerInfo->At(0).iChargeLevel;
   122 		iCurrentBatteryCharger = iBatteryChargerInfo->At(0).iChargeLevel;
   192  * @param aReqHandle	The request handle associated with this request.
   186  * @param aReqHandle	The request handle associated with this request.
   193  * @param aPckg1		This is populated with the Battery Charger flags.
   187  * @param aPckg1		This is populated with the Battery Charger flags.
   194  * @return TInt			Standard error value.
   188  * @return TInt			Standard error value.
   195  */
   189  */
   196 	{
   190 	{
   197 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSIMBATTERYCHARGER_GETBATTERYINFO_1, ">>CSimBatteryCharger::GetBatteryInfo");
   191 	LOGMISC1(">>CSimBatteryCharger::GetBatteryInfo");
   198 	TPckg<RMobilePhone::TMobilePhoneBatteryInfoV1>* batteryInfoPckg = (TPckg<RMobilePhone::TMobilePhoneBatteryInfoV1>*)aInfo;
   192 	TPckg<RMobilePhone::TMobilePhoneBatteryInfoV1>* batteryInfoPckg = (TPckg<RMobilePhone::TMobilePhoneBatteryInfoV1>*)aInfo;
   199 	RMobilePhone::TMobilePhoneBatteryInfoV1& batteryInfo = (*batteryInfoPckg)();
   193 	RMobilePhone::TMobilePhoneBatteryInfoV1& batteryInfo = (*batteryInfoPckg)();
   200 
   194 
   201 	// Check that the data structure is supported by the simulated TSY version
   195 	// Check that the data structure is supported by the simulated TSY version
   202 	TInt err = iPhone->CheckSimTsyVersion(batteryInfo);
   196 	TInt err = iPhone->CheckSimTsyVersion(batteryInfo);
   212 		return KErrNone;
   206 		return KErrNone;
   213 		}
   207 		}
   214 
   208 
   215 	batteryInfo.iChargeLevel=iCurrentBatteryCharger;
   209 	batteryInfo.iChargeLevel=iCurrentBatteryCharger;
   216 	batteryInfo.iStatus = iCurrentStatus;
   210 	batteryInfo.iStatus = iCurrentStatus;
   217 	OstTraceDefExt2(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSIMBATTERYCHARGER_GETBATTERYINFO_2, "<<CSimBatteryCharger::GetBatteryInfo with level=%d and status=%d",iCurrentBatteryCharger,iCurrentStatus);
   211 	LOGMISC3("<<CSimBatteryCharger::GetBatteryInfo with level=%d and status=%d",iCurrentBatteryCharger,iCurrentStatus);
   218 	iPhone->ReqCompleted(aReqHandle,iCurrentErr);
   212 	iPhone->ReqCompleted(aReqHandle,iCurrentErr);
   219 	return KErrNone;
   213 	return KErrNone;
   220 	}
   214 	}
   221 
   215 
   222 TInt CSimBatteryCharger::NotifyBatteryInfoChange(TTsyReqHandle aReqHandle, TDes8* aInfo)
   216 TInt CSimBatteryCharger::NotifyBatteryInfoChange(TTsyReqHandle aReqHandle, TDes8* aInfo)
   227  *
   221  *
   228  * @param aPckg1		The first parameter package.  This is populated with the Battery Charger flags.
   222  * @param aPckg1		The first parameter package.  This is populated with the Battery Charger flags.
   229  * @return TInt			Standard error value.
   223  * @return TInt			Standard error value.
   230  */
   224  */
   231 	{
   225 	{
   232 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSIMBATTERYCHARGER_NOTIFYBATTERYINFOCHANGE_1, ">>CSimBatteryCharger::NotifyBatteryInfoChange");
   226 	LOGMISC1(">>CSimBatteryCharger::NotifyBatteryInfoChange");
   233 	TPckg<RMobilePhone::TMobilePhoneBatteryInfoV1>* batteryInfoPckg=(TPckg<RMobilePhone::TMobilePhoneBatteryInfoV1>*)aInfo;
   227 	TPckg<RMobilePhone::TMobilePhoneBatteryInfoV1>* batteryInfoPckg=(TPckg<RMobilePhone::TMobilePhoneBatteryInfoV1>*)aInfo;
   234 	RMobilePhone::TMobilePhoneBatteryInfoV1& batteryInfo=(*batteryInfoPckg)();
   228 	RMobilePhone::TMobilePhoneBatteryInfoV1& batteryInfo=(*batteryInfoPckg)();
   235 
   229 
   236 	// Check that the data structure is supported by the simulated TSY version
   230 	// Check that the data structure is supported by the simulated TSY version
   237 	TInt err = iPhone->CheckSimTsyVersion(batteryInfo);
   231 	TInt err = iPhone->CheckSimTsyVersion(batteryInfo);
   259  * Cancel a previous request to be notified of a change in Battery Charger.
   253  * Cancel a previous request to be notified of a change in Battery Charger.
   260  */
   254  */
   261 	{
   255 	{
   262 	if(iBatteryChargerNotificationPending)
   256 	if(iBatteryChargerNotificationPending)
   263 		{
   257 		{
   264 		OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSIMBATTERYCHARGER_NOTIFYBATTERYINFOCANCEL_1, "CSimBatteryCharger::NotifyBatteryInfoChange has been cancelled");
   258 		LOGMISC1("CSimBatteryCharger::NotifyBatteryInfoChange has been cancelled");
   265 		iBatteryChargerNotificationPending=EFalse;
   259 		iBatteryChargerNotificationPending=EFalse;
   266 		iPhone->ReqCompleted(iBatteryChargerNotificationReqHandle,KErrCancel);
   260 		iPhone->ReqCompleted(iBatteryChargerNotificationReqHandle,KErrCancel);
   267 		}
   261 		}
   268 	else
   262 	else
   269 		OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSIMBATTERYCHARGER_NOTIFYBATTERYINFOCANCEL_2, "CSimBatteryCharger::NotifyBatteryInfoChange was not outstanding and hasn't been cancelled");
   263 		LOGMISC1("CSimBatteryCharger::NotifyBatteryInfoChange was not outstanding and hasn't been cancelled");
   270 	}
   264 	}
   271 
   265 
   272 
   266 
   273 
   267 
   274 void CSimBatteryCharger::TimerCallBack(TInt /*aId*/)
   268 void CSimBatteryCharger::TimerCallBack(TInt /*aId*/)
   298 	if(iBatteryChargerNotificationPending)
   292 	if(iBatteryChargerNotificationPending)
   299 		{
   293 		{
   300 		iBatteryChargerNotificationPending=EFalse;
   294 		iBatteryChargerNotificationPending=EFalse;
   301 		(*iBatteryChargerNofificationValue).iChargeLevel=iCurrentBatteryCharger;
   295 		(*iBatteryChargerNofificationValue).iChargeLevel=iCurrentBatteryCharger;
   302 		(*iBatteryChargerNofificationValue).iStatus=iCurrentStatus;
   296 		(*iBatteryChargerNofificationValue).iStatus=iCurrentStatus;
   303 		OstTraceDefExt2(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSIMBATTERYCHARGER_TIMERCALLBACK_1, "<<CSimBatteryCharger::NotifyBatteryInfoChange with level=%d and status=%d",iCurrentBatteryCharger,iCurrentStatus);
   297 		LOGMISC3("<<CSimBatteryCharger::NotifyBatteryInfoChange with level=%d and status=%d",iCurrentBatteryCharger,iCurrentStatus);
   304 		iPhone->ReqCompleted(iBatteryChargerNotificationReqHandle,iCurrentErr);
   298 		iPhone->ReqCompleted(iBatteryChargerNotificationReqHandle,iCurrentErr);
   305 		}
   299 		}
   306 	iTimer->Start(iBatteryChargerInfo->At(iBatteryChargerIndex).iDuration,this);
   300 	iTimer->Start(iBatteryChargerInfo->At(iBatteryChargerIndex).iDuration,this);
   307 	}
   301 	}
   308 
   302