bluetoothengine/btmac/src/btmac/btmsrfcomm.cpp
changeset 0 f63038272f30
equal deleted inserted replaced
-1:000000000000 0:f63038272f30
       
     1 /*
       
     2 * Copyright (c) 2005-2006 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:  The RFCOMM connected state definition
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 //#include <bteng.h>
       
    21 #include <btaccTypes.h>
       
    22 
       
    23 #include "btmrfcommsock.h"
       
    24 #include "btmsrfcomm.h"
       
    25 #include "btmsctrl.h"
       
    26 #include "btmssniffm.h"
       
    27 #include "btmsdisconnect.h"
       
    28 #include "btmsopenaudio.h"
       
    29 #include "debug.h"
       
    30 #include "btmchandlerapi.h"
       
    31 #include "btmcprofileid.h"
       
    32 
       
    33 // ======== MEMBER FUNCTIONS ========
       
    34 
       
    35 CBtmsRfcomm* CBtmsRfcomm::NewL(CBtmMan& aParent, TRequestStatus* aStatus, 
       
    36     CBtmRfcommSock* aSock, TRequestCategory aRequestCat)
       
    37     {
       
    38     CBtmsRfcomm* self = new( ELeave ) CBtmsRfcomm(aParent, aStatus, aSock, aRequestCat);
       
    39     CleanupStack::PushL(self);
       
    40     self->ConstructL();
       
    41     CleanupStack::Pop(self);
       
    42     return self;
       
    43     }
       
    44 
       
    45 CBtmsRfcomm::~CBtmsRfcomm()
       
    46     {
       
    47     }
       
    48 
       
    49 void CBtmsRfcomm::EnterL()
       
    50     {
       
    51     TRACE_STATE(_L("[BTMAC State] Rfcomm"))
       
    52     Parent().LoadCmdHandlerL(EBtmcHFP0105, iRfcomm->Remote(), iRfcomm->AccessoryInitiatedConnection());
       
    53 	}
       
    54 
       
    55 void CBtmsRfcomm::CancelConnectL()
       
    56     {
       
    57     TRACE_FUNC
       
    58     if (StateRequest() && iRequestCat == ERequestConnect)
       
    59         {
       
    60         CompleteStateRequest(KErrCancel);
       
    61         CBtmsDisconnect* next = CBtmsDisconnect::NewL(Parent(), NULL, SwapStateRfcommSock());
       
    62         CleanupStack::PushL(next);
       
    63         Parent().ChangeStateL(next);
       
    64         CleanupStack::Pop(next);
       
    65         }
       
    66     }
       
    67 
       
    68 void CBtmsRfcomm::DisconnectL(const TBTDevAddr& aAddr, TRequestStatus& aStatus)
       
    69     {
       
    70     TRACE_FUNC
       
    71     if (aAddr == iRfcomm->Remote())
       
    72         {
       
    73         aStatus =  KRequestPending;
       
    74         Parent().ChangeStateL(CBtmsDisconnect::NewL(Parent(), &aStatus, SwapStateRfcommSock()));
       
    75         }
       
    76     else
       
    77         {
       
    78         CompleteRequest(&aStatus, KErrNotFound);
       
    79         }
       
    80     }
       
    81 
       
    82 void CBtmsRfcomm::OpenAudioLinkL(const TBTDevAddr& aAddr, TRequestStatus& aStatus)
       
    83     {
       
    84     TRACE_FUNC
       
    85     if (aAddr == iRfcomm->Remote())
       
    86         {
       
    87         SetStateRequest(aStatus);
       
    88         aStatus = KRequestPending;
       
    89         iRequestCat = ERequestOpenAudio;
       
    90         }
       
    91     else
       
    92         {
       
    93         CompleteRequest(&aStatus, KErrNotFound);
       
    94         }
       
    95     }
       
    96 
       
    97 void CBtmsRfcomm::CancelOpenAudioLinkL(const TBTDevAddr& aAddr)
       
    98     {
       
    99     TRACE_FUNC
       
   100     if (aAddr == iRfcomm->Remote() && iRequestCat == ERequestOpenAudio)
       
   101         {
       
   102         CompleteStateRequest(KErrCancel);
       
   103         iRequestCat = ERequestNone;
       
   104         }
       
   105     }
       
   106     
       
   107 void CBtmsRfcomm::RfcommErrorL(TInt aErr)
       
   108     {
       
   109     CompleteStateRequest(aErr);
       
   110     }
       
   111 
       
   112 void CBtmsRfcomm::SlcIndicateL(TBool aSlc)
       
   113     {
       
   114     TRACE_FUNC
       
   115     if (!aSlc)
       
   116         {
       
   117         CBtmsDisconnect* next = CBtmsDisconnect::NewL(Parent(), SwapStateRequest(), SwapStateRfcommSock());
       
   118         next->SetConnectFailReason(KErrCouldNotConnect);
       
   119         Parent().ChangeStateL(next);
       
   120         }
       
   121     else
       
   122         {
       
   123         if (StateRequest() && iRequestCat == ERequestConnect)
       
   124             CompleteStateRequest(KErrNone);
       
   125         else
       
   126             Parent().NewAccessory(iRfcomm->Remote(), EHFP);
       
   127         if (StateRequest() && iRequestCat == ERequestOpenAudio)
       
   128             {
       
   129             Parent().ChangeStateL(CBtmsOpenAudio::NewL(Parent(), SwapStateRequest(), SwapStateRfcommSock(), NULL));
       
   130             }
       
   131         else
       
   132             {
       
   133             if (iRfcomm->IsInSniff())
       
   134                 {
       
   135                 Parent().ChangeStateL(CBtmsSniffm::NewL(Parent(), SwapStateRfcommSock(), NULL));
       
   136                 }
       
   137             else
       
   138                 {
       
   139                 Parent().ChangeStateL(CBtmsCtrl::NewL(Parent(), SwapStateRfcommSock(), NULL));
       
   140                 }
       
   141             }
       
   142         }
       
   143     }
       
   144 
       
   145 TBool CBtmsRfcomm::CanDisableNrec()
       
   146     {
       
   147     return ETrue;
       
   148     }
       
   149 
       
   150 CBtmsRfcomm::CBtmsRfcomm(CBtmMan& aParent, TRequestStatus* aStatus, 
       
   151     CBtmRfcommSock* aRfcomm, TRequestCategory aRequestCat)
       
   152     : CBtmsInuse(aParent, aStatus, aRfcomm), iRequestCat(aRequestCat)
       
   153     {
       
   154     iRfcomm->SetObserver(*this);
       
   155     }
       
   156 
       
   157 void CBtmsRfcomm::ConstructL()
       
   158     {
       
   159     }
       
   160