Important Update:

- DeviceCore:
  - Added PollCycle variable (not used here)
- WatchdogCore:
  - Return "true" on in Process()
- SelectableCore:
  - Minor update (code compacted)
- Application/Function:
  - Added CApplication as friend of CFunction
  - Added param WaitToTerminate on Function
  - Application Run() only exists if all (WaitToTerminate) functions
    has terminated cleanly.
This commit is contained in:
Charl Wentzel
2019-03-09 20:41:25 +02:00
parent 3626909786
commit 889df6c7de
6 changed files with 27 additions and 24 deletions

View File

@@ -17,6 +17,7 @@
//---------------------------------------------------------------------------
// Global Vars
extern bool Terminate;
extern char * ProcessName;
//---------------------------------------------------------------------------
@@ -405,7 +406,8 @@ CFunctionCore * CApplication::GetFunction( const char * Name )
bool CApplication::Run( bool TerminateOnError )
{
bool AllGood = true;
bool CleanTerminate = true;
bool ProcessTerminate = false;
TFunctionItem * FunctionItem;
// Check for FD Events/States
@@ -416,15 +418,17 @@ bool CApplication::Run( bool TerminateOnError )
// Process Functions
for (FunctionItem = FirstFunction; FunctionItem; FunctionItem = FunctionItem->Next )
{
if (!FunctionItem->Function->Process())
{
if (TerminateOnError)
ProcessTerminate = !FunctionItem->Function->Process();
if (TerminateOnError) {
if (ProcessTerminate)
Terminate = true;
if (FunctionItem->Function->WaitToTerminate && !ProcessTerminate)
CleanTerminate = false;
}
}
if (Terminate && TerminateOnError && CleanTerminate)
return false;
else {
AllGood = false;
}
}
}
return AllGood;
else
return true;
}
//---------------------------------------------------------------------------

View File

@@ -30,6 +30,7 @@ extern CApplication * Application;
CDeviceCore::CDeviceCore( const char * pName, const char * pType ) : CFunctionCore( pName, pType )
{
// Polling
PollCycle = 0;
PollStep = 0;
PollInterval = 250;
SetStartTime( &PollWait );

View File

@@ -31,8 +31,8 @@ const char DataTypeName[][20] = { "None", "Unsigned16", "Signed16", "Unsigned32_
// Structure prototypes
typedef struct SDevice TDevice;
typedef struct SDeviceParam TDeviceParam;
typedef struct SDeviceParamGroup TDeviceParamGroup;
typedef struct SDeviceParamItem TDeviceParamItem;
typedef struct SDeviceParamGroup TDeviceParamGroup; // Parameter group, e.g. used with polling parameters
typedef struct SDeviceParamItem TDeviceParamItem; // Placeholder parameters in Parameter groups
//---------------------------------------------------------------------------
@@ -138,6 +138,7 @@ protected:
TChannel * EventChannel = NULL;
// Poll
int PollCycle; // Device Polling state, e.g. Init, Connect, Run, Disonnect, Shutdown
int PollStep; // Position in polling sequence
timeval PollWait; // Time at which last poll was done
long PollInterval; // Minimum delay between polls

View File

@@ -60,6 +60,7 @@ protected:
// Function Definition
const char * Type = NULL;
char * Name = NULL;
bool WaitToTerminate = false;
// Channels
TChannel * FirstChannel = NULL;
@@ -138,6 +139,8 @@ public:
virtual bool LinkInputChannel( const char * ChannelName, const char * OutFunctionName, const char * OutChannelName, bool Bidirectional );
virtual bool LinkOutputChannel( const char * ChannelName, const char * InFunctionName, const char * InChannelName, bool Bidirectional );
virtual bool Process() = 0;
friend class CApplication;
};
//---------------------------------------------------------------------------

View File

@@ -2564,20 +2564,18 @@ bool CSelectableCore::Process()
{
THandle * Handle = NULL;
// Check all handles
// Process all Handles
Handle = FirstHandle;
while (Handle)
{
// Auto manage handles
if ((Handle->State == csOpenRequest))
{
if ((Handle->State == csOpenRequest)) {
// Resolve then open socket
if (Timeout( Handle->LastAction, Handle->ResolveDelay )) {
Open( Handle, false );
}
}
else if (((Handle->State != csOpen) && Handle->AutoManage && Handle->Persistent) )
{
else if (((Handle->State != csOpen) && Handle->AutoManage && Handle->Persistent) ) {
// Try to re-open port after delay
if (Timeout( Handle->LastAction, Handle->ReopenDelay )) {
Open( Handle, false );
@@ -2585,11 +2583,9 @@ bool CSelectableCore::Process()
}
// Check Input buffers
if (Handle->InBuffer && (Handle->InBuffer->Len() > 0))
{
if (Handle->InBuffer && (Handle->InBuffer->Len() > 0)) {
// Check duration since last PortIn
if (Timeout( Handle->InStart, Handle->InTimeout ))
{
if (Timeout( Handle->InStart, Handle->InTimeout )) {
// Process Input
ProcessInputBuffer( Handle, true );
@@ -2599,14 +2595,12 @@ bool CSelectableCore::Process()
}
// Check for auto close (but not on servers)
if ((Handle->State == csOpen) && (Handle->Type != ctTCPserver) && (Handle->Type != ctUNIXserver) && Handle->AutoManage && !Handle->Persistent)
{
if ((Handle->State == csOpen) && Handle->AutoManage && !Handle->Persistent && (Handle->Type != ctTCPserver) && (Handle->Type != ctUNIXserver)) {
// Close port after timeout
if (Timeout( Handle->LastAction, Handle->CloseTimeout )) {
Close( Handle, true );
}
}
Handle = Handle->Next;
}
return true;

View File

@@ -88,7 +88,7 @@ bool CWatchdogCore::Process()
SetStartTime( &PingTimer );
}
return false;
return true;
}
//---------------------------------------------------------------------------