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