00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "CBatteryInfo.h"
00033
00041 CBatteryInfo* CBatteryInfo::NewL(MExecAsync* aController)
00042 {
00043 CBatteryInfo* self = new(ELeave) CBatteryInfo(aController);
00044 CleanupStack::PushL(self);
00045 self->ConstructL();
00046 CleanupStack::Pop(self);
00047 return self;
00048 }
00049
00054 CBatteryInfo::~CBatteryInfo()
00055 {
00056 Cancel();
00057 }
00058
00062 void CBatteryInfo::DoStartRequestL()
00063 {
00064 _LIT( KNotifyPanic, "CBatteryInfo Get Method" );
00065 __ASSERT_ALWAYS( !IsActive(), User::Panic( KNotifyPanic, 1 ));
00066 iRequestNotify = EFalse;
00067
00068
00069 iTelephony->GetBatteryInfo(iStatus, iBatteryInfoV1Pckg);
00070 SetActive();
00071 }
00072
00079 CBatteryInfo::CBatteryInfo(MExecAsync* aController)
00080 : CISVAPIAsync(aController, KBatteryInfo),
00081 iBatteryInfoV1Pckg(iBatteryInfoV1)
00082 {
00083
00084 }
00085
00089 void CBatteryInfo::ConstructL()
00090 {
00091
00092 }
00093
00098 void CBatteryInfo::RunL()
00099 {
00100 CTelephony::TBatteryInfoV1 BatteryInfo = iBatteryInfoV1;
00101
00102 if(iStatus != KErrNone)
00103 {
00104 iConsole->Printf(KError);
00105
00106
00107 iConsole->Printf(_L("%d\n"), iStatus.Int());
00108 }
00109 else
00110 {
00111
00112 CTelephony::TBatteryStatus batteryStatus = BatteryInfo.iStatus;
00113 TUint chargeLevel = BatteryInfo.iChargeLevel;
00114 if (iRequestNotify)
00115 {
00116 iConsole->ClearScreen();
00117 iConsole->Printf(_L("~*THIS IS A NOTIFICATION*~\n"));
00118 }
00119 iConsole->Printf(KBatteryInfoMsg);
00120 iConsole->Printf(_L("Charge is %d\n"), chargeLevel);
00121 switch (batteryStatus)
00122 {
00123 case CTelephony::EPowerStatusUnknown:
00124 iConsole->Printf(_L("EPowerStatusUnknown %d\n"), batteryStatus);
00125 break;
00126 case CTelephony::EPoweredByBattery:
00127 iConsole->Printf(_L("EPoweredByBattery %d\n"), batteryStatus);
00128 break;
00129 case CTelephony::EBatteryConnectedButExternallyPowered:
00130 iConsole->Printf(_L("EBatteryConnectedButExternallyPowered %d\n"), batteryStatus);
00131 break;
00132 case CTelephony::ENoBatteryConnected:
00133 iConsole->Printf(_L("ENoBatteryConnected %d\n"), batteryStatus);
00134 break;
00135 case CTelephony::EPowerFault:
00136 iConsole->Printf(_L("EPowerFault %d\n"), batteryStatus);
00137 break;
00138 default:
00139 iConsole->Printf(KError);
00140 }
00141 }
00142 if (iRequestNotify)
00143 {
00144 DoRequestNotificationL();
00145 }
00146 else
00147 {
00148 ExampleComplete();
00149 }
00150 }
00151
00155 void CBatteryInfo::DoRequestNotificationL()
00156 {
00157
00158
00159 _LIT( KNotifyPanic, "CBatteryInfo Notify Method" );
00160 __ASSERT_ALWAYS( !IsActive(), User::Panic( KNotifyPanic, 1 ));
00161 iRequestNotify = ETrue;
00162
00163
00164 iTelephony->NotifyChange( iStatus,
00165 CTelephony::EBatteryInfoChange,
00166 iBatteryInfoV1Pckg );
00167 SetActive();
00168 }
00169
00173 void CBatteryInfo::DoCancel()
00174 {
00175
00176 iTelephony->CancelAsync(CTelephony::EBatteryInfoChangeCancel);
00177 }
00178