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:
@@ -17,6 +17,7 @@
|
|||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
// Global Vars
|
// Global Vars
|
||||||
|
extern bool Terminate;
|
||||||
extern char * ProcessName;
|
extern char * ProcessName;
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
@@ -405,7 +406,8 @@ CFunctionCore * CApplication::GetFunction( const char * Name )
|
|||||||
|
|
||||||
bool CApplication::Run( bool TerminateOnError )
|
bool CApplication::Run( bool TerminateOnError )
|
||||||
{
|
{
|
||||||
bool AllGood = true;
|
bool CleanTerminate = true;
|
||||||
|
bool ProcessTerminate = false;
|
||||||
TFunctionItem * FunctionItem;
|
TFunctionItem * FunctionItem;
|
||||||
|
|
||||||
// Check for FD Events/States
|
// Check for FD Events/States
|
||||||
@@ -416,15 +418,17 @@ bool CApplication::Run( bool TerminateOnError )
|
|||||||
// Process Functions
|
// Process Functions
|
||||||
for (FunctionItem = FirstFunction; FunctionItem; FunctionItem = FunctionItem->Next )
|
for (FunctionItem = FirstFunction; FunctionItem; FunctionItem = FunctionItem->Next )
|
||||||
{
|
{
|
||||||
if (!FunctionItem->Function->Process())
|
ProcessTerminate = !FunctionItem->Function->Process();
|
||||||
{
|
if (TerminateOnError) {
|
||||||
if (TerminateOnError)
|
if (ProcessTerminate)
|
||||||
return false;
|
Terminate = true;
|
||||||
else {
|
if (FunctionItem->Function->WaitToTerminate && !ProcessTerminate)
|
||||||
AllGood = false;
|
CleanTerminate = false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return AllGood;
|
if (Terminate && TerminateOnError && CleanTerminate)
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ extern CApplication * Application;
|
|||||||
CDeviceCore::CDeviceCore( const char * pName, const char * pType ) : CFunctionCore( pName, pType )
|
CDeviceCore::CDeviceCore( const char * pName, const char * pType ) : CFunctionCore( pName, pType )
|
||||||
{
|
{
|
||||||
// Polling
|
// Polling
|
||||||
|
PollCycle = 0;
|
||||||
PollStep = 0;
|
PollStep = 0;
|
||||||
PollInterval = 250;
|
PollInterval = 250;
|
||||||
SetStartTime( &PollWait );
|
SetStartTime( &PollWait );
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ const char DataTypeName[][20] = { "None", "Unsigned16", "Signed16", "Unsigned32_
|
|||||||
// Structure prototypes
|
// Structure prototypes
|
||||||
typedef struct SDevice TDevice;
|
typedef struct SDevice TDevice;
|
||||||
typedef struct SDeviceParam TDeviceParam;
|
typedef struct SDeviceParam TDeviceParam;
|
||||||
typedef struct SDeviceParamGroup TDeviceParamGroup;
|
typedef struct SDeviceParamGroup TDeviceParamGroup; // Parameter group, e.g. used with polling parameters
|
||||||
typedef struct SDeviceParamItem TDeviceParamItem;
|
typedef struct SDeviceParamItem TDeviceParamItem; // Placeholder parameters in Parameter groups
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -138,6 +138,7 @@ protected:
|
|||||||
TChannel * EventChannel = NULL;
|
TChannel * EventChannel = NULL;
|
||||||
|
|
||||||
// Poll
|
// Poll
|
||||||
|
int PollCycle; // Device Polling state, e.g. Init, Connect, Run, Disonnect, Shutdown
|
||||||
int PollStep; // Position in polling sequence
|
int PollStep; // Position in polling sequence
|
||||||
timeval PollWait; // Time at which last poll was done
|
timeval PollWait; // Time at which last poll was done
|
||||||
long PollInterval; // Minimum delay between polls
|
long PollInterval; // Minimum delay between polls
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ protected:
|
|||||||
// Function Definition
|
// Function Definition
|
||||||
const char * Type = NULL;
|
const char * Type = NULL;
|
||||||
char * Name = NULL;
|
char * Name = NULL;
|
||||||
|
bool WaitToTerminate = false;
|
||||||
|
|
||||||
// Channels
|
// Channels
|
||||||
TChannel * FirstChannel = NULL;
|
TChannel * FirstChannel = NULL;
|
||||||
@@ -138,6 +139,8 @@ public:
|
|||||||
virtual bool LinkInputChannel( const char * ChannelName, const char * OutFunctionName, const char * OutChannelName, bool Bidirectional );
|
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 LinkOutputChannel( const char * ChannelName, const char * InFunctionName, const char * InChannelName, bool Bidirectional );
|
||||||
virtual bool Process() = 0;
|
virtual bool Process() = 0;
|
||||||
|
|
||||||
|
friend class CApplication;
|
||||||
};
|
};
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -2564,20 +2564,18 @@ bool CSelectableCore::Process()
|
|||||||
{
|
{
|
||||||
THandle * Handle = NULL;
|
THandle * Handle = NULL;
|
||||||
|
|
||||||
// Check all handles
|
// Process all Handles
|
||||||
Handle = FirstHandle;
|
Handle = FirstHandle;
|
||||||
while (Handle)
|
while (Handle)
|
||||||
{
|
{
|
||||||
// Auto manage handles
|
// Auto manage handles
|
||||||
if ((Handle->State == csOpenRequest))
|
if ((Handle->State == csOpenRequest)) {
|
||||||
{
|
|
||||||
// Resolve then open socket
|
// Resolve then open socket
|
||||||
if (Timeout( Handle->LastAction, Handle->ResolveDelay )) {
|
if (Timeout( Handle->LastAction, Handle->ResolveDelay )) {
|
||||||
Open( Handle, false );
|
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
|
// Try to re-open port after delay
|
||||||
if (Timeout( Handle->LastAction, Handle->ReopenDelay )) {
|
if (Timeout( Handle->LastAction, Handle->ReopenDelay )) {
|
||||||
Open( Handle, false );
|
Open( Handle, false );
|
||||||
@@ -2585,11 +2583,9 @@ bool CSelectableCore::Process()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check Input buffers
|
// Check Input buffers
|
||||||
if (Handle->InBuffer && (Handle->InBuffer->Len() > 0))
|
if (Handle->InBuffer && (Handle->InBuffer->Len() > 0)) {
|
||||||
{
|
|
||||||
// Check duration since last PortIn
|
// Check duration since last PortIn
|
||||||
if (Timeout( Handle->InStart, Handle->InTimeout ))
|
if (Timeout( Handle->InStart, Handle->InTimeout )) {
|
||||||
{
|
|
||||||
// Process Input
|
// Process Input
|
||||||
ProcessInputBuffer( Handle, true );
|
ProcessInputBuffer( Handle, true );
|
||||||
|
|
||||||
@@ -2599,14 +2595,12 @@ bool CSelectableCore::Process()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check for auto close (but not on servers)
|
// 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
|
// Close port after timeout
|
||||||
if (Timeout( Handle->LastAction, Handle->CloseTimeout )) {
|
if (Timeout( Handle->LastAction, Handle->CloseTimeout )) {
|
||||||
Close( Handle, true );
|
Close( Handle, true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle = Handle->Next;
|
Handle = Handle->Next;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ bool CWatchdogCore::Process()
|
|||||||
SetStartTime( &PingTimer );
|
SetStartTime( &PingTimer );
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user