diff --git a/DeviceCore.cpp b/DeviceCore.cpp index 125c6cb..fcfb818 100644 --- a/DeviceCore.cpp +++ b/DeviceCore.cpp @@ -70,17 +70,17 @@ bool CDeviceCore::Init( CDataMember * FunctionConfig ) if (!(CmdChannel = GetChannel( "Command" ))) CmdChannel = AddChannel( "Command", CH_ready ); else - SetChannelState( CmdChannel, CH_ready ); + SetChannelInState( CmdChannel, CH_ready ); if (!(DeviceChannel = GetChannel( "Device" ))) DeviceChannel = AddChannel( "Device", CH_ready ); else - SetChannelState( DeviceChannel, CH_ready ); + SetChannelInState( DeviceChannel, CH_ready ); if (!(EventChannel = GetChannel( "Event" ))) EventChannel = AddChannel( "Event", CH_ready ); else - SetChannelState( EventChannel, CH_ready ); + SetChannelInState( EventChannel, CH_ready ); // Load Polling configuration PollConfig = Config->GetChild( "Polling", true ); diff --git a/FunctionCore.cpp b/FunctionCore.cpp index 1b0de8a..6b9eac6 100644 --- a/FunctionCore.cpp +++ b/FunctionCore.cpp @@ -198,7 +198,7 @@ TChannel * CFunctionCore::AddChannel( const char * ChannelName, const EChannelSt } //--------------------------------------------------------------------------- -bool CFunctionCore::SetChannelState( TChannel * Channel, const EChannelState State ) +bool CFunctionCore::SetChannelInState( TChannel * Channel, const EChannelState State ) { EChannelState OldState = Channel->InState; TChannelLink * LinkChannel; @@ -210,12 +210,18 @@ bool CFunctionCore::SetChannelState( TChannel * Channel, const EChannelState Sta // Update state Channel->InState = State; if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Update Channel '%s' - In:%s", - ProcessName, Name, Channel->Name, ChannelStateName[State] ); + ProcessName, Name, Channel->Ref, ChannelStateName[State] ); // Update linked channels LinkChannel = Channel->FirstLink; while (LinkChannel) { + if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Update Link Channel '%s'-->'%s' - In:%s", + ProcessName, Name, Channel->Ref, LinkChannel->Channel->Ref, ChannelStateName[State] ); + + // Trigger Linked Channel Events LinkChannel->Function->ChannelStateEvent( LinkChannel->Channel, Channel->Ref, OldState, State ); + LinkChannel->Function->UpdateChannelOutState( LinkChannel->Channel ); + LinkChannel = LinkChannel->Next; } @@ -223,21 +229,11 @@ bool CFunctionCore::SetChannelState( TChannel * Channel, const EChannelState Sta } //--------------------------------------------------------------------------- -bool CFunctionCore::ChannelStateEvent( TChannel * Channel, const char * SourceRef, const EChannelState OldState, const EChannelState NewState ) +bool CFunctionCore::UpdateChannelOutState( TChannel * Channel ) { - TChannelLink * UpdateChannel; TChannelLink * LinkChannel; EChannelState OutState; - // Validate - if (!Channel) - return false; - if (!(UpdateChannel = GetLinkChannel( Channel, SourceRef ))) - return false; - - if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Update Link Channel '%s'-->'%s' - In:%s", - ProcessName, Name, Channel->Name, UpdateChannel->Channel->Ref, ChannelStateName[NewState] ); - // Check if channel Out state changed OutState = CH_off; LinkChannel = Channel->FirstLink; @@ -251,13 +247,13 @@ bool CFunctionCore::ChannelStateEvent( TChannel * Channel, const char * SourceRe Channel->OutState = OutState; if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Update Channel '%s' - Out:%s", - ProcessName, Name, Channel->Name, ChannelStateName[OutState] ); + ProcessName, Name, Channel->Ref, ChannelStateName[OutState] ); } return true; } //--------------------------------------------------------------------------- -EChannelState CFunctionCore::ChannelOutState( TChannel * Channel, const char * TargetRef ) +EChannelState CFunctionCore::GetChannelOutState( TChannel * Channel, const char * TargetRef ) { TChannelLink * LinkChannel = NULL; @@ -325,6 +321,14 @@ bool CFunctionCore::LinkChannel( const char * ChannelName, const char * LinkFunc // Log Event if (Log) Log->Message( LogLevel, dlLow, "%s/%s: Reverse Channel Linked - '%s'-->'%s' - In:%s, Out:%s", ProcessName, Name, LinkChannel->Ref, (*LinkedChannel)->Channel->Ref, ((Output)? "Yes" : "No"), ((Input)? "Yes" : "No") ); + + // Trigger Forward Channel Events + LinkFunction->ChannelStateEvent( LinkChannel, Channel->Ref, CH_off, Channel->InState ); + LinkFunction->UpdateChannelOutState( LinkChannel ); + + // Trigger Reverse Channel Events + ChannelStateEvent( Channel, LinkChannel->Ref, CH_off, LinkChannel->InState ); + UpdateChannelOutState( Channel ); return true; } //--------------------------------------------------------------------------- @@ -371,6 +375,10 @@ bool CFunctionCore::UnlinkChannel( const char * ChannelName, const char * LinkFu delete *LinkedChannel; *LinkedChannel = NextLinkedChannel; } + + // Trigger Channel Events + LinkFunction->UpdateChannelOutState( LinkChannel ); + UpdateChannelOutState( Channel ); return true; } //--------------------------------------------------------------------------- diff --git a/FunctionCore.h b/FunctionCore.h index 807414b..f17bfec 100644 --- a/FunctionCore.h +++ b/FunctionCore.h @@ -121,9 +121,10 @@ public: // Manage Channels 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 OldState, const EChannelState NewState ); - virtual EChannelState ChannelOutState( TChannel * Channel, const char * TargetRef ); + virtual bool SetChannelInState( TChannel * Channel, const EChannelState State ); + virtual bool ChannelStateEvent( TChannel * Channel, const char * SourceRef, const EChannelState OldState, const EChannelState NewState ) { return true; }; + virtual bool UpdateChannelOutState( TChannel * Channel ); + virtual EChannelState GetChannelOutState( 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/SelectableBare.cpp b/SelectableBare.cpp index b0f2134..cddcfac 100644 --- a/SelectableBare.cpp +++ b/SelectableBare.cpp @@ -191,7 +191,7 @@ bool CSelectableBare::HandleState( THandle * Handle, EConnectState State ) else ChannelState = CH_off; if (Handle->Channel->InState != ChannelState) - SetChannelState( Handle->Channel, ChannelState ); + SetChannelInState( Handle->Channel, ChannelState ); } return true; }