cbsatplugin/atmisccmdplugin/src/cbccommandhandler.cpp
author hgs
Fri, 28 May 2010 17:03:06 +0300
changeset 32 19bd632b5100
parent 26 b78e66e88238
permissions -rw-r--r--
201021
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
 * All rights reserved.
hgs
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
 * Initial Contributors:
hgs
parents:
diff changeset
     9
 * Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    10
 *
hgs
parents:
diff changeset
    11
 * Contributors:
hgs
parents:
diff changeset
    12
 * Description :
hgs
parents:
diff changeset
    13
 *
hgs
parents:
diff changeset
    14
 */
hgs
parents:
diff changeset
    15
hgs
parents:
diff changeset
    16
#include "cbccommandhandler.h"
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
#include "atmisccmdpluginconsts.h"
hgs
parents:
diff changeset
    19
#include "debug.h"
hgs
parents:
diff changeset
    20
hgs
parents:
diff changeset
    21
CCBCCommandHandler* CCBCCommandHandler::NewL(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone)
hgs
parents:
diff changeset
    22
    {
hgs
parents:
diff changeset
    23
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
    24
    CCBCCommandHandler* self = new (ELeave) CCBCCommandHandler(aCallback, aATCmdParser, aPhone);
hgs
parents:
diff changeset
    25
    CleanupStack::PushL(self);
hgs
parents:
diff changeset
    26
    self->ConstructL();
hgs
parents:
diff changeset
    27
    CleanupStack::Pop(self);
hgs
parents:
diff changeset
    28
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
    29
    return self;
hgs
parents:
diff changeset
    30
    }
hgs
parents:
diff changeset
    31
hgs
parents:
diff changeset
    32
CCBCCommandHandler::CCBCCommandHandler(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone) :
hgs
parents:
diff changeset
    33
    CATCmdAsyncBase(aCallback, aATCmdParser, aPhone)
hgs
parents:
diff changeset
    34
    {
hgs
parents:
diff changeset
    35
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
    36
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
    37
    }
hgs
parents:
diff changeset
    38
hgs
parents:
diff changeset
    39
void CCBCCommandHandler::ConstructL()
hgs
parents:
diff changeset
    40
    {
hgs
parents:
diff changeset
    41
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
    42
    iReply.CreateL(KDefaultCmdBufLength);
hgs
parents:
diff changeset
    43
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
    44
    }
hgs
parents:
diff changeset
    45
hgs
parents:
diff changeset
    46
CCBCCommandHandler::~CCBCCommandHandler()
hgs
parents:
diff changeset
    47
    {
hgs
parents:
diff changeset
    48
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
    49
    Cancel();
hgs
parents:
diff changeset
    50
    iReply.Close();
hgs
parents:
diff changeset
    51
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
    52
    }
hgs
parents:
diff changeset
    53
hgs
parents:
diff changeset
    54
void CCBCCommandHandler::HandleCommand(const TDesC8& /*aCmd*/, RBuf8& /*aReply*/, TBool /*aReplyNeeded*/)
hgs
parents:
diff changeset
    55
    {
32
hgs
parents: 26
diff changeset
    56
    TRACE_FUNC_ENTRY
26
hgs
parents:
diff changeset
    57
    iReply.Zero();
hgs
parents:
diff changeset
    58
 
hgs
parents:
diff changeset
    59
    TAtCommandParser::TCommandHandlerType cmdHandlerType = iATCmdParser.CommandHandlerType();
hgs
parents:
diff changeset
    60
    
hgs
parents:
diff changeset
    61
    switch (cmdHandlerType)
hgs
parents:
diff changeset
    62
        {
hgs
parents:
diff changeset
    63
        case (TAtCommandParser::ECmdHandlerTypeTest):
hgs
parents:
diff changeset
    64
            {
hgs
parents:
diff changeset
    65
            iCallback->CreateReplyAndComplete( EReplyTypeOther, KCBCSupportedCmdsList);
hgs
parents:
diff changeset
    66
            break;
hgs
parents:
diff changeset
    67
            }
hgs
parents:
diff changeset
    68
        case (TAtCommandParser::ECmdHandlerTypeBase):
hgs
parents:
diff changeset
    69
            {
hgs
parents:
diff changeset
    70
            iPhone.GetBatteryInfo(iStatus, iBatteryInfo);
hgs
parents:
diff changeset
    71
            SetActive();
hgs
parents:
diff changeset
    72
            break;
hgs
parents:
diff changeset
    73
            }
hgs
parents:
diff changeset
    74
        default:
hgs
parents:
diff changeset
    75
            {
hgs
parents:
diff changeset
    76
            iCallback->CreateReplyAndComplete(EReplyTypeError);
hgs
parents:
diff changeset
    77
            break;
hgs
parents:
diff changeset
    78
            }
hgs
parents:
diff changeset
    79
        }
hgs
parents:
diff changeset
    80
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
    81
    }
hgs
parents:
diff changeset
    82
hgs
parents:
diff changeset
    83
void CCBCCommandHandler::RunL()
hgs
parents:
diff changeset
    84
    {
hgs
parents:
diff changeset
    85
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
    86
    if (iStatus.Int() == KErrNone)
hgs
parents:
diff changeset
    87
        {
hgs
parents:
diff changeset
    88
        iReply.Append(KAtCBC);
hgs
parents:
diff changeset
    89
        // status is mapped according to AT command spec: 
hgs
parents:
diff changeset
    90
        //    <bcs>:
hgs
parents:
diff changeset
    91
        //    0 MT is powered by the battery
hgs
parents:
diff changeset
    92
        //    1 MT has a battery connected, but is not powered by it
hgs
parents:
diff changeset
    93
        //    2 MT does not have a battery connected
hgs
parents:
diff changeset
    94
        //    3 Recognized power fault, calls inhibited
hgs
parents:
diff changeset
    95
        switch(iBatteryInfo.iStatus)
hgs
parents:
diff changeset
    96
            {
hgs
parents:
diff changeset
    97
            case (RMobilePhone::EPoweredByBattery):
hgs
parents:
diff changeset
    98
                {
hgs
parents:
diff changeset
    99
                iReply.AppendNum(0);
hgs
parents:
diff changeset
   100
                break;
hgs
parents:
diff changeset
   101
                }
hgs
parents:
diff changeset
   102
            case (RMobilePhone::EBatteryConnectedButExternallyPowered):
hgs
parents:
diff changeset
   103
                {
hgs
parents:
diff changeset
   104
                iReply.AppendNum(1);
hgs
parents:
diff changeset
   105
                break;
hgs
parents:
diff changeset
   106
                }
hgs
parents:
diff changeset
   107
            case (RMobilePhone::ENoBatteryConnected):
hgs
parents:
diff changeset
   108
                {
hgs
parents:
diff changeset
   109
                iReply.AppendNum(2);
hgs
parents:
diff changeset
   110
                break;
hgs
parents:
diff changeset
   111
                }
hgs
parents:
diff changeset
   112
            case (RMobilePhone::EPowerFault):
hgs
parents:
diff changeset
   113
            default:
hgs
parents:
diff changeset
   114
                {
hgs
parents:
diff changeset
   115
                iReply.AppendNum(3);
hgs
parents:
diff changeset
   116
                break;
hgs
parents:
diff changeset
   117
                }
hgs
parents:
diff changeset
   118
            }
hgs
parents:
diff changeset
   119
hgs
parents:
diff changeset
   120
        iReply.Append(',');
hgs
parents:
diff changeset
   121
        iReply.AppendNum(iBatteryInfo.iChargeLevel);
hgs
parents:
diff changeset
   122
        iReply.Append(KOKCRLF);
hgs
parents:
diff changeset
   123
        
hgs
parents:
diff changeset
   124
        iCallback->CreateReplyAndComplete(EReplyTypeOther, iReply);
hgs
parents:
diff changeset
   125
        }
hgs
parents:
diff changeset
   126
    else
hgs
parents:
diff changeset
   127
        {
hgs
parents:
diff changeset
   128
        iCallback->CreateCMEReplyAndComplete(iStatus.Int());   
hgs
parents:
diff changeset
   129
        }
hgs
parents:
diff changeset
   130
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   131
    }
hgs
parents:
diff changeset
   132
hgs
parents:
diff changeset
   133
void CCBCCommandHandler::DoCancel()
hgs
parents:
diff changeset
   134
    {
hgs
parents:
diff changeset
   135
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   136
    iPhone.CancelAsyncRequest(EMobilePhoneGetBatteryInfo);
hgs
parents:
diff changeset
   137
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   138
    }