serialserver/packetloopbackcsy/inc/LoopbackQueue.h
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2004-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 // This file implements a queue for the loopback driver
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20 */
       
    21 
       
    22 #ifndef __LOOPBACK_QUEUE_H__
       
    23 #define __LOOPBACK_QUEUE_H__
       
    24 
       
    25 #include <cs_port.h>
       
    26 #include "SLOGGER.H"
       
    27 #include <d32comm.h>
       
    28 #include <c32comm.h>
       
    29 #include <e32hal.h>
       
    30 #include <e32base.h>
       
    31 
       
    32 #include "LoopbackConfig.h"
       
    33 #include "LoopbackTimer.h"
       
    34 
       
    35 /**
       
    36  A queue class of descriptors - all of the data for the desctiptors is contained in this class
       
    37  */
       
    38 NONSHARABLE_CLASS(CTPtr8Queue) : CBase
       
    39 	{
       
    40 public:
       
    41 	static CTPtr8Queue* NewL(TInt aBufferLength, TInt aQueueLength);
       
    42 	~CTPtr8Queue();
       
    43 	TPtr8& GetNewBuffer();
       
    44 	TPtr8& DequeueFirstBuffer();
       
    45 	const TPtr8& PeekFirstBuffer() const;
       
    46 	TInt QueueLength() const;
       
    47 	TBool IsEmpty() const;
       
    48 	TBool IsFull() const;
       
    49 	void Clear();
       
    50 private:
       
    51 	CTPtr8Queue(TInt aQueueLength);
       
    52 	void ConstructL(TInt aBufferLength, TInt aQueueLength);
       
    53 
       
    54 	/** Index of the first buffer in the queue */
       
    55 	TInt iFirstBuffer;
       
    56 	/** Index of the next buffer in the queue */
       
    57 	TInt iNextBuffer;
       
    58 	/** True if the buffer is full (iFirstBuffer should also equal iNextBuffer */
       
    59 	TBool iQueueFull;
       
    60 	
       
    61 	/** Pointer to the descriptors, each of which represents an element in the queue */
       
    62 	CArrayFixFlat<TPtr8> iDescriptors;
       
    63 	/** Buffer for all of the data in all of the elements of the queue */
       
    64 	TDesC8 *iBuffer;
       
    65 	};
       
    66 
       
    67 /**
       
    68  Contains the read and write queues for a given port
       
    69  */
       
    70 NONSHARABLE_CLASS(MLoopbackQueue)
       
    71 	{
       
    72 public:
       
    73 	virtual ~MLoopbackQueue();
       
    74 	virtual TPtrC8 PeekNextReadBuffer(TBool& aCompleteIfBufferNotFull) const = 0;
       
    75 	virtual void DiscardNextReadBuffer() = 0;
       
    76 	virtual void AppendToReadBuffer(TDesC8& aSrcData) = 0;
       
    77 	virtual TPtrC8 PeekNextWriteBuffer() const = 0;
       
    78 	virtual void DiscardNextWriteBuffer() = 0;
       
    79 	virtual TPtr8 AppendToWriteBuffer(TInt aLength) = 0;
       
    80 	virtual TBool IsWriteBufferEmpty() const = 0;
       
    81 	virtual TBool IsWriteBufferFull(TInt aLength) const = 0;
       
    82 	virtual TBool IsReadBufferEmpty() const = 0;
       
    83 	virtual TBool IsReadBufferFull(TInt aLength) const = 0;
       
    84 	virtual TInt BufferSize() const = 0;
       
    85 	virtual void Clear() = 0;
       
    86 	};
       
    87 
       
    88 /**
       
    89  Contains the read and write queues for a given port
       
    90  */
       
    91 NONSHARABLE_CLASS(CPacketBufferQueue) : public CBase, public MLoopbackQueue
       
    92 	{
       
    93 public:
       
    94 	static CPacketBufferQueue* NewL(TInt aBufferLength, TInt aQueueLength);
       
    95 	~CPacketBufferQueue();
       
    96 	void DiscardNextReadBuffer();
       
    97 	TPtrC8 PeekNextReadBuffer(TBool& aCompleteIfBufferNotFull) const;
       
    98 	TPtr8 AppendToWriteBuffer(TInt aLength);
       
    99 	void DiscardNextWriteBuffer();
       
   100 	TPtrC8 PeekNextWriteBuffer() const;
       
   101 	void AppendToReadBuffer(TDesC8& aSrcData);
       
   102 	TBool IsWriteBufferEmpty() const;
       
   103 	TBool IsWriteBufferFull(TInt aLength) const;
       
   104 	TBool IsReadBufferEmpty() const;
       
   105 	TBool IsReadBufferFull(TInt aLength) const;
       
   106 	TInt BufferSize() const;
       
   107 	void Clear();
       
   108 private:
       
   109 	CPacketBufferQueue(TInt aBufferLength);
       
   110 	void ConstructL(TInt aBufferLength, TInt aQueueLength);
       
   111 
       
   112 	/** The length of each element in each queue */
       
   113 	TInt iBufferLength;
       
   114 
       
   115 	/** The read queue for a port */
       
   116 	CTPtr8Queue *iReadQueue;
       
   117 	/** The write queue for a port */
       
   118 	CTPtr8Queue *iWriteQueue;
       
   119 	};
       
   120 
       
   121 /**
       
   122  Contains the read and write queues for a given port
       
   123  */
       
   124 NONSHARABLE_CLASS(CSerialBufferQueue) : public CBase, public MLoopbackQueue
       
   125 	{
       
   126 public:
       
   127 	static CSerialBufferQueue* NewL(TInt aBufferLength, TCommConfigV01* aConfig);
       
   128 	~CSerialBufferQueue();
       
   129 	void DiscardNextReadBuffer();
       
   130 	TPtrC8 PeekNextReadBuffer(TBool& aCompleteIfBufferNotFull) const;
       
   131 	void AppendToReadBuffer(TDesC8& aSrcData);
       
   132 	TPtrC8 PeekNextWriteBuffer() const;
       
   133 	void DiscardNextWriteBuffer();
       
   134 	TPtr8 AppendToWriteBuffer(TInt aLength);
       
   135 	TBool IsWriteBufferEmpty() const;
       
   136 	TBool IsWriteBufferFull(TInt aLength) const;
       
   137 	TBool IsReadBufferEmpty() const;
       
   138 	TBool IsReadBufferFull(TInt aLength) const;
       
   139 	TInt BufferSize() const;
       
   140 	void Clear();
       
   141 private:
       
   142 	CSerialBufferQueue(TInt aBufferLength, TCommConfigV01* aConfig);
       
   143 	void ConstructL(TInt aBufferLength);
       
   144 	TPtrC8 NextBuffer(const TPtrC8& aBuffer, TBool& aTerminatorFound) const;
       
   145 	
       
   146 
       
   147 	/** The length of each element in each queue */
       
   148 	TInt iBufferLength;
       
   149 	
       
   150 	TCommConfigV01 *iConfig;
       
   151 
       
   152 	HBufC8* iWriteBuffer;
       
   153 	TPtr8 iWriteData;
       
   154 	HBufC8* iReadBuffer;
       
   155 	TPtr8 iReadData;
       
   156 	};
       
   157 
       
   158 #endif
       
   159