epoc32/include/c32comm.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
parent 0 061f57f2323e
child 4 837f303aceeb
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
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 C32COMM_H
williamr@2
    26
#define C32COMM_H
williamr@2
    27
williamr@2
    28
/** @file
williamr@2
    29
williamr@2
    30
C32 header file to be included by the clients.
williamr@2
    31
Defines the main interface to C32, RCommServ and RComm
williamr@2
    32
*/
williamr@2
    33
williamr@2
    34
#include <e32base.h>
williamr@2
    35
#include <d32comm.h>
williamr@2
    36
williamr@2
    37
/**
williamr@2
    38
@publishedAll
williamr@2
    39
@released	
williamr@2
    40
*/
williamr@2
    41
IMPORT_C TInt StartC32();
williamr@2
    42
IMPORT_C TInt StartC32WithCMISuppressions(const TDesC& aCMISuppressionList);
williamr@2
    43
williamr@2
    44
/**
williamr@2
    45
C32 major version number.
williamr@2
    46
@internalAll
williamr@2
    47
*/
williamr@2
    48
const TUint KEC32MajorVersionNumber = 1;  
williamr@2
    49
/**
williamr@2
    50
C32 minor version number.
williamr@2
    51
@internalAll
williamr@2
    52
*/
williamr@2
    53
const TUint KEC32MinorVersionNumber = 0;  
williamr@2
    54
/**
williamr@2
    55
C32 build version number.
williamr@2
    56
@internalAll
williamr@2
    57
*/
williamr@2
    58
const TUint KEC32BuildVersionNumber = 605;
williamr@2
    59
williamr@2
    60
/**
williamr@2
    61
@internalComponent
williamr@2
    62
*/
williamr@2
    63
const TDesC& KCommServerName(void);
williamr@2
    64
williamr@2
    65
/** Specifies the mode in which a port is opened.
williamr@2
    66
williamr@2
    67
We specify the mode when it is opened, and the mode cannot thereafter be
williamr@2
    68
changed. If we open the port in Shared mode, other clients of the comms
williamr@2
    69
server can use the same port while we have it open. If we open the port
williamr@2
    70
in Exclusive mode, then it is locked for our own use and any attempt to
williamr@2
    71
access it from another process will fail. Furthermore, our own attempt
williamr@2
    72
to open a port in exclusive mode will fail if another process has already
williamr@2
    73
opened the port in shared mode.
williamr@2
    74
 
williamr@2
    75
Infra-red ports using IRCOMM.CSY can be opened in either shared or exclusive 
williamr@2
    76
mode. However they SHOULD only be opened in Exclusive mode, since opening 
williamr@2
    77
them any other way warm-boots the computer.
williamr@2
    78
 
williamr@2
    79
@publishedAll
williamr@2
    80
@released	
williamr@2
    81
*/
williamr@2
    82
enum TCommAccess
williamr@2
    83
    {
williamr@2
    84
	/** Once open, the port cannot be used by any other RComm clients. An attempt to 
williamr@2
    85
	open a port in exclusive mode will fail if another process has already opened 
williamr@2
    86
	the port in shared mode. */
williamr@2
    87
	ECommExclusive,  
williamr@2
    88
	/** The port can be shared by other RComm clients who open in the same mode. */
williamr@2
    89
	ECommShared,    
williamr@2
    90
	/** Allows another client to pre-empt the session with an open request in one of 
williamr@2
    91
	the other two modes. The port will be lost if other clients are trying to open it.*/
williamr@2
    92
	ECommPreemptable 
williamr@2
    93
    };
williamr@2
    94
/**
williamr@2
    95
Use full buffering. Used by RComm::SetMode().
williamr@2
    96
williamr@2
    97
@publishedAll	
williamr@2
    98
@released
williamr@2
    99
*/
williamr@2
   100
const TUint KCommBufferFull    = 0x0000; 
williamr@2
   101
/**
williamr@2
   102
Use partial buffering. Used by RComm::SetMode().
williamr@2
   103
williamr@2
   104
@publishedAll	
williamr@2
   105
@released
williamr@2
   106
*/
williamr@2
   107
const TUint KCommBufferPartial = 0x0001;  
williamr@2
   108
williamr@2
   109
williamr@2
   110
/**
williamr@2
   111
trace flags for debugging purposes
williamr@2
   112
@internalComponent
williamr@2
   113
*/
williamr@2
   114
enum TC32Trace 
williamr@2
   115
	{
williamr@2
   116
	ETraceC32Startup = 0x00000001,
williamr@2
   117
	ETraceC32Panic   = 0x00000002,
williamr@2
   118
	ETraceC32Request = 0x00000004,
williamr@2
   119
	ETraceC32IPC     = 0x00000008,
williamr@2
   120
	ETraceC32All     = 0xFFFFFFFF,
williamr@2
   121
	};
williamr@2
   122
williamr@2
   123
/**
williamr@2
   124
Used by the package TCommServerConfig to configure the comm port.
williamr@2
   125
williamr@2
   126
Holds the buffer configuration settings for the comms server. 
williamr@2
   127
williamr@2
   128
The comms server copies data between the descriptors provided by the client 
williamr@2
   129
and the buffers used by the serial port drivers, for each read and write request. 
williamr@2
   130
There are two methods by which this can be accomplished. Full buffering means 
williamr@2
   131
that the comms server will always attempt to allocate enough memory to satisfy 
williamr@2
   132
any reads or writes in a single copy, while partial buffering means that the 
williamr@2
   133
comms server will allocate a static buffer and use partial copies to transfer 
williamr@2
   134
data to the serial driver. When a port is opened, the default is full buffering. 
williamr@2
   135
williamr@2
   136
@publishedAll
williamr@2
   137
@released
williamr@2
   138
*/
williamr@2
   139
struct TCommServerConfigV01
williamr@2
   140
	{
williamr@2
   141
	/** Buffering option: either KCommBufferFull or KCommBufferPartial */
williamr@2
   142
	TUint iBufFlags; ///< contains buffer flags e.g for partial read/write
williamr@2
   143
	/** Size of server buffer if partial buffering is being used */
williamr@2
   144
	TUint iBufSize;  ///< size of the Tx/Rx buffer
williamr@2
   145
	};
williamr@2
   146
williamr@2
   147
/** Package buffer for a server configuration object. TCommServerConfig is used 
williamr@2
   148
as an argument to RComm::Mode() and RComm::SetMode(). 
williamr@2
   149
williamr@2
   150
@publishedAll	
williamr@2
   151
@released
williamr@2
   152
*/
williamr@2
   153
typedef TPckgBuf<TCommServerConfigV01> TCommServerConfig; 
williamr@2
   154
williamr@2
   155
/** Maximum length of port full name, TPortDescription (48 characters).
williamr@2
   156
williamr@2
   157
@publishedAll	
williamr@2
   158
@released
williamr@2
   159
 */
williamr@2
   160
const TInt KMaxPortDescription = 0x30; 
williamr@2
   161
/** Maximum length of the Port Prefix format name, as used by TPortName (16 characters). 
williamr@2
   162
williamr@2
   163
@publishedAll	
williamr@2
   164
@released
williamr@2
   165
*/
williamr@2
   166
const TInt KMaxPortName = 0x10;        
williamr@2
   167
williamr@2
   168
/** Reset the receive buffer 
williamr@2
   169
williamr@2
   170
@publishedAll	
williamr@2
   171
@released
williamr@2
   172
*/
williamr@2
   173
const TUint KCommResetRx = 0x00000001;  ///< to by used as flag by RComm::ResetBuffers
williamr@2
   174
/** Reset the transmit buffer 
williamr@2
   175
williamr@2
   176
@publishedAll	
williamr@2
   177
@released
williamr@2
   178
*/
williamr@2
   179
const TUint KCommResetTx = 0x00000002;  ///< to by used as flag by RComm::ResetBuffers
williamr@2
   180
/** Port name. Used by TSerialInfo::iName. 
williamr@2
   181
williamr@2
   182
@publishedAll	
williamr@2
   183
@released
williamr@2
   184
*/
williamr@2
   185
typedef TBuf<KMaxPortName> TPortName;            
williamr@2
   186
/** Full port name/description. Used by TSerialInfo::iDescription. 
williamr@2
   187
williamr@2
   188
@publishedAll	
williamr@2
   189
@released
williamr@2
   190
*/
williamr@2
   191
typedef TBuf<KMaxPortDescription> TPortDescription; 
williamr@2
   192
williamr@2
   193
williamr@2
   194
class TSerialInfo
williamr@2
   195
/** Describes a serial protocol's general capabilities.
williamr@2
   196
williamr@2
   197
Used by RCommServ::GetPortInfo to retrieve information
williamr@2
   198
about the comm ports and the CSY.
williamr@2
   199
williamr@2
   200
Notes:
williamr@2
   201
williamr@2
   202
1. The lowest port need not necessarily be numbered zero.
williamr@2
   203
williamr@2
   204
2. At least one port is always guaranteed. 
williamr@2
   205
williamr@2
   206
3. The full name of the serial port (used when opening it) consists of the name 
williamr@2
   207
  returned by TSerialInfo (the Port Prefix), followed by a double colon separator, followed by 
williamr@2
   208
  the unit number (port number) as an ASCII number (for instance COMM::0). 
williamr@2
   209
williamr@2
   210
@publishedAll	
williamr@2
   211
@released
williamr@2
   212
*/
williamr@2
   213
	{
williamr@2
   214
public:
williamr@2
   215
	/** Description of the CSY meant only for human reading. It
williamr@2
   216
	can be up to KMaxPortDescription (48) characters long. */
williamr@2
   217
	TPortDescription iDescription; ///< description of the port (CSY)
williamr@2
   218
	/** The short name of the port (Port Prefix). This is used in calls to RComm::Open(). It can be up to 
williamr@2
   219
	KMaxPortName (i.e. 16) characters long. */
williamr@2
   220
	TPortName iName;               ///< name of the port
williamr@2
   221
	TUint iLowUnit;                ///< The lowest port number supported by the serial module
williamr@2
   222
	TUint iHighUnit;               ///< the highest port number supported by the serial module
williamr@2
   223
	};
williamr@2
   224
williamr@2
   225
/**
williamr@2
   226
Specifies the DTE/DCE role in which a port is opened.
williamr@2
   227
williamr@2
   228
@see RComm::Open() 
williamr@2
   229
@publishedAll	
williamr@2
   230
@released
williamr@2
   231
*/
williamr@2
   232
enum TCommRole
williamr@2
   233
	{
williamr@2
   234
	/** Port takes on role of DTE. (DTE=computer).
williamr@2
   235
	This is the default.
williamr@2
   236
	*/
williamr@2
   237
		ECommRoleDTE, 
williamr@2
   238
	/** Port takes on role of DCE. (DCE=modem).
williamr@2
   239
	*/
williamr@2
   240
		ECommRoleDCE  
williamr@2
   241
	};
williamr@2
   242
williamr@2
   243
class RComm;
williamr@2
   244
williamr@2
   245
williamr@2
   246
class RCommServ : public RSessionBase
williamr@2
   247
/** Represents a session with the serial comms server. 
williamr@2
   248
Functions are provided for connection 
williamr@2
   249
to the server and for loading and unloading different comms modules, and services 
williamr@2
   250
for finding out the name and numbers of the available ports. 
williamr@2
   251
williamr@2
   252
Sessions with the serial comms server are not shareable.
williamr@2
   253
williamr@2
   254
Comms modules are also known as "CSY"s due to their ".CSY" extension,
williamr@2
   255
 derived from the term "Comms SYstem".
williamr@2
   256
williamr@2
   257
This class is not intended for user derivation.
williamr@2
   258
williamr@2
   259
@publishedAll	
williamr@2
   260
@released */
williamr@2
   261
	{
williamr@2
   262
public:
williamr@2
   263
	IMPORT_C RCommServ();
williamr@2
   264
	IMPORT_C TInt Connect();
williamr@2
   265
	IMPORT_C TVersion Version() const;
williamr@2
   266
williamr@2
   267
	IMPORT_C TInt LoadCommModule(const TDesC& aFileName);
williamr@2
   268
	IMPORT_C TInt UnloadCommModule(const TDesC& aName);
williamr@2
   269
	IMPORT_C TInt NumPorts(TInt& aNum);
williamr@2
   270
	IMPORT_C TInt GetPortInfo(const TDesC& aName, TSerialInfo& aInfo);
williamr@2
   271
	IMPORT_C TInt GetPortInfo(TInt aIndex, TDes& aModuleName, TSerialInfo& aInfo);
williamr@2
   272
williamr@2
   273
	IMPORT_C TInt __DbgMarkHeap();
williamr@2
   274
	IMPORT_C TInt __DbgCheckHeap(TInt aCount);
williamr@2
   275
	IMPORT_C TInt __DbgMarkEnd(TInt aCount);
williamr@2
   276
	IMPORT_C TInt __DbgFailNext(TInt aCount);
williamr@2
   277
	IMPORT_C TInt __DbgSetTraceMask(TC32Trace aMask);
williamr@2
   278
williamr@2
   279
	IMPORT_C static TInt CreateThreadInCommProc(const TDesC& aLibraryName, const TDesC& aThreadName, TThreadFunction aFunction, TInt aStackSize, TInt aHeapMinSize, TInt aHeapMaxSize);
williamr@2
   280
private:
williamr@2
   281
	static TBool IsServerThreadL();
williamr@2
   282
	};
williamr@2
   283
//
williamr@2
   284
williamr@2
   285
struct TCommDebugInfo; // defined in d32comm.h
williamr@2
   286
williamr@2
   287
williamr@2
   288
class RComm : public RSubSessionBase
williamr@2
   289
/** A sub-session to the C32 Serial Server used for addressing a serial port.
williamr@2
   290
williamr@2
   291
All the necessary functions are provided by this class for communicating via 
williamr@2
   292
a port, including functions for opening, closing, reading, writing, 
williamr@2
   293
port configuration and capability checking. An RComm session represents
williamr@2
   294
a single serial port and once opened cannot be altered to represent another port.
williamr@2
   295
williamr@2
   296
Ports are referenced by a character string whose format is referred to as Port Prefix format.
williamr@2
   297
This format is also known as the CSY internal name, and the ports "short" name in older releases.
williamr@2
   298
williamr@2
   299
@publishedAll	
williamr@2
   300
@released
williamr@2
   301
*/
williamr@2
   302
		{
williamr@2
   303
public:
williamr@2
   304
	IMPORT_C RComm();
williamr@2
   305
	IMPORT_C TInt Open(RCommServ& aServer, const TDesC& aName, TCommAccess aMode);
williamr@2
   306
	IMPORT_C TInt Open(RCommServ& aServer, const TDesC& aName, TCommAccess aMode, TCommRole aRole);
williamr@2
   307
	IMPORT_C void OpenWhenAvailable(TRequestStatus& aStatus, RCommServ& aServer, const TDesC& aName);
williamr@2
   308
	IMPORT_C void OpenWhenAvailable(TRequestStatus& aStatus, RCommServ& aServer, const TDesC& aName, TCommRole aRole);
williamr@2
   309
	IMPORT_C void OpenWhenAvailableCancel();
williamr@2
   310
	IMPORT_C void Read(TRequestStatus& aStatus, TDes8& aDes);
williamr@2
   311
	IMPORT_C void Read(TRequestStatus& aStatus, TDes8& aDes, TInt aLength);
williamr@2
   312
	IMPORT_C void Read(TRequestStatus& aStatus, TTimeIntervalMicroSeconds32 aTimeOut, TDes8& aDes);
williamr@2
   313
	IMPORT_C void Read(TRequestStatus& aStatus, TTimeIntervalMicroSeconds32 aTimeOut, TDes8& aDes, TInt aLength);
williamr@2
   314
	IMPORT_C void ReadOneOrMore(TRequestStatus& aStatus, TDes8& aDes);
williamr@2
   315
	IMPORT_C TInt ReadCancel();
williamr@2
   316
	IMPORT_C TInt QueryReceiveBuffer() const;
williamr@2
   317
	IMPORT_C TInt ResetBuffers(TUint aFlags=(KCommResetRx|KCommResetTx));
williamr@2
   318
	IMPORT_C void Write(TRequestStatus& aStatus, const TDesC8& aDes);
williamr@2
   319
	IMPORT_C void Write(TRequestStatus& aStatus, const TDesC8& aDes, TInt aLength);
williamr@2
   320
	IMPORT_C void Write(TRequestStatus& aStatus, TTimeIntervalMicroSeconds32 aTimeOut, const TDesC8& aDes);
williamr@2
   321
	IMPORT_C void Write(TRequestStatus& aStatus, TTimeIntervalMicroSeconds32 aTimeOut, const TDesC8& aDes, TInt aLength);
williamr@2
   322
	IMPORT_C TInt WriteCancel();
williamr@2
   323
	IMPORT_C void Break(TRequestStatus& aStatus, TTimeIntervalMicroSeconds32 aTime);
williamr@2
   324
	IMPORT_C TInt BreakCancel();
williamr@2
   325
	IMPORT_C TInt Cancel();
williamr@2
   326
	IMPORT_C TInt Config(TDes8& aConfig) const;
williamr@2
   327
	IMPORT_C TInt SetConfig(const TDesC8& aConfig);
williamr@2
   328
	IMPORT_C TInt Caps(TDes8& aCaps) const;
williamr@2
   329
	IMPORT_C TInt SetMode(const TCommServerConfig& aConfig);
williamr@2
   330
	IMPORT_C TInt Mode(TCommServerConfig& aConfig) const;
williamr@2
   331
	IMPORT_C TUint Signals(TUint aSignalMask = 0x3F) const;
williamr@2
   332
	IMPORT_C TInt SetSignalsToMark(TUint aSignalMask);
williamr@2
   333
	IMPORT_C TInt SetSignalsToSpace(TUint aSignalMask);
williamr@2
   334
	IMPORT_C TInt ReceiveBufferLength() const;
williamr@2
   335
	IMPORT_C TInt SetReceiveBufferLength(TInt aLength);
williamr@2
   336
	IMPORT_C void Close();
williamr@2
   337
	inline void SetSignals(TUint aSetMask, TUint aClearMask);
williamr@2
   338
	IMPORT_C void NotifySignalChange(TRequestStatus& aStatus, TUint& aSignals, TUint aSignalMask=0x3F);
williamr@2
   339
	IMPORT_C TInt NotifySignalChangeCancel() const;
williamr@2
   340
	IMPORT_C void NotifyConfigChange(TRequestStatus& aStatus, TDes8& aNewConfig) const;
williamr@2
   341
	IMPORT_C TInt NotifyConfigChangeCancel() const;
williamr@2
   342
	IMPORT_C void NotifyFlowControlChange(TRequestStatus& aStatus, TFlowControl& aFlowControl);
williamr@2
   343
	IMPORT_C TInt NotifyFlowControlChangeCancel() const;	  
williamr@2
   344
	IMPORT_C void NotifyBreak(TRequestStatus& aStatus) const;
williamr@2
   345
	IMPORT_C TInt NotifyBreakCancel() const;
williamr@2
   346
	IMPORT_C void NotifyDataAvailable(TRequestStatus& aStatus) const;
williamr@2
   347
	IMPORT_C TInt NotifyDataAvailableCancel() const;
williamr@2
   348
	IMPORT_C void NotifyOutputEmpty(TRequestStatus& aStatus) const;
williamr@2
   349
	IMPORT_C TInt NotifyOutputEmptyCancel() const;
williamr@2
   350
	IMPORT_C TInt GetFlowControlStatus(TFlowControl& aFlowControl) const;
williamr@2
   351
	IMPORT_C TInt GetRole(TCommRole& aRole) const;
williamr@2
   352
williamr@2
   353
	IMPORT_C TInt SetAccessMode(TCommAccess aNewMode);
williamr@2
   354
	IMPORT_C TInt DebugState(TCommDebugInfo&);
williamr@2
   355
williamr@2
   356
#ifdef _DEBUG_DEVCOMM
williamr@2
   357
	IMPORT_C TInt RComm::DebugInfo(TDes8& aDes);
williamr@2
   358
#endif
williamr@2
   359
private:
williamr@2
   360
	TPtr8 iSignalsNotification; ///< pointer to the signals to be changed during notification
williamr@2
   361
	TPtr8 iFlowNotification;    ///< pointer to the flow control to be changed during notification
williamr@2
   362
	};
williamr@2
   363
	
williamr@2
   364
#include <c32comm.inl>
williamr@2
   365
williamr@2
   366
#endif // C32COMM_H