bluetooth/btstack/eirman/eirmanager.h
changeset 0 29b1cd4cb562
child 17 32ba20339036
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @internalComponent
       
    19 */
       
    20 
       
    21 #ifndef _EIRMANAGER_H
       
    22 #define _EIRMANAGER_H
       
    23 
       
    24 #include <e32base.h>
       
    25 #include <bluetooth/hcicommandqueueclient.h>
       
    26 #include <bluetooth/eirmanshared.h>
       
    27 
       
    28 class CLinkMgrProtocol;
       
    29 class MHCICommandQueue;
       
    30 
       
    31 // Magic numbers
       
    32 
       
    33 const TUint8 KOfferPending		= 0x01;
       
    34 const TUint8 KNeedOffer 		= 0x02;
       
    35 
       
    36 const TInt KLengthInvalid = -1;
       
    37 
       
    38 // Reserved bytes for each tag, this is used by the 1st iteration of calculation
       
    39 const TInt KReservedNameBytes = 101;
       
    40 const TInt KReservedUuid16Bytes = 50;
       
    41 const TInt KReservedUuid128Bytes = 50;
       
    42 const TInt KReservedManufacturerSpecificDataBytes = 22;
       
    43 const TInt KReservedTxPowerLevelBytes = 3;
       
    44 
       
    45 const TInt KDeviceNameGranularity = 1;
       
    46 const TInt K16BitUuidGranularity = 2;
       
    47 const TInt K128BitUuidGranularity = 16;
       
    48 
       
    49 const TInt KWriteEirTimeout = 2000000; // 2 seconds
       
    50 
       
    51 class MEirManagerNotifiee
       
    52 	{
       
    53 public:
       
    54 	virtual void MemnEirBlockAvailable(TEirTag aTag, TUint aSpaceForTag)=0;
       
    55 	};
       
    56 
       
    57 class REirOwnerDetails
       
    58 	{
       
    59 public:
       
    60 	HBufC8*			iTagData;
       
    61 	MEirManagerNotifiee*	iNotifiee;
       
    62 	TEirDataMode 	iEirDataMode;
       
    63 	TInt			iOfferedBytes;
       
    64 	TInt			iRequiredBytes;
       
    65 	TUint8			iState;
       
    66 	};
       
    67 
       
    68 class CEirManager;
       
    69 
       
    70 NONSHARABLE_CLASS(CWriteEirTimer) : public CTimer
       
    71 	{
       
    72 	public:
       
    73 		static CWriteEirTimer* NewL(CEirManager& aEirManager);
       
    74 		void Start();
       
    75 	private:
       
    76 		CWriteEirTimer(CEirManager& aEirManager);
       
    77 		void ConstructL();
       
    78 		void RunL();
       
    79 		TInt RunError(TInt aError);
       
    80 	private:
       
    81 		CEirManager& iEirManager;
       
    82 	};
       
    83 
       
    84 NONSHARABLE_CLASS(CEirManager) : public CBase, public MHCICommandQueueClient
       
    85 	{
       
    86 public:
       
    87 	static CEirManager* NewL(MHCICommandQueue& aCommandQueue, CLinkMgrProtocol& aLinkMgrProtocol);
       
    88 	~CEirManager();
       
    89 
       
    90 	TInt RegisterTag(TEirTag aTag, MEirManagerNotifiee& aNotifiee);
       
    91 	void DeregisterTag(TEirTag aTag);
       
    92 	TInt SetData(TEirTag aTag, TDesC8& aData, TEirDataMode aEirDataMode);
       
    93 	
       
    94 	// from MHCICommandQueueClient
       
    95 	void MhcqcCommandEventReceived(const THCIEventBase& aEvent, const CHCICommandBase* aRelatedCommand);
       
    96 	void MhcqcCommandErrored(TInt aErrorCode, const CHCICommandBase* aCommand);
       
    97 	
       
    98 	TInt NewData(TEirTag aTag, TInt aRequiredBytes);
       
    99 	void TryToUpdateHostController();
       
   100 	void UpdateHostControllerL();
       
   101 
       
   102 private:
       
   103 	CEirManager(MHCICommandQueue& aCommandQueue, CLinkMgrProtocol& aLinkMgrProtocol);
       
   104 	void ConstructL();
       
   105 	
       
   106 	void UnhookClient(TEirTag aTag);
       
   107 	inline TBool TagValid(TEirTag aTag) const;
       
   108 	TBool TagAllowed(TEirTag aTag) const;
       
   109 	TBool TagPresent(TEirTag aTag) const;
       
   110 	TBool OffersPending() const;
       
   111 	TBool NeedToOffer() const;
       
   112 	TInt TagCount() const;
       
   113 	void NotifyClients();
       
   114 	void DoNotify(TEirTag aTag);
       
   115 	void FindTagData(TEirTag aTag, HBufC8**& aOutPointerToData);
       
   116 	TInt EIRPacketSize() const;
       
   117 	void ComputeOfferLengths();
       
   118 	void ComputeClientInitialOffer(TEirTag aTag, TInt& aTotalSpare, TInt aReservedBytes,
       
   119 								   TBool aIsAllOrNothing = EFalse);
       
   120 	void ComputeClientFinalOffer(TEirTag aTag, TInt& aTotalSpare, TUint aGranularity,
       
   121 								 TBool aIsAllOrNothing = EFalse);
       
   122 	void WriteExtendedInquiryResponseL(TBool aFECRequired, const TDesC8& aEir);
       
   123 
       
   124 private:
       
   125 	TFixedArray<REirOwnerDetails, EEirTagRESERVED>  iNotifiees;
       
   126 	TEirTag					iCurrentlySettingTag;
       
   127 	TUint					iLengthForNotifiee;
       
   128 	TBool					iOffersStale;
       
   129 	TUint					iCmdId;
       
   130 	TUint					iCmdCount;
       
   131 
       
   132 	// unowned
       
   133 	MHCICommandQueue& 		iCommandQueue;
       
   134 	CLinkMgrProtocol&		iLinkMgrProtocol;
       
   135 	// owned
       
   136 	CWriteEirTimer*			iWriteEirTimer;
       
   137 	};
       
   138 	
       
   139 #include "eirmanager.inl"
       
   140 
       
   141 #endif // _EIRMANAGER_H