examples/Telephony/ETel3rdPartyExample/PhoneMonitoring/CBatteryInfo.cpp

00001 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
00002 // All rights reserved.
00003 // This component and the accompanying materials are made available
00004 // under the terms of "Eclipse Public License v1.0"
00005 // which accompanies this distribution, and is available
00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00007 //
00008 // Initial Contributors:
00009 // Nokia Corporation - initial contribution.
00010 //
00011 // Contributors:
00012 //
00013 // Description:
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         // Retrieves the status and charge level of the phone battery.
00054         iTelephony->GetBatteryInfo(iStatus, iBatteryInfoV1Pckg);
00055         SetActive();
00056         }
00057 
00064 CBatteryInfo::CBatteryInfo(MExecAsync* aController)
00065         : CISVAPIAsync(aController, KBatteryInfo),
00066           iBatteryInfoV1Pckg(iBatteryInfoV1)
00067         {
00068         // Empty method
00069         }
00070 
00074 void CBatteryInfo::ConstructL()
00075         {
00076         // Empty method
00077         }
00078 
00083 void CBatteryInfo::RunL()
00084         {
00085         CTelephony::TBatteryInfoV1 BatteryInfo = iBatteryInfoV1;
00086 
00087         if(iStatus != KErrNone)
00088                 {
00089                 iConsole->Printf(KError);
00090                 
00091                 // Print the error status code
00092                 iConsole->Printf(_L("%d\n"), iStatus.Int());
00093                 }
00094         else
00095                 {
00096                 // Print Battery Info
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         // Panics if this object is already performing an asynchronous operation.
00143         // Application will panic if you call SetActive() on an already active object.
00144         _LIT( KNotifyPanic, "CBatteryInfo Notify Method" );
00145         __ASSERT_ALWAYS( !IsActive(), User::Panic( KNotifyPanic, 1 ));
00146         iRequestNotify = ETrue;
00147         
00148         // Registers interest in receiving change notifications for events.
00149         iTelephony->NotifyChange(       iStatus,
00150                                                                 CTelephony::EBatteryInfoChange,
00151                                                                 iBatteryInfoV1Pckg );
00152         SetActive();
00153         }
00154 
00158 void CBatteryInfo::DoCancel()
00159         {
00160         // Cancels an outstanding asynchronous request.
00161         iTelephony->CancelAsync(CTelephony::EBatteryInfoChangeCancel);
00162         }
00163 

Generated by  doxygen 1.6.2