bthci/hci2implementations/hctls/bcsp/inc/hctlbcspFrameQueue.h
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 // Copyright (c) 2006-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 HCTLBCSPFRAMEQUEUE_H
       
    22 #define HCTLBCSPFRAMEQUEUE_H
       
    23 
       
    24 #include <e32base.h>
       
    25 
       
    26 // To Turn on window debuggng #define _DEBUG_WINDOW
       
    27 #undef _DEBUG_WINDOW
       
    28 
       
    29 class CHCTLBcspSequencer;
       
    30 class CHCTLBcsp;
       
    31 class CTxHctlBcspFrame;
       
    32 
       
    33 NONSHARABLE_CLASS(CHCTLBcspWindow) : public CBase
       
    34 /**
       
    35 Window and associated functions to contain a queue of frames
       
    36 handles acknowledgement of a particular received frame and moves the window onwards
       
    37 within the scope of total number of sequence IDs
       
    38 
       
    39 Is only used by CHCTLBcspFrameQueue
       
    40 */
       
    41 	{
       
    42 public:
       
    43 	static CHCTLBcspWindow *NewL(TInt aWindowSize, TInt aFrameSize, TInt aNumberOfSeqIds);
       
    44 	~CHCTLBcspWindow();
       
    45 
       
    46 	TInt FreeFrames();
       
    47 
       
    48     CTxHctlBcspFrame* WriteFrame(); // Gets the write frame and moves the WritePosn
       
    49 	CTxHctlBcspFrame* ReadFrame();  // Gets the read frame and moves the ReadPosn
       
    50 
       
    51 	TBool Acknowledged(TInt AckNo);
       
    52 	TInt StartOfWindow() const;
       
    53  	void Reset();
       
    54 
       
    55 private:
       
    56 	void ConstructL(TInt aFrameSize);
       
    57 	CHCTLBcspWindow(TInt aWindowSize, TInt aNumberOfSeqIds);
       
    58 
       
    59 	// Two simple inline private methods to reduce complexity of code whilst maintaining
       
    60 	// efficiency
       
    61 	TInt ToSeqId(TInt aIndex) const;
       
    62 	TInt ToWindowIndex(TInt aSeqId) const; 
       
    63 	void IncrementSeqId(TInt &aSeqId) const;
       
    64 	CTxHctlBcspFrame *GetFrame(TInt aIndex);
       
    65 
       
    66 	// Internal consistency checking for the class
       
    67     void __DbgTestInvariant() const;
       
    68 	
       
    69 #ifdef _DEBUG_WINDOW
       
    70 	void TraceQueue();
       
    71 	void TraceWindowVars() const;
       
    72 #endif
       
    73 
       
    74 
       
    75 private:
       
    76 	TInt iStartOfWindow;
       
    77 	TInt iReadPosition;
       
    78 	TInt iHighReadPosition;
       
    79 	TInt iWritePosition;
       
    80 	TInt iEndOfWindow;
       
    81 	TInt iWindowSize;
       
    82 	TInt iNumberOfSeqIds;
       
    83 	TSglQue<CTxHctlBcspFrame> iFrameQue;
       
    84 
       
    85 	// This class stores most of its indices as SequneceIds, the only exception being
       
    86 	// iWindowSize which is used in the conversion between SequenceIds and WindowIndex.
       
    87 	//
       
    88 	//   SequenceIds          Window Index
       
    89 	//                     |
       
    90 	//   iStartOfWindow    +   .
       
    91 	//                     |   .
       
    92 	//   iReadIndex        |   .
       
    93 	//                     |   .
       
    94 	//   iHighReadIndex    |   .
       
    95 	//                     |   .
       
    96 	//   iWriteIndex       |   .
       
    97 	//                     |   .
       
    98 	//   iEndOfWindow      +   iWindowSize
       
    99 	//                     |
       
   100 	//                     |
       
   101 	//                     |
       
   102 	//   iNumberOfSeqIds   |
       
   103 	};
       
   104 
       
   105 NONSHARABLE_CLASS(CHCTLBcspFrameQueue) : public CBase
       
   106 /**
       
   107 This is used by CHCTLBcsp to queue frames for transmission
       
   108 the frames queued are stored in CHCTLBcspWindow
       
   109 there are two windows used 
       
   110 	one for reliable frames
       
   111 	one for unreliable frames
       
   112 */
       
   113 	{
       
   114 public:
       
   115 	static CHCTLBcspFrameQueue* NewL(CHCTLBcsp &aBcsp);
       
   116 	~CHCTLBcspFrameQueue();
       
   117 
       
   118 	void SetSequencer(CHCTLBcspSequencer& aSequencer);
       
   119 
       
   120 	// Methods called by sequencer
       
   121 	// Gets the next frame for sending 
       
   122 	// (aFrame is the slip encoded frame
       
   123 	//  returned by this method)
       
   124 	//
       
   125 	// returns: -
       
   126 	//
       
   127 	// KErrNone          - all is fine
       
   128 	// KErrNothingToSend - nothing 
       
   129 	//                     available to
       
   130 	//                     send
       
   131 	// KErrMaxRetries    - exceeded max 
       
   132 	//                     retries for a
       
   133 	//                     frame
       
   134 	TInt GetNextFrame(TDesC8* &aFrame, TBool& aIsReliable);
       
   135 
       
   136 	TBool AckReceived(TInt aAckValue); // Ack has been Received
       
   137 	void AckTimeout();                 // Rx Ack Timer has expired
       
   138 
       
   139 	// Methods called by CHCTLBcsp
       
   140 	TInt AddReliableFrame  (const TDesC8 &aData, TUint8 aProtocolId);
       
   141 	void AddUnreliableFrame(const TDesC8 &aData, TUint8 aProtocolId, 
       
   142 												 TUint8 aAck,
       
   143 												 TBool aCRCEnabled);
       
   144 
       
   145 	void AddUnreliableFrame(TUint8 aProtocolId, 
       
   146 							TUint8 aAck,
       
   147 							TBool aCRCEnabled);
       
   148 	void Reset();
       
   149 
       
   150 private:
       
   151 	void CanSend(); 
       
   152 	void ConstructL();
       
   153 	CHCTLBcspFrameQueue(CHCTLBcsp& aBcsp);
       
   154 
       
   155 private:
       
   156 	// Not owned by this class
       
   157 	CHCTLBcspSequencer* iSequencer; // For calls to Wakeup()
       
   158 	CHCTLBcsp& iBcsp; // For calls to CanSend()
       
   159 
       
   160 	// Owned by this class
       
   161 	CHCTLBcspWindow* iReliableQueue;
       
   162 	CHCTLBcspWindow* iUnreliableQueue;
       
   163 
       
   164 	HBufC8* iSlipEncodedFrame;
       
   165 	};
       
   166 
       
   167 #endif // HCTLBCSPFRAMEQUEUE_H