bluetoothengine/btmac/src/BTMonoCmdHandler/btmccallinghandler.cpp
changeset 0 f63038272f30
child 1 6a1fe72036e3
equal deleted inserted replaced
-1:000000000000 0:f63038272f30
       
     1 /*
       
     2 * Copyright (c) 2005 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:  call cmd handling. 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include "atcodec.h"
       
    22 #include "btengprivatepskeys.h"
       
    23 #include "btmccallinghandler.h"
       
    24 #include "btmcprotocol.h"
       
    25 #include "debug.h"
       
    26 
       
    27 const TInt KCallingResponse = 30;
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // CBtmcCallingHandler::NewL
       
    31 // -----------------------------------------------------------------------------
       
    32 CBtmcCallingHandler* CBtmcCallingHandler::NewL(CBtmcProtocol& aProtocol) 
       
    33     {
       
    34     CBtmcCallingHandler* self = new(ELeave) CBtmcCallingHandler(aProtocol);
       
    35     CleanupStack::PushL(self);
       
    36     self->ConstructL();
       
    37     CleanupStack::Pop(self);
       
    38     return self;
       
    39     }
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CBtmcCallingHandler::~CBtmcCallingHandler
       
    43 // -----------------------------------------------------------------------------
       
    44 CBtmcCallingHandler::~CBtmcCallingHandler()
       
    45     {
       
    46     TRACE_FUNC_ENTRY
       
    47     delete iActive;
       
    48     iCmdProperty.Close();
       
    49     TRACE_FUNC_EXIT
       
    50     }
       
    51 
       
    52 
       
    53 void CBtmcCallingHandler::HandleCallingCmdL(const CATCommand& aCmd)
       
    54     {
       
    55     TRACE_FUNC_ENTRY
       
    56     TRACE_ASSERT(!iBusy, KErrInUse)
       
    57     TInt err = iCmdProperty.Set(aCmd.Des());
       
    58     if (err)
       
    59     	{
       
    60     	TRACE_INFO((_L8("PS set returned %d"), err))
       
    61         CATResult* nok = CATResult::NewLC(EATERROR);
       
    62         iProtocol.SendResponseL(*nok);
       
    63         CleanupStack::PopAndDestroy(nok);
       
    64         iProtocol.CmdHandlingCompletedL();
       
    65     	}
       
    66     else
       
    67         {
       
    68         iBusy = ETrue;
       
    69         iCmdId = aCmd.Id();
       
    70         iActive = CBtmcActive::NewL(*this, CActive::EPriorityStandard, KCallingResponse);
       
    71         iCmdProperty.Subscribe(iActive->iStatus);
       
    72         iActive->GoActive();
       
    73         }
       
    74     TRACE_FUNC_EXIT
       
    75     }
       
    76 
       
    77 TBool CBtmcCallingHandler::ActiveCmdHandling() const
       
    78     {
       
    79     return iBusy;
       
    80     }
       
    81 
       
    82 TBool CBtmcCallingHandler::ActiveChldHandling() const
       
    83     {
       
    84     return iBusy && ( iCmdId == EATCHLD );
       
    85     }
       
    86 
       
    87 void CBtmcCallingHandler::RequestCompletedL(CBtmcActive& aActive, TInt aErr)
       
    88     {
       
    89     switch (aActive.ServiceId())
       
    90         {
       
    91         case KCallingResponse:
       
    92             {
       
    93             delete iActive;
       
    94             iActive = NULL;
       
    95             if (!iBusy)
       
    96                 {
       
    97                 break;
       
    98                 }
       
    99             iBusy = EFalse;
       
   100             TInt result = KErrNone;
       
   101             if (!aErr)
       
   102                 {
       
   103                 TBuf8<KMaxATSize> buf;
       
   104                 aErr = iCmdProperty.Get(buf);
       
   105                 if (!aErr && buf.Length() >= sizeof(TInt))
       
   106                     {
       
   107                     const TUint8* ptr = buf.Ptr();
       
   108                     result = *((const TInt*)ptr);
       
   109                     }
       
   110                 }
       
   111             TRACE_INFO((_L("resp %d"), result))
       
   112             TATId atid = EATOK;
       
   113             if (aErr || result)
       
   114                 {
       
   115                 atid = EATERROR;
       
   116                 if (iCmdId == EATBVRA)
       
   117                     {
       
   118                     iProtocol.VoiceRecognitionError();
       
   119                     }
       
   120                 }
       
   121             
       
   122             CATResult* nok = CATResult::NewLC(atid);
       
   123             iProtocol.SendResponseL(*nok);
       
   124             CleanupStack::PopAndDestroy(nok);
       
   125             iProtocol.CmdHandlingCompletedL();
       
   126             break;
       
   127             }
       
   128         default:
       
   129             break;
       
   130         }
       
   131     }
       
   132 
       
   133 void CBtmcCallingHandler::CancelRequest(TInt aServiceId)
       
   134     {
       
   135     switch (aServiceId)
       
   136         {
       
   137         case KCallingResponse:
       
   138             {
       
   139             iCmdProperty.Cancel();
       
   140             break;    
       
   141             }
       
   142         default:
       
   143             break;
       
   144         }
       
   145     }
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // CBtmcCallingHandler::CBtmcCallingHandler
       
   149 // -----------------------------------------------------------------------------
       
   150 CBtmcCallingHandler::CBtmcCallingHandler(CBtmcProtocol& aProtocol)
       
   151     : iProtocol(aProtocol)
       
   152     {
       
   153     }
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // CBtmcCallingHandler::ConstructL
       
   157 // -----------------------------------------------------------------------------
       
   158 void CBtmcCallingHandler::ConstructL()
       
   159     {
       
   160     TRACE_FUNC
       
   161     iCmdProperty.Attach(KPSUidBluetoothEnginePrivateCategory, KBTATCodec);
       
   162     TRACE_FUNC_EXIT  
       
   163     }
       
   164     
       
   165 // End of file