Important Update:

- FunctionCore/SelectableCore:
  - Replace Channel->State with InState
  - Add Channel-OutState (ready for output) updated by ChannelStateEvent()
- TimingCore:
  - Add GetUpCounter() for calculating uptime string (in seconds)
This commit is contained in:
Charl Wentzel
2019-06-23 10:38:27 +02:00
parent 207caa696d
commit e9b50f1af9
4 changed files with 80 additions and 28 deletions

View File

@@ -186,11 +186,13 @@ TChannel * CFunctionCore::AddChannel( const char * ChannelName, const EChannelSt
(*Channel)->Name = strdup( ChannelName );
(*Channel)->Ref = (char*)malloc( strlen(Name)+strlen(ChannelName)+2 );
sprintf( (*Channel)->Ref, "%s/%s", Name, ChannelName );
(*Channel)->State = State;
(*Channel)->InState = State;
(*Channel)->OutState = CH_off;
// Log Event
if (Log) Log->Message( LogLevel, dlLow, "%s/%s: Channel '%s' - Created, Ref:'%s', State:%s",
ProcessName, Name, ChannelName, (*Channel)->Ref, ChannelStateName[(*Channel)->State] );
if (Log) Log->Message( LogLevel, dlLow, "%s/%s: Channel '%s' - Created, Ref:'%s', In:%s, Out:%s",
ProcessName, Name, ChannelName, (*Channel)->Ref,
ChannelStateName[(*Channel)->InState], ChannelStateName[(*Channel)->OutState]);
}
return *Channel;
}
@@ -198,7 +200,7 @@ TChannel * CFunctionCore::AddChannel( const char * ChannelName, const EChannelSt
bool CFunctionCore::SetChannelState( TChannel * Channel, const EChannelState State )
{
EChannelState OldState = Channel->State;
EChannelState OldState = Channel->InState;
TChannelLink * LinkChannel;
// Validate
@@ -206,8 +208,8 @@ bool CFunctionCore::SetChannelState( TChannel * Channel, const EChannelState Sta
return false;
// Update state
Channel->State = State;
if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Update Channel '%s' - State:%s",
Channel->InState = State;
if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Update Channel '%s' - In:%s",
ProcessName, Name, Channel->Name, ChannelStateName[State] );
// Update linked channels
@@ -223,16 +225,34 @@ bool CFunctionCore::SetChannelState( TChannel * Channel, const EChannelState Sta
bool CFunctionCore::ChannelStateEvent( TChannel * Channel, const char * SourceRef, const EChannelState OldState, const EChannelState NewState )
{
TChannelLink * UpdateChannel;
TChannelLink * LinkChannel;
EChannelState OutState;
// Validate
if (!Channel)
return false;
if (!(LinkChannel = GetLinkChannel( Channel, SourceRef )))
if (!(UpdateChannel = GetLinkChannel( Channel, SourceRef )))
return false;
if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Update Link Channel '%s'-->'%s' - State:%s",
ProcessName, Name, Channel->Name, LinkChannel->Channel->Ref, ChannelStateName[NewState] );
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;
while (LinkChannel) {
if (LinkChannel->Channel->InState > OutState)
OutState = LinkChannel->Channel->InState;
LinkChannel = LinkChannel->Next;
}
if (OutState != Channel->OutState) {
// Update output state
Channel->OutState = OutState;
if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Update Channel '%s' - Out:%s",
ProcessName, Name, Channel->Name, ChannelStateName[OutState] );
}
return true;
}
//---------------------------------------------------------------------------
@@ -240,22 +260,20 @@ bool CFunctionCore::ChannelStateEvent( TChannel * Channel, const char * SourceRe
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;
if (!Channel) {
return CH_off;
}
else if (!TargetRef || !*TargetRef) {
return Channel->OutState;
}
else if ((LinkChannel = GetLinkChannel( Channel, TargetRef ))) {
return LinkChannel->Channel->InState;
}
else {
return CH_off;
}
return State;
}
//---------------------------------------------------------------------------
@@ -373,9 +391,9 @@ int CFunctionCore::Input( const char * ChannelName, const char * SourceRef, cons
ProcessName, Name, ((SourceRef && *SourceRef)? SourceRef : "(Any)"), ChannelName );
return 0;
}
else if (!Channel->State) {
else if (!Channel->InState) {
if (Log) Log->Message( LogLevel, dlHigh, "%s/%s: Channel '%s'->'%s' - Input rejected, Channel %s",
ProcessName, Name, ((SourceRef && *SourceRef)? SourceRef : "(Any)"), ChannelName, ChannelStateName[Channel->State] );
ProcessName, Name, ((SourceRef && *SourceRef)? SourceRef : "(Any)"), ChannelName, ChannelStateName[Channel->InState] );
return 0;
}