Important Update:

- FunctionCore
  - So not set Function JSON "config" param to empty object by default
  - Change TChannelLink to reference Channel direct
  - Add Input/Output to TChannelLink
    - Replace LinkChannel() Bidirectional param with Input/Output param
    - Update JSON config as well
  - Implement Channel "Ready" state and events
    - Remove Input/OutputEnabled parameters and related methods
    - Remove from JSON config as well
    - Update AddChannel() method accordingly
  - Add Ref param to struct TChannel
- SelectableCore:
  - Convert inline ChangeState() to non-inline method
  - Move ChangeState() to last step in open/close methods
  - Add Channels in Not Ready state
  - Change Channel state when Handle state changed
- DeviceCore:
  - Add Channels in Ready state
- FileCore:
  - Add Channel in Not Ready state
This commit is contained in:
Charl Wentzel
2019-06-05 19:13:04 +02:00
parent fa6825b72a
commit 08fce64629
7 changed files with 202 additions and 154 deletions

View File

@@ -112,7 +112,7 @@ THandle * CSelectableBare::CreateHandle( const char * HandleName, bool CreateCh
// Create Matching Channel
if (CreateChannel) {
(*Handle)->Channel = AddChannel( HandleName );
(*Handle)->Channel = AddChannel( HandleName, false );
}
return *Handle;
@@ -218,6 +218,31 @@ bool CSelectableBare::ClearHandle( THandle * Handle )
}
//---------------------------------------------------------------------------
bool CSelectableBare::ChangeState( THandle * Handle, EConnectState State )
{
bool Ready;
// Validate
if (!Handle || (Handle->State == State))
return false;
// Set Call back
if (Handle->StateCallback[ (int)State ])
(Handle->StateCallback[ (int)State ])( this, Handle, State );
// Change state
Handle->State = State;
// Update Channel
if (Handle->Channel) {
Ready = ((Handle->State == csOpen) || (Handle->State == csDataWaiting));
if (Handle->Channel->Ready != Ready)
SetChannelState( Handle->Channel, Ready );
}
return true;
}
//---------------------------------------------------------------------------
bool CSelectableBare::SetCallback( THandle * Handle, EConnectState pState, FHandleCallback pCallback )
{
// Validate
@@ -356,6 +381,7 @@ int CSelectableBare::Open( THandle * Handle, bool DelayResolve )
{
THandle * NewHandle = NULL;
// Validate
if (!Handle || (Handle->Type == ctNone)) {
return -1;
@@ -391,11 +417,11 @@ int CSelectableBare::Open( THandle * Handle, bool DelayResolve )
Selector->Add( Handle->FD, true, false, Handle, this );
}
// Set state
ChangeState( Handle, csOpen );
// Set timer (for re-open or auto-close)
SetStartTime( &Handle->LastAction );
// Set state
ChangeState( Handle, csOpen );
return (NewHandle)? NewHandle->FD : -1;
};
//---------------------------------------------------------------------------
@@ -411,7 +437,16 @@ bool CSelectableBare::Close( THandle * Handle, bool QuickReopen )
// Close Handle
Fail = (close( Handle->FD ))? true : false;
ChangeState( Handle, ((Fail)? csFailed : csClosed) );
// Remove from Select List
if (!Fail && Selector) {
if (Handle->Type != ctUDPremote) {
Selector->Remove( Handle->FD, true, true );
}
}
// Reset FD
Handle->FD = ((Fail)? Handle->FD : -1);
// Start timer (for re-open)
if (QuickReopen)
@@ -423,15 +458,8 @@ bool CSelectableBare::Close( THandle * Handle, bool QuickReopen )
if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Handle '%s' - %s",
ProcessName, Name, Handle->Name, ((Fail)? "failed" : "closed") );
// Remove from Select List
if (!Fail && Selector) {
if (Handle->Type != ctUDPremote) {
Selector->Remove( Handle->FD, true, true );
}
}
// Reset FD
Handle->FD = ((Fail)? Handle->FD : -1);
// Set State
ChangeState( Handle, ((Fail)? csFailed : csClosed) );
return true;
}
//---------------------------------------------------------------------------
@@ -695,9 +723,9 @@ int CSelectableBare::Input( const char * ChannelName, const char * SourceRef, co
ProcessName, Name, ((SourceRef && *SourceRef)? SourceRef : "(Any)"), ChannelName );
return 0;
}
else if (!Channel->InputEnabled) {
else if (!Channel->Ready) {
// Channel disabled
if (Log) Log->Message( LogLevel, dlHigh, "%s/%s: Channel '%s'->'%s' - Input rejected, Channel input disabled",
if (Log) Log->Message( LogLevel, dlHigh, "%s/%s: Channel '%s'->'%s' - Input rejected, Channel not Ready",
ProcessName, Name, ((SourceRef && *SourceRef)? SourceRef : "(Any)"), ChannelName );
return 0;
}