From 253eb91824c3d7829b8c26032e1bcc0e129b886d Mon Sep 17 00:00:00 2001 From: Charl Wentzel Date: Mon, 10 Jun 2019 17:25:31 +0200 Subject: [PATCH] Important Update: - FunctionCore: - Add OldState to ChannelStateEvent() - Add new method ChannelOutState() - Update Logging levels - SelectableCore: - Restart LastAction timer of Name Resolve fail (cause delayed re-open) - Watchdog: - Move JSON PingInterval param to "Config" object --- FunctionCore.cpp | 33 ++++++++++++++++++++++++++++----- FunctionCore.h | 3 ++- SelectableCore.cpp | 5 ++++- WatchdogCore.cpp | 2 +- 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/FunctionCore.cpp b/FunctionCore.cpp index 6a3450f..3fc9596 100644 --- a/FunctionCore.cpp +++ b/FunctionCore.cpp @@ -202,6 +202,7 @@ TChannel * CFunctionCore::AddChannel( const char * ChannelName, const EChannelSt bool CFunctionCore::SetChannelState( TChannel * Channel, const EChannelState State ) { + EChannelState OldState = Channel->State; TChannelLink * LinkChannel; // Validate @@ -210,13 +211,13 @@ bool CFunctionCore::SetChannelState( TChannel * Channel, const EChannelState Sta // Update state Channel->State = State; - if (Log) Log->Message( LogLevel, dlLow, "%s/%s: Update Channel '%s' - State:%s", + if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Update Channel '%s' - State:%s", ProcessName, Name, Channel->Name, ChannelStateName[State] ); // Update linked channels LinkChannel = Channel->FirstLink; while (LinkChannel) { - LinkChannel->Function->ChannelStateEvent( LinkChannel->Channel, Channel->Ref, State ); + LinkChannel->Function->ChannelStateEvent( LinkChannel->Channel, Channel->Ref, OldState, State ); LinkChannel = LinkChannel->Next; } @@ -224,7 +225,7 @@ bool CFunctionCore::SetChannelState( TChannel * Channel, const EChannelState Sta } //--------------------------------------------------------------------------- -bool CFunctionCore::ChannelStateEvent( TChannel * Channel, const char * SourceRef, const EChannelState State ) +bool CFunctionCore::ChannelStateEvent( TChannel * Channel, const char * SourceRef, const EChannelState OldState, const EChannelState NewState ) { TChannelLink * LinkChannel; @@ -233,13 +234,35 @@ bool CFunctionCore::ChannelStateEvent( TChannel * Channel, const char * SourceRe if (!(LinkChannel = GetLinkChannel( Channel, SourceRef ))) return false; - if (Log) Log->Message( LogLevel, dlLow, "%s/%s: Update Link Channel '%s'-->'%s' - State:%s", - ProcessName, Name, Channel->Name, LinkChannel->Channel->Ref, ChannelStateName[State] ); + if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Update Link Channel '%s'-->'%s' - State:%s", + ProcessName, Name, Channel->Name, LinkChannel->Channel->Ref, ChannelStateName[NewState] ); return true; } //--------------------------------------------------------------------------- +EChannelState CFunctionCore::ChannelOutState( TChannel * Channel, const char * TargetRef ) +{ + TChannelLink * LinkChannel = NULL; + EChannelState State = CH_off; + + // Validate + if (!Channel) + return State; + + // Check if any linked channels are ready + LinkChannel = Channel->FirstLink; + while (LinkChannel) { + if (!TargetRef || !*TargetRef || !strcasecmp( TargetRef, LinkChannel->Channel->Ref )) { + if (LinkChannel->Channel->State > State) + State = LinkChannel->Channel->State; + } + LinkChannel = LinkChannel->Next; + } + return State; +} +//--------------------------------------------------------------------------- + // Automated Data Input/Output bool CFunctionCore::LinkChannel( const char * ChannelName, const char * LinkFunctionName, const char * LinkChannelName, bool Input, bool Output ) { diff --git a/FunctionCore.h b/FunctionCore.h index 72227e0..090bdd2 100644 --- a/FunctionCore.h +++ b/FunctionCore.h @@ -121,7 +121,8 @@ public: virtual TChannel * AddChannel( const char * ChannelName, const EChannelState State ); virtual bool SetChannelState( TChannel * Channel, const EChannelState State ); - virtual bool ChannelStateEvent( TChannel * Channel, const char * SourceRef, const EChannelState State ); + virtual bool ChannelStateEvent( TChannel * Channel, const char * SourceRef, const EChannelState OldState, const EChannelState NewState ); + virtual EChannelState ChannelOutState( TChannel * Channel, const char * TargetRef ); // Pushing Data Output -> Input virtual int Output( const char * ChannelName, const char * TargetRef, const bool SourceRef, const char * Data, int Len = -1 ); diff --git a/SelectableCore.cpp b/SelectableCore.cpp index 8561774..4703eaa 100644 --- a/SelectableCore.cpp +++ b/SelectableCore.cpp @@ -1060,6 +1060,7 @@ bool CSelectableCore::ResolveAddress( THandle * Handle ) DestroyResolveReq( Handle, true ); HandleState( Handle, csFailed ); + SetStartTime( &Handle->LastAction ); // Allow delay before retrying resolve return false; } return false; @@ -1101,6 +1102,7 @@ bool CSelectableCore::HandleResolve( THandle * Handle ) DestroyResolveReq( Handle, true ); HandleState( Handle, csFailed ); + SetStartTime( &Handle->LastAction ); // Allow delay before retrying resolve return false; } @@ -1120,6 +1122,7 @@ bool CSelectableCore::HandleResolve( THandle * Handle ) Handle->AddressInfo = NULL; HandleState( Handle, csFailed ); + SetStartTime( &Handle->LastAction ); // Allow delay before retrying resolve return false; } @@ -1807,7 +1810,7 @@ bool CSelectableCore::Close( THandle * Handle, bool QuickReopen ) }; // Change State - HandleState( Handle, ((Fail)? csFailed : csClosed) ); + HandleState( Handle, ((Fail)? csFailed : csClosed) ); return true; } //--------------------------------------------------------------------------- diff --git a/WatchdogCore.cpp b/WatchdogCore.cpp index cebd535..c040958 100644 --- a/WatchdogCore.cpp +++ b/WatchdogCore.cpp @@ -63,7 +63,7 @@ bool CWatchdogCore::Init( CDataMember * FunctionConfig ) return false; // Set specific parameters - SetInterval( FunctionConfig->GetChInt( "Parameters/PingInterval", 500, true )); + SetInterval( Config->GetChInt( "PingInterval", 500, true )); // Create handle and set reference, if not done if (!(Ping = GetHandle( "Ping" )))