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