Major update:

- Rename Function LocalIO -> Channel (Parameters & Methods)
This commit is contained in:
Charl Wentzel
2016-08-23 13:19:43 +02:00
parent 5ea05d119e
commit 7564e6a288
6 changed files with 146 additions and 147 deletions

View File

@@ -33,8 +33,8 @@ CFunctionCore::CFunctionCore( const char * FunctionName, CLogCore * pLog, EDebug
Name = NULL;
}
// IO Functions
FirstIO = NULL;
// Channels
FirstChannel = NULL;
// Output
Log = pLog;
@@ -48,42 +48,41 @@ CFunctionCore::CFunctionCore( const char * FunctionName, CLogCore * pLog, EDebug
CFunctionCore::~CFunctionCore()
{
TLocalIO * NextIO = NULL;
TLinkedIO * NextLinkedIO = NULL;
TChannel * NextChannel = NULL;
TChannelLink * NextLinkedChannel = NULL;
// Destroy IO
while (FirstIO)
// Destroy Channels
while (FirstChannel)
{
// Destroy Parameters
if (FirstIO->Name) {
free( FirstIO->Name );
if (FirstChannel->Name) {
free( FirstChannel->Name );
}
// Destroy Linked Inputs
while (FirstIO->FirstInput) {
if (FirstIO->FirstInput->IOName) {
free( FirstIO->FirstInput->IOName );
while (FirstChannel->FirstInput) {
if (FirstChannel->FirstInput->Name) {
free( FirstChannel->FirstInput->Name );
}
NextLinkedIO = FirstIO->FirstInput->Next;
free( FirstIO->FirstInput );
FirstIO->FirstInput = NextLinkedIO;
NextLinkedChannel = FirstChannel->FirstInput->Next;
free( FirstChannel->FirstInput );
FirstChannel->FirstInput = NextLinkedChannel;
}
// Destroy Linked Outputs
while (FirstIO->FirstOutput) {
if (FirstIO->FirstOutput->IOName) {
free( FirstIO->FirstOutput->IOName );
while (FirstChannel->FirstOutput) {
if (FirstChannel->FirstOutput->Name) {
free( FirstChannel->FirstOutput->Name );
}
NextLinkedIO = FirstIO->FirstOutput->Next;
free( FirstIO->FirstOutput );
FirstIO->FirstOutput = NextLinkedIO;
NextLinkedChannel = FirstChannel->FirstOutput->Next;
free( FirstChannel->FirstOutput );
FirstChannel->FirstOutput = NextLinkedChannel;
}
// Destroy Local IO
// Destroy Local IO
NextIO = FirstIO->Next;
free( FirstIO );
FirstIO = NextIO;
// Destroy Channel
NextChannel = FirstChannel->Next;
free( FirstChannel );
FirstChannel = NextChannel;
}
// Report status
@@ -97,116 +96,116 @@ CFunctionCore::~CFunctionCore()
}
//---------------------------------------------------------------------------
TLocalIO * CFunctionCore::AddLocalIO( const char * IOName )
TChannel * CFunctionCore::AddChannel( const char * ChannelName )
{
TLocalIO ** LocalIO = NULL;
TChannel ** Channel = NULL;
// Validate
if (!IOName) {
if (!ChannelName) {
return NULL;
}
// Check if exists
LocalIO = &FirstIO;
while (*LocalIO && strcmp( IOName, (*LocalIO)->Name )) {
LocalIO = &((*LocalIO)->Next);
Channel = &FirstChannel;
while (*Channel && strcmp( ChannelName, (*Channel)->Name )) {
Channel = &((*Channel)->Next);
}
// Create if not exist
if (!*LocalIO) {
if (!*Channel) {
// Create
*LocalIO = (TLocalIO*)malloc( sizeof(TLocalIO) );
memset( *LocalIO, 0, sizeof(TLocalIO) );
*Channel = (TChannel*)malloc( sizeof(TChannel) );
memset( *Channel, 0, sizeof(TChannel) );
// Set Name
(*LocalIO)->Name = (char*)malloc( strlen(IOName)+1 );
strcpy( (*LocalIO)->Name, IOName );
(*Channel)->Name = (char*)malloc( strlen(ChannelName)+1 );
strcpy( (*Channel)->Name, ChannelName );
// Log Event
if (Log) Log->Message( DebugLevel, dlLow, "%s: Local IO '%s' - Created", Name, IOName );
if (Log) Log->Message( DebugLevel, dlLow, "%s: Channel '%s' - Created", Name, ChannelName );
}
return *LocalIO;
return *Channel;
}
//---------------------------------------------------------------------------
// Automated Data Input/Output
bool CFunctionCore::AddInput( const char * IOName, CFunctionCore * OutFunction, const char * OutputName, bool Bidirectional )
bool CFunctionCore::LinkInputChannel( const char * ChannelName, CFunctionCore * OutFunction, const char * OutChannelName, bool Bidirectional )
{
TLocalIO * LocalIO = NULL;
TLinkedIO ** LinkedIO = NULL;
TChannel * Channel = NULL;
TChannelLink ** LinkedChannel = NULL;
// Get IO
if (!OutFunction || !OutFunction || !(LocalIO = GetLocalIO( IOName ))) {
// Get Channel
if (!OutFunction || !OutFunction || !(Channel = GetChannel( ChannelName ))) {
return false;
}
// Check if linked IO exists
LinkedIO = &(LocalIO->FirstInput);
while (*LinkedIO && (((*LinkedIO)->Function != OutFunction) || strcmp( (*LinkedIO)->IOName, OutputName ) )) {
LinkedIO = &((*LinkedIO)->Next);
// Check if linked Channel exists
LinkedChannel = &(Channel->FirstInput);
while (*LinkedChannel && (((*LinkedChannel)->Function != OutFunction) || strcmp( (*LinkedChannel)->Name, OutChannelName ) )) {
LinkedChannel = &((*LinkedChannel)->Next);
}
// Create if not found
if (!*LinkedIO)
if (!*LinkedChannel)
{
// Create
*LinkedIO = (TLinkedIO*)malloc( sizeof(TLinkedIO) );
memset( *LinkedIO, 0, sizeof( TLinkedIO ));
*LinkedChannel = (TChannelLink*)malloc( sizeof(TChannelLink) );
memset( *LinkedChannel, 0, sizeof( TChannelLink ));
// Set Parameters
(*LinkedIO)->Function = OutFunction;
(*LinkedIO)->IOName = (char*)malloc( strlen(OutputName)+1 );
strcpy( (*LinkedIO)->IOName, OutputName );
(*LinkedChannel)->Function = OutFunction;
(*LinkedChannel)->Name = (char*)malloc( strlen(OutChannelName)+1 );
strcpy( (*LinkedChannel)->Name, OutChannelName );
// Log Event
if (Log) Log->Message( DebugLevel, dlLow, "%s: Input Linked - '%s'/'%s' <-- '%s'/'%s'", Name, Name, IOName, OutFunction->GetName(), OutputName );
if (Log) Log->Message( DebugLevel, dlLow, "%s: Input Linked - '%s'/'%s' <-- '%s'/'%s'", Name, Name, ChannelName, OutFunction->GetName(), OutChannelName );
}
// Link Return direction as well
if (Bidirectional) {
return OutFunction->AddInput( OutputName, this, IOName, false );
return OutFunction->LinkInputChannel( OutChannelName, this, ChannelName, false );
}
return true;
}
//---------------------------------------------------------------------------
bool CFunctionCore::AddOutput( const char * IOName, CFunctionCore * InFunction, const char * InputName, bool Bidirectional )
bool CFunctionCore::LinkOutputChannel( const char * ChannelName, CFunctionCore * InFunction, const char * InChannelName, bool Bidirectional )
{
TLocalIO * LocalIO = NULL;
TLinkedIO ** LinkedIO = NULL;
TChannel * Channel = NULL;
TChannelLink ** LinkedChannel = NULL;
// Get IO
if (!InFunction || !InputName || !(LocalIO = GetLocalIO( IOName ))) {
// Get Channel
if (!InFunction || !InChannelName || !(Channel = GetChannel( ChannelName ))) {
return false;
}
// Check if linked IO exists
LinkedIO = &(LocalIO->FirstOutput);
while (*LinkedIO && (((*LinkedIO)->Function != InFunction) || strcmp( (*LinkedIO)->IOName, InputName ) )) {
LinkedIO = &((*LinkedIO)->Next);
// Check if linked Channel exists
LinkedChannel = &(Channel->FirstOutput);
while (*LinkedChannel && (((*LinkedChannel)->Function != InFunction) || strcmp( (*LinkedChannel)->Name, InChannelName ) )) {
LinkedChannel = &((*LinkedChannel)->Next);
}
// Create if not found
if (!*LinkedIO)
if (!*LinkedChannel)
{
// Create
*LinkedIO = (TLinkedIO*)malloc( sizeof(TLinkedIO) );
memset( *LinkedIO, 0, sizeof( TLinkedIO ));
*LinkedChannel = (TChannelLink*)malloc( sizeof(TChannelLink) );
memset( *LinkedChannel, 0, sizeof( TChannelLink ));
// Set Parameters
(*LinkedIO)->Function = InFunction;
(*LinkedIO)->IOName = (char*)malloc( strlen(InputName)+1 );
strcpy( (*LinkedIO)->IOName, InputName );
(*LinkedChannel)->Function = InFunction;
(*LinkedChannel)->Name = (char*)malloc( strlen(InChannelName)+1 );
strcpy( (*LinkedChannel)->Name, InChannelName );
// Log Event
if (Log) Log->Message( DebugLevel, dlLow, "%s: Output Linked - '%s'/'%s' --> '%s'/'%s'", Name, Name, IOName, InFunction->GetName(), InputName );
if (Log) Log->Message( DebugLevel, dlLow, "%s: Output Linked - '%s'/'%s' --> '%s'/'%s'", Name, Name, ChannelName, InFunction->GetName(), InChannelName );
}
// Link return direction as well
if (Bidirectional) {
return InFunction->AddOutput( InputName, this, IOName, false );
return InFunction->LinkOutputChannel( InChannelName, this, ChannelName, false );
}
return true;
@@ -214,77 +213,77 @@ bool CFunctionCore::AddOutput( const char * IOName, CFunctionCore * InFunction,
//---------------------------------------------------------------------------
// Manual Data Input/Output
int CFunctionCore::Input( const char * IOName, const char * Data, int MaxLen )
int CFunctionCore::Input( const char * ChannelName, const char * Data, int MaxLen )
{
TLocalIO * LocalIO = NULL;
TChannel * Channel = NULL;
// Validate
if (!IOName || !Data) {
if (!ChannelName || !Data) {
return 0;
}
else if (MaxLen == -1) {
MaxLen = strlen( Data );
}
// Get IO
if (!(LocalIO = GetLocalIO( IOName )))
// Get Channel
if (!(Channel = GetChannel( ChannelName )))
{
// Log event
if (Log) Log->Message( DebugLevel, dlHigh, "%s: Local IO '%s' - Input rejected, Local IO not found", Name, IOName );
if (Log) Log->Message( DebugLevel, dlHigh, "%s: Channel '%s' - Input rejected, Channel not found", Name, ChannelName );
return 0;
}
// Log event
if (Log) Log->Output( DebugLevel, dlHigh, OutputDisplay, Data, MaxLen, "%s: Local IO '%s' - IN:", Name, IOName );
if (Log) Log->Output( DebugLevel, dlHigh, OutputDisplay, Data, MaxLen, "%s: Channel '%s' - IN:", Name, ChannelName );
// Return processed bytes
return MaxLen;
}
//---------------------------------------------------------------------------
int CFunctionCore::Output( const char * IOName, const char * Data, int Len )
int CFunctionCore::Output( const char * ChanelName, const char * Data, int Len )
{
TLocalIO * LocalIO = NULL;
TChannel * Channel = NULL;
// Validate
if (!IOName || !Data) {
if (!ChanelName || !Data) {
return 0;
} else if (Len == -1) {
Len = strlen( Data );
}
// Get IO
if (!(LocalIO = GetLocalIO( IOName )))
// Get Channel
if (!(Channel = GetChannel( ChanelName )))
{
// Log Event
if (Log) Log->Message( DebugLevel, dlHigh, "%s: Local IO '%s' - Output rejected, Local IO not found", Name, IOName );
if (Log) Log->Message( DebugLevel, dlHigh, "%s: Channel '%s' - Output rejected, Channel not found", Name, ChanelName );
return 0;
}
// Return processed bytes
return Output( LocalIO, Data, Len );
return Output( Channel, Data, Len );
}
//---------------------------------------------------------------------------
int CFunctionCore::Output( const TLocalIO * LocalIO, const char * Data, int Len )
int CFunctionCore::Output( const TChannel * Channel, const char * Data, int Len )
{
TLinkedIO * Output = NULL;
TChannelLink * OutChannel = NULL;
// Validate
if (!LocalIO || !Data) {
if (!Channel || !Data) {
return 0;
} else if (Len == -1) {
Len = strlen( Data );
}
// Log event
if (Log) Log->Output( DebugLevel, dlHigh, OutputDisplay, Data, Len, "%s: Local IO '%s' - OUT:", Name, LocalIO->Name );
if (Log) Log->Output( DebugLevel, dlHigh, OutputDisplay, Data, Len, "%s: Channel '%s' - OUT:", Name, Channel->Name );
// Pass output to all linked inputs
Output = LocalIO->FirstOutput;
while (Output) {
Output->Function->Input( Output->IOName, Data, Len );
Output = Output->Next;
OutChannel = Channel->FirstOutput;
while (OutChannel) {
OutChannel->Function->Input( OutChannel->Name, Data, Len );
OutChannel = OutChannel->Next;
}
// Return processed bytes