Important Update:
- Channels (FunctionCore & SelectableBare): - Added state "Standby", allow auto-managed handle to be opened - SelectableCore: - Set default "Persistent" state for sockets based on type - Remove Process() method (no different from SelectableBare - DateTimeCore: - Added BuildDateTimeStr() methods to build date for values - JSONparseCore: - Added error message to file operations
This commit is contained in:
@@ -114,6 +114,7 @@ bool CSelectableCore::Init( CDataMember * FunctionConfig )
|
||||
short Parity;
|
||||
short FlowCtrl;
|
||||
short Queue;
|
||||
bool Persitent;
|
||||
|
||||
// Call Previous load config
|
||||
if (!CFunctionCore::Init( FunctionConfig ))
|
||||
@@ -170,6 +171,7 @@ bool CSelectableCore::Init( CDataMember * FunctionConfig )
|
||||
SerialConfig->GetChInt( "DataBits", 8, true ),
|
||||
Parity, SerialConfig->GetChInt( "StopBits", 1, true ),
|
||||
FlowCtrl, SerialConfig->GetChInt( "DataWait", 0, true ));
|
||||
Persitent = true;
|
||||
}
|
||||
}
|
||||
else if (!strcasecmp( Type, "LinePrinter" ))
|
||||
@@ -180,6 +182,7 @@ bool CSelectableCore::Init( CDataMember * FunctionConfig )
|
||||
Address = (char*)HandleConfig->GetChStr( "Port/Address", NULL, true ); // Get default value
|
||||
}
|
||||
SetLinePrinterHandle( Handle, Address );
|
||||
Persitent = true;
|
||||
}
|
||||
else if (!strcasecmp( Type, "UNIXserver" ))
|
||||
{
|
||||
@@ -190,6 +193,7 @@ bool CSelectableCore::Init( CDataMember * FunctionConfig )
|
||||
}
|
||||
Queue = HandleConfig->GetChInt( "Socket/Queue", 2, true );
|
||||
SetUnixHandle( Handle, ctUNIXserver, Address, Queue );
|
||||
Persitent = true;
|
||||
}
|
||||
else if (!strcasecmp( Type, "UNIXclient" ))
|
||||
{
|
||||
@@ -199,69 +203,75 @@ bool CSelectableCore::Init( CDataMember * FunctionConfig )
|
||||
Address = (char*)HandleConfig->GetChStr( "Socket/Address", NULL, true ); // Get default Address value
|
||||
}
|
||||
SetUnixHandle( Handle, ctUNIXclient, Address, 0 );
|
||||
Persitent = false;
|
||||
}
|
||||
else if (!strcasecmp( Type, "UDPserver" ))
|
||||
{
|
||||
if ((Name = (char*)HandleConfig->GetChStr( "Socket/Name", NULL )) && (AddressDef = GetHandleAddress( Handle, Name ))) {
|
||||
Address = (char*)AddressDef->GetChStr( "Address", NULL, true ); // Get address list value
|
||||
Port = (char*)AddressDef->GetChStr( "Port", "0", true ); // Get AddressList Port value
|
||||
Port = (char*)AddressDef->GetChStr( "Port", "0", true ); // Get AddressList Port value
|
||||
} else {
|
||||
Address = (char*)HandleConfig->GetChStr( "Socket/Address", NULL, true ); // Get default Address value
|
||||
Port = (char*)HandleConfig->GetChStr( "Socket/Port", "0", true ); // Get default Port value
|
||||
Port = (char*)HandleConfig->GetChStr( "Socket/Port", "0", true ); // Get default Port value
|
||||
}
|
||||
SetSocketHandle( Handle, ctUDPserver, Address, strlcase(Port), 0 );
|
||||
Persitent = true;
|
||||
}
|
||||
else if (!strcasecmp( Type, "UDPclient" ))
|
||||
{
|
||||
if ((Name = (char*)HandleConfig->GetChStr( "Socket/Name", NULL )) && (AddressDef = GetHandleAddress( Handle, Name ))) {
|
||||
Address = (char*)AddressDef->GetChStr( "Address", NULL, true ); // Get address list value
|
||||
Port = (char*)AddressDef->GetChStr( "Port", "0", true ); // Get AddressList Port value
|
||||
Port = (char*)AddressDef->GetChStr( "Port", "0", true ); // Get AddressList Port value
|
||||
} else {
|
||||
Address = (char*)HandleConfig->GetChStr( "Socket/Address", NULL, true ); // Get default Address value
|
||||
Port = (char*)HandleConfig->GetChStr( "Socket/Port", "0", true ); // Get default Port value
|
||||
Port = (char*)HandleConfig->GetChStr( "Socket/Port", "0", true ); // Get default Port value
|
||||
}
|
||||
SetSocketHandle( Handle, ctUDPclient, Address, strlcase(Port), 0 );
|
||||
Persitent = false;
|
||||
}
|
||||
else if (!strcasecmp( Type, "TCPserver" ))
|
||||
{
|
||||
if ((Name = (char*)HandleConfig->GetChStr( "Socket/Name", NULL )) && (AddressDef = GetHandleAddress( Handle, Name ))) {
|
||||
Address = (char*)AddressDef->GetChStr( "Address", NULL, true ); // Get address list value
|
||||
Port = (char*)AddressDef->GetChStr( "Port", "0", true ); // Get AddressList Port value
|
||||
Port = (char*)AddressDef->GetChStr( "Port", "0", true ); // Get AddressList Port value
|
||||
} else {
|
||||
Address = (char*)HandleConfig->GetChStr( "Socket/Address", NULL, true ); // Get default Address value
|
||||
Port = (char*)HandleConfig->GetChStr( "Socket/Port", "0", true ); // Get default Port value
|
||||
Port = (char*)HandleConfig->GetChStr( "Socket/Port", "0", true ); // Get default Port value
|
||||
}
|
||||
Queue = HandleConfig->GetChInt( "Socket/Queue", 2, true );
|
||||
SetSocketHandle( Handle, ctTCPserver, Address, strlcase(Port), Queue );
|
||||
Persitent = true;
|
||||
}
|
||||
else if (!strcasecmp( Type, "TCPclient" ))
|
||||
{
|
||||
if ((Name = (char*)HandleConfig->GetChStr( "Socket/Name", NULL )) && (AddressDef = GetHandleAddress( Handle, Name ))) {
|
||||
Address = (char*)AddressDef->GetChStr( "Address", NULL, true ); // Get address list value
|
||||
Port = (char*)AddressDef->GetChStr( "Port", "0", true ); // Get AddressList Port value
|
||||
Port = (char*)AddressDef->GetChStr( "Port", "0", true ); // Get AddressList Port value
|
||||
} else {
|
||||
Address = (char*)HandleConfig->GetChStr( "Socket/Address", NULL, true ); // Get default Address value
|
||||
Port = (char*)HandleConfig->GetChStr( "Socket/Port", "0", true ); // Get default Port value
|
||||
Port = (char*)HandleConfig->GetChStr( "Socket/Port", "0", true ); // Get default Port value
|
||||
}
|
||||
SetSocketHandle( Handle, ctTCPclient, Address, strlcase(Port), 0 );
|
||||
Persitent = false;
|
||||
}
|
||||
else if (!strcasecmp( Type, "ForkPipe" )) {
|
||||
Address = (char*)HandleConfig->GetChStr( "Fork/ExecPath", NULL, true ); // Get default value
|
||||
SetForkPipeHandle( Handle, Address );
|
||||
Persitent = true;
|
||||
}
|
||||
|
||||
// Set Auto Manage
|
||||
SetAutoManage( Handle, HandleConfig->GetChBool( "AutoManage/Enabled", true, true ),
|
||||
HandleConfig->GetChBool( "AutoManage/Persistent", false, true ),
|
||||
HandleConfig->GetChInt( "AutoManage/ReopenDelay", 2000, true ),
|
||||
HandleConfig->GetChInt( "AutoManage/CloseTimeout", 2000, true ));
|
||||
SetAutoManage( Handle, HandleConfig->GetChBool( "AutoManage/Enabled", true, true ),
|
||||
HandleConfig->GetChBool( "AutoManage/Persistent", Persitent, true ),
|
||||
HandleConfig->GetChInt( "AutoManage/ReopenDelay", 2000, true ),
|
||||
HandleConfig->GetChInt( "AutoManage/CloseTimeout", 2000, true ));
|
||||
|
||||
// Input buffer
|
||||
SetInBuffer( Handle, HandleConfig->GetChInt( "InputBuffer/Size", 0 ),
|
||||
HandleConfig->GetChInt( "InputBuffer/Timeout", 250 ),
|
||||
HandleConfig->GetChStr( "InputBuffer/Marker", "" ),
|
||||
HandleConfig->GetChInt( "InputBuffer/MarkerLen", 0 ) );
|
||||
SetOutBuffer( Handle, HandleConfig->GetChInt( "OutputBuffer/Size", 0 ) );
|
||||
SetInBuffer( Handle, HandleConfig->GetChInt( "InputBuffer/Size", 0 ),
|
||||
HandleConfig->GetChInt( "InputBuffer/Timeout", 250 ),
|
||||
HandleConfig->GetChStr( "InputBuffer/Marker", "" ),
|
||||
HandleConfig->GetChInt( "InputBuffer/MarkerLen", 0 ) );
|
||||
SetOutBuffer( Handle, HandleConfig->GetChInt( "OutputBuffer/Size", 0 ) );
|
||||
|
||||
// Next
|
||||
HandleConfig = HandleConfig->GetNextPeer();
|
||||
@@ -2330,51 +2340,6 @@ int CSelectableCore::OutputHandle( THandle * Handle, const char * Data, int Len
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool CSelectableCore::Process()
|
||||
{
|
||||
THandle * Handle = NULL;
|
||||
|
||||
// Process all Handles
|
||||
Handle = FirstHandle;
|
||||
while (Handle)
|
||||
{
|
||||
// Auto manage handles
|
||||
if (Handle->State == csPrepared) {
|
||||
// Proceed to open
|
||||
Open( Handle );
|
||||
}
|
||||
else if ((Handle->State != csOpen) && Handle->AutoManage && Handle->Persistent) {
|
||||
// Try to re-open port after delay
|
||||
if (Timeout( Handle->LastAction, Handle->ReopenDelay )) {
|
||||
Open( Handle );
|
||||
}
|
||||
}
|
||||
|
||||
// Check Input buffers
|
||||
if (Handle->InBuffer && (Handle->InBuffer->Len() > 0)) {
|
||||
// Check duration since last PortIn
|
||||
if (Timeout( Handle->InStart, Handle->InTimeout )) {
|
||||
// Process Input
|
||||
ProcessInputBuffer( Handle, true );
|
||||
|
||||
// Reset timer
|
||||
ClearStartTime( &(Handle->InStart) );
|
||||
}
|
||||
}
|
||||
|
||||
// Check for auto close (but not on servers)
|
||||
if ((Handle->State == csOpen) && Handle->AutoManage && !Handle->Persistent && (Handle->Type != ctTCPserver) && (Handle->Type != ctUNIXserver)) {
|
||||
// Close port after timeout
|
||||
if (Timeout( Handle->LastAction, Handle->CloseTimeout )) {
|
||||
Close( Handle, true );
|
||||
}
|
||||
}
|
||||
Handle = Handle->Next;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
// Set serial port configuration parameters
|
||||
bool CSelectableCore::WriteSerialConfig( THandle * Handle )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user