cbsatplugin/atmisccmdplugin/src/cnumcommandhandler.cpp
changeset 26 b78e66e88238
child 32 19bd632b5100
equal deleted inserted replaced
25:9c3798b88e30 26:b78e66e88238
       
     1 // Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // This file contains the implementation of the AT+CNUM command
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "cnumcommandhandler.h"
       
    19 
       
    20 #include <mmretrieve.h>
       
    21 
       
    22 #include "atmisccmdpluginconsts.h"
       
    23 #include "debug.h"
       
    24 
       
    25 CCNUMCommandHandler* CCNUMCommandHandler::NewL(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser,
       
    26                                                 RMobilePhone& aPhone, RTelServer& aTelServer)
       
    27     {
       
    28     TRACE_FUNC_ENTRY
       
    29     CCNUMCommandHandler* self = new (ELeave) CCNUMCommandHandler(aCallback, aATCmdParser, aPhone, aTelServer );
       
    30     CleanupStack::PushL(self);
       
    31     self->ConstructL();
       
    32     CleanupStack::Pop(self);
       
    33     TRACE_FUNC_EXIT
       
    34     return self;
       
    35     }
       
    36 
       
    37 CCNUMCommandHandler::CCNUMCommandHandler(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser,
       
    38                                          RMobilePhone& aPhone, RTelServer& aTelServer) :
       
    39         CATCmdAsyncBase(aCallback, aATCmdParser, aPhone),
       
    40         iTelServer(aTelServer),
       
    41         iOwnStoreInfoPckg(iOwnStoreInfo),
       
    42         iOwnNumberEntryPckg(iOwnNumberEntry)
       
    43     {
       
    44     }
       
    45 
       
    46 void CCNUMCommandHandler::ConstructL()
       
    47     {
       
    48     iReplyBuffer.CreateL(KDefaultCmdBufLength);
       
    49     }
       
    50 
       
    51 CCNUMCommandHandler::~CCNUMCommandHandler()
       
    52     {
       
    53     TRACE_FUNC_ENTRY
       
    54     Cancel();
       
    55     iReplyBuffer.Close();
       
    56     iOwnNumberStore.Close();
       
    57     TRACE_FUNC_EXIT
       
    58     }
       
    59 
       
    60 void CCNUMCommandHandler::HandleCommand( const TDesC8& /*aCmd*/,
       
    61                                    RBuf8& /*aReply*/,
       
    62                                    TBool /*aReplyNeeded */)
       
    63     {
       
    64     TRACE_FUNC_ENTRY
       
    65     TAtCommandParser::TCommandHandlerType cmdHandlerType = iATCmdParser.CommandHandlerType();
       
    66     
       
    67     switch (cmdHandlerType)
       
    68         {
       
    69         case (TAtCommandParser::ECmdHandlerTypeBase):
       
    70             {
       
    71             // Handle AT+CNUM
       
    72             // step 1 check if the phone support Own Number Store
       
    73             //  and open the store if supported
       
    74            
       
    75             iReplyBuffer.Zero();
       
    76             // only open a subsession to OwnNumberStore when necessary
       
    77             if(iOwnNumberStore.SubSessionHandle() == 0)
       
    78                 {
       
    79                 TName tsyName;
       
    80                 TInt ret = iTelServer.GetTsyName(0, tsyName);
       
    81                 if(ret != KErrNone)
       
    82                     {
       
    83                     Trace(KDebugPrintD, "GetTsyName returned error ", ret);
       
    84                     iCallback->CreateReplyAndComplete(EReplyTypeError);
       
    85                     break;
       
    86                     }
       
    87                 
       
    88                 TBool isSupported = EFalse;
       
    89                 // TODO: isSupported should be checked
       
    90                 ret = iTelServer.IsSupportedByModule(tsyName, KETelFuncMobileOwnNumberStore, isSupported);
       
    91                 if(ret != KErrNone)
       
    92                     {
       
    93                     Trace(KDebugPrintD, "IsSupportedByModule returned error ", ret);
       
    94                     iCallback->CreateReplyAndComplete(EReplyTypeError);
       
    95                     break;
       
    96                     }
       
    97                 
       
    98                 Trace(KDebugPrintD, "before open OwnNumberstore", 0);
       
    99                 ret = iOwnNumberStore.Open(iPhone);
       
   100                 if(ret != KErrNone)
       
   101                     {
       
   102                     Trace(KDebugPrintD, "Open OwnNumberStore returned error ", ret);
       
   103                     iCallback->CreateReplyAndComplete(EReplyTypeError);
       
   104                     break;
       
   105                     }
       
   106                 }
       
   107             // step 2 Get number of own number entries stored.
       
   108             iOwnNumberStore.GetInfo(iStatus, iOwnStoreInfoPckg);
       
   109             iPendingEvent = EMobilePhoneStoreGetInfo;
       
   110             SetActive();
       
   111              
       
   112             break;
       
   113             }
       
   114         case (TAtCommandParser::ECmdHandlerTypeTest):
       
   115             {
       
   116             // Handle AT+CNUM=?
       
   117             iCallback->CreateReplyAndComplete( EReplyTypeOk );
       
   118             break;
       
   119             }
       
   120         default:
       
   121             {
       
   122             iCallback->CreateReplyAndComplete(EReplyTypeError);
       
   123             break;
       
   124             }
       
   125         }
       
   126     TRACE_FUNC_EXIT
       
   127     }
       
   128 
       
   129 void CCNUMCommandHandler::HandleCommandCancel()
       
   130     {
       
   131     TRACE_FUNC_ENTRY
       
   132     Cancel();
       
   133     TRACE_FUNC_EXIT
       
   134     }
       
   135 
       
   136 void CCNUMCommandHandler::RunL()
       
   137     {
       
   138     TRACE_FUNC_ENTRY
       
   139     if(iStatus.Int() != KErrNone)
       
   140         {
       
   141         Trace(KDebugPrintD, "Pending event id: ", iPendingEvent);
       
   142         iCallback->CreateCMEReplyAndComplete(iStatus.Int());
       
   143        }
       
   144     else if(iPendingEvent == EMobilePhoneStoreGetInfo)
       
   145         { // step 3 check the number of entries
       
   146         Trace(KDebugPrintD, "Number of Owner's numbers: ", iOwnStoreInfo.iUsedEntries);
       
   147         if(iOwnStoreInfo.iUsedEntries < 1)
       
   148             {
       
   149             // complete with OK if no owner's number
       
   150             iCallback->CreateReplyAndComplete(EReplyTypeOk);
       
   151             }
       
   152         else
       
   153             {
       
   154             // step 4 Read the first owner's number entry
       
   155             iOwnNumberEntry.iIndex = 0;
       
   156             iOwnNumberStore.Read(iStatus,iOwnNumberEntryPckg);
       
   157             iPendingEvent = EMobilePhoneStoreRead;
       
   158             SetActive();
       
   159             }
       
   160         }
       
   161     else
       
   162         {
       
   163         ASSERT(iPendingEvent == EMobilePhoneStoreRead);
       
   164         // step 5 append a phone number entry to the reply buffer
       
   165         if(iOwnNumberEntry.iNumber.iTelNumber.Compare(KNullDesC) != 0)
       
   166             {
       
   167             // 129 is the type of address octet in interger format
       
   168             _LIT8(KATNumReply, "\r\n+CNUM: ,\"%S\",129");
       
   169             TBuf8<RMobilePhone::KMaxMobileTelNumberSize > telNumber8;
       
   170             telNumber8.Copy(iOwnNumberEntry.iNumber.iTelNumber);
       
   171             iReplyBuffer.AppendFormat(KATNumReply, &telNumber8);
       
   172             }
       
   173         // check if there is any more owner's number
       
   174         if(iOwnNumberEntry.iIndex < iOwnStoreInfo.iUsedEntries)
       
   175             { // step 6 read next entry 
       
   176             ++iOwnNumberEntry.iIndex;
       
   177             Trace(KDebugPrintD, "Next number id", iOwnNumberEntry.iIndex);
       
   178             iOwnNumberStore.Read(iStatus,iOwnNumberEntryPckg);
       
   179             iPendingEvent = EMobilePhoneStoreRead;
       
   180             SetActive();
       
   181             }
       
   182         else
       
   183             { // final step: all entries are retrieved. send them back to the AT server
       
   184             iReplyBuffer.Append(KOKCRLF);
       
   185             iCallback->CreateReplyAndComplete(EReplyTypeOther, iReplyBuffer);
       
   186             }
       
   187         }
       
   188 
       
   189     TRACE_FUNC_EXIT
       
   190     }
       
   191 
       
   192 void CCNUMCommandHandler::DoCancel()
       
   193     {
       
   194     TRACE_FUNC_ENTRY
       
   195     iCallback->CreateReplyAndComplete(EReplyTypeError);
       
   196     TRACE_FUNC_EXIT
       
   197     }