26
|
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 |
{
|
32
|
56 |
TRACE_FUNC_ENTRY
|
26
|
57 |
iReply.Zero();
|
|
58 |
|
|
59 |
TAtCommandParser::TCommandHandlerType cmdHandlerType = iATCmdParser.CommandHandlerType();
|
|
60 |
|
|
61 |
switch (cmdHandlerType)
|
|
62 |
{
|
|
63 |
case (TAtCommandParser::ECmdHandlerTypeTest):
|
|
64 |
{
|
|
65 |
iCallback->CreateReplyAndComplete( EReplyTypeOther, KCBCSupportedCmdsList);
|
|
66 |
break;
|
|
67 |
}
|
|
68 |
case (TAtCommandParser::ECmdHandlerTypeBase):
|
|
69 |
{
|
|
70 |
iPhone.GetBatteryInfo(iStatus, iBatteryInfo);
|
|
71 |
SetActive();
|
|
72 |
break;
|
|
73 |
}
|
|
74 |
default:
|
|
75 |
{
|
|
76 |
iCallback->CreateReplyAndComplete(EReplyTypeError);
|
|
77 |
break;
|
|
78 |
}
|
|
79 |
}
|
|
80 |
TRACE_FUNC_EXIT
|
|
81 |
}
|
|
82 |
|
|
83 |
void CCBCCommandHandler::RunL()
|
|
84 |
{
|
|
85 |
TRACE_FUNC_ENTRY
|
|
86 |
if (iStatus.Int() == KErrNone)
|
|
87 |
{
|
|
88 |
iReply.Append(KAtCBC);
|
|
89 |
// status is mapped according to AT command spec:
|
|
90 |
// <bcs>:
|
|
91 |
// 0 MT is powered by the battery
|
|
92 |
// 1 MT has a battery connected, but is not powered by it
|
|
93 |
// 2 MT does not have a battery connected
|
|
94 |
// 3 Recognized power fault, calls inhibited
|
|
95 |
switch(iBatteryInfo.iStatus)
|
|
96 |
{
|
|
97 |
case (RMobilePhone::EPoweredByBattery):
|
|
98 |
{
|
|
99 |
iReply.AppendNum(0);
|
|
100 |
break;
|
|
101 |
}
|
|
102 |
case (RMobilePhone::EBatteryConnectedButExternallyPowered):
|
|
103 |
{
|
|
104 |
iReply.AppendNum(1);
|
|
105 |
break;
|
|
106 |
}
|
|
107 |
case (RMobilePhone::ENoBatteryConnected):
|
|
108 |
{
|
|
109 |
iReply.AppendNum(2);
|
|
110 |
break;
|
|
111 |
}
|
|
112 |
case (RMobilePhone::EPowerFault):
|
|
113 |
default:
|
|
114 |
{
|
|
115 |
iReply.AppendNum(3);
|
|
116 |
break;
|
|
117 |
}
|
|
118 |
}
|
|
119 |
|
|
120 |
iReply.Append(',');
|
|
121 |
iReply.AppendNum(iBatteryInfo.iChargeLevel);
|
|
122 |
iReply.Append(KOKCRLF);
|
|
123 |
|
|
124 |
iCallback->CreateReplyAndComplete(EReplyTypeOther, iReply);
|
|
125 |
}
|
|
126 |
else
|
|
127 |
{
|
|
128 |
iCallback->CreateCMEReplyAndComplete(iStatus.Int());
|
|
129 |
}
|
|
130 |
TRACE_FUNC_EXIT
|
|
131 |
}
|
|
132 |
|
|
133 |
void CCBCCommandHandler::DoCancel()
|
|
134 |
{
|
|
135 |
TRACE_FUNC_ENTRY
|
|
136 |
iPhone.CancelAsyncRequest(EMobilePhoneGetBatteryInfo);
|
|
137 |
TRACE_FUNC_EXIT
|
|
138 |
}
|