24
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
// INCLUDE FILES
|
|
21 |
#include "ChargingStatusObserver.h"
|
|
22 |
#include <ctsy/tflogger.h>
|
|
23 |
|
|
24 |
// ======== MEMBER FUNCTIONS ========
|
|
25 |
|
|
26 |
CChargingStatusObserver* CChargingStatusObserver::NewL(
|
|
27 |
MChargingStatusNotifier& aChargingStatusNotifier )
|
|
28 |
{
|
|
29 |
CChargingStatusObserver* self = CChargingStatusObserver::NewLC( aChargingStatusNotifier );
|
|
30 |
CleanupStack::Pop(self);
|
|
31 |
return self;
|
|
32 |
}
|
|
33 |
|
|
34 |
CChargingStatusObserver* CChargingStatusObserver::NewLC(
|
|
35 |
MChargingStatusNotifier& aChargingStatusNotifier )
|
|
36 |
{
|
|
37 |
CChargingStatusObserver* self = new ( ELeave ) CChargingStatusObserver(
|
|
38 |
aChargingStatusNotifier );
|
|
39 |
CleanupStack::PushL(self);
|
|
40 |
self->ConstructL();
|
|
41 |
return self;
|
|
42 |
}
|
|
43 |
|
|
44 |
CChargingStatusObserver::~CChargingStatusObserver()
|
|
45 |
{
|
|
46 |
Cancel();
|
|
47 |
iChargingStatus.Close();
|
|
48 |
}
|
|
49 |
|
|
50 |
void CChargingStatusObserver::ConstructL()
|
|
51 |
{
|
|
52 |
User::LeaveIfError( iChargingStatus.Attach( KPSUidHWRMPowerState,
|
|
53 |
KHWRMChargingStatus ) );
|
|
54 |
RunL();
|
|
55 |
}
|
|
56 |
|
|
57 |
CChargingStatusObserver::CChargingStatusObserver(
|
|
58 |
MChargingStatusNotifier& aChargingStatusNotifier ) :
|
|
59 |
CActive(EPriorityStandard),
|
|
60 |
iChargingStatusNotifier( aChargingStatusNotifier )
|
|
61 |
{
|
|
62 |
CActiveScheduler::Add( this );
|
|
63 |
}
|
|
64 |
|
|
65 |
// -----------------------------------------------------------------------------
|
|
66 |
// CChargingStatusObserver::RunL
|
|
67 |
// Handles CChargingStatusObserver::GetBatteryInfo request completion event.
|
|
68 |
//
|
|
69 |
// -----------------------------------------------------------------------------
|
|
70 |
//
|
|
71 |
void CChargingStatusObserver::RunL()
|
|
72 |
{
|
|
73 |
RMobilePhone::TMobilePhoneBatteryInfoV1 batteryInfo;
|
|
74 |
batteryInfo.iStatus = RMobilePhone::EPowerStatusUnknown;
|
|
75 |
|
|
76 |
TInt errorStatus( iStatus.Int() );
|
|
77 |
|
|
78 |
// resubscribe before processing new value to prevent missing updates
|
|
79 |
iChargingStatus.Subscribe( iStatus );
|
|
80 |
SetActive();
|
|
81 |
|
|
82 |
if ( KErrNone != errorStatus )
|
|
83 |
{
|
|
84 |
TFLOGSTRING2("TSY: CChargingStatusObserver::RunL - iStatus: %d", errorStatus );
|
|
85 |
iChargingStatusNotifier.NotifyChargingStatus( errorStatus,
|
|
86 |
batteryInfo );
|
|
87 |
return;
|
|
88 |
}
|
|
89 |
|
|
90 |
// property updated, get new value
|
|
91 |
TInt level( 0 );
|
|
92 |
TInt error = iChargingStatus.Get( level );
|
|
93 |
TFLOGSTRING2("TSY: CChargingStatusObserver::RunL error: %d", error);
|
|
94 |
|
|
95 |
if ( KErrNone == error )
|
|
96 |
{
|
|
97 |
EPSHWRMChargingStatus chargingStatus = (EPSHWRMChargingStatus)level;
|
|
98 |
|
|
99 |
switch ( chargingStatus )
|
|
100 |
{
|
|
101 |
case EChargingStatusNotConnected:
|
|
102 |
batteryInfo.iStatus = RMobilePhone::EPoweredByBattery;
|
|
103 |
break;
|
|
104 |
|
|
105 |
case EChargingStatusAlmostComplete:
|
|
106 |
case EChargingStatusChargingComplete:
|
|
107 |
case EChargingStatusCharging:
|
|
108 |
batteryInfo.iStatus =
|
|
109 |
RMobilePhone::EBatteryConnectedButExternallyPowered;
|
|
110 |
break;
|
|
111 |
|
|
112 |
case EChargingStatusNotCharging:
|
|
113 |
batteryInfo.iStatus = RMobilePhone::EPoweredByBattery;
|
|
114 |
break;
|
|
115 |
|
|
116 |
case EChargingStatusError:
|
|
117 |
default:
|
|
118 |
batteryInfo.iStatus = RMobilePhone::EPowerStatusUnknown;
|
|
119 |
break;
|
|
120 |
}
|
|
121 |
}
|
|
122 |
iChargingStatusNotifier.NotifyChargingStatus( error, batteryInfo );
|
|
123 |
}
|
|
124 |
|
|
125 |
// -----------------------------------------------------------------------------
|
|
126 |
// CChargingStatusObserver::DoCancel
|
|
127 |
// Cancellation of an outstanding request
|
|
128 |
//
|
|
129 |
// -----------------------------------------------------------------------------
|
|
130 |
//
|
|
131 |
void CChargingStatusObserver::DoCancel()
|
|
132 |
{
|
|
133 |
iChargingStatus.Cancel();
|
|
134 |
}
|
|
135 |
|
|
136 |
// End of File
|