Major Update:

- Implemented global var DebugLevel
- Update LogCore to check DebugLevel
- Added many log messages and standadised all log messages
- Further improved validation checks on all methods
- Updated SelectCore, only remove SelectHandle from list during Test()
- Close Handles in SelectableCore destructor
Bug fixes:
- Non-blocking Client Socket Connection now working correctly
- Remove FD from Select lists at the correct time
This commit is contained in:
Charl Wentzel
2016-05-26 15:03:13 +02:00
parent 9ace97c1a3
commit c01c8f5e9b
8 changed files with 532 additions and 235 deletions

View File

@@ -17,6 +17,11 @@
//---------------------------------------------------------------------------
extern char ProcessName[];
extern char LogStr[]; // Access to global temporary log messages string
//---------------------------------------------------------------------------
// Life cycle
CFunctionCore::CFunctionCore( const char * FunctionName )
{
@@ -31,6 +36,10 @@ CFunctionCore::CFunctionCore( const char * FunctionName )
// IO Functions
FirstIO = NULL;
// Report status
sprintf( LogStr, "Function '%s' - Created", FunctionName );
LogMessage( ProcessName, dlLow, LogStr );
}
//---------------------------------------------------------------------------
@@ -39,11 +48,6 @@ CFunctionCore::~CFunctionCore()
TLocalIO * NextIO = NULL;
TLinkedIO * NextLinkedIO = NULL;
// Destroy pointers
if (Name) {
free( Name );
}
// Destroy IO
while (FirstIO)
{
@@ -78,6 +82,16 @@ CFunctionCore::~CFunctionCore()
free( FirstIO );
FirstIO = NextIO;
}
// Report status
sprintf( LogStr, "Function '%s' - Destroyed", Name );
LogMessage( ProcessName, dlLow, LogStr );
// Destroy Name
if (Name) {
free( Name );
}
}
//---------------------------------------------------------------------------
@@ -105,56 +119,16 @@ TLocalIO * CFunctionCore::AddLocalIO( const char * IOName )
// Set Name
(*LocalIO)->Name = (char*)malloc( strlen(IOName)+1 );
strcpy( (*LocalIO)->Name, IOName );
// Log Event
sprintf( LogStr, "Local IO '%s' - Created", IOName );
LogMessage( Name, dlMedium, LogStr );
}
return *LocalIO;
}
//---------------------------------------------------------------------------
// Manual Data Input/Output
int CFunctionCore::Input( const char * IOName, const char * Buffer, int MaxLen )
{
TLocalIO * LocalIO = NULL;
// Validate
if (!IOName || !Buffer) {
return 0;
}
else if (MaxLen == -1) {
MaxLen = strlen( Buffer );
}
// Get IO
if (!(LocalIO = GetLocalIO( IOName ))) {
return 0;
}
// Do something and acknowledge size received
return MaxLen;
}
//---------------------------------------------------------------------------
int CFunctionCore::Output( const char * IOName, const char * Buffer, int Len )
{
TLocalIO * LocalIO = NULL;
// Validate
if (!IOName || !Buffer) {
return 0;
} else if (Len == -1) {
Len = strlen( Buffer );
}
// Get IO
if (!(LocalIO = GetLocalIO( IOName ))) {
return 0;
}
// Do something and acknowledge size received
return Len;
}
//---------------------------------------------------------------------------
// Automated Data Input/Output
bool CFunctionCore::AddInput( const char * IOName, CFunctionCore * OutFunction, const char * OutputName )
{
@@ -162,7 +136,7 @@ bool CFunctionCore::AddInput( const char * IOName, CFunctionCore * OutFunction,
TLinkedIO ** LinkedIO = NULL;
// Get IO
if (!(LocalIO = GetLocalIO( IOName ))) {
if (!OutFunction || !OutFunction || !(LocalIO = GetLocalIO( IOName ))) {
return false;
}
@@ -183,6 +157,10 @@ bool CFunctionCore::AddInput( const char * IOName, CFunctionCore * OutFunction,
(*LinkedIO)->Function = OutFunction;
(*LinkedIO)->IOName = (char*)malloc( strlen(OutputName)+1 );
strcpy( (*LinkedIO)->IOName, OutputName );
// Log Event
sprintf( LogStr, "Input Linked - '%s'/'%s' <-- '%s'/'%s'", Name, IOName, OutFunction->GetName(), OutputName );
LogMessage( Name, dlMedium, LogStr );
}
return true;
@@ -195,7 +173,7 @@ bool CFunctionCore::AddOutput( const char * IOName, CFunctionCore * InFunction,
TLinkedIO ** LinkedIO = NULL;
// Get IO
if (!(LocalIO = GetLocalIO( IOName ))) {
if (!InFunction || !InputName || !(LocalIO = GetLocalIO( IOName ))) {
return false;
}
@@ -216,10 +194,73 @@ bool CFunctionCore::AddOutput( const char * IOName, CFunctionCore * InFunction,
(*LinkedIO)->Function = InFunction;
(*LinkedIO)->IOName = (char*)malloc( strlen(InputName)+1 );
strcpy( (*LinkedIO)->IOName, InputName );
}
// Log Event
sprintf( LogStr, "Output Linked - '%s'/'%s' --> '%s'/'%s'", Name, IOName, InFunction->GetName(), InputName );
LogMessage( Name, dlMedium, LogStr );
}
return true;
}
//---------------------------------------------------------------------------
// Manual Data Input/Output
int CFunctionCore::Input( const char * IOName, const char * Data, int MaxLen )
{
TLocalIO * LocalIO = NULL;
// Validate
if (!IOName || !Data) {
return 0;
}
else if (MaxLen == -1) {
MaxLen = strlen( Data );
}
// Get IO
if (!(LocalIO = GetLocalIO( IOName )))
{
// Log event
sprintf( LogStr, "%s: Local IO '%s' - Input rejected, Local IO not found", Name, IOName );
LogMessage( Name, dlMedium, LogStr );
return 0;
}
// Log event
sprintf( LogStr, "%s: Local IO '%s' - IN:", Name, IOName );
ShowOutput( LogStr, dlMedium, OUT_NORMAL, Data, MaxLen );
// Return processed bytes
return MaxLen;
}
//---------------------------------------------------------------------------
int CFunctionCore::Output( const char * IOName, const char * Data, int Len )
{
TLocalIO * LocalIO = NULL;
// Validate
if (!IOName || !Data) {
return 0;
} else if (Len == -1) {
Len = strlen( Data );
}
// Get IO
if (!(LocalIO = GetLocalIO( IOName )))
{
// Log Event
sprintf( LogStr, "%s: Local IO '%s' - Output rejected, Local IO not found", Name, IOName );
LogMessage( Name, dlMedium, LogStr );
return 0;
}
// Log event
sprintf( LogStr, "%s: Local IO '%s' - OUT:", Name, IOName );
ShowOutput( LogStr, dlMedium, OUT_NORMAL, Data, Len );
// Return processed bytes
return Len;
}
//---------------------------------------------------------------------------