Important Update:
- FunctionCore:
- Improve Channel Events:
- Remove important actions from ChannelStateEvent()
(now only used for custom actions)
- Add new method UpdateChannelOutState()
- Add Channel Events to Link and Unlink actions
- Rename SetChannelState() -> SetChannelInState()
- Use Channel->Ref (instead of name) on all channel events
- DeviceCore/SelectableCore:
- Rename SetChannelState() -> SetChannelInState()
This commit is contained in:
@@ -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;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user