bluetoothengine/btaudioman/src/basrvacc.cpp
changeset 0 f63038272f30
child 2 0b192a3a05a4
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 an accessory management.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "basrvacc.h"
       
    21 #include "basrvaccman.h"
       
    22 #include "basrvrvc.h"
       
    23 #include "basrvaccstatequery.h"
       
    24 #include "basrvpowercontrolagent.h"
       
    25 #include "debug.h"
       
    26 
       
    27 // ================= MEMBER FUNCTIONS =======================
       
    28 
       
    29 CBasrvAcc* CBasrvAcc::NewL(CBasrvAccMan& aAccMan)
       
    30     {
       
    31     CBasrvAcc* self = CBasrvAcc::NewLC(aAccMan);
       
    32     CleanupStack::Pop();
       
    33     return self;
       
    34     }
       
    35 
       
    36 CBasrvAcc* CBasrvAcc::NewLC(CBasrvAccMan& aAccMan)
       
    37     {
       
    38     CBasrvAcc* self = new(ELeave) CBasrvAcc(aAccMan);
       
    39     CleanupStack::PushL(self);
       
    40     self->ConstructL();
       
    41     return self;
       
    42     }
       
    43 
       
    44 CBasrvAcc::~CBasrvAcc()
       
    45     {
       
    46     delete iState;
       
    47     delete iRvc;
       
    48     delete iPowerController;
       
    49     TRACE_FUNC
       
    50     }
       
    51     
       
    52 const TBTDevAddr& CBasrvAcc::Remote()
       
    53     {
       
    54     return iAccInfo.iAddr;
       
    55     }
       
    56 
       
    57 void CBasrvAcc::ConnectL(const TBTDevAddr& aAddr)
       
    58     { 
       
    59     TRACE_FUNC
       
    60     if (!iState)
       
    61         {
       
    62         iAccInfo.SetBDAddress(aAddr);
       
    63         iState = CBasrvAccStateQuery::NewL(*this, ETrue);
       
    64         iState->EnterL();
       
    65         }
       
    66     else
       
    67         {
       
    68         iState->ConnectL(aAddr);
       
    69         }
       
    70     }
       
    71 
       
    72 void CBasrvAcc::CancelConnect()
       
    73     {
       
    74     TRACE_FUNC
       
    75     if (iState)
       
    76         {
       
    77         iState->CancelConnect();
       
    78         }
       
    79     }
       
    80 
       
    81 void CBasrvAcc::DisconnectL()
       
    82     {
       
    83     TRACE_FUNC
       
    84     if (iState)
       
    85         {
       
    86         iState->DisconnectL();
       
    87         }
       
    88     }
       
    89 
       
    90 void CBasrvAcc::AccessoryConnectedL(const TBTDevAddr& aAddr, TProfiles aProfile)
       
    91     {
       
    92     TRACE_FUNC
       
    93     if (!iState)
       
    94         {
       
    95         iAccInfo.SetBDAddress(aAddr);
       
    96         iAccInfo.iConnProfiles = aProfile;
       
    97         iAccInfo.iSuppProfiles = aProfile;
       
    98         iState = CBasrvAccStateQuery::NewL(*this, EFalse);
       
    99         iState->EnterL();
       
   100         }
       
   101     else if (aAddr == iAccInfo.iAddr)
       
   102         {
       
   103         iState->AccessoryConnected(aProfile);
       
   104         }
       
   105     }
       
   106 
       
   107 void CBasrvAcc::AccOpenedAudio(TProfiles aProfile)
       
   108     {
       
   109     TRACE_FUNC
       
   110     iState->AccOpenedAudio(aProfile);
       
   111     }
       
   112 
       
   113 void CBasrvAcc::AccClosedAudio(TProfiles aProfile)
       
   114     {
       
   115     TRACE_FUNC
       
   116     iState->AccClosedAudio(aProfile);
       
   117     }
       
   118     
       
   119 void CBasrvAcc::AccessoryDisconnectedL(TProfiles aProfile)
       
   120     {
       
   121     TRACE_FUNC
       
   122     iState->AccessoryDisconnectedL(aProfile);
       
   123     }
       
   124 
       
   125 void CBasrvAcc::OpenAudioL(TAccAudioType aType)
       
   126     {
       
   127     TRACE_FUNC
       
   128     iState->OpenAudioL(aType);
       
   129     }
       
   130 
       
   131 void CBasrvAcc::CloseAudioL(TAccAudioType aType)
       
   132     {
       
   133     TRACE_FUNC
       
   134     iState->CloseAudioL(aType);
       
   135     }
       
   136 
       
   137 const TAccInfo* CBasrvAcc::AccInfo(const TBTDevAddr& aAddr)
       
   138     {
       
   139     TRACE_FUNC
       
   140     if (iAccInfo.iAddr == aAddr)
       
   141         {
       
   142         return &iAccInfo;
       
   143         }
       
   144     return NULL;
       
   145     }
       
   146 
       
   147 void CBasrvAcc::ChangeStateL(CBasrvAccState* aNewState)
       
   148     {
       
   149     TRACE_FUNC_ENTRY
       
   150     delete iState;
       
   151     iState = aNewState;
       
   152     if (iState)
       
   153         {
       
   154         TInt err = KErrNone;
       
   155         TRAP(err, iState->EnterL());
       
   156         if (err)
       
   157             {
       
   158             ChangeStateL(iState->ErrorOnEntry(err));
       
   159             }
       
   160         }
       
   161     if (!iState)
       
   162         {
       
   163         iAccMan.AccObsoleted(this, iAccInfo.iAddr);
       
   164         }
       
   165     TRACE_FUNC_EXIT
       
   166     }
       
   167     
       
   168 CBasrvAccMan& CBasrvAcc::AccMan()
       
   169     {
       
   170     return iAccMan;
       
   171     }
       
   172 
       
   173 
       
   174 TAccInfo& CBasrvAcc::AccInfo()
       
   175     {
       
   176     return iAccInfo;
       
   177     }
       
   178 
       
   179 TBTEngConnectionStatus CBasrvAcc::ConnectionStatus() const
       
   180     {
       
   181     if (iState)
       
   182         {
       
   183         return iState->ConnectionStatus();
       
   184         }
       
   185     
       
   186     return EBTEngNotConnected;
       
   187     }
       
   188 
       
   189 void CBasrvAcc::RequestSniffMode()
       
   190     {
       
   191     if (!(AccInfo().iSuppProfiles & EHFP) && !(AccInfo().iSuppProfiles & EStereo))
       
   192         {
       
   193         return; // No power mode handling with HSP
       
   194         }
       
   195     
       
   196     if (!iPowerController)
       
   197         {
       
   198         TRAP_IGNORE(iPowerController = CBasrvPowerControlAgent::NewL(iAccInfo.iAddr));
       
   199         }
       
   200     
       
   201     if (iPowerController)
       
   202         {
       
   203         iPowerController->RequestSniffMode();
       
   204         }
       
   205     }
       
   206 
       
   207 void CBasrvAcc::RequestActiveMode()
       
   208     {
       
   209     if (!(AccInfo().iSuppProfiles & EHFP) && !(AccInfo().iSuppProfiles & EStereo))
       
   210         {
       
   211         return; // No power mode handling with HSP
       
   212         }
       
   213     if (!iPowerController)
       
   214         {
       
   215         TRAP_IGNORE(iPowerController = CBasrvPowerControlAgent::NewL(iAccInfo.iAddr));
       
   216         }
       
   217     if (iPowerController)
       
   218         {
       
   219         iPowerController->RequestActiveMode();
       
   220         }
       
   221     }
       
   222 
       
   223 void CBasrvAcc::CancelPowerModeControl()
       
   224     {
       
   225     if (iPowerController)
       
   226         {
       
   227         iPowerController->CancelPowerModeControl();
       
   228         }
       
   229     }
       
   230 
       
   231 void CBasrvAcc::NotifyLinkChange2Rvc()
       
   232     {
       
   233     if (!iRvc)
       
   234         iRvc = CBasrvRvc::New(*this);
       
   235     if (iRvc)
       
   236         {
       
   237         iRvc->Update(iAccInfo.iConnProfiles, iAccInfo.iAudioOpenedProfiles);
       
   238         }
       
   239     }
       
   240 
       
   241 void CBasrvAcc::PreventLowPowerMode()
       
   242     {
       
   243     TRACE_FUNC
       
   244     if (!iPowerController)
       
   245         {
       
   246         TRAP_IGNORE(iPowerController = CBasrvPowerControlAgent::NewL(iAccInfo.iAddr));
       
   247         }
       
   248     if (iPowerController)
       
   249         {
       
   250         iPowerController->PreventLowPowerMode();
       
   251         }
       
   252     }
       
   253     
       
   254 void CBasrvAcc::AllowLowPowerMode()
       
   255     {
       
   256     TRACE_FUNC
       
   257     if (iPowerController)
       
   258         {
       
   259         iPowerController->AllowLowPowerMode();
       
   260         }
       
   261     }
       
   262 
       
   263 
       
   264 CBasrvAcc::CBasrvAcc(CBasrvAccMan& aAccMan)
       
   265     : iAccMan(aAccMan)
       
   266     {
       
   267     TRACE_FUNC
       
   268     iAccInfo.SetBDAddress(TBTDevAddr());
       
   269     }
       
   270 
       
   271 void CBasrvAcc::ConstructL()
       
   272     {
       
   273     }
       
   274 
       
   275 //  End of File