Important Update:

- SelectableCore:
  - Made GetType() & GetState() public methods
  - Update logs in Input()
- FunctionCore:
  - Add Input/OutputEnabled parameters with Get/Set methods.
  - Update logging in Input() and Output()
  - Check if input/output enabled in Input() and Output()
This commit is contained in:
Charl Wentzel
2017-07-05 10:59:24 +02:00
parent c50d920f94
commit 748b62d235
4 changed files with 88 additions and 48 deletions

View File

@@ -110,7 +110,7 @@ bool CFunctionCore::LoadConfig( CDataTree * pDataTree, const char * pBasePath )
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
TChannel * CFunctionCore::AddChannel( const char * ChannelName ) TChannel * CFunctionCore::AddChannel( const char * ChannelName, const bool pInputEnable, const bool pOutputEnable )
{ {
TChannel ** Channel = NULL; TChannel ** Channel = NULL;
@@ -139,6 +139,10 @@ TChannel * CFunctionCore::AddChannel( const char * ChannelName )
if (Log) Log->Message( DebugLevel, dlLow, "%s: Channel '%s' - Created", Name, ChannelName ); if (Log) Log->Message( DebugLevel, dlLow, "%s: Channel '%s' - Created", Name, ChannelName );
} }
// Set parameters
(*Channel)->InputEnabled = pInputEnable;
(*Channel)->OutputEnabled = pOutputEnable;
return *Channel; return *Channel;
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@@ -235,47 +239,47 @@ int CFunctionCore::Input( const char * ChannelName, const char * Data, int MaxLe
if (!ChannelName || !Data) { if (!ChannelName || !Data) {
return 0; return 0;
} }
else if (MaxLen == -1) {
MaxLen = strlen( Data );
}
// Get Channel // Get Channel
if (!(Channel = GetChannel( ChannelName ))) if (!(Channel = GetChannel( ChannelName ))) {
{ // Channel not found
// Log event
if (Log) Log->Message( DebugLevel, dlHigh, "%s: Channel '%s' - Input rejected, Channel not found", Name, ChannelName ); if (Log) Log->Message( DebugLevel, dlHigh, "%s: Channel '%s' - Input rejected, Channel not found", Name, ChannelName );
return 0; return 0;
} }
else if (!Channel->InputEnabled) {
// Log event // Channel disabled
if (Log) Log->Output( DebugLevel, dlHigh, OutputDisplay, Data, MaxLen, "%s: Channel '%s' - IN:", Name, ChannelName ); if (Log) Log->Message( DebugLevel, dlHigh, "%s: Channel '%s' - Input rejected, Channel input disabled", Name, ChannelName );
return 0;
// Return processed bytes }
return MaxLen; else {
// Return processed bytes
if (MaxLen == -1) {
MaxLen = strlen( Data );
}
if (Log) Log->Output( DebugLevel, dlHigh, OutputDisplay, Data, MaxLen, "%s: Channel '%s' - IN:", Name, ChannelName );
return MaxLen;
}
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
int CFunctionCore::Output( const char * ChanelName, const char * Data, int Len ) int CFunctionCore::Output( const char * ChannelName, const char * Data, int Len )
{ {
TChannel * Channel = NULL; TChannel * Channel = NULL;
// Validate // Validate
if (!ChanelName || !Data) { if (!ChannelName) {
return 0; return 0;
} else if (Len == -1) {
Len = strlen( Data );
} }
// Get Channel // Get Channel
if (!(Channel = GetChannel( ChanelName ))) if (!(Channel = GetChannel( ChannelName ))) {
{ if (Log) Log->Message( DebugLevel, dlHigh, "%s: Channel '%s' - Output rejected, Channel not found", Name, ChannelName );
// Log Event
if (Log) Log->Message( DebugLevel, dlHigh, "%s: Channel '%s' - Output rejected, Channel not found", Name, ChanelName );
return 0; return 0;
} }
else {
// Return processed bytes // Return processed bytes
return Output( Channel, Data, Len ); return Output( Channel, Data, Len );
}
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@@ -286,14 +290,21 @@ int CFunctionCore::Output( const TChannel * Channel, const char * Data, int Len
// Validate // Validate
if (!Channel || !Data) { if (!Channel || !Data) {
return 0; return 0;
} else if (Len == -1) { }
Len = strlen( Data );
// Check if enabled
if (!Channel->OutputEnabled) {
if (Log) Log->Message( DebugLevel, dlHigh, "%s: Channel '%s' - Output rejected, Channel output disabled", Name, Channel->Name );
return 0;
} }
// Log event // Log event
if (Log) Log->Output( DebugLevel, dlHigh, OutputDisplay, Data, Len, "%s: Channel '%s' - OUT:", Name, Channel->Name ); if (Log) Log->Output( DebugLevel, dlHigh, OutputDisplay, Data, Len, "%s: Channel '%s' - OUT:", Name, Channel->Name );
// Pass output to all linked inputs // Pass output to all linked inputs
if (Len == -1) {
Len = strlen( Data );
}
OutChannel = Channel->FirstOutput; OutChannel = Channel->FirstOutput;
while (OutChannel) { while (OutChannel) {
OutChannel->Function->Input( OutChannel->Name, Data, Len ); OutChannel->Function->Input( OutChannel->Name, Data, Len );

View File

@@ -34,6 +34,9 @@ struct SChannel
TChannelLink * FirstInput; TChannelLink * FirstInput;
TChannelLink * FirstOutput; TChannelLink * FirstOutput;
bool InputEnabled;
bool OutputEnabled;
TChannel * Next; TChannel * Next;
}; };
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@@ -67,10 +70,10 @@ protected:
// Manage Channel // Manage Channel
inline TChannel * GetChannel( const char * Name ) { inline TChannel * GetChannel( const char * Name ) {
if (!Name) return NULL;
TChannel * Channel = FirstChannel; TChannel * Channel = FirstChannel;
while (Channel && strcmp( Name, Channel->Name )) { while (Channel && strcmp( Name, Channel->Name ))
Channel = Channel->Next; Channel = Channel->Next;
}
return Channel; return Channel;
} }
@@ -88,7 +91,27 @@ public:
inline const char * GetName() { return Name; }; inline const char * GetName() { return Name; };
// Manage Channels // Manage Channels
virtual TChannel * AddChannel( const char * ChannelName ); virtual TChannel * AddChannel( const char * ChannelName, const bool pInputEnable = true, const bool pOutputEnabled = true );
inline bool SetChannelOutEnable( const char * ChannelName, const bool pOutputEnable ) {
TChannel * Channel = GetChannel( ChannelName );
if (!Channel) return false;
Channel->OutputEnabled = pOutputEnable;
return true;
}
inline bool SetChannelInEnable( const char * ChannelName, const bool pInputEnable ) {
TChannel * Channel = GetChannel( ChannelName );
if (!Channel) return false;
Channel->InputEnabled = pInputEnable;
return true;
}
inline bool isInputEnabled( const char * ChannelName ) {
TChannel * Channel = GetChannel( ChannelName );
return ((Channel)? Channel->InputEnabled : false);
}
inline bool isOutputEnabled( const char * ChannelName ) {
TChannel * Channel = GetChannel( ChannelName );
return ((Channel)? Channel->OutputEnabled : false);
}
// Manual Data Input/Output // Manual Data Input/Output
virtual int Input( const char * ChannelName, const char * Data, int MaxLen = -1 ); virtual int Input( const char * ChannelName, const char * Data, int MaxLen = -1 );

View File

@@ -1146,21 +1146,20 @@ int CSelectableCore::Input( const char * ChannelName, const char * Data, int Len
if (!ChannelName || !Data) { if (!ChannelName || !Data) {
return 0; return 0;
} }
else if (Len == -1) {
Len = strlen( Data );
}
// Get File handle // Get File handle
if (!(Handle = GetHandle( ChannelName ))) if (!(Handle = GetHandle( ChannelName ))) {
{ // Handle not found
// Log event if (Log) Log->Message( DebugLevel, dlHigh, "%s: Channel '%s' - Input rejected, Handle not found", Name, ChannelName );
if (Log) Log->Message( DebugLevel, dlHigh, "%s: Channel '%s' - Input rejected, Input not found", Name, ChannelName );
return 0; return 0;
} }
// Check that handle is open else if (Handle->Channel && !Handle->Channel->InputEnabled) {
else if (Handle->State != csOpen) // Handle is not open
{ if (Log) Log->Message( DebugLevel, dlHigh, "%s: Channel '%s' - Input rejected, Channel input disabled", Name, ChannelName );
// Log event return 0;
}
else if (Handle->State != csOpen) {
// Handle is not open
if (Log) Log->Message( DebugLevel, dlHigh, "%s: Channel '%s' - Input rejected, Handle not Open", Name, ChannelName ); if (Log) Log->Message( DebugLevel, dlHigh, "%s: Channel '%s' - Input rejected, Handle not Open", Name, ChannelName );
return 0; return 0;
} }
@@ -1168,6 +1167,11 @@ int CSelectableCore::Input( const char * ChannelName, const char * Data, int Len
// Log event // Log event
if (Log) Log->Output( DebugLevel, dlHigh, OutputDisplay, Data, Len, "%s: Channel '%s' - IN:", Name, ChannelName ); if (Log) Log->Output( DebugLevel, dlHigh, OutputDisplay, Data, Len, "%s: Channel '%s' - IN:", Name, ChannelName );
// Check packet length
if (Len == -1) {
Len = strlen( Data );
}
if (Handle->Type == ctServer) if (Handle->Type == ctServer)
{ {
// Cannot write to server socket, so Update Remote Client connections individually // Cannot write to server socket, so Update Remote Client connections individually

View File

@@ -171,14 +171,6 @@ protected:
THandle * Handle = GetHandle( HandleName ); THandle * Handle = GetHandle( HandleName );
return ((Handle)? Handle->FD : -1); return ((Handle)? Handle->FD : -1);
}; };
inline EConnectType GetType( const char * HandleName ) {
THandle * Handle = GetHandle( HandleName );
return ((Handle)? Handle->Type : ctNone);
};
inline EConnectState GetState( const char * HandleName ) {
THandle * Handle = GetHandle( HandleName );
return ((Handle)? Handle->State : csNone);
};
// General fucntions // General fucntions
inline bool ChangeState( THandle * Handle, EConnectState State ) { inline bool ChangeState( THandle * Handle, EConnectState State ) {
@@ -264,6 +256,16 @@ public:
inline virtual bool Write( const char * HandleName ) { return (Write( GetHandle( HandleName ))); }; inline virtual bool Write( const char * HandleName ) { return (Write( GetHandle( HandleName ))); };
inline virtual bool Write( int FD ) { return (Write( GetHandle( FD ))); }; inline virtual bool Write( int FD ) { return (Write( GetHandle( FD ))); };
// Info
inline EConnectType GetType( const char * HandleName ) {
THandle * Handle = GetHandle( HandleName );
return ((Handle)? Handle->Type : ctNone);
};
inline EConnectState GetState( const char * HandleName ) {
THandle * Handle = GetHandle( HandleName );
return ((Handle)? Handle->State : csNone);
};
// Function Interface // Function Interface
virtual int Input( const char *ChannelName, const char * Buffer, int BufLen = -1 ); virtual int Input( const char *ChannelName, const char * Buffer, int BufLen = -1 );
virtual bool Process(); virtual bool Process();