Minor update: code compacting

This commit is contained in:
2022-07-22 11:56:19 +02:00
parent fd3738567a
commit 7dfdfdb4ce
10 changed files with 129 additions and 248 deletions

View File

@@ -45,8 +45,7 @@ CFunctionCore::~CFunctionCore()
TChannel * NextChannel = NULL;
// Destroy Channels
while (FirstChannel)
{
while (FirstChannel) {
// Destroy Linked Channels
while (FirstChannel->FirstLink)
UnlinkChannel( FirstChannel->Name, FirstChannel->FirstLink->Function->Name, FirstChannel->FirstLink->Channel->Name );
@@ -122,13 +121,10 @@ bool CFunctionCore::InitChannelLinks( CDataMember * LinkConfig )
// Process each Channel
ChannelMember = LinkConfig->GetFirstChild();
while (ChannelMember)
{
if ((Channel = GetChannel( ChannelMember->GetName() )))
{
while (ChannelMember) {
if ((Channel = GetChannel( ChannelMember->GetName() ))) {
FunctionMember = ChannelMember->GetElement( 0 );
while (FunctionMember)
{
while (FunctionMember) {
// Get Parameters
LinkChannel( Channel->Name,
FunctionMember->GetChStr( "Function", NULL, true ),
@@ -167,15 +163,13 @@ TChannel * CFunctionCore::AddChannel( const char * ChannelName, const EChannelSt
TChannel ** Channel = NULL;
// Validate
if (!ChannelName) {
if (!ChannelName)
return NULL;
}
// Check if exists
Channel = &FirstChannel;
while (*Channel && strcmp( ChannelName, (*Channel)->Name )) {
while (*Channel && strcmp( ChannelName, (*Channel)->Name ))
Channel = &((*Channel)->Next);
}
// Create if not exist
if (!*Channel) {
@@ -224,7 +218,6 @@ bool CFunctionCore::SetChannelInState( TChannel * Channel, const EChannelState S
LinkChannel = LinkChannel->Next;
}
return true;
}
//---------------------------------------------------------------------------
@@ -258,18 +251,14 @@ EChannelState CFunctionCore::GetChannelOutState( TChannel * Channel, const char
TChannelLink * LinkChannel = NULL;
// Validate
if (!Channel) {
if (!Channel)
return CH_off;
}
else if (!TargetRef || !*TargetRef) {
else if (!TargetRef || !*TargetRef)
return Channel->OutState;
}
else if ((LinkChannel = GetLinkChannel( Channel, TargetRef ))) {
else if ((LinkChannel = GetLinkChannel( Channel, TargetRef )))
return LinkChannel->Channel->InState;
}
else {
else
return CH_off;
}
}
//---------------------------------------------------------------------------
@@ -284,9 +273,8 @@ bool CFunctionCore::LinkChannel( const char * ChannelName, const char * LinkFunc
// Check if Channels & Function exist
if (!(Channel = GetChannel( ChannelName )) ||
!(LinkFunction = Application->GetFunction( LinkFunctionName )) ||
!(LinkChannel = LinkFunction->GetChannel( LinkChannelName )) ) {
!(LinkChannel = LinkFunction->GetChannel( LinkChannelName )) )
return false;
}
// Check if linked Channel exists
LinkedChannel = &(Channel->FirstLink);
@@ -344,9 +332,8 @@ bool CFunctionCore::UnlinkChannel( const char * ChannelName, const char * LinkFu
// Check if Channels & Function exist
if (!(Channel = GetChannel( ChannelName )) ||
!(LinkFunction = Application->GetFunction( LinkFunctionName )) ||
!(LinkChannel = LinkFunction->GetChannel( LinkChannelName )) ) {
!(LinkChannel = LinkFunction->GetChannel( LinkChannelName )) )
return false;
}
// Check if linked Channel exists
LinkedChannel = &(Channel->FirstLink);
@@ -388,9 +375,8 @@ int CFunctionCore::Input( const char * ChannelName, const char * SourceRef, cons
TChannel * Channel = NULL;
// Validate
if (!ChannelName || !*ChannelName || !Data) {
if (!ChannelName || !*ChannelName || !Data)
return 0;
}
// Get Channel
if (!(Channel = GetChannel( ChannelName ))) {
@@ -406,9 +392,9 @@ int CFunctionCore::Input( const char * ChannelName, const char * SourceRef, cons
}
// Return processed bytes
if (Len == -1) {
if (Len == -1)
Len = strlen( Data );
}
if (Log) Log->Output( LogLevel, dlHigh, LogOutput, Data, Len, "%s/%s: Channel '%s'->'%s' - IN:",
ProcessName, Name, ((SourceRef && *SourceRef)? SourceRef : "(Any)"), ChannelName );
return Len;
@@ -421,9 +407,8 @@ int CFunctionCore::Output( const char * ChannelName, const char * TargetRef, con
TChannel * Channel = NULL;
// Validate
if (!ChannelName || !*ChannelName) {
if (!ChannelName || !*ChannelName)
return 0;
}
// Get Channel
if (!(Channel = GetChannel( ChannelName ))) {
@@ -445,9 +430,8 @@ int CFunctionCore::Output( const TChannel * Channel, const char * TargetRef, con
int OutLen = 0;
// Validate
if (!Channel || !Data) {
if (!Channel || !Data)
return 0;
}
// Log event
if (Log) Log->Output( LogLevel, dlHigh, ((!OutputFormat)? LogOutput : OutputFormat), Data, Len, "%s/%s: Channel '%s'->'%s' - OUT:",