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:
@@ -70,17 +70,17 @@ bool CDeviceCore::Init( CDataMember * FunctionConfig )
|
|||||||
if (!(CmdChannel = GetChannel( "Command" )))
|
if (!(CmdChannel = GetChannel( "Command" )))
|
||||||
CmdChannel = AddChannel( "Command", CH_ready );
|
CmdChannel = AddChannel( "Command", CH_ready );
|
||||||
else
|
else
|
||||||
SetChannelState( CmdChannel, CH_ready );
|
SetChannelInState( CmdChannel, CH_ready );
|
||||||
|
|
||||||
if (!(DeviceChannel = GetChannel( "Device" )))
|
if (!(DeviceChannel = GetChannel( "Device" )))
|
||||||
DeviceChannel = AddChannel( "Device", CH_ready );
|
DeviceChannel = AddChannel( "Device", CH_ready );
|
||||||
else
|
else
|
||||||
SetChannelState( DeviceChannel, CH_ready );
|
SetChannelInState( DeviceChannel, CH_ready );
|
||||||
|
|
||||||
if (!(EventChannel = GetChannel( "Event" )))
|
if (!(EventChannel = GetChannel( "Event" )))
|
||||||
EventChannel = AddChannel( "Event", CH_ready );
|
EventChannel = AddChannel( "Event", CH_ready );
|
||||||
else
|
else
|
||||||
SetChannelState( EventChannel, CH_ready );
|
SetChannelInState( EventChannel, CH_ready );
|
||||||
|
|
||||||
// Load Polling configuration
|
// Load Polling configuration
|
||||||
PollConfig = Config->GetChild( "Polling", true );
|
PollConfig = Config->GetChild( "Polling", true );
|
||||||
|
|||||||
@@ -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;
|
EChannelState OldState = Channel->InState;
|
||||||
TChannelLink * LinkChannel;
|
TChannelLink * LinkChannel;
|
||||||
@@ -210,12 +210,18 @@ bool CFunctionCore::SetChannelState( TChannel * Channel, const EChannelState Sta
|
|||||||
// Update state
|
// Update state
|
||||||
Channel->InState = State;
|
Channel->InState = State;
|
||||||
if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Update Channel '%s' - In:%s",
|
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
|
// Update linked channels
|
||||||
LinkChannel = Channel->FirstLink;
|
LinkChannel = Channel->FirstLink;
|
||||||
while (LinkChannel) {
|
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->ChannelStateEvent( LinkChannel->Channel, Channel->Ref, OldState, State );
|
||||||
|
LinkChannel->Function->UpdateChannelOutState( LinkChannel->Channel );
|
||||||
|
|
||||||
LinkChannel = LinkChannel->Next;
|
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;
|
TChannelLink * LinkChannel;
|
||||||
EChannelState OutState;
|
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
|
// Check if channel Out state changed
|
||||||
OutState = CH_off;
|
OutState = CH_off;
|
||||||
LinkChannel = Channel->FirstLink;
|
LinkChannel = Channel->FirstLink;
|
||||||
@@ -251,13 +247,13 @@ bool CFunctionCore::ChannelStateEvent( TChannel * Channel, const char * SourceRe
|
|||||||
Channel->OutState = OutState;
|
Channel->OutState = OutState;
|
||||||
|
|
||||||
if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Update Channel '%s' - Out:%s",
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
EChannelState CFunctionCore::ChannelOutState( TChannel * Channel, const char * TargetRef )
|
EChannelState CFunctionCore::GetChannelOutState( TChannel * Channel, const char * TargetRef )
|
||||||
{
|
{
|
||||||
TChannelLink * LinkChannel = NULL;
|
TChannelLink * LinkChannel = NULL;
|
||||||
|
|
||||||
@@ -325,6 +321,14 @@ bool CFunctionCore::LinkChannel( const char * ChannelName, const char * LinkFunc
|
|||||||
// Log Event
|
// Log Event
|
||||||
if (Log) Log->Message( LogLevel, dlLow, "%s/%s: Reverse Channel Linked - '%s'-->'%s' - In:%s, Out:%s",
|
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") );
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
@@ -371,6 +375,10 @@ bool CFunctionCore::UnlinkChannel( const char * ChannelName, const char * LinkFu
|
|||||||
delete *LinkedChannel;
|
delete *LinkedChannel;
|
||||||
*LinkedChannel = NextLinkedChannel;
|
*LinkedChannel = NextLinkedChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Trigger Channel Events
|
||||||
|
LinkFunction->UpdateChannelOutState( LinkChannel );
|
||||||
|
UpdateChannelOutState( Channel );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -121,9 +121,10 @@ public:
|
|||||||
// Manage Channels
|
// Manage Channels
|
||||||
virtual TChannel * AddChannel( const char * ChannelName, const EChannelState State );
|
virtual TChannel * AddChannel( const char * ChannelName, const EChannelState State );
|
||||||
|
|
||||||
virtual bool SetChannelState( TChannel * Channel, const EChannelState State );
|
virtual bool SetChannelInState( TChannel * Channel, const EChannelState State );
|
||||||
virtual bool ChannelStateEvent( TChannel * Channel, const char * SourceRef, const EChannelState OldState, const EChannelState NewState );
|
virtual bool ChannelStateEvent( TChannel * Channel, const char * SourceRef, const EChannelState OldState, const EChannelState NewState ) { return true; };
|
||||||
virtual EChannelState ChannelOutState( TChannel * Channel, const char * TargetRef );
|
virtual bool UpdateChannelOutState( TChannel * Channel );
|
||||||
|
virtual EChannelState GetChannelOutState( TChannel * Channel, const char * TargetRef );
|
||||||
|
|
||||||
// Pushing Data Output -> Input
|
// Pushing Data Output -> Input
|
||||||
virtual int Output( const char * ChannelName, const char * TargetRef, const bool SourceRef, const char * Data, int Len = -1 );
|
virtual int Output( const char * ChannelName, const char * TargetRef, const bool SourceRef, const char * Data, int Len = -1 );
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ bool CSelectableBare::HandleState( THandle * Handle, EConnectState State )
|
|||||||
else
|
else
|
||||||
ChannelState = CH_off;
|
ChannelState = CH_off;
|
||||||
if (Handle->Channel->InState != ChannelState)
|
if (Handle->Channel->InState != ChannelState)
|
||||||
SetChannelState( Handle->Channel, ChannelState );
|
SetChannelInState( Handle->Channel, ChannelState );
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user