bluetoothengine/btsac/btrcc/inc/btrccLinker.h
changeset 0 f63038272f30
child 9 a42ed326b458
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:  State Machine of BTRCC
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef BTRCCLINKER_H
       
    20 #define BTRCCLINKER_H
       
    21 
       
    22 
       
    23 //  INCLUDES
       
    24 #include <e32base.h>
       
    25 #include <bttypes.h> // BT protocol wide types
       
    26 #include <e32property.h> // pub-sub definitions
       
    27 #include <remconbatterytarget.h>
       
    28 #include <remconbatterytargetobserver.h>
       
    29 #include <absolutevolumeapitargetobserver.h>
       
    30 #include <remconinterfaceselector.h>
       
    31 
       
    32 #include "btrccVolumeLevelControllerBase.h"
       
    33 
       
    34 // DATA TYPES
       
    35 enum TBTRCCStateIndex
       
    36     {
       
    37     EStateIndexIdle = 0,
       
    38     EStateIndexConnecting,
       
    39     EStateIndexConnected,
       
    40     EStateIndexDisconnect
       
    41     };
       
    42     
       
    43 // FORWARD DECLARATIONS
       
    44 class MBTAccObserver;
       
    45 class CRemConInterfaceSelector;
       
    46 class CRemConCoreApiController;
       
    47 class CBTRCCVolumeLevelController;
       
    48 class CRemConCoreApiTarget;
       
    49 class CPlayerStarter;
       
    50 class CBTRCCBrowsingAdapter;
       
    51 
       
    52 // CLASS DECLARATION
       
    53 
       
    54 /**
       
    55 *  The main controller for BT Remote Control Profile. Notifies BT Accessory Server
       
    56 * about changes in remote contorl profile connections. Perform requests from BT Accessory
       
    57 * Server to disconnect the accessory. 
       
    58 */
       
    59 NONSHARABLE_CLASS(CBTRCCLinker) : public CActive, public MRemConBatteryTargetObserver, public MBTRCCVolumeControllerObserver
       
    60 	{
       
    61     private:
       
    62         /**
       
    63         * The base class of state
       
    64         */
       
    65         class TState
       
    66             {
       
    67             public:
       
    68                 
       
    69                 /**
       
    70                 * Entry of this state
       
    71                 * @param aStatus the client status, will be completed when this state should exit.
       
    72                 */
       
    73                 virtual void Enter() = 0;
       
    74                 
       
    75                 /**
       
    76                 * Called by parent's DoCancel
       
    77                 * Cancels the outstanding operations in this state.
       
    78                 */
       
    79                 virtual void DoCancel();
       
    80 
       
    81                 virtual void Connect(const TBTDevAddr& aAddr, TRequestStatus& aStatus);
       
    82 
       
    83                 virtual void CancelConnect(const TBTDevAddr& aAddr);                
       
    84                 
       
    85                 /**
       
    86                 * Makes a request to disconnect the connection.
       
    87                 * @param aBdAddress	BT device address of remote side
       
    88                 */
       
    89                 virtual void Disconnect(TRequestStatus& aStatus, const TBTDevAddr& aAddr);
       
    90                 
       
    91                 /**
       
    92                 * This will be called whenever an async operation to RemCon FW completes.
       
    93                 */
       
    94                 virtual void RemConRequestCompleted(TInt aErr);
       
    95                 
       
    96                 virtual void UpdateRemoteVolumeControling(TBool aActivated);
       
    97                 
       
    98             protected:
       
    99             
       
   100                 /**
       
   101                 * Default constructor
       
   102                 */
       
   103                 TState(CBTRCCLinker& aParent);
       
   104                                 
       
   105             protected:
       
   106                 CBTRCCLinker& iParent;
       
   107             };
       
   108         friend class TState;
       
   109 
       
   110         class TStateIdle : public TState
       
   111             {
       
   112             public:
       
   113 
       
   114                 TStateIdle(CBTRCCLinker& aParent);
       
   115  
       
   116                 void Enter();
       
   117 
       
   118                 void DoCancel();
       
   119 
       
   120                 void Connect(const TBTDevAddr& aAddr, TRequestStatus& aStatus);
       
   121                 
       
   122                 void RemConRequestCompleted(TInt aErr);
       
   123             };
       
   124         friend class TStateIdle;
       
   125 
       
   126         class TStateConnecting : public TState
       
   127             {
       
   128             public:
       
   129 
       
   130                 TStateConnecting(CBTRCCLinker& aParent);
       
   131  
       
   132                 void Enter();
       
   133 
       
   134                 void DoCancel();
       
   135 
       
   136                 void CancelConnect(const TBTDevAddr& aAddr);
       
   137                 
       
   138                 void RemConRequestCompleted(TInt aErr);
       
   139                 
       
   140             private:
       
   141                 TBool iConnectCanceled;
       
   142             };
       
   143         friend class TStateConnecting;
       
   144         
       
   145         class TStateConnected : public TState
       
   146             {
       
   147             public:
       
   148                 TStateConnected(CBTRCCLinker& aParent);
       
   149  
       
   150                 void Enter();
       
   151              
       
   152                 void DoCancel();
       
   153                 
       
   154                 void Connect(const TBTDevAddr& aAddr, TRequestStatus& aStatus);
       
   155                 
       
   156                 void Disconnect(TRequestStatus& aStatus, const TBTDevAddr& aAddr);
       
   157                 
       
   158                 void RemConRequestCompleted(TInt aErr);
       
   159                 
       
   160                 void UpdateRemoteVolumeControling(TBool aActivated);
       
   161             };
       
   162         friend class TStateConnected;  
       
   163 
       
   164         class TStateDisconnect : public TState
       
   165             {
       
   166             public:
       
   167                 TStateDisconnect(CBTRCCLinker& aParent);
       
   168  
       
   169                 void Enter();
       
   170 
       
   171                 void DoCancel();
       
   172                 
       
   173                 void RemConRequestCompleted(TInt aErr);
       
   174             };
       
   175         friend class TStateDisconnect;
       
   176                       
       
   177     public:  // Constructors and destructor
       
   178         
       
   179         /**
       
   180         * Two-phased constructor.
       
   181         * After construction the instance is ready to serve requests.
       
   182         * Also starts listening to incoming connections from BT audio 
       
   183         * accessories.
       
   184         */
       
   185         static CBTRCCLinker* NewL(MBTAccObserver& aAccObserver);
       
   186         
       
   187         /**
       
   188         * Destructor.
       
   189         * Removes service and security registrations and stops listening to
       
   190         * incoming connections.
       
   191         */
       
   192         virtual ~CBTRCCLinker();
       
   193 
       
   194 		void MrcbstoBatteryStatus(TControllerBatteryStatus& aBatteryStatus);
       
   195 
       
   196     public: // New functions
       
   197         
       
   198         void Connect(const TBTDevAddr& aAddr, TRequestStatus& aStatus);
       
   199 
       
   200         void CancelConnect(const TBTDevAddr& aAddr);        
       
   201 
       
   202         /**
       
   203         * DiSconnects from the currently connected BT audio accessory.
       
   204         * @return                   None.
       
   205         */
       
   206         void Disconnect(TRequestStatus& aStatus, const TBTDevAddr& aAddr);
       
   207         
       
   208         MBTAccObserver& AccObserver();
       
   209         
       
   210         void ActivateRemoteVolumeControl();
       
   211 
       
   212         void DeActivateRemoteVolumeControl();
       
   213 
       
   214     public:  // From MBTRCCVolumeControllerObserver 
       
   215         void VolumeControlError(TInt aError);                 
       
   216 
       
   217     private:  // From CActive
       
   218 
       
   219         /**
       
   220         * Gets called when the asynchronous control connection open operation 
       
   221         * completes. Informs the control connection observer about the 
       
   222         * connection.
       
   223         * @param                            None.
       
   224         * @return                           None.
       
   225         */
       
   226         void RunL();
       
   227 
       
   228 		/**
       
   229         * Gets called if RunL leaves 
       
   230         * @param                            None.
       
   231         * @return                           None.
       
   232         */
       
   233 	    TInt RunError(TInt aError);
       
   234 
       
   235         /**
       
   236         * Cancels the ongoing control connection open operation and informs
       
   237         * the control connection observer about that.
       
   238         * @param                            None.
       
   239         * @return                           None.
       
   240         */
       
   241         void DoCancel();
       
   242 
       
   243 
       
   244     private:
       
   245 
       
   246         /**
       
   247         * C++ default constructor.
       
   248         */
       
   249         CBTRCCLinker(MBTAccObserver& aAccObserver);
       
   250 
       
   251         /**
       
   252         * Symbian 2nd phase constructor.
       
   253         */
       
   254         void ConstructL();
       
   255         
       
   256         /**
       
   257         * Connect the accessory.
       
   258         */
       
   259         void DoConnect();
       
   260 
       
   261         void DoSubscribeConnetionStatus();
       
   262 
       
   263         void DoCancelSubscribe();
       
   264         
       
   265         /**
       
   266         * DiSconnects from the currently connected BT audio accessory.
       
   267         * @return                   None.
       
   268         */
       
   269         void DoDisconnect();
       
   270         
       
   271         void ChangeState(TBTRCCStateIndex aNextState);    
       
   272 
       
   273         /**
       
   274         * Re-orient AVRCP bearer plugin to the remote for the current connect /disconnect request
       
   275         */
       
   276         TInt DoRemConOrientation();
       
   277         
       
   278         /**
       
   279         * aConnectedAddr will hold the remote BD address if there is a connection.
       
   280         * otherwise it is TBTDevAddr()
       
   281         */
       
   282         void DoGetRemConConnectionStatus(RArray<TBTDevAddr>& aConnects);
       
   283 
       
   284         void StartRemoteVolumeControl();
       
   285         
       
   286         void StopRemoteVolumeControl();
       
   287 
       
   288         void ResetVolmeControlSetting();
       
   289 
       
   290    private:    // Data
       
   291     
       
   292 		CRemConInterfaceSelector *iInterfaceSelector; 
       
   293 		
       
   294 		// For receiving the accessory battery status
       
   295         CRemConBatteryApiTarget *iRemConBatteryTgt;
       
   296         
       
   297 	    CRemConCoreApiTarget* iCoreTarget; // not own
       
   298 	    
       
   299 	    CPlayerStarter* iPlayerStarter; // owned
       
   300 	    
       
   301         // For handling the browsing commands. 
       
   302 	    CBTRCCBrowsingAdapter *iBrowsingAdapter;
       
   303 
       
   304 	    // This is only needed for disconnecting a AVRCP connection
       
   305         // when AVRCP Remote Volume Control is not supported.
       
   306         CRemConInterfaceSelector *iInterfaceSelectorForDisconnectingTargetSession; 
       
   307         
       
   308         TBTDevAddr iRemoteAddr;
       
   309         
       
   310 		MBTAccObserver& iAccObserver;
       
   311 
       
   312         RPointerArray<TState> iStateArray;  // Array of all states in BTRCC 
       
   313         TBTRCCStateIndex iCurrentStateIndex;  // Index of current state
       
   314 
       
   315         TRequestStatus* iClientRequest;
       
   316         TBool iRemConOriented;
       
   317         
       
   318         TBool iRvcActivated;
       
   319         
       
   320         CBTRCCVolumeLevelControllerBase* iVolController;
       
   321         CBTRCCVolumeLevelControllerBase* iAbsoluteVolController;
       
   322         CBTRCCVolumeLevelControllerBase* iLegacyVolController;
       
   323         
       
   324         TInt iRegisterVolumeChangeNotificationCounter;//Counter for re-register for remote volume control notification
       
   325 };
       
   326 
       
   327 
       
   328 #endif      // BTRCCLINKER_H
       
   329             
       
   330 // End of File