|
1 /* |
|
2 * Copyright (c) 2010 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 * Initial Contributors: |
|
9 * Nokia Corporation - initial contribution. |
|
10 * |
|
11 * Contributors: |
|
12 * Description : |
|
13 * |
|
14 */ |
|
15 |
|
16 #include "cbccommandhandler.h" |
|
17 |
|
18 #include "atmisccmdpluginconsts.h" |
|
19 #include "debug.h" |
|
20 |
|
21 CCBCCommandHandler* CCBCCommandHandler::NewL(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone) |
|
22 { |
|
23 TRACE_FUNC_ENTRY |
|
24 CCBCCommandHandler* self = new (ELeave) CCBCCommandHandler(aCallback, aATCmdParser, aPhone); |
|
25 CleanupStack::PushL(self); |
|
26 self->ConstructL(); |
|
27 CleanupStack::Pop(self); |
|
28 TRACE_FUNC_EXIT |
|
29 return self; |
|
30 } |
|
31 |
|
32 CCBCCommandHandler::CCBCCommandHandler(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone) : |
|
33 CATCmdAsyncBase(aCallback, aATCmdParser, aPhone) |
|
34 { |
|
35 TRACE_FUNC_ENTRY |
|
36 TRACE_FUNC_EXIT |
|
37 } |
|
38 |
|
39 void CCBCCommandHandler::ConstructL() |
|
40 { |
|
41 TRACE_FUNC_ENTRY |
|
42 iReply.CreateL(KDefaultCmdBufLength); |
|
43 TRACE_FUNC_EXIT |
|
44 } |
|
45 |
|
46 CCBCCommandHandler::~CCBCCommandHandler() |
|
47 { |
|
48 TRACE_FUNC_ENTRY |
|
49 Cancel(); |
|
50 iReply.Close(); |
|
51 TRACE_FUNC_EXIT |
|
52 } |
|
53 |
|
54 void CCBCCommandHandler::HandleCommand(const TDesC8& /*aCmd*/, RBuf8& /*aReply*/, TBool /*aReplyNeeded*/) |
|
55 { |
|
56 iReply.Zero(); |
|
57 |
|
58 TAtCommandParser::TCommandHandlerType cmdHandlerType = iATCmdParser.CommandHandlerType(); |
|
59 |
|
60 switch (cmdHandlerType) |
|
61 { |
|
62 case (TAtCommandParser::ECmdHandlerTypeTest): |
|
63 { |
|
64 iCallback->CreateReplyAndComplete( EReplyTypeOther, KCBCSupportedCmdsList); |
|
65 break; |
|
66 } |
|
67 case (TAtCommandParser::ECmdHandlerTypeBase): |
|
68 { |
|
69 iPhone.GetBatteryInfo(iStatus, iBatteryInfo); |
|
70 SetActive(); |
|
71 break; |
|
72 } |
|
73 default: |
|
74 { |
|
75 iCallback->CreateReplyAndComplete(EReplyTypeError); |
|
76 break; |
|
77 } |
|
78 } |
|
79 TRACE_FUNC_EXIT |
|
80 } |
|
81 |
|
82 void CCBCCommandHandler::HandleCommandCancel() |
|
83 { |
|
84 TRACE_FUNC_ENTRY |
|
85 Cancel(); |
|
86 TRACE_FUNC_EXIT |
|
87 } |
|
88 |
|
89 |
|
90 void CCBCCommandHandler::RunL() |
|
91 { |
|
92 TRACE_FUNC_ENTRY |
|
93 if (iStatus.Int() == KErrNone) |
|
94 { |
|
95 iReply.Append(KAtCBC); |
|
96 // status is mapped according to AT command spec: |
|
97 // <bcs>: |
|
98 // 0 MT is powered by the battery |
|
99 // 1 MT has a battery connected, but is not powered by it |
|
100 // 2 MT does not have a battery connected |
|
101 // 3 Recognized power fault, calls inhibited |
|
102 switch(iBatteryInfo.iStatus) |
|
103 { |
|
104 case (RMobilePhone::EPoweredByBattery): |
|
105 { |
|
106 iReply.AppendNum(0); |
|
107 break; |
|
108 } |
|
109 case (RMobilePhone::EBatteryConnectedButExternallyPowered): |
|
110 { |
|
111 iReply.AppendNum(1); |
|
112 break; |
|
113 } |
|
114 case (RMobilePhone::ENoBatteryConnected): |
|
115 { |
|
116 iReply.AppendNum(2); |
|
117 break; |
|
118 } |
|
119 case (RMobilePhone::EPowerFault): |
|
120 default: |
|
121 { |
|
122 iReply.AppendNum(3); |
|
123 break; |
|
124 } |
|
125 } |
|
126 |
|
127 iReply.Append(','); |
|
128 iReply.AppendNum(iBatteryInfo.iChargeLevel); |
|
129 iReply.Append(KOKCRLF); |
|
130 |
|
131 iCallback->CreateReplyAndComplete(EReplyTypeOther, iReply); |
|
132 } |
|
133 else |
|
134 { |
|
135 iCallback->CreateCMEReplyAndComplete(iStatus.Int()); |
|
136 } |
|
137 TRACE_FUNC_EXIT |
|
138 } |
|
139 |
|
140 void CCBCCommandHandler::DoCancel() |
|
141 { |
|
142 TRACE_FUNC_ENTRY |
|
143 iPhone.CancelAsyncRequest(EMobilePhoneGetBatteryInfo); |
|
144 TRACE_FUNC_EXIT |
|
145 } |