bluetoothengine/btaudioman/src/basrvaccstateattach.cpp
changeset 0 f63038272f30
child 6 6a29d5ad0713
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:  Implementation of Attach state.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "basrvaccstateattach.h"
       
    21 #include "basrvaccstatedisconnect.h"
       
    22 #include "basrvaccstateattached.h"
       
    23 #include "debug.h"
       
    24 
       
    25 const TInt KAttachRequestId = 10;
       
    26 
       
    27 // ================= MEMBER FUNCTIONS =======================
       
    28 
       
    29 CBasrvAccStateAttach* CBasrvAccStateAttach::NewL(CBasrvAcc& aParent, TBool aConnecting)
       
    30     {
       
    31     CBasrvAccStateAttach* self=new(ELeave) CBasrvAccStateAttach(aParent, aConnecting);
       
    32     CleanupStack::PushL(self);
       
    33     self->ConstructL();
       
    34     CleanupStack::Pop(self);
       
    35     return self;
       
    36     }
       
    37 
       
    38 CBasrvAccStateAttach::~CBasrvAccStateAttach()
       
    39     {
       
    40     delete iActive;
       
    41     TRACE_FUNC
       
    42     }
       
    43 
       
    44 void CBasrvAccStateAttach::EnterL()
       
    45     {
       
    46     StatePrint(_L("Attach"));    
       
    47     Parent().AccMan().AccfwConnectionL(&(AccInfo()))->AttachAccessory(AccInfo().iAddr, iActive->iStatus);
       
    48     iActive->GoActive();
       
    49     }
       
    50 
       
    51 CBasrvAccState* CBasrvAccStateAttach::ErrorOnEntry(TInt aReason)
       
    52     {
       
    53     TRACE_FUNC
       
    54     TRAP_IGNORE(Parent().AccMan().ConnectCompletedL(AccInfo().iAddr, aReason, AccInfo().iSuppProfiles));
       
    55     CBasrvAccState* next = NULL;
       
    56     TRAP_IGNORE(next = CBasrvAccStateDisconnect::NewL(Parent()));
       
    57     return next;
       
    58     }
       
    59 
       
    60 TBTEngConnectionStatus CBasrvAccStateAttach::ConnectionStatus() const
       
    61     {
       
    62     return EBTEngConnecting;
       
    63     }
       
    64 
       
    65 void CBasrvAccStateAttach::CancelConnect()
       
    66     {
       
    67     TRACE_FUNC
       
    68     iActive->Cancel();
       
    69     CBasrvAccState* next = NULL;
       
    70     TRAP_IGNORE(next = CBasrvAccStateDisconnect::NewL(Parent()));
       
    71     TRAP_IGNORE(Parent().ChangeStateL(next));
       
    72     }
       
    73 
       
    74 
       
    75 void CBasrvAccStateAttach::DisconnectL()
       
    76     {
       
    77     TRACE_FUNC
       
    78     iActive->Cancel();
       
    79     Parent().ChangeStateL(CBasrvAccStateDisconnect::NewL(Parent()));
       
    80     }
       
    81      
       
    82 void CBasrvAccStateAttach::AccessoryDisconnectedL(TProfiles aProfile)
       
    83     {
       
    84     TRACE_FUNC
       
    85     ProfileDisconnected(aProfile);
       
    86     AccClosedAudio(aProfile);
       
    87     StatePrint(_L("Attach"));
       
    88     if (!AccInfo().iConnProfiles)
       
    89         {
       
    90         if (iConnecting)
       
    91             {
       
    92             Parent().AccMan().ConnectCompletedL(AccInfo().iAddr, KErrDisconnected, AccInfo().iSuppProfiles);
       
    93             }
       
    94         iActive->Cancel();
       
    95         Parent().ChangeStateL(NULL);
       
    96         }
       
    97     }
       
    98 
       
    99 void CBasrvAccStateAttach::RequestCompletedL(CBasrvActive& aActive)
       
   100     {
       
   101     TRACE_FUNC
       
   102     if (iConnecting && aActive.iStatus == KErrNone)
       
   103         {
       
   104         Parent().AccMan().ConnectCompletedL(AccInfo().iAddr, aActive.iStatus.Int(), AccInfo().iConnProfiles);
       
   105         }
       
   106         
       
   107     if (aActive.iStatus == KErrNone)
       
   108         {
       
   109         Parent().AccMan().ListenAudioRequestL();        	
       
   110         Parent().AccMan().PluginMan().AccInUse();
       
   111         Parent().ChangeStateL(CBasrvAccStateAttached::NewL(Parent(), !iConnecting));
       
   112         }
       
   113     else
       
   114         {
       
   115         Parent().ChangeStateL(CBasrvAccStateDisconnect::NewL(Parent(), aActive.iStatus.Int()));
       
   116         }
       
   117     }
       
   118     
       
   119 void CBasrvAccStateAttach::CancelRequest(CBasrvActive& /*aActive*/)
       
   120     {
       
   121     TRACE_FUNC
       
   122     CBasrvAccfwIf* accif = NULL;
       
   123     TRAP_IGNORE(accif = Parent().AccMan().AccfwConnectionL());
       
   124     if (accif)
       
   125         accif->CancelAttachAccessory(AccInfo().iAddr);
       
   126     }
       
   127 
       
   128 CBasrvAccStateAttach::CBasrvAccStateAttach(CBasrvAcc& aParent, TBool aConnecting)
       
   129     : CBasrvAccState(aParent, NULL), iConnecting(aConnecting)
       
   130     {
       
   131     }
       
   132  
       
   133 void CBasrvAccStateAttach::ConstructL()
       
   134     {
       
   135     iActive = CBasrvActive::NewL(*this, CActive::EPriorityStandard, KAttachRequestId);
       
   136     }
       
   137