Major update:
- DataTreeCore:
- Bug fix: GetMember() error if member not found
- FunctionCore: (affected: SelectableCore, FileCore, WatchdogCore)
- Made destructor virual
- Standardize method parameter naming, e.g. pName, pLog
- Renamed parameters: DebugLevel -> LogLevel, OutputDisplay -> LogOutput
- Reinstated parameter BaseMember
- Removed logging parameters from constructor
- Created method InitLoggging() (shows "Function Created" message)
- Split LoadConfig() method into parts:
- Implemented public LoadConfig() methods
- Implemented LoadConfigData() method, load parameters from DataTree
- WatchdogCore:
- Derive from CSelectableCore instead of CFunctionCore
- Rename parameter: PingTimeout -> PingInterval
- Replace Ping Channel with Handle only
- Add method SetInterval()
- Send command direct to handle with (channel) Input()
- SelectableCore:
- Rename parameters: Auto -> AutoManage, ReopenTimeout -> ReopenDelay
- Implemented own virtual LoadConfigData() method
- DeviceCore:
- Made all logging conditional: if (Log) Log->Message(...)
- SelectCore:
- Renamed parameters: DebugLevel -> LogLevel
This commit is contained in:
133
FunctionCore.cpp
133
FunctionCore.cpp
@@ -22,12 +22,12 @@ extern char * ProcessName;
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
// Life cycle
|
||||
CFunctionCore::CFunctionCore( const char * FunctionName, CLogCore * pLog, EDebugLevel pDebugLevel, int pOuputDisplay )
|
||||
CFunctionCore::CFunctionCore( const char * pName, CLogCore * pLog )
|
||||
{
|
||||
// Set name
|
||||
if (FunctionName) {
|
||||
Name = (char*)malloc( strlen(FunctionName)+1 );
|
||||
strcpy( Name, FunctionName );
|
||||
if (pName) {
|
||||
Name = (char*)malloc( strlen(pName)+1 );
|
||||
strcpy( Name, pName );
|
||||
}
|
||||
else {
|
||||
Name = NULL;
|
||||
@@ -35,17 +35,15 @@ CFunctionCore::CFunctionCore( const char * FunctionName, CLogCore * pLog, EDebug
|
||||
|
||||
// Data Tree
|
||||
DataTree = NULL;
|
||||
BaseMember = NULL;
|
||||
|
||||
// Channels
|
||||
FirstChannel = NULL;
|
||||
|
||||
// Output
|
||||
Log = pLog;
|
||||
OutputDisplay = pOuputDisplay;
|
||||
DebugLevel = pDebugLevel;
|
||||
|
||||
// Report status
|
||||
if (Log) Log->Message( DebugLevel, dlLow, "%s: Function '%s' - Created", ProcessName, FunctionName );
|
||||
LogLevel = dlNone;
|
||||
LogOutput = OUT_NORMAL;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
@@ -89,7 +87,7 @@ CFunctionCore::~CFunctionCore()
|
||||
}
|
||||
|
||||
// Report status
|
||||
if (Log) Log->Message( DebugLevel, dlLow, "%s: Function '%s' - Destroyed", ProcessName, Name );
|
||||
if (Log) Log->Message( LogLevel, dlLow, "%s: Function '%s' - Destroyed", ProcessName, Name );
|
||||
|
||||
// Destroy Name
|
||||
if (Name) {
|
||||
@@ -100,20 +98,107 @@ CFunctionCore::~CFunctionCore()
|
||||
|
||||
bool CFunctionCore::LoadConfig( CDataTree * pDataTree, const char * pBasePath )
|
||||
{
|
||||
TDataMember * BaseMember;
|
||||
|
||||
// Validate
|
||||
if (!(DataTree = pDataTree) ||
|
||||
!(BaseMember = DataTree->GetMember( NULL, pBasePath, true )))
|
||||
if (!(DataTree = pDataTree) || !(BaseMember = DataTree->GetMember( NULL, pBasePath, true )))
|
||||
return false;
|
||||
|
||||
// Load configuration
|
||||
LoadConfigData();
|
||||
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool CFunctionCore::LoadConfig( CDataTree * pDataTree, TDataMember * pBaseMember )
|
||||
{
|
||||
// Validate
|
||||
if (!(DataTree = pDataTree) || !(BaseMember = pBaseMember ))
|
||||
return false;
|
||||
|
||||
// Load configuration
|
||||
LoadConfigData();
|
||||
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool CFunctionCore::LoadConfigData()
|
||||
{
|
||||
TDataMember * TempMember;
|
||||
char * TempStr;
|
||||
|
||||
// Set Name
|
||||
Name = (char*)malloc( strlen(BaseMember->Name)+1 );
|
||||
strcpy( Name, BaseMember->Name );
|
||||
|
||||
// Get debug level
|
||||
LogLevel = dlNone;
|
||||
TempStr = (char*)DataTree->GetStr( BaseMember, "Log/Level", "Medium", true );
|
||||
if (!strcasecmp( TempStr, "Low" ))
|
||||
LogLevel = dlLow;
|
||||
else if (!strcasecmp( TempStr, "Medium" ))
|
||||
LogLevel = dlMedium;
|
||||
else if (!strcasecmp( TempStr, "High" ))
|
||||
LogLevel = dlHigh;
|
||||
|
||||
// Set debug output
|
||||
LogOutput = 0;
|
||||
TempMember = DataTree->GetMember( BaseMember, "Log/Output[0]", true );
|
||||
while (TempMember)
|
||||
{
|
||||
if (!strcasecmp( TempMember->Value, "Normal"))
|
||||
LogOutput |= OUT_NORMAL;
|
||||
else if (!strcasecmp( TempMember->Value, "Bin"))
|
||||
LogOutput |= OUT_BIN;
|
||||
else if (!strcasecmp( TempMember->Value, "Hex"))
|
||||
LogOutput |= OUT_HEX;
|
||||
else if (!strcasecmp( TempMember->Value, "Count"))
|
||||
LogOutput |= OUT_COUNT;
|
||||
else if (!strcasecmp( TempMember->Value, "AsIs"))
|
||||
LogOutput |= OUT_ASIS;
|
||||
else if (!strcasecmp( TempMember->Value, "CRLF"))
|
||||
LogOutput |= OUT_CRLF;
|
||||
|
||||
// Next
|
||||
TempMember = DataTree->GetNextChild( TempMember );
|
||||
}
|
||||
|
||||
// Set Logging
|
||||
InitLogging( LogLevel, LogOutput );
|
||||
|
||||
// Set debug output
|
||||
FirstChannel = NULL;
|
||||
TempMember = DataTree->GetFirstChild( DataTree->GetMember( BaseMember, "Channels", true ) );
|
||||
while (TempMember)
|
||||
{
|
||||
AddChannel( DataTree->GetStr( TempMember, "Name" ),
|
||||
DataTree->GetBool( TempMember, "InputEnabled", true, true ),
|
||||
DataTree->GetBool( TempMember, "OutputEnabled", false, true ));
|
||||
|
||||
// Next
|
||||
TempMember = DataTree->GetNextChild( TempMember );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool CFunctionCore::InitLogging( EDebugLevel pDebugLevel, int pOutputDisplay )
|
||||
{
|
||||
// Output
|
||||
LogLevel = pDebugLevel;
|
||||
LogOutput = pOutputDisplay;
|
||||
|
||||
// Report status
|
||||
if (Log) Log->Message( LogLevel, dlLow, "%s: Function '%s' - Created", ProcessName, Name );
|
||||
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool CFunctionCore::SetDebugLevel( EDebugLevel pDebugLevel )
|
||||
{
|
||||
DebugLevel = pDebugLevel;
|
||||
LogLevel = pDebugLevel;
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
@@ -144,7 +229,7 @@ TChannel * CFunctionCore::AddChannel( const char * ChannelName, const bool pInpu
|
||||
strcpy( (*Channel)->Name, ChannelName );
|
||||
|
||||
// Log Event
|
||||
if (Log) Log->Message( DebugLevel, dlLow, "%s: Channel '%s' - Created", Name, ChannelName );
|
||||
if (Log) Log->Message( LogLevel, dlLow, "%s: Channel '%s' - Created", Name, ChannelName );
|
||||
}
|
||||
|
||||
// Set parameters
|
||||
@@ -185,7 +270,7 @@ bool CFunctionCore::LinkInputChannel( const char * ChannelName, CFunctionCore *
|
||||
strcpy( (*LinkedChannel)->Name, OutChannelName );
|
||||
|
||||
// Log Event
|
||||
if (Log) Log->Message( DebugLevel, dlLow, "%s: Input Linked - '%s'/'%s' <-- '%s'/'%s'", Name, Name, ChannelName, OutFunction->GetName(), OutChannelName );
|
||||
if (Log) Log->Message( LogLevel, dlLow, "%s: Input Linked - '%s'/'%s' <-- '%s'/'%s'", Name, Name, ChannelName, OutFunction->GetName(), OutChannelName );
|
||||
}
|
||||
|
||||
// Link Return direction as well
|
||||
@@ -226,7 +311,7 @@ bool CFunctionCore::LinkOutputChannel( const char * ChannelName, CFunctionCore *
|
||||
strcpy( (*LinkedChannel)->Name, InChannelName );
|
||||
|
||||
// Log Event
|
||||
if (Log) Log->Message( DebugLevel, dlLow, "%s: Output Linked - '%s'/'%s' --> '%s'/'%s'", Name, Name, ChannelName, InFunction->GetName(), InChannelName );
|
||||
if (Log) Log->Message( LogLevel, dlLow, "%s: Output Linked - '%s'/'%s' --> '%s'/'%s'", Name, Name, ChannelName, InFunction->GetName(), InChannelName );
|
||||
}
|
||||
|
||||
// Link return direction as well
|
||||
@@ -251,12 +336,12 @@ int CFunctionCore::Input( const char * ChannelName, const char * Data, int MaxLe
|
||||
// Get Channel
|
||||
if (!(Channel = GetChannel( ChannelName ))) {
|
||||
// Channel not found
|
||||
if (Log) Log->Message( DebugLevel, dlHigh, "%s: Channel '%s' - Input rejected, Channel not found", Name, ChannelName );
|
||||
if (Log) Log->Message( LogLevel, dlHigh, "%s: Channel '%s' - Input rejected, Channel not found", Name, ChannelName );
|
||||
return 0;
|
||||
}
|
||||
else if (!Channel->InputEnabled) {
|
||||
// Channel disabled
|
||||
if (Log) Log->Message( DebugLevel, dlHigh, "%s: Channel '%s' - Input rejected, Channel input disabled", Name, ChannelName );
|
||||
if (Log) Log->Message( LogLevel, dlHigh, "%s: Channel '%s' - Input rejected, Channel input disabled", Name, ChannelName );
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
@@ -264,7 +349,7 @@ int CFunctionCore::Input( const char * ChannelName, const char * Data, int MaxLe
|
||||
if (MaxLen == -1) {
|
||||
MaxLen = strlen( Data );
|
||||
}
|
||||
if (Log) Log->Output( DebugLevel, dlHigh, OutputDisplay, Data, MaxLen, "%s: Channel '%s' - IN:", Name, ChannelName );
|
||||
if (Log) Log->Output( LogLevel, dlHigh, LogOutput, Data, MaxLen, "%s: Channel '%s' - IN:", Name, ChannelName );
|
||||
return MaxLen;
|
||||
}
|
||||
}
|
||||
@@ -281,7 +366,7 @@ int CFunctionCore::Output( const char * ChannelName, const char * Data, int Len
|
||||
|
||||
// Get Channel
|
||||
if (!(Channel = GetChannel( ChannelName ))) {
|
||||
if (Log) Log->Message( DebugLevel, dlHigh, "%s: Channel '%s' - Output rejected, Channel not found", Name, ChannelName );
|
||||
if (Log) Log->Message( LogLevel, dlHigh, "%s: Channel '%s' - Output rejected, Channel not found", Name, ChannelName );
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
@@ -302,12 +387,12 @@ int CFunctionCore::Output( const TChannel * Channel, const char * Data, int Len
|
||||
|
||||
// Check if enabled
|
||||
if (!Channel->OutputEnabled) {
|
||||
if (Log) Log->Message( DebugLevel, dlHigh, "%s: Channel '%s' - Output rejected, Channel output disabled", Name, Channel->Name );
|
||||
if (Log) Log->Message( LogLevel, dlHigh, "%s: Channel '%s' - Output rejected, Channel output disabled", Name, Channel->Name );
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Log event
|
||||
if (Log) Log->Output( DebugLevel, dlHigh, OutputDisplay, Data, Len, "%s: Channel '%s' - OUT:", Name, Channel->Name );
|
||||
if (Log) Log->Output( LogLevel, dlHigh, LogOutput, Data, Len, "%s: Channel '%s' - OUT:", Name, Channel->Name );
|
||||
|
||||
// Pass output to all linked inputs
|
||||
if (Len == -1) {
|
||||
|
||||
Reference in New Issue
Block a user