00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "CBatteryInfo.h"
00018
00026 CBatteryInfo* CBatteryInfo::NewL(MExecAsync* aController)
00027 {
00028 CBatteryInfo* self = new(ELeave) CBatteryInfo(aController);
00029 CleanupStack::PushL(self);
00030 self->ConstructL();
00031 CleanupStack::Pop(self);
00032 return self;
00033 }
00034
00039 CBatteryInfo::~CBatteryInfo()
00040 {
00041 Cancel();
00042 }
00043
00047 void CBatteryInfo::DoStartRequestL()
00048 {
00049 _LIT( KNotifyPanic, "CBatteryInfo Get Method" );
00050 __ASSERT_ALWAYS( !IsActive(), User::Panic( KNotifyPanic, 1 ));
00051 iRequestNotify = EFalse;
00052
00053
00054 iTelephony->GetBatteryInfo(iStatus, iBatteryInfoV1Pckg);
00055 SetActive();
00056 }
00057
00064 CBatteryInfo::CBatteryInfo(MExecAsync* aController)
00065 : CISVAPIAsync(aController, KBatteryInfo),
00066 iBatteryInfoV1Pckg(iBatteryInfoV1)
00067 {
00068
00069 }
00070
00074 void CBatteryInfo::ConstructL()
00075 {
00076
00077 }
00078
00083 void CBatteryInfo::RunL()
00084 {
00085 CTelephony::TBatteryInfoV1 BatteryInfo = iBatteryInfoV1;
00086
00087 if(iStatus != KErrNone)
00088 {
00089 iConsole->Printf(KError);
00090
00091
00092 iConsole->Printf(_L("%d\n"), iStatus.Int());
00093 }
00094 else
00095 {
00096
00097 CTelephony::TBatteryStatus batteryStatus = BatteryInfo.iStatus;
00098 TUint chargeLevel = BatteryInfo.iChargeLevel;
00099 if (iRequestNotify)
00100 {
00101 iConsole->ClearScreen();
00102 iConsole->Printf(_L("~*THIS IS A NOTIFICATION*~\n"));
00103 }
00104 iConsole->Printf(KBatteryInfoMsg);
00105 iConsole->Printf(_L("Charge is %d\n"), chargeLevel);
00106 switch (batteryStatus)
00107 {
00108 case CTelephony::EPowerStatusUnknown:
00109 iConsole->Printf(_L("EPowerStatusUnknown %d\n"), batteryStatus);
00110 break;
00111 case CTelephony::EPoweredByBattery:
00112 iConsole->Printf(_L("EPoweredByBattery %d\n"), batteryStatus);
00113 break;
00114 case CTelephony::EBatteryConnectedButExternallyPowered:
00115 iConsole->Printf(_L("EBatteryConnectedButExternallyPowered %d\n"), batteryStatus);
00116 break;
00117 case CTelephony::ENoBatteryConnected:
00118 iConsole->Printf(_L("ENoBatteryConnected %d\n"), batteryStatus);
00119 break;
00120 case CTelephony::EPowerFault:
00121 iConsole->Printf(_L("EPowerFault %d\n"), batteryStatus);
00122 break;
00123 default:
00124 iConsole->Printf(KError);
00125 }
00126 }
00127 if (iRequestNotify)
00128 {
00129 DoRequestNotificationL();
00130 }
00131 else
00132 {
00133 ExampleComplete();
00134 }
00135 }
00136
00140 void CBatteryInfo::DoRequestNotificationL()
00141 {
00142
00143
00144 _LIT( KNotifyPanic, "CBatteryInfo Notify Method" );
00145 __ASSERT_ALWAYS( !IsActive(), User::Panic( KNotifyPanic, 1 ));
00146 iRequestNotify = ETrue;
00147
00148
00149 iTelephony->NotifyChange( iStatus,
00150 CTelephony::EBatteryInfoChange,
00151 iBatteryInfoV1Pckg );
00152 SetActive();
00153 }
00154
00158 void CBatteryInfo::DoCancel()
00159 {
00160
00161 iTelephony->CancelAsync(CTelephony::EBatteryInfoChangeCancel);
00162 }
00163