|
1 /* |
|
2 * Copyright (c) 2008-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 #include "tpropertybatterycharging.h" |
|
19 |
|
20 #include <e32property.h> //Publish & Subscribe header |
|
21 |
|
22 #include <centralrepository.h> |
|
23 #include "usbbatterycharging.h" |
|
24 #include"tbatterychargingdefinitions.h" |
|
25 |
|
26 |
|
27 LOCAL_C void ConsoleMainL(); |
|
28 |
|
29 GLDEF_C TInt E32Main() |
|
30 { |
|
31 __UHEAP_MARK; |
|
32 CTrapCleanup* cleanup=CTrapCleanup::New(); // get clean-up stack |
|
33 |
|
34 TRAPD(error, ConsoleMainL() ); |
|
35 |
|
36 __ASSERT_ALWAYS(!error,User::Panic(_L("TPropertyBatteryCharging"), error)); |
|
37 delete cleanup; // destroy clean-up stack |
|
38 __UHEAP_MARKEND; |
|
39 return KErrNone; |
|
40 } |
|
41 |
|
42 void ConsoleMainL() |
|
43 { |
|
44 CActiveScheduler* myScheduler = new(ELeave) CActiveScheduler; |
|
45 CleanupStack::PushL(myScheduler); |
|
46 CActiveScheduler::Install(myScheduler); |
|
47 |
|
48 CPropertyBatteryCharging* propertyBatCharg = CPropertyBatteryCharging::NewL(); |
|
49 CleanupStack::PushL(propertyBatCharg); |
|
50 |
|
51 RProcess::Rendezvous(KErrNone); |
|
52 |
|
53 CActiveScheduler::Start(); |
|
54 |
|
55 CleanupStack::PopAndDestroy(2, myScheduler); |
|
56 } |
|
57 |
|
58 CPropertyBatteryCharging* CPropertyBatteryCharging::NewL() |
|
59 /** |
|
60 * Constructs a CDummyUsbDevice object. |
|
61 * |
|
62 * @return A new CDummyUsbDevice object |
|
63 */ |
|
64 { |
|
65 CPropertyBatteryCharging* r = new (ELeave) CPropertyBatteryCharging(); |
|
66 CleanupStack::PushL(r); |
|
67 r->ConstructL(); |
|
68 CleanupStack::Pop(); |
|
69 return r; |
|
70 } |
|
71 |
|
72 CPropertyBatteryCharging::~CPropertyBatteryCharging() |
|
73 /** |
|
74 * Destructor. |
|
75 */ |
|
76 { |
|
77 |
|
78 delete iActiveWriteRepository; |
|
79 delete iActiveReadChargingCurrent; |
|
80 delete iRepository; |
|
81 iProperty.Close(); |
|
82 |
|
83 } |
|
84 |
|
85 CPropertyBatteryCharging::CPropertyBatteryCharging() |
|
86 /** |
|
87 * Constructor. |
|
88 */ |
|
89 { |
|
90 |
|
91 } |
|
92 |
|
93 void CPropertyBatteryCharging::ConstructL() |
|
94 /** |
|
95 * Performs 2nd phase construction of the USB device. |
|
96 */ |
|
97 { |
|
98 |
|
99 iActiveWriteRepository = CActivePropertyWriteRepository::NewL(*this); |
|
100 iActiveReadChargingCurrent = CActivePropertyReadChargingCurrent::NewL(*this); |
|
101 |
|
102 iRepository = CRepository::NewL(KUsbBatteryChargingCentralRepositoryUid); |
|
103 |
|
104 DefinePropertyL(KBattChargWriteRepositoryUid, KBattChargWriteRepositoryAckKey,RProperty::EInt); |
|
105 DefinePropertyL(KBattChargReadPropertyCurrentUid,KBattChargReadCurrentChargingAckKey,RProperty::EByteArray); |
|
106 |
|
107 iActiveWriteRepository->Request(); |
|
108 iActiveReadChargingCurrent->Request(); |
|
109 |
|
110 } |
|
111 |
|
112 void CPropertyBatteryCharging::DefinePropertyL(const TInt32 aCategory, TUint aKey,RProperty::TType eType) |
|
113 { |
|
114 |
|
115 |
|
116 _LIT_SECURITY_POLICY_PASS(KAlwaysPass); |
|
117 |
|
118 TInt err = iProperty.Define(TUid::Uid(aCategory), |
|
119 aKey, |
|
120 eType, |
|
121 KAlwaysPass, |
|
122 KAlwaysPass |
|
123 ); |
|
124 if ( err != KErrAlreadyExists ) |
|
125 { |
|
126 User::LeaveIfError(err); |
|
127 } |
|
128 } |
|
129 |
|
130 |
|
131 void CPropertyBatteryCharging::MpsoPropertyReadChanged() |
|
132 { |
|
133 |
|
134 TInt current; |
|
135 TInt err = RProperty::Get(KPropertyUidUsbBatteryChargingCategory, |
|
136 KPropertyUidUsbBatteryChargingChargingCurrent, current); |
|
137 |
|
138 TDataFromPropBattChargToTBatteryCharging toSend; |
|
139 toSend.iCurrent=current; |
|
140 toSend.iError=err; |
|
141 |
|
142 TPckgBuf<TDataFromPropBattChargToTBatteryCharging> tmp(toSend); |
|
143 |
|
144 err = iProperty.Set(TUid::Uid(KBattChargReadPropertyCurrentUid), |
|
145 KBattChargReadCurrentChargingAckKey, |
|
146 tmp); |
|
147 ASSERT(!err); |
|
148 |
|
149 } |
|
150 |
|
151 void CPropertyBatteryCharging::MpsoPropertyWriteChanged(const TInt aValue) |
|
152 { |
|
153 TInt err = iRepository->Set(KUsbBatteryChargingKeyEnabledUserSetting, aValue); |
|
154 |
|
155 TInt error = iProperty.Set(TUid::Uid(KBattChargWriteRepositoryUid), |
|
156 KBattChargWriteRepositoryAckKey, |
|
157 err); |
|
158 ASSERT(!error); |
|
159 |
|
160 } |
|
161 |
|
162 |
|
163 |