bluetoothengine/btaudioman/src/basrvaccman.cpp
branchRCL_3
changeset 6 6a29d5ad0713
parent 2 0b192a3a05a4
child 21 53b7818cd282
equal deleted inserted replaced
2:0b192a3a05a4 6:6a29d5ad0713
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:  Implementation of an accessory management.
    14 * Description:  Implementation of an accessory management.
    15 *  Version     : %version:  14.1.8 %
    15 *  Version     : %version:  14.1.10 %
    16 *
    16 *
    17 */
    17 */
    18 
    18 
    19 
    19 
    20 // INCLUDE FILES
    20 // INCLUDE FILES
    21 #include <centralrepository.h>
    21 #include <centralrepository.h>
       
    22 #include <btengdomaincrkeys.h>
    22 #include "basrvaccman.h"
    23 #include "basrvaccman.h"
    23 #include "BTAccSession.h"
    24 #include "BTAccSession.h"
    24 #include "BTAccClientSrv.h"
    25 #include "BTAccClientSrv.h"
    25 #include "basrvacc.h"
    26 #include "basrvacc.h"
    26 #include "BTAccInfo.h"
    27 #include "BTAccInfo.h"
    42     self->ConstructL();
    43     self->ConstructL();
    43     CleanupStack::Pop(self);
    44     CleanupStack::Pop(self);
    44     return self;
    45     return self;
    45     }
    46     }
    46 
    47 
       
    48 void CBasrvAccMan::ConstructL()
       
    49     {
       
    50     iAsyncHandlingActive = 
       
    51         CBasrvActive::NewL(*this, CActive::EPriorityStandard, KAsyncHandlingRequest);
       
    52     
       
    53     CRepository* cenrep = NULL;
       
    54     TRAP_IGNORE(cenrep = CRepository::NewL(KCRUidBluetoothEngine));
       
    55     TInt avrcpVol = EBTAvrcpVolCTNotSupported;
       
    56     TInt autoDisconnect = EBTDisconnectIfAudioOpenFails;
       
    57     if (cenrep)
       
    58         {
       
    59         cenrep->Get(KBTAvrcpVolCTLV, avrcpVol);
       
    60         cenrep->Get(KBTDisconnectIfAudioOpenFailsLV, autoDisconnect);
       
    61         delete cenrep;
       
    62         }
       
    63     iAvrcpVolCTSupported = (avrcpVol == EBTAvrcpVolCTSupported);
       
    64     iDisconnectIfAudioOpenFails = (autoDisconnect == EBTDisconnectIfAudioOpenFails);
       
    65     TRACE_INFO((_L("[AVRCP_Vol_CT] %d [DisconnectIfAudioOpenFails] %d"), 
       
    66         iAvrcpVolCTSupported, iDisconnectIfAudioOpenFails))
       
    67     LoadServicesL();
       
    68     }
       
    69 
    47 CBasrvAccMan::~CBasrvAccMan()
    70 CBasrvAccMan::~CBasrvAccMan()
    48     {
    71     {
    49     delete iOpenListener;
    72     delete iOpenListener;
    50     delete iCloseListener;
    73     delete iCloseListener;
    51     delete iAsyncHandlingActive;
    74     delete iAsyncHandlingActive;
    75     delete iAccfw;
    98     delete iAccfw;
    76     delete iPluginMan;
    99     delete iPluginMan;
    77     iNotifierArray.ResetAndDestroy();
   100     iNotifierArray.ResetAndDestroy();
    78     iNotifierArray.Close();
   101     iNotifierArray.Close();
    79     iClientRequests.Close();
   102     iClientRequests.Close();
    80     DestructVariant();
       
    81     TRACE_FUNC    
   103     TRACE_FUNC    
    82     }
   104     }
    83 
   105 
    84 void CBasrvAccMan::LoadServicesL()
   106 void CBasrvAccMan::LoadServicesL()
    85     {
   107     {
   150         TClientRequestCache request;
   172         TClientRequestCache request;
   151         request.iSession = &aSession;
   173         request.iSession = &aSession;
   152         request.iRequest = EBTAccSrvDisconnectAccessory;
   174         request.iRequest = EBTAccSrvDisconnectAccessory;
   153         request.iAddr = aAddr;
   175         request.iAddr = aAddr;
   154         iClientRequests.AppendL(request);
   176         iClientRequests.AppendL(request);
       
   177         
       
   178         //remove the last item from the RArray if a leave occurs later
       
   179         TCleanupItem cleanupItem(CleanupLastItemFromClientRequestsArray, &iClientRequests);
       
   180         CleanupStack::PushL(cleanupItem);
       
   181         
   155         iAccs[idx]->DisconnectL();
   182         iAccs[idx]->DisconnectL();
       
   183         
       
   184         CleanupStack::Pop(&iClientRequests);
   156         }
   185         }
   157     else
   186     else
   158         {
   187         {
   159         aSession.DisconnectCompleted(EAnyMonoAudioProfiles, KErrNotFound);
   188         aSession.DisconnectCompleted(EAnyMonoAudioProfiles, KErrNotFound);
   160         }
   189         }
   414     }
   443     }
   415 
   444 
   416 void CBasrvAccMan::ShowNote(TBTGenericInfoNoteType aNote, const TBTDevAddr& aAddr)
   445 void CBasrvAccMan::ShowNote(TBTGenericInfoNoteType aNote, const TBTDevAddr& aAddr)
   417     {
   446     {
   418     TRACE_INFO((_L("CBasrvAccMan::ShowNote %d"), aNote))
   447     TRACE_INFO((_L("CBasrvAccMan::ShowNote %d"), aNote))
   419     TRAPD(err, iNotifierArray.Append(CBasrvActiveNotifier::NewL(*this, CActive::EPriorityStandard, KShowNoteRequest, aAddr, aNote)));
   448     TRAPD(err, DoShowNoteL(aNote, aAddr));
   420     if (err)
   449     if (err != KErrNone)
   421         {
   450         {
   422         TRACE_ERROR((_L("could not construct active notifer object")))
   451         TRACE_ERROR((_L("could not construct active notifer object")))
   423         return;
   452         return;
   424         }
   453         }
       
   454     }
       
   455 
       
   456 void CBasrvAccMan::DoShowNoteL(TBTGenericInfoNoteType aNote, const TBTDevAddr& aAddr)
       
   457     {
       
   458     CBasrvActiveNotifier* activeNotifier = CBasrvActiveNotifier::NewL(*this, CActive::EPriorityStandard, KShowNoteRequest, aAddr, aNote);
       
   459     
       
   460     CleanupStack::PushL(activeNotifier);
       
   461     iNotifierArray.AppendL(activeNotifier);
       
   462     CleanupStack::Pop(activeNotifier);
   425     }
   463     }
   426 
   464 
   427 void CBasrvAccMan::FilterProfileSupport(TAccInfo& aInfo)
   465 void CBasrvAccMan::FilterProfileSupport(TAccInfo& aInfo)
   428     {
   466     {
   429     TInt pluginbit = iPluginMan->AvailablePlugins();
   467     TInt pluginbit = iPluginMan->AvailablePlugins();
   727             break;
   765             break;
   728             }
   766             }
   729         case KAsyncHandlingRequest:
   767         case KAsyncHandlingRequest:
   730             {
   768             {
   731             DoAudioRequestL();
   769             DoAudioRequestL();
   732             delete iAsyncHandlingActive;
       
   733             iAsyncHandlingActive = NULL;
       
   734             break;
   770             break;
   735             }
   771             }
   736         default:
   772         default:
   737             {
   773             {
   738             
   774             
   758     }
   794     }
   759     
   795     
   760 void CBasrvAccMan::DoAudioRequestL()
   796 void CBasrvAccMan::DoAudioRequestL()
   761     {
   797     {
   762     TRACE_FUNC
   798     TRACE_FUNC
   763     if (iAudioRequests.Count() && !iAudioRequests[0].iOngoing && (!iAsyncHandlingActive || !iAsyncHandlingActive->IsActive()))
   799     if (iAudioRequests.Count() && !iAudioRequests[0].iOngoing && !iAsyncHandlingActive->IsActive())
   764         {
   800         {
   765         iAudioRequests[0].iOngoing = ETrue;
   801         iAudioRequests[0].iOngoing = ETrue;
   766         TInt err = KErrNotFound;
   802         TInt err = KErrNotFound;
   767         TInt idx = FindAcc(iAudioRequests[0].iAddr);
   803         TInt idx = FindAcc(iAudioRequests[0].iAddr);
   768         if (idx >= 0)
   804         if (idx >= 0)
   825     req.iAddr = aAddr;
   861     req.iAddr = aAddr;
   826     req.iAudioType = aType;
   862     req.iAudioType = aType;
   827     req.iReqType = ERejectAudioOpenedByAcc;
   863     req.iReqType = ERejectAudioOpenedByAcc;
   828     req.iOngoing = EFalse;
   864     req.iOngoing = EFalse;
   829     TInt idx = 0;
   865     TInt idx = 0;
   830     if (iAudioRequests.Count() && iAudioRequests[0].iOngoing)
   866     if (iAudioRequests.Count() && iAudioRequests[0].iOngoing && !iAsyncHandlingActive->IsActive())
   831         {
   867         {
   832         idx = 1;
   868         idx = 1;
   833         }
   869         }
   834     TInt err = iAudioRequests.Insert(req, idx);
   870     TInt err = iAudioRequests.Insert(req, idx);
   835     TRACE_INFO_SEG(
   871     TRACE_INFO_SEG(
   837         TBuf<12> buf;
   873         TBuf<12> buf;
   838         iCloseAddr.GetReadable(buf);
   874         iCloseAddr.GetReadable(buf);
   839         Trace(_L("[Audio Request buf] 2(Reject) %d at '%S', to index %d"), iCloseType, &buf, idx);
   875         Trace(_L("[Audio Request buf] 2(Reject) %d at '%S', to index %d"), iCloseType, &buf, idx);
   840         });
   876         });
   841 
   877 
   842     if (!err && !iAsyncHandlingActive && !iAudioRequests[0].iOngoing)
   878     if ((err == KErrNone) && !iAudioRequests[0].iOngoing)
   843         {
   879         {
   844         // Start rejection asynchronously
   880         iAsyncHandlingActive->iStatus = KRequestPending;
   845         iAsyncHandlingActive = 
   881         TRequestStatus* sta = &(iAsyncHandlingActive->iStatus);
   846             CBasrvActive::New(*this, CActive::EPriorityStandard, KAsyncHandlingRequest);
   882         User::RequestComplete(sta, KErrNone);
   847         if (iAsyncHandlingActive)
   883         iAsyncHandlingActive->GoActive();
   848             {
       
   849             iAsyncHandlingActive->iStatus = KRequestPending;
       
   850             TRequestStatus* sta = &(iAsyncHandlingActive->iStatus);
       
   851             User::RequestComplete(sta, KErrNone);
       
   852             iAsyncHandlingActive->GoActive();
       
   853             }
       
   854         }
   884         }
   855     }
   885     }
   856 
   886 
   857 void CBasrvAccMan::CleanupLastItemFromClientRequestsArray(TAny* aPtr)
   887 void CBasrvAccMan::CleanupLastItemFromClientRequestsArray(TAny* aPtr)
   858     {
   888     {