epoc32/include/cs_port.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 2 2fe1408b6811
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
williamr@2
     1
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
williamr@2
     2
// All rights reserved.
williamr@2
     3
// This component and the accompanying materials are made available
williamr@4
     4
// under the terms of "Eclipse Public License v1.0"
williamr@2
     5
// which accompanies this distribution, and is available
williamr@4
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
williamr@2
     7
//
williamr@2
     8
// Initial Contributors:
williamr@2
     9
// Nokia Corporation - initial contribution.
williamr@2
    10
//
williamr@2
    11
// Contributors:
williamr@2
    12
//
williamr@2
    13
// Description:
williamr@2
    14
//
williamr@2
    15
williamr@2
    16
williamr@2
    17
williamr@2
    18
#ifndef CS_PORT_H
williamr@2
    19
#define CS_PORT_H
williamr@2
    20
williamr@2
    21
#include <c32comm.h>
williamr@2
    22
williamr@2
    23
/** 
williamr@2
    24
@file
williamr@2
    25
defines the classes CPort and CSerial. This file should be included by the CSY
williamr@2
    26
williamr@2
    27
@publishedAll	
williamr@2
    28
@released
williamr@2
    29
*/
williamr@2
    30
williamr@2
    31
/** Delta timer interval */
williamr@2
    32
const TInt KDeltaTimerInterval = 100000;     
williamr@2
    33
/** The UID for the CSY */          
williamr@2
    34
const TInt KUidUnicodeCommServerModuleV02 = 0x10005054;
williamr@2
    35
williamr@2
    36
/**
williamr@2
    37
Defines the internal port access mode.
williamr@2
    38
williamr@2
    39
@publishedAll	
williamr@2
    40
@released
williamr@2
    41
*/
williamr@2
    42
// Important note!: must have the same order as TCommAccess in c32comm.h
williamr@2
    43
enum TInternalCommAccess
williamr@2
    44
	{
williamr@2
    45
    /**  Exclusive mode. Must be first */
williamr@2
    46
	EIntCommExclusive          = 0, 
williamr@2
    47
	/**  Shared mode. Must be second */
williamr@2
    48
	EIntCommShared             = 1, 
williamr@2
    49
	/**  Preemptable mode. Must be third */
williamr@2
    50
	EIntCommPreemptable        = 2, 
williamr@2
    51
	/**  Wait until the port is closed */
williamr@2
    52
	EIntCommWaitUntilAvailable = 3  
williamr@2
    53
	};
williamr@2
    54
williamr@2
    55
class CPortManager;
williamr@2
    56
williamr@2
    57
williamr@2
    58
williamr@2
    59
class CommTimer 
williamr@2
    60
/**
williamr@2
    61
Static utility class for global timer handling designed for use by Serial Server plug-ins (CSYs).
williamr@2
    62
williamr@2
    63
@publishedAll	
williamr@2
    64
@released
williamr@2
    65
*/
williamr@2
    66
	{
williamr@2
    67
public:
williamr@2
    68
	IMPORT_C static void Queue(TTimeIntervalMicroSeconds32 aTimeInMicroSeconds, TDeltaTimerEntry& aHandle);
williamr@2
    69
	IMPORT_C static void Remove(TDeltaTimerEntry& aHandle);
williamr@2
    70
	static CDeltaTimer* GetTimer();
williamr@2
    71
	};
williamr@2
    72
williamr@2
    73
class CCommSession;
williamr@2
    74
class CSerial;
williamr@2
    75
williamr@2
    76
williamr@2
    77
williamr@2
    78
williamr@2
    79
class CPort : public CObject
williamr@2
    80
/** Base class for implementations of serial protocol module ports. Its functions 
williamr@2
    81
are called by the comms server in response to client calls to RComm. 
williamr@2
    82
williamr@2
    83
The class implements CObject to obtain reference counting behaviour. The reference 
williamr@2
    84
count is incremented when a port is first created, and, for ports in shared 
williamr@2
    85
mode, on every later opening.
williamr@2
    86
williamr@2
    87
CPort is an abstract class which defines many pure virtual functions which 
williamr@2
    88
derived classes must implement. Most of these pure virtual functions correspond 
williamr@2
    89
to the client interface of the RComm class.
williamr@2
    90
williamr@2
    91
Created when the first client does an Open request passing its name.
williamr@2
    92
Destroyed only when it deletes itself (following a call to Destruct).
williamr@2
    93
williamr@2
    94
@publishedAll	
williamr@2
    95
@released */
williamr@2
    96
	{
williamr@2
    97
	// Warning:  No CPort::ConstructL, so can't use iExtra members until after construction.
williamr@2
    98
private:
williamr@2
    99
	class CExtra : public CBase
williamr@2
   100
		{
williamr@2
   101
	public:
williamr@2
   102
		CCommSession* iBreakOwner;
williamr@2
   103
		CCommSession* iPreemptableOwner;
williamr@2
   104
		CCommSession* iPreemptedSession;
williamr@2
   105
		CCommSession* iWaitAvailableOwner;  // Also the SetAccess owner.
williamr@2
   106
		RMessagePtr2   iBlockedSetAccess; 
williamr@2
   107
		};
williamr@2
   108
williamr@2
   109
friend class CPortManager;
williamr@2
   110
williamr@2
   111
public:
williamr@2
   112
	typedef TCommAccess TAccess;
williamr@2
   113
williamr@2
   114
	void CommRead(const RMessage2& aMessage,CCommSession* aClient); // Start read operation
williamr@2
   115
	void CommReadCancel(TInt aHandle, CCommSession* aClient);
williamr@2
   116
	void CommWrite(const RMessage2& aMessage,CCommSession* aClient); // Start Write opneration
williamr@2
   117
	void CommWriteCancel(TInt aHandle, CCommSession* aClient);
williamr@2
   118
	void CommBreak(const RMessage2& aMessage,CCommSession* aClient);	// Start Break operation
williamr@2
   119
	void CommBreakCancel(TInt aHandle, CCommSession* aClient);
williamr@2
   120
	void CommCancel(TInt aHandle, CCommSession* aClient); // Cancel all blocked operation.
williamr@2
   121
williamr@2
   122
	void CommConfig(const RMessage2& aMessage, CCommSession& aSession) const;
williamr@2
   123
	void CommSetConfig(const RMessage2& aMessage, CCommSession& aSession);
williamr@2
   124
	void CommSetServerConfig(const RMessage2& aMessage, CCommSession& aSession);
williamr@2
   125
	void CommGetServerConfig(const RMessage2& aMessage, CCommSession& aSession);
williamr@2
   126
	void CommCaps(const RMessage2& aMessage, CCommSession& aSession);
williamr@2
   127
	void CommSignals(const RMessage2& aMessage, CCommSession& aSession);
williamr@2
   128
	void CommSetSignalsToMark(const RMessage2& aMessage, CCommSession& aSession);
williamr@2
   129
	void CommSetSignalsToSpace(const RMessage2& aMessage, CCommSession& aSession);
williamr@2
   130
	void CommReceiveBufferLength(const RMessage2& aMessage, CCommSession& aSession) const;
williamr@2
   131
	void CommSetReceiveBufferLength(const RMessage2& aMessage, CCommSession& aSession);
williamr@2
   132
	void CommQueryReceiveBuffer(const RMessage2& aMessage, CCommSession& aSession) const;
williamr@2
   133
	void CommResetBuffers(const RMessage2& aMessage, CCommSession& aSession);
williamr@2
   134
	void CommSetAccess(const RMessage2& aMessage, CCommSession& aSession);
williamr@2
   135
	TBool IsBlockedSetAccessWaiting(CCommSession& aClient);
williamr@2
   136
	void CommSetAccessCancel(TInt aHandle, CCommSession* aClient);
williamr@2
   137
	void CommDebugState(const RMessage2& aMessage, CCommSession& aSession);
williamr@2
   138
williamr@2
   139
	TBool TakeOwnershipForReading(const RMessage2& aMessage,CCommSession* aClient);		// Check if a read request is valid and take ownership of port
williamr@2
   140
	TBool TakeOwnershipForWriting(const RMessage2& aMessage,CCommSession* aClient);		// Check if a Write request is valid and take ownership of port
williamr@2
   141
	TBool TakeOwnershipForBreaking(const RMessage2& aMessage,CCommSession* aClient);		// Check if a Break request is valid and take ownership of port
williamr@2
   142
williamr@2
   143
	void InitL(TDesC8 &aName);	// Not used
williamr@2
   144
	static TInt WriteTimerExpiredHandler(TAny* aPtr);
williamr@2
   145
	static TInt ReadTimerExpiredHandler(TAny* aPtr);
williamr@2
   146
	TBool AreAnyPending();
williamr@2
   147
williamr@2
   148
	void CommGetRole(const RMessage2& aMessage, CCommSession* aClient);
williamr@2
   149
	void CommGetFlowControlStatus(const RMessage2& aMessage, CCommSession* aClient);
williamr@2
   150
williamr@2
   151
	void CommNotifySignalChange(const RMessage2& aMessage, CCommSession* aClient);
williamr@2
   152
	TBool TakeOwnershipForSignals(const RMessage2& aMessage,CCommSession* aClient);
williamr@2
   153
	void CommNotifyFlowControlChange(const RMessage2& aMessage, CCommSession* aClient);
williamr@2
   154
	TBool TakeOwnershipForFlowControl(const RMessage2& aMessage,CCommSession* aClient);
williamr@2
   155
	void CommNotifyConfigChange(const RMessage2& aMessage, CCommSession* aClient);
williamr@2
   156
	TBool TakeOwnershipForConfig(const RMessage2& aMessage,CCommSession* aClient);
williamr@2
   157
	void CommNotifyBreak(const RMessage2& aMessage, CCommSession* aClient);
williamr@2
   158
	TBool TakeOwnershipForBreak(const RMessage2& aMessage, CCommSession* aClient);
williamr@2
   159
	void CommNotifyDataAvailable(const RMessage2& aMessage, CCommSession* aClient);
williamr@2
   160
	TBool TakeOwnershipForNotifyDataAvailable(const RMessage2 &aMessage,CCommSession* aClient);
williamr@2
   161
	void CommNotifyOutputEmpty(const RMessage2 &aMessage, CCommSession* aClient);
williamr@2
   162
	TBool TakeOwnershipForNotifyOutputEmpty(const RMessage2 &aMessage,CCommSession* aClient);
williamr@2
   163
williamr@2
   164
	void CommNotifySignalChangeCancel(TInt aHandle, CCommSession* aClient);
williamr@2
   165
	void CommNotifyConfigChangeCancel(TInt aHandle, CCommSession* aClient);
williamr@2
   166
	void CommNotifyFlowControlChangeCancel(TInt aHandle, CCommSession* aClient);
williamr@2
   167
	void CommNotifyBreakCancel(TInt aHandle, CCommSession* aClient);
williamr@2
   168
	void CommNotifyDataAvailableCancel(TInt aHandle, CCommSession* aClient);
williamr@2
   169
	void CommNotifyOutputEmptyCancel(TInt aHandle, CCommSession* aClient);
williamr@2
   170
williamr@2
   171
	TBool SessionHasBeenPreempted(CCommSession* aSession);
williamr@2
   172
	TBool SessionIsAwaitingOpen(CCommSession* aSession);
williamr@2
   173
	void FreeSession(CCommSession* aSession);
williamr@2
   174
williamr@2
   175
public:
williamr@2
   176
	IMPORT_C TInt IPCRead(const TAny* aPtr, TDes8& aDes, TInt aOffset=0) const;
williamr@2
   177
	IMPORT_C TInt IPCWrite(const TAny* aPtr, const TDesC8& aDes, TInt aOffset=0) const;
williamr@2
   178
	IMPORT_C CPort();
williamr@2
   179
	IMPORT_C void ReadCompleted(TInt anError);		// Called by a CPort to complete a read.
williamr@2
   180
	IMPORT_C void WriteCompleted(TInt anError);		// Called by a CPort to complete a write
williamr@2
   181
	IMPORT_C void BreakCompleted(TInt anError);		// Called by a CPort to complete a break
williamr@2
   182
	IMPORT_C virtual ~CPort();
williamr@2
   183
	IMPORT_C void Close();
williamr@2
   184
	IMPORT_C void SignalChangeCompleted(const TUint& aSignals, TInt anError);					// Called by a CPort to complete a signal notify
williamr@2
   185
	IMPORT_C void ConfigChangeCompleted(const TDesC8& aNewConfig, TInt anError);				// Called by a CPort to complete a config notify.
williamr@2
   186
	IMPORT_C void FlowControlChangeCompleted(const TFlowControl& aFlowControl, TInt anError);	// Called by a CPort to complete a flow control notify
williamr@2
   187
	IMPORT_C void BreakNotifyCompleted(TInt anError);			// Called by a CPort to complete a break signal notify
williamr@2
   188
	IMPORT_C void NotifyDataAvailableCompleted(TInt anError);	// Called by a CPort to complete a break signal notify
williamr@2
   189
	IMPORT_C void NotifyOutputEmptyCompleted(TInt anError);		// Called by a CPort to complete a break signal notify
williamr@2
   190
williamr@2
   191
public:
williamr@2
   192
	//
williamr@2
   193
	// Pure virtual methods - to be implemented by the CSY
williamr@2
   194
	//
williamr@2
   195
williamr@4
   196
	// Called by manager when access count is 0 - CSY port must call 'delete this'
williamr@2
   197
	/** Specifies the protocol for port destruction. It is called by the comms server 
williamr@2
   198
	when the last client-side reference to a CPort object has been closed and 
williamr@2
   199
	the CPort must be deleted. The comms server will not delete a CPort other 
williamr@2
   200
	than by calling Destruct().
williamr@2
   201
	
williamr@2
   202
	The implementation should perform any asynchronous shutdown operations on 
williamr@2
   203
	its own resources and, when these operations have completed, should delete 
williamr@2
   204
	this. */
williamr@2
   205
	virtual void Destruct()=0;
williamr@4
   206
	// Queue a read - called by CPort when client wants to read
williamr@4
   207
	// Note: if the value in aLength is negative, this means
williamr@4
   208
	//       ReadOneOrMore and the CSY must invert the number
williamr@2
   209
	/** Specifies the protocol for reading from the port. It is called by the comms 
williamr@2
   210
	server in response to a RComm::Read() or RComm::ReadOneOrMore() request from 
williamr@2
   211
	the client.
williamr@2
   212
	
williamr@2
   213
	A negative value for aLength is used to flag that the read request was from 
williamr@2
   214
	RComm::ReadOneOrMore() rather than from RComm::Read(). The maximum length 
williamr@2
   215
	of data to be read is the absolute value of aLength.
williamr@2
   216
	
williamr@2
   217
	The implementation should use IPCWrite() to write the data to the client's 
williamr@2
   218
	buffer. When all the data has been read, the function should call ReadCompleted(). 
williamr@2
   219
	
williamr@2
   220
	
williamr@2
   221
	@param aClientBuffer Pointer into client address space to the descriptor containing 
williamr@2
   222
	the client's buffer 
williamr@2
   223
	@param aLength The amount of data to be read */
williamr@2
   224
	virtual void StartRead(const TAny* aClientBuffer, TInt aLength)=0;
williamr@4
   225
	// Cancel a pending read
williamr@2
   226
	/** Specifies the protocol for cancelling reading from the port. It is called by 
williamr@2
   227
	the comms server in response to a RComm::ReadCancel() request from the client or
williamr@2
   228
	when the iReadTimer timer expires.
williamr@2
   229
	
williamr@2
   230
	The implementation should abort any processing which was taking place as a 
williamr@2
   231
	result of the read request. Do not call ReadCompleted(). */
williamr@2
   232
	virtual void ReadCancel()=0;
williamr@4
   233
	// Get the size of the receive buffer from the real serial port
williamr@2
   234
	/** Specifies a protocol for requesting the number of bytes that are currently 
williamr@2
   235
	waiting in the port's receive buffer. It is called by the comms server in 
williamr@2
   236
	response to a RComm::QueryReceiveBuffer() request from the client.
williamr@2
   237
	
williamr@2
   238
	@param aLength On return, the number of bytes currently waiting to be read 
williamr@2
   239
	from the receive buffer. 
williamr@2
   240
	@return A system wide error code. */
williamr@2
   241
	virtual TInt QueryReceiveBuffer(TInt& aLength) const=0;
williamr@4
   242
	// reset Tx and Rx buffers
williamr@2
   243
	/** Specifies a protocol for resetting the receive and/or transmit buffers to zero 
williamr@2
   244
	length. It is called by the comms server in response to a RComm::ResetBuffers() 
williamr@2
   245
	request from the client.
williamr@2
   246
	
williamr@2
   247
	@param aFlags Bitmask of the following flags: KCommResetRx to reset the receive 
williamr@2
   248
	buffer; KCommResetTx to reset the transmit buffer */
williamr@2
   249
	virtual void ResetBuffers(TUint aFlags)=0;
williamr@4
   250
	// Queue a write - called by CPort when client wants to write
williamr@2
   251
	/** Specifies the protocol for writing to the port. It is called by the comms server 
williamr@2
   252
	in response to a RComm::Write() request from the client.
williamr@2
   253
	
williamr@2
   254
	The implementation should use IPCRead() to get the data to write from the 
williamr@2
   255
	client's buffer. When all the data has been written, the function should call 
williamr@2
   256
	WriteCompleted(). 
williamr@2
   257
	
williamr@2
   258
	@param aClientBuffer Pointer into client address space to the descriptor containing 
williamr@2
   259
	the client's buffer 
williamr@2
   260
	@param aLength The amount of data to be written */
williamr@2
   261
	virtual void StartWrite(const TAny* aClientBuffer, TInt aLength)=0;
williamr@4
   262
	// Cancel a pending write
williamr@2
   263
	/** Specifies the protocol for cancelling writing to the port. It is called by 
williamr@2
   264
	the comms server in response to a RComm::WriteCancel() request from the client.
williamr@2
   265
	
williamr@2
   266
	The implementation should abort any processing which was taking place as a 
williamr@2
   267
	result of the write request. Do not call WriteCompleted(). */
williamr@2
   268
	virtual void WriteCancel()=0;
williamr@4
   269
	// Queue a break
williamr@2
   270
	/** Specifies the protocol for setting a break condition at the port. It is called 
williamr@2
   271
	by the comms server in response to a RComm::Break() request from the client.
williamr@2
   272
	
williamr@2
   273
	When the break is complete, the function should call BreakCompleted(). 
williamr@2
   274
	
williamr@2
   275
	@param aTime Time period to break for in microseconds */
williamr@2
   276
	virtual void Break(TInt aTime)=0;
williamr@4
   277
	// Cancel a pending break
williamr@2
   278
	/** Specifies the protocol for cancelling a break request. It is called by the 
williamr@2
   279
	comms server in response to a RComm::BreakCancel() request from the client.
williamr@2
   280
	
williamr@2
   281
	The implementation should abort any processing which was taking place as a 
williamr@2
   282
	result of the break request. Do not call BreakCompleted(). */
williamr@2
   283
	virtual void BreakCancel()=0;
williamr@4
   284
	// Pass a config request - return in descriptor
williamr@2
   285
	/** Specifies a protocol for getting the current configuration of the serial port. 
williamr@2
   286
	It is called by the comms server in response to a RComm::GetConfig() request 
williamr@2
   287
	from the client.
williamr@2
   288
	
williamr@2
   289
	@param aPackage A packaged TCommConfig buffer, set on return to the current 
williamr@2
   290
	configuration of the serial port 
williamr@2
   291
	@return A system wide error code */
williamr@2
   292
	virtual TInt GetConfig(TDes8& aPackage) const=0;
williamr@4
   293
	// Set config with package in the descriptor
williamr@2
   294
	/** Specifies a protocol for setting the configuration of the port. It is called 
williamr@2
   295
	by the comms server in response to a RComm::SetConfig() request from the client.
williamr@2
   296
	
williamr@2
   297
	@param aPackage A packaged TCommConfig buffer holding the new configuration 
williamr@2
   298
	values 
williamr@2
   299
	@return A system error code */
williamr@2
   300
	virtual TInt SetConfig(const TDesC8& aPackage)=0;
williamr@4
   301
	// Set the port to use partial reads/writes
williamr@2
   302
	/** Specifies a protocol for setting the buffer mode. It is called by the comms 
williamr@2
   303
	server in response to a RComm::SetMode() request from the client.
williamr@2
   304
	
williamr@2
   305
	@param aPackage A TCommServerConfig package buffer holding the mode settings 
williamr@2
   306
	@return A system-wide error code */
williamr@2
   307
	virtual TInt SetServerConfig(const TDesC8& aPackage)=0;
williamr@4
   308
	// Get the server configs from the CSY
williamr@2
   309
	/** Specifies a protocol for getting the buffer mode. It is called by the comms 
williamr@2
   310
	server in response to a RComm::Mode() request from the client.
williamr@2
   311
	
williamr@2
   312
	@param aPackage A TCommServerConfig package buffer that, on return, holds 
williamr@2
   313
	the current buffer mode settings 
williamr@2
   314
	@return A system error code */
williamr@2
   315
	virtual TInt GetServerConfig(TDes8& aPackage)=0;
williamr@4
   316
	// Read capabilities from the driver
williamr@2
   317
	/** Specifies a protocol for getting the port capabilities. It is called by the 
williamr@2
   318
	comms server in response to a RComm::Caps() request from the client.
williamr@2
   319
	
williamr@2
   320
	@param aPackage A TCommCaps package buffer that, on return, holds the port 
williamr@2
   321
	capabilities 
williamr@2
   322
	@return A system error code */
williamr@2
   323
	virtual TInt GetCaps(TDes8& aPackage)=0;
williamr@4
   324
	// Get the status of the signal pins
williamr@2
   325
	/** Specifies a protocol for getting the status of the serial port control lines. 
williamr@2
   326
	It is called by the comms server in response to a RComm::GetSignals() request 
williamr@2
   327
	from the client.
williamr@2
   328
	
williamr@2
   329
	@param aSignals An integer with the bits set to reflect the status of the 
williamr@2
   330
	handshaking lines. 
williamr@2
   331
	@return A system error code */
williamr@2
   332
	virtual TInt GetSignals(TUint& aSignals)=0;
williamr@4
   333
	// Set selected signals to high (logical 1)
williamr@2
   334
	/** Specifies a protocol for setting serial port control lines. It is called by 
williamr@2
   335
	the comms server in response to a RComm::SetSignals() request from the client.
williamr@2
   336
	
williamr@2
   337
	@param aSignals A bitmask of the handshaking lines to set 
williamr@2
   338
	@return A system error code */
williamr@2
   339
	virtual TInt SetSignalsToMark(TUint aSignals)=0;
williamr@4
   340
	// Set selected signals to low (logical 0)
williamr@2
   341
	/** Specifies a protocol for clearing serial port control lines. It is called by 
williamr@2
   342
	the comms server in response to a RComm::SetSignals() request from the client.
williamr@2
   343
	
williamr@2
   344
	@param aSignals A bitmask of the handshaking lines to clear 
williamr@2
   345
	@return A system error code */
williamr@2
   346
	virtual TInt SetSignalsToSpace(TUint aSignals)=0;
williamr@4
   347
	// Get size of Tx and Rx buffer
williamr@2
   348
	/** Specifies a protocol for requesting the size of the serial port buffers. It 
williamr@2
   349
	is called by the comms server in response to a RComm::ReceiveBufferLength() 
williamr@2
   350
	request from the client.
williamr@2
   351
	
williamr@2
   352
	@param aLength The current size of the serial port buffers in bytes 
williamr@2
   353
	@return A system error code */
williamr@2
   354
	virtual TInt GetReceiveBufferLength(TInt& aLength) const=0;
williamr@4
   355
	// Set size of Tx and Rx buffer
williamr@2
   356
	/** Specifies a protocol for setting the size of the serial port buffers. It is 
williamr@2
   357
	called by the comms server in response to a RComm::SetReceiveBufferLength() 
williamr@2
   358
	request from the client.
williamr@2
   359
	
williamr@2
   360
	@param aLength Requested size of the serial port buffers in bytes 
williamr@2
   361
	@return A system error code */
williamr@2
   362
	virtual TInt SetReceiveBufferLength(TInt aLength)=0;
williamr@2
   363
	virtual void FreeMemory();	// csys have their own implementation, e.g. ECUART
williamr@4
   364
	// Notify client when the signals change
williamr@2
   365
	/** Specifies the protocol for setting a "signal change" notification. It is called 
williamr@2
   366
	by the comms server in response to a RComm::NotifySignalChange() request from 
williamr@2
   367
	the client.
williamr@2
   368
	
williamr@2
   369
	@param aSignalMask Signal mask passed by client */
williamr@2
   370
	virtual void NotifySignalChange(TUint aSignalMask)=0;
williamr@4
   371
	// Cancel an outstanding signal change notification
williamr@2
   372
	/** Specifies the protocol for cancelling a "signal change" notification. It is called 
williamr@2
   373
	by the comms server in response to a RComm::NotifySignalChangeCancel() request 
williamr@2
   374
	from the client. */
williamr@2
   375
	virtual void NotifySignalChangeCancel()=0;
williamr@4
   376
	// Notify client when the configation changes
williamr@2
   377
	/** Specifies the protocol for setting a "configuration change" notification. It 
williamr@2
   378
	is called by the comms server in response to a RComm::NotifyConfigChange() 
williamr@2
   379
	request from the client. */
williamr@2
   380
	virtual void NotifyConfigChange()=0;
williamr@4
   381
	// Cancel an outstanding config change notification
williamr@2
   382
	/** Specifies the protocol for cancelling a "configuration change" notification. 
williamr@2
   383
	It is called by the comms server in response to a RComm::NotifyConfigChangeCancel() 
williamr@2
   384
	request from the client. */
williamr@2
   385
	virtual void NotifyConfigChangeCancel()=0;
williamr@4
   386
	// Notify client when the flow control changes
williamr@2
   387
	/** Specifies the protocol for setting a "flow control change" notification. It is 
williamr@2
   388
	called by the comms server in response to a RComm::NotifyFlowControlChange() 
williamr@2
   389
	request from the client. */
williamr@2
   390
	virtual void NotifyFlowControlChange()=0;
williamr@4
   391
	// Cancel an outstanding flow control change notification
williamr@2
   392
	/** Specifies the protocol for cancelling a "flow control change" notification. It 
williamr@2
   393
	is called by the comms server in response to a RComm::NotifyFlowControlChangeCancel() 
williamr@2
   394
	request from the client. */
williamr@2
   395
	virtual void NotifyFlowControlChangeCancel()=0;
williamr@4
   396
	// Notify client when a break occurs
williamr@2
   397
	/** Specifies the protocol for setting a "break" notification. It is called by the 
williamr@2
   398
	comms server in response to a RComm::NotifyBreak() request from the client. */
williamr@2
   399
	virtual void NotifyBreak()=0;
williamr@4
   400
	// Cancel an outstanding break notification
williamr@2
   401
	/** Specifies the protocol for cancelling a "break" notification. It is called by 
williamr@2
   402
	the comms server in response to a RComm::NotifyBreakCancel() request from 
williamr@2
   403
	the client. */
williamr@2
   404
	virtual void NotifyBreakCancel()=0;
williamr@4
   405
	// Notify client when data is available
williamr@2
   406
	/** Specifies the protocol for setting a "data available" notification. It is called 
williamr@2
   407
	
williamr@2
   408
	by the comms server in response to a RComm::NotifyDataAvailable() request 
williamr@2
   409
	from the client. */
williamr@2
   410
	virtual void NotifyDataAvailable()=0;
williamr@4
   411
	// Cancel an outstanding data available notification
williamr@2
   412
	/** Specifies the protocol for cancelling a "data available" notification. It is 
williamr@2
   413
	called by the comms server in response to a RComm::NotifyDataAvailableCancel() 
williamr@2
   414
	request from the client. */
williamr@2
   415
	virtual void NotifyDataAvailableCancel()=0;
williamr@4
   416
	// Notify client when output buffer is empty
williamr@2
   417
	/** Specifies the protocol for setting a transmit buffer empty notification. It 
williamr@2
   418
	is called by the comms server in response to a RComm::NotifyOutputEmpty() 
williamr@2
   419
	request from the client. */
williamr@2
   420
	virtual void NotifyOutputEmpty()=0;
williamr@4
   421
	// Cancel an outstanding output empty notification
williamr@2
   422
	/** Specifies the protocol for cancelling a transmit buffer empty notification. 
williamr@2
   423
	It is called by the comms server in response to a RComm::NotifyOutputEmptyCancel() 
williamr@2
   424
	request from the client. */
williamr@2
   425
	virtual void NotifyOutputEmptyCancel()=0;
williamr@4
   426
	// Get the flow control status
williamr@2
   427
	/** Gets flow control status. It is called by the comms server in response to a 
williamr@2
   428
	RComm::SetMode() request from the client.
williamr@2
   429
	
williamr@2
   430
	@param aFlowControl Flow control status to return to the client 
williamr@2
   431
	@return A system-wide error code */
williamr@2
   432
	virtual TInt GetFlowControlStatus(TFlowControl& aFlowControl)=0;
williamr@4
   433
	// Get the role of this port unit
williamr@2
   434
	/** Gets DCE/DTE role. It is called by the comms server in response to a RComm::GetRole() 
williamr@2
   435
	request from the client.
williamr@2
   436
	
williamr@2
   437
	@param aRole On return, DCE/DTE role to return to the client 
williamr@2
   438
	@return A system-wide error code */
williamr@2
   439
	virtual TInt GetRole(TCommRole& aRole)=0;
williamr@4
   440
	// Set the role of this port unit
williamr@2
   441
	/** Sets DCE/DTE role. It is called by the comms server in response to a RComm::Open() 
williamr@2
   442
	request from the client.
williamr@2
   443
	
williamr@2
   444
	@param aRole DCE/DTE role 
williamr@2
   445
	@return A system-wide error code */
williamr@2
   446
	virtual TInt SetRole(TCommRole aRole)=0;
williamr@2
   447
williamr@2
   448
// Accessors
williamr@2
   449
#ifdef _DEBUG_DEVCOMM
williamr@2
   450
	virtual void DoDumpDebugInfo(const RMessage2 &aMessage)=0;
williamr@2
   451
#endif
williamr@2
   452
private:
williamr@2
   453
	void DoOpenL(CCommSession* aSession, TInternalCommAccess aMode, TCommRole aRole,TBool aIsNew);
williamr@2
   454
	void DoPreemption();
williamr@2
   455
williamr@4
   456
	TDeltaTimerEntry iReadTimer;  //< delta timer entry for read timeouts
williamr@4
   457
	TBool iReadTimerPending;      //< true if a read timer is pending
williamr@4
   458
	TDeltaTimerEntry iWriteTimer; //< delta timer entry for write timeouts
williamr@4
   459
	TBool iWriteTimerPending;     //< true if a write timer is pending
williamr@4
   460
	TInternalCommAccess iMode;    //< access mode for this port
williamr@4
   461
	CCommSession* iReadOwner;     //< pointer to the read session
williamr@4
   462
	TInt iReadOwnerHandle;        //< handle to the read session
williamr@4
   463
	CCommSession* iWriteOwner;    //< pointer to the write session
williamr@4
   464
	TInt iWriteOwnerHandle;       //< handle to the write session
williamr@2
   465
	// Binary compatible
williamr@2
   466
	// Was: CCommSession* iBreakOwner;  Replace with:
williamr@4
   467
	CExtra* iExtra;               //< pointer to the CExtra object for pre-emptable handling
williamr@4
   468
#define iBreakOwner (iExtra->iBreakOwner) //< forwards iBreakOwner to iExtra->iBreakOwner
williamr@2
   469
williamr@4
   470
	TInt iBreakOwnerHandle;                  //< handle to the break owner
williamr@4
   471
	CCommSession* iSignalOwner;              //< pointer to the signal session
williamr@4
   472
	TInt iSignalOwnerHandle;                 //< handle to the signal session
williamr@4
   473
	CCommSession* iFlowControlOwner;         //< pointer to the flow control session
williamr@4
   474
	TInt iFlowControlOwnerHandle;            //< handle to the flow control session
williamr@4
   475
	CCommSession* iConfigOwner;              //< pointer to the config session
williamr@4
   476
	TInt iConfigOwnerHandle;                 //< handle to the config session
williamr@4
   477
	CCommSession* iBreakNotifyOwner;         //< pointer to the break notify session
williamr@4
   478
	TInt iBreakNotifyOwnerHandle;            //< handle to the break notify session
williamr@4
   479
	CCommSession* iNotifyDataAvailableOwner; //< pointer to the data available session
williamr@4
   480
	TInt iNotifyDataAvailableOwnerHandle;    //< handle to the data available session
williamr@4
   481
	CCommSession* iNotifyOutputEmptyOwner;   //< pointer to the output empty session
williamr@4
   482
	TInt iNotifyOutputEmptyOwnerHandle;      //< handle to the output empty session
williamr@2
   483
williamr@4
   484
	RMessagePtr2 iBlockedRead;                //< pointer to the read request message
williamr@4
   485
	RMessagePtr2 iBlockedWrite;               //< pointer to the write request message
williamr@4
   486
	RMessagePtr2 iBlockedBreak;               //< pointer to the break request message
williamr@2
   487
williamr@2
   488
	/**The encapsulated message*/
williamr@4
   489
	RMessagePtr2 iBlockedSignalChange;			//< holds the notify signal change message
williamr@2
   490
	/**Private padding to preserve BC with earlier versions*/
williamr@2
   491
	TInt iBlockedSignalChangeDummyPadding[7];
williamr@2
   492
williamr@2
   493
	/**The encapsulated message*/
williamr@4
   494
	RMessagePtr2 iBlockedConfigChange;			//< holds the notify config change message
williamr@2
   495
	/**Private padding to preserve BC with earlier versions*/
williamr@2
   496
	TInt iBlockedConfigChangeDummyPadding[7];
williamr@2
   497
williamr@2
   498
	/**The encapsulated message*/
williamr@4
   499
	RMessagePtr2 iBlockedFlowControlChange;		//< holds the notify flow control change message
williamr@2
   500
	/**Private padding to preserve BC with earlier versions*/
williamr@2
   501
	TInt iBlockedFlowControlChangeDummyPadding[7];
williamr@2
   502
williamr@4
   503
	RMessagePtr2 iBlockedBreakNotify;         //< pointer to the notify break request message
williamr@4
   504
	RMessagePtr2 iBlockedNotifyDataAvailable; //< pointer to the notify data available request message
williamr@4
   505
	RMessagePtr2 iBlockedNotifyOutputEmpty;   //< pointer to the notify output empty request message
williamr@2
   506
williamr@4
   507
	CPortManager* iPortManager;              //< Not Used. Not to be exposed to deriving classes of CPort.
williamr@2
   508
	IMPORT_C virtual void CPort_Reserved1();
williamr@4
   509
	TAny* iCPort_Reserved;                   //< reserved pointer
williamr@2
   510
	};
williamr@2
   511
williamr@2
   512
williamr@2
   513
//
williamr@2
   514
// forward declaration
williamr@2
   515
//
williamr@2
   516
class CLibUnloader;
williamr@2
   517
williamr@2
   518
williamr@2
   519
class CSerial : public CObject
williamr@2
   520
/** 
williamr@2
   521
Factory for a single CPort object.
williamr@2
   522
williamr@2
   523
CSerial is the base class for implementations of serial port factories. It is intended to be
williamr@2
   524
overridden by the CSY so that C32 can call in and ask the CSY to create serial ports. In this way
williamr@2
   525
the factory is responsible for creating instances of CPort-derived classes 
williamr@2
   526
for the protocol of the CSY. It also provides query functions, which return general information 
williamr@2
   527
about the capabilities of the serial protocol implemented by the CSY.
williamr@2
   528
williamr@2
   529
Owned by the CPort object it creates.
williamr@2
   530
williamr@2
   531
Writing derived classes:
williamr@2
   532
williamr@2
   533
The pure virtual NewPortL() and Info() functions must be implemented in derived 
williamr@2
   534
classes. Serial protocol modules which can take differing action based on 
williamr@2
   535
the version of the comms server should also override QueryVersionSupported(). 
williamr@2
   536
williamr@2
   537
@publishedAll
williamr@2
   538
@released
williamr@2
   539
*/
williamr@2
   540
	{
williamr@2
   541
public:
williamr@2
   542
	IMPORT_C CSerial();
williamr@2
   543
	IMPORT_C ~CSerial();
williamr@2
   544
	IMPORT_C virtual TBool QueryVersionSupported(const TVersion& aVersion) const;
williamr@2
   545
	void ConstructL(RLibrary& aLib);
williamr@2
   546
public:
williamr@2
   547
	//
williamr@2
   548
	// pure virtuals to be implemented by the CSY
williamr@2
   549
	//
williamr@2
   550
williamr@4
   551
	// Create a new port for the supplied unit number
williamr@2
   552
	/** Specifies the protocol for creating a new serial port for the protocol. The 
williamr@2
   553
	comms server calls this function in response to a RComm:Open() call.
williamr@2
   554
	
williamr@2
   555
	Typically, the implementation would call NewL() on the protocol's CPort-based 
williamr@2
   556
	class. Any resources required by the new port object should be done at this 
williamr@2
   557
	stage. If the serial port object cannot be created for any reason, NewPortL() 
williamr@2
   558
	should leave with an appropriate error code.
williamr@2
   559
	
williamr@2
   560
	The interpretation of unit numbers is specific to the particular serial protocol 
williamr@2
   561
	module. However, unit numbers on Symbian OS should be zero-based. For the 
williamr@2
   562
	default built-in serial ports implemented by the serial protocol module ecuart.csy, 
williamr@2
   563
	the unit numbers refer to the hardware ports, with 0 being the first port 
williamr@2
   564
	on the machine. If a second request is made to create a port with a unit number 
williamr@2
   565
	that has already been created and not destroyed, NewPortL() should leave with 
williamr@2
   566
	KErrAlreadyExists.
williamr@2
   567
	
williamr@2
   568
	@param aUnit The unit number to be created. */
williamr@2
   569
	virtual CPort* NewPortL(const TUint aUnit)=0;
williamr@4
   570
	// Get info about this CSY, fill in the supplied structure.
williamr@2
   571
	/** Specifies the protocol for getting the information about the serial protocol.
williamr@2
   572
	
williamr@2
   573
	Implementations should fill in the TSerialInfo structure to reflect the protocol's 
williamr@2
   574
	capabilities.
williamr@2
   575
	
williamr@2
   576
	@param aSerialInfo On return, set to indicate the capabilities of the serial 
williamr@2
   577
	protocol. */
williamr@2
   578
	virtual void Info(TSerialInfo &aSerialInfo)=0;
williamr@2
   579
williamr@2
   580
	void ModuleName(TDes& aName);
williamr@2
   581
williamr@2
   582
	IMPORT_C virtual TSecurityPolicy PortPlatSecCapability(TUint aPort) const;
williamr@2
   583
williamr@2
   584
protected:
williamr@2
   585
	/** Module version number. The class should initialise this member with its version 
williamr@2
   586
	number from its constructor. */
williamr@4
   587
	TVersion iVersion;                         //< holds the version of the CSY
williamr@2
   588
private:
williamr@4
   589
	CLibUnloader* iLibUnloader;                //< pointer to the library unloader
williamr@2
   590
	IMPORT_C virtual void CSerial_Reserved1();
williamr@4
   591
	TAny* iCSerial_Reserved;                   //< reserved pointer for future BC
williamr@2
   592
	};
williamr@2
   593
williamr@2
   594
/** This typedef defines the form of the ordinal-1 entry point function to a serial 
williamr@2
   595
protocol module. The function should create and return a concrete CSerial-derived 
williamr@2
   596
class, which will then be used by the comms server.
williamr@2
   597
williamr@2
   598
Each serial protocol module should only ever create a single serial protocol 
williamr@2
   599
factory object. If the entry point is called twice without the first factory 
williamr@2
   600
object being destroyed, this function should leave with KErrGeneral. */
williamr@4
   601
typedef CSerial *(*TSerialNewL)(); //< function type of CSY module entry point
williamr@2
   602
williamr@2
   603
#endif // CS_PORT_H