Major update:
- General bug fixes - Implement search for multi-character marker search in BufferCore Replaced FindChar() method with FindStr() method - Implemented LocalIO and LinkedIO in FunctionCore - Connect LocalIO with FD in SelectableCore - Implement Write buffer with Write Select in SelectableCore - Improve validation checks in SelectableCore - Use Handle ptr instead of Handle Names for Config methods
This commit is contained in:
169
FunctionCore.cpp
169
FunctionCore.cpp
@@ -30,42 +30,193 @@ CFunctionCore::CFunctionCore( const char * FunctionName )
|
||||
}
|
||||
|
||||
// IO Functions
|
||||
OutFunction = NULL;
|
||||
FirstIO = NULL;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
CFunctionCore::~CFunctionCore()
|
||||
{
|
||||
TLocalIO * NextIO = NULL;
|
||||
TLinkedIO * NextLinkedIO = NULL;
|
||||
|
||||
// Destroy pointers
|
||||
if (Name) {
|
||||
free( Name );
|
||||
}
|
||||
|
||||
// Destroy IO
|
||||
while (FirstIO)
|
||||
{
|
||||
// Destroy Parameters
|
||||
if (FirstIO->Name) {
|
||||
free( FirstIO->Name );
|
||||
}
|
||||
|
||||
// Destroy Linked Inputs
|
||||
while (FirstIO->FirstInput) {
|
||||
if (FirstIO->FirstInput->IOName) {
|
||||
free( FirstIO->FirstInput->IOName );
|
||||
}
|
||||
NextLinkedIO = FirstIO->FirstInput->Next;
|
||||
free( FirstIO->FirstInput );
|
||||
FirstIO->FirstInput = NextLinkedIO;
|
||||
}
|
||||
|
||||
// Destroy Linked Outputs
|
||||
while (FirstIO->FirstOutput) {
|
||||
if (FirstIO->FirstOutput->IOName) {
|
||||
free( FirstIO->FirstOutput->IOName );
|
||||
}
|
||||
NextLinkedIO = FirstIO->FirstOutput->Next;
|
||||
free( FirstIO->FirstOutput );
|
||||
FirstIO->FirstOutput = NextLinkedIO;
|
||||
}
|
||||
|
||||
// Destroy Local IO
|
||||
// Destroy Local IO
|
||||
NextIO = FirstIO->Next;
|
||||
free( FirstIO );
|
||||
FirstIO = NextIO;
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
TLocalIO * CFunctionCore::AddLocalIO( const char * IOName )
|
||||
{
|
||||
TLocalIO ** LocalIO = NULL;
|
||||
|
||||
// Validate
|
||||
if (!IOName) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Check if exists
|
||||
LocalIO = &FirstIO;
|
||||
while (*LocalIO && strcmp( IOName, (*LocalIO)->Name )) {
|
||||
LocalIO = &((*LocalIO)->Next);
|
||||
}
|
||||
|
||||
// Create if not exist
|
||||
if (!*LocalIO) {
|
||||
// Create
|
||||
*LocalIO = (TLocalIO*)malloc( sizeof(TLocalIO) );
|
||||
memset( *LocalIO, 0, sizeof(TLocalIO) );
|
||||
|
||||
// Set Name
|
||||
(*LocalIO)->Name = (char*)malloc( strlen(IOName)+1 );
|
||||
strcpy( (*LocalIO)->Name, IOName );
|
||||
}
|
||||
|
||||
return *LocalIO;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
// Manual Data Input/Output
|
||||
int CFunctionCore::Input( int InputID, const char * Buffer, int MaxLen )
|
||||
int CFunctionCore::Input( const char * IOName, const char * Buffer, int MaxLen )
|
||||
{
|
||||
return 0;
|
||||
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( int OutputID, const char * Buffer, int Len )
|
||||
int CFunctionCore::Output( const char * IOName, const char * Buffer, int Len )
|
||||
{
|
||||
return 0;
|
||||
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( int InputID, CFunctionCore * OutFunction, int OutputID )
|
||||
bool CFunctionCore::AddInput( const char * IOName, CFunctionCore * OutFunction, const char * OutputName )
|
||||
{
|
||||
return false;
|
||||
TLocalIO * LocalIO = NULL;
|
||||
TLinkedIO ** LinkedIO = NULL;
|
||||
|
||||
// Get IO
|
||||
if (!(LocalIO = GetLocalIO( IOName ))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if linked IO exists
|
||||
LinkedIO = &(LocalIO->FirstInput);
|
||||
while (*LinkedIO && (((*LinkedIO)->Function != OutFunction) || strcmp( (*LinkedIO)->IOName, OutputName ) )) {
|
||||
LinkedIO = &((*LinkedIO)->Next);
|
||||
}
|
||||
|
||||
// Create if not found
|
||||
if (!*LinkedIO)
|
||||
{
|
||||
// Create
|
||||
*LinkedIO = (TLinkedIO*)malloc( sizeof(TLinkedIO) );
|
||||
memset( *LinkedIO, 0, sizeof( TLinkedIO ));
|
||||
|
||||
// Set Parameters
|
||||
(*LinkedIO)->Function = OutFunction;
|
||||
(*LinkedIO)->IOName = (char*)malloc( strlen(OutputName)+1 );
|
||||
strcpy( (*LinkedIO)->IOName, OutputName );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool CFunctionCore::AddOutput( int OutputID, CFunctionCore * InFunction, int InputID )
|
||||
bool CFunctionCore::AddOutput( const char * IOName, CFunctionCore * InFunction, const char * InputName )
|
||||
{
|
||||
OutFunction = InFunction;
|
||||
TLocalIO * LocalIO = NULL;
|
||||
TLinkedIO ** LinkedIO = NULL;
|
||||
|
||||
// Get IO
|
||||
if (!(LocalIO = GetLocalIO( IOName ))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if linked IO exists
|
||||
LinkedIO = &(LocalIO->FirstOutput);
|
||||
while (*LinkedIO && (((*LinkedIO)->Function != InFunction) || strcmp( (*LinkedIO)->IOName, InputName ) )) {
|
||||
LinkedIO = &((*LinkedIO)->Next);
|
||||
}
|
||||
|
||||
// Create if not found
|
||||
if (!*LinkedIO)
|
||||
{
|
||||
// Create
|
||||
*LinkedIO = (TLinkedIO*)malloc( sizeof(TLinkedIO) );
|
||||
memset( *LinkedIO, 0, sizeof( TLinkedIO ));
|
||||
|
||||
// Set Parameters
|
||||
(*LinkedIO)->Function = InFunction;
|
||||
(*LinkedIO)->IOName = (char*)malloc( strlen(InputName)+1 );
|
||||
strcpy( (*LinkedIO)->IOName, InputName );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user