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