Merge branch 'master' into HitNotBLE

# Conflicts:
#	SelectableCore.cpp
#	SelectableCore.h
This commit is contained in:
Charl Wentzel
2019-04-03 17:02:52 +02:00
13 changed files with 680 additions and 562 deletions

View File

@@ -37,6 +37,7 @@ const char ConnectStateName[][15] = { "None", "OpenRequest", "WaitingToOpen", "O
#define NO_FLOWCTRL 0
#define HW_FLOWCTRL 1
#define SW_FLOWCTRL 2
#define RS485_FLOWCTRL 3
//---------------------------------------------------------------------------
@@ -56,16 +57,16 @@ typedef void (*FHandleCallback)( CSelectableBare * Function, THandle * Handle, E
// List of Handles for Select Object
struct SSelectHandle {
// File Descriptor
int FD;
bool Read;
bool Write;
int FD = -1;
bool Read = false;
bool Write = false;
// Event Object
THandle * Handle;
CSelectableBare * Function;
THandle * Handle = NULL;
CSelectableBare * Function = NULL;
// List
TSelectHandle * Next;
TSelectHandle * Next = NULL;
};
//---------------------------------------------------------------------------
@@ -73,63 +74,63 @@ struct SSelectHandle {
// List or Handles for Selectable Function Object
struct SHandle {
// Description
char * Name;
EConnectType Type;
char * Name = NULL;
EConnectType Type = ctNone;
// State
int FD;
EConnectState State;
int FD = -1;
EConnectState State = csNone;
bool AutoManage;
bool Persistent;
timeval LastAction;
long ReopenDelay; // millisecs before trying to re-open socket
long CloseTimeout; // millisecs of no traffic before closing socket
bool AutoManage = false;
bool Persistent = false;
timeval LastAction = {0,0};
long ReopenDelay = 1000; // millisecs before trying to re-open socket
long CloseTimeout = 1000; // millisecs of no traffic before closing socket
// Callback functions
FHandleCallback StateCallback[ 7 ];
FHandleCallback StateCallback[ 7 ] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL};
// Type specific parameters
char * Path; // Port (file)name or Exec path
char * Path = NULL; // Port (file)name or Exec path
// Fork config
pid_t ChildPID; // Forked child PID
// Socket config
char * HostName; // Host name or IP adddress
char * PortName; // Socket port no or protocol, e.g. "80" or "HTTP"
struct addrinfo * AddressList; // List of resolved IP Addresses for host name
struct addrinfo * AddressInfo; // Current selected IP Address
bool AddressFailed; // Indicate failure to connect to address
short Queue; // Max waiting connections
long ResolveDelay; // Delay before resolving hostname via DNS
char * HostName = NULL; // Host name or IP adddress
char * PortName = NULL; // Socket port no or protocol, e.g. "80" or "HTTP"
struct addrinfo * AddressList = NULL; // List of resolved IP Addresses for host name
struct addrinfo * AddressInfo = NULL; // Current selected IP Address
bool AddressFailed = false; // Indicate failure to connect to address
short Queue = 2; // Max waiting connections
long ResolveDelay = 0; // Delay before resolving hostname via DNS
// Serial Port config
bool SerialConfig;
int InBaudrate;
int OutBaudrate;
short DataBits;
short Parity;
short StopBits;
short FlowCtrl;
int DataWait;
bool SerialConfig = false;
int InBaudrate = 0;
int OutBaudrate = 0;
short DataBits = 0;
short Parity = NO_PARITY;
short StopBits = 0;
short FlowCtrl = NO_FLOWCTRL;
int DataWait = 0;
// Buffers
CRollingBuffer * InBuffer;
CRollingBuffer * OutBuffer;
CRollingBuffer * InBuffer = NULL;
CRollingBuffer * OutBuffer = NULL;
// Input Markers
char * InMarker;
int InMarkerLen;
char * InMarker = NULL;
int InMarkerLen = 0;
// Input Timer
timeval InStart;
long InTimeout; // millisecs
timeval InStart = {0,0};
long InTimeout = 0; // millisecs
// List / Tree
TChannel * Channel;
THandle * Parent;
THandle * Next;
TChannel * Channel = NULL;
THandle * Parent = NULL;
THandle * Next = NULL;
};
//---------------------------------------------------------------------------
@@ -138,7 +139,7 @@ class CSelect
{
protected:
// List
TSelectHandle * FirstHandle;
TSelectHandle * FirstHandle = NULL;
// Select Variables
fd_set ReadTestFDS;
@@ -148,12 +149,12 @@ protected:
fd_set WriteFDS;
// Configuration
int MaxFD;
timeval Timeout;
int MaxFD = 0;
timeval Timeout = {0,0};
// Output
CLogCore * Log;
EDebugLevel LogLevel;
CLogCore * Log = NULL;
EDebugLevel LogLevel = dlNone;
public:
// Life Cycle
@@ -185,10 +186,10 @@ class CSelectableBare : public CFunctionCore
{
protected:
// FDs
THandle * FirstHandle;
THandle * FirstHandle = NULL;
// Select interface
CSelect * Selector;
CSelect * Selector = NULL;
// Managing File Handles
bool RemoveHandle( THandle * Handle );
@@ -254,6 +255,7 @@ public:
// General port parameters
THandle * CreateHandle( const char * HandleName, bool CreateChannel );
virtual CDataMember * GetHandleAddress( THandle * Handle, const char * HandleRef );
bool SetCallback( THandle * Handle, EConnectState pState, FHandleCallback pCallback );
bool SetAutoManage( THandle * Handle, bool AutoManage, bool Persistent, int ReopenDelay = 0, int CloseTimeout = 0 );