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