serialserver/packetloopbackcsy/inc/Loopback.h
changeset 0 dfb7c4ff071f
child 27 cd9717388750
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 // Loopback.cpp
       
    15 // This file implements a loopback driver for use with 3GNIF test harness.
       
    16 // 
       
    17 //
       
    18 
       
    19 /**
       
    20  @file
       
    21 */
       
    22 
       
    23 #ifndef __LOOPBACK_H__
       
    24 #define __LOOPBACK_H__
       
    25 
       
    26 #include <c32comm.h>
       
    27 
       
    28 #include "LoopbackConfig.h"
       
    29 #include "LoopbackTimer.h"
       
    30 #include "LoopbackQueue.h"
       
    31 
       
    32 const TUint KCommLowUnit=0;
       
    33 
       
    34 #if defined(__WINS__)
       
    35 const TUint KCommHighUnit=1;
       
    36 #else // _MARM_
       
    37 const TUint KCommHighUnit=0;
       
    38 #endif
       
    39 
       
    40 
       
    41 _LIT(KSerialDescription, "Packet Loopback CSY");
       
    42 _LIT(KSerialName, "PKTLOOPBACK");
       
    43 
       
    44 class CHWPort;
       
    45 
       
    46 /**
       
    47  * This class is the factory port object.  It drives the "entry point object" which
       
    48  * makes the reset of the objects do their work.  It is based on the basic serial port
       
    49  * class CSerial.
       
    50  */
       
    51 NONSHARABLE_CLASS(CHWPortFactory) : public CSerial
       
    52 	{
       
    53 public:
       
    54     CHWPortFactory();
       
    55     ~CHWPortFactory();
       
    56 	virtual CPort * NewPortL(const TUint aUnit);
       
    57 	virtual void Info(TSerialInfo &aSerialInfo);
       
    58 	void Remove(CHWPort* aPort);
       
    59 	CHWPort* FindPort(TUint aUnit);
       
    60 	TPortType PortType() const;
       
    61 public: //CSerial
       
    62 	TSecurityPolicy PortPlatSecCapability(TUint aPort) const;
       
    63 private:
       
    64 	/** All ports created by this factory */
       
    65 	RArray<CHWPort*> iPorts;
       
    66 	/** Retrieves settings from the 'loopback.ini' file */
       
    67 	CLoopbackConfig* iLoopbackConfig;
       
    68 	
       
    69 	TPortType iPortType;
       
    70 	};
       
    71 
       
    72 /**
       
    73  *	This class is the object that interfaces with the commserver.  An instance of this class
       
    74  *	represents one port in the loopback driver.
       
    75  */
       
    76 NONSHARABLE_CLASS(CHWPort) : public CPort, public MTimerCallBack, public MFlowControlChangeCallBack
       
    77 	{
       
    78 public:
       
    79 	static CHWPort * NewSerialLoopbackL(TUint aUnit, TUint aDelay, TUint aBufferSize);
       
    80 	static CHWPort * NewPacketLoopbackL(TUint aUnit, TUint aDelay, TUint aPacketLength, TUint aQueueLength);
       
    81 private:
       
    82 	CHWPort(TUint aUnit);
       
    83 	void ConstructPacketLoopbackL(TUint aDelay, TUint aPacketLength, TUint aQueueLength);
       
    84 	void ConstructSerialLoopbackL(TUint aDelay, TUint aBufferSize);
       
    85 
       
    86 public:
       
    87 	TUint PortName() const;
       
    88 	virtual void StartRead(const TAny* aClientBuffer,TInt aLength);
       
    89 	virtual void ReadCancel();
       
    90 	virtual TInt QueryReceiveBuffer(TInt& aLength) const;
       
    91 	virtual void ResetBuffers(TUint aFlags);
       
    92 	virtual void StartWrite(const TAny* aClientBuffer,TInt aLength);
       
    93 	virtual void WriteCancel();
       
    94 	virtual void Break(TInt aTime);
       
    95 	virtual void BreakCancel();
       
    96 	virtual TInt GetConfig(TDes8& aDes) const;
       
    97 	virtual TInt SetConfig(const TDesC8& aDes);
       
    98 	virtual TInt SetServerConfig(const TDesC8& aDes);
       
    99 	virtual TInt GetServerConfig(TDes8& aDes);
       
   100 	virtual TInt GetCaps(TDes8& aDes);
       
   101 	virtual TInt GetSignals(TUint& aSignals);
       
   102 	virtual TInt SetSignalsToMark(TUint aSignals);
       
   103 	virtual TInt SetSignalsToSpace(TUint aSignals);
       
   104 	virtual TInt GetReceiveBufferLength(TInt& aLength) const;
       
   105 	virtual TInt SetReceiveBufferLength(TInt aSignals);
       
   106 	virtual void Destruct();
       
   107 	virtual void FreeMemory();
       
   108 	virtual void NotifySignalChange(TUint aSignalMask);
       
   109 	virtual void NotifySignalChangeCancel();
       
   110 	virtual void NotifyConfigChange();
       
   111 	virtual void NotifyConfigChangeCancel();
       
   112 	virtual void NotifyFlowControlChange();
       
   113 	virtual void NotifyFlowControlChangeCancel();
       
   114 	virtual void NotifyBreak();
       
   115 	virtual void NotifyBreakCancel();
       
   116 	virtual void NotifyDataAvailable();
       
   117 	virtual void NotifyDataAvailableCancel();
       
   118 	virtual void NotifyOutputEmpty();
       
   119 	virtual void NotifyOutputEmptyCancel();
       
   120 	virtual TInt GetFlowControlStatus(TFlowControl& aFlowControl);
       
   121 	virtual TInt GetRole(TCommRole& aRole);
       
   122 	virtual TInt SetRole(TCommRole aRole);
       
   123 
       
   124 	virtual void StartFlowControl();
       
   125 	virtual void StopFlowControl();
       
   126 	
       
   127 	TInt GetReadRequestStatus();
       
   128 	TInt GetWriteRequestStatus();
       
   129 
       
   130 	virtual ~CHWPort();
       
   131 public:
       
   132 	void SetLoopbackPort(CHWPort* aHWPort);
       
   133 	TInt WriteBuf(const TAny* aClientBuffer,TInt aLength);
       
   134 	void TryToCompleteRead();
       
   135 	TInt GetFlowControl() const;
       
   136 private:
       
   137 	void StartWriteDelayTimer();
       
   138 
       
   139 public:
       
   140 	void TimerCallBack();
       
   141 	/** Timer to control how long a given CPort::Write takes */
       
   142 	CLoopbackTimer *iWriteDelayTimer;
       
   143 
       
   144 private:
       
   145 	/** The configuration of this port */
       
   146 	TPckgBuf<TCommConfigV01> iConfig;
       
   147 
       
   148 	/** Contains buffer for all reads and writes on this port */
       
   149 	MLoopbackQueue* iReadWriteQueue;
       
   150 
       
   151 	/** The role for this port */
       
   152 	TCommRole iRole;
       
   153 
       
   154 	/** This port's loopback port, which can be NULL before a loopback port is assigned */
       
   155 	CHWPort* iLoopbackPort;
       
   156 	/** Indicates if there is a read pending for later completion */
       
   157 	TBool iReadPending;
       
   158 	/** Should the current read (even if it is pending) complete before the buffer is full? */
       
   159 	TBool iReadOneOrMore;
       
   160 
       
   161 	/** Pointer to the client buffer to be filled by a read */
       
   162 	const TAny* iClientReadBuffer;
       
   163 	/** Length of the client buffer to be filled by a read */
       
   164 	TInt iClientReadBufferLength;
       
   165 	
       
   166 	/** The port number for this port */
       
   167 	TUint iPortName;
       
   168 	/** The configured port type (either packet or serial) */
       
   169 	TPortType iPortType;
       
   170 
       
   171 	/** Pointer to object that listens to changes in flow control for this port - it is created on construction */
       
   172 	CFlowControlChange *iFlowControlChange;
       
   173 	};
       
   174 
       
   175 #endif
       
   176