Important update:
- SelectableCore:
- Rename methods: SetSerialPortConfig() -> WriteSerialConfig(),
GetSerialPortConfig() -> ReadSerialConfig(),
InputHandle() -> OutputHandle(),
ProcessBuffer() -> ProcessInputBuffer()
SetPortHandle(config)() -> SetSerialHandle(Config)()
- Rename serial port identification: "Port" -> "SerialPort"
- Update logs accordingly
- Add LinePrinter Port
- Add to LoadConfig()
- Add SetLinePrinterHandle() & OpenLinePrinterPort() methods
- Add handling for open/read/write/close events
- Add CloseDelay for AutoManage (non-persistent) ports
- Rename handle timer: ReopenStart -> LastAction
- Reset timer on all open/read/write/close events
- Check for Close timeout in Process() and close port
- Remove CloseChildren parameter on Close() method
- Add QuickReopen parameter to Close() method
- SelectCore:
- Overwrite existing handle - not yet removed
- Handle In/Out baudrate on serial port separately
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
// Types required for connections
|
||||
typedef enum { ctNone = 0, ctPort = 1, ctForkPipe = 2, ctServer = 3, ctRemoteClient = 4, ctClient = 5 } EConnectType;
|
||||
typedef enum { ctNone = 0, ctSerial = 1, ctLinePrinter = 2, ctServer = 3, ctRemoteClient = 4, ctClient = 5, ctForkPipe = 6 } EConnectType;
|
||||
const char ConnectTypeName[][15] = { "None", "Port", "ForkPipe", "Server", "RemoteClient", "Client" };
|
||||
|
||||
typedef enum { csNone = 0, csWaitingtoOpen = 1, csOpen = 2, csDataWaiting = 3, csClosed = 4, csFailed = 5 } EConnectState;
|
||||
@@ -76,8 +76,11 @@ struct SHandle {
|
||||
int FD;
|
||||
EConnectState State;
|
||||
|
||||
bool AutoManage;
|
||||
bool Persistent;
|
||||
bool AutoManage;
|
||||
bool Persistent;
|
||||
timeval LastAction;
|
||||
long ReopenDelay; // millisecs
|
||||
long CloseTimeout; // millisecs
|
||||
|
||||
// Callback functions
|
||||
FHandleCallback StateCallback[ 6 ];
|
||||
@@ -95,7 +98,8 @@ struct SHandle {
|
||||
bool KeepAlive; // Socket keep alive
|
||||
|
||||
bool SerialConfig;
|
||||
int Baudrate;
|
||||
int InBaudrate;
|
||||
int OutBaudrate;
|
||||
short DataBits;
|
||||
short Parity;
|
||||
short StopBits;
|
||||
@@ -114,10 +118,6 @@ struct SHandle {
|
||||
timeval InStart;
|
||||
long InTimeout; // millisecs
|
||||
|
||||
// Reopen Timer
|
||||
timeval ReopenStart;
|
||||
long ReopenDelay; // millisecs
|
||||
|
||||
// List / Tree
|
||||
TChannel * Channel;
|
||||
THandle * Parent;
|
||||
@@ -199,23 +199,27 @@ protected:
|
||||
}
|
||||
|
||||
// Port Operations
|
||||
virtual int OpenPort( THandle * Handle );
|
||||
int OpenSerialPort( THandle * Handle );
|
||||
bool WriteSerialConfig( THandle * Handle );
|
||||
bool ReadSerialConfig( THandle * Handle );
|
||||
|
||||
int OpenLinePrinterPort( THandle * Handle );
|
||||
|
||||
// ForkPipe Operations
|
||||
virtual int OpenForkPipe( THandle * Handle );
|
||||
int OpenForkPipe( THandle * Handle );
|
||||
|
||||
// Socket Operations
|
||||
bool ResolveAddress( THandle * Handle );
|
||||
virtual int OpenServerSocket( THandle * Handle );
|
||||
virtual int OpenRemoteClientSocket( THandle * Handle );
|
||||
virtual int OpenClientSocket( THandle * Handle );
|
||||
bool ResolveAddress( THandle * Handle );
|
||||
int OpenServerSocket( THandle * Handle );
|
||||
int OpenRemoteClientSocket( THandle * Handle );
|
||||
int OpenClientSocket( THandle * Handle );
|
||||
|
||||
// Mutual Operations
|
||||
int ReadFromFD( int FD, char * Data, int MaxLen );
|
||||
int WriteToFD( int FD, const char * Data, int Len, bool Force );
|
||||
|
||||
// Buffer operations
|
||||
virtual bool ProcessBuffer( THandle * Handle, bool Force );
|
||||
virtual bool ProcessInputBuffer( THandle * Handle, bool Force );
|
||||
|
||||
// Specific operations
|
||||
bool BuildArgs( const char * ExecPath, int &Count, char * Args[] );
|
||||
@@ -253,28 +257,29 @@ public:
|
||||
// General port parameters
|
||||
THandle * CreateHandle( const char * HandleName, bool CreateChannel );
|
||||
bool SetCallback( THandle * Handle, EConnectState pState, FHandleCallback pCallback );
|
||||
bool SetAutoManage( THandle * Handle, bool AutoManage, bool Persistent, int ReopenTime = 0 );
|
||||
bool SetAutoManage( THandle * Handle, bool AutoManage, bool Persistent, int ReopenDelay = 0, int CloseTimeout = 0 );
|
||||
bool SetInBuffer( THandle * Handle, int InBufSize, int InTimeout, const char * InMarker, int InMarkerLen );
|
||||
bool SetOutBuffer( THandle * Handle, int OutBufSize );
|
||||
|
||||
// Specific port parameters
|
||||
bool SetPortHandle( THandle * Handle, const char * FileName );
|
||||
bool SetPortHandleSerial( THandle * Handle, int Baudrate, short DataBits, short Parity, short StopBits, short FlowCtrl, int DataWait );
|
||||
bool SetSerialHandle( THandle * Handle, const char * FileName );
|
||||
bool SetSerialHandleConfig( THandle * Handle, int Baudrate, short DataBits, short Parity, short StopBits, short FlowCtrl, int DataWait );
|
||||
bool SetLinePrinterHandle( THandle * Handle, const char * FileName );
|
||||
bool SetForkPipeHandle( THandle * Handle, const char * ExecPath );
|
||||
bool SetSocketHandle( THandle * Handle, EConnectType Type, const char * HostName, const char * PortName, bool KeepAlive );
|
||||
bool ClearHandle( THandle * Handle );
|
||||
|
||||
// FD Operations
|
||||
virtual int Open( THandle * Handle );
|
||||
virtual bool Close( THandle * Handle, bool CloseChildren = false );
|
||||
virtual bool Close( THandle * Handle, bool QuickReopen );
|
||||
virtual bool Read( THandle * Handle );
|
||||
virtual bool Write( THandle * Handle );
|
||||
|
||||
// FD operations
|
||||
inline virtual int Open( const char * HandleName ) { return (Open( GetHandle( HandleName ))); };
|
||||
|
||||
inline virtual bool Close( const char * HandleName, bool CloseChildren = false ) { return (Close( GetHandle( HandleName ), CloseChildren )); };
|
||||
inline virtual bool Close( int FD, bool CloseChildren = false ) { return (Close( GetHandle( FD ), CloseChildren )); };
|
||||
inline virtual bool Close( const char * HandleName, bool QuickReopen ) { return (Close( GetHandle( HandleName ), QuickReopen )); };
|
||||
inline virtual bool Close( int FD, bool QuickReopen ) { return (Close( GetHandle( FD ), QuickReopen )); };
|
||||
|
||||
inline virtual bool Read( const char * HandleName ) { return (Read( GetHandle( HandleName ))); };
|
||||
inline virtual bool Read( int FD ) { return (Read( GetHandle( FD ))); };
|
||||
@@ -282,9 +287,6 @@ public:
|
||||
inline virtual bool Write( const char * HandleName ) { return (Write( GetHandle( HandleName ))); };
|
||||
inline virtual bool Write( int FD ) { return (Write( GetHandle( FD ))); };
|
||||
|
||||
bool SetSerialPortConfig( THandle * Handle );
|
||||
bool GetSerialPortConfig( THandle * Handle );
|
||||
|
||||
// Info
|
||||
inline EConnectType GetType( const char * HandleName ) {
|
||||
THandle * Handle = GetHandle( HandleName );
|
||||
@@ -297,7 +299,7 @@ public:
|
||||
|
||||
// Function Interface
|
||||
virtual int Input( const char * ChannelName, const char * Buffer, int BufLen = -1 );
|
||||
int InputHandle( THandle * Handle, const char * Data, int Len );
|
||||
int OutputHandle( THandle * Handle, const char * Data, int Len );
|
||||
virtual bool Process();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user