Home2L - C/C++ API v1.4-0-g38cc (2024-05-25)
Smart Tools for a Private Home
List of all members
CServiceKeeper Class Reference

Description

Service keeper: Helper class to keep an unreliable service running.

This class takes care of keeping a service running by scheduling re-open attempts according to some given strategy.

The class can be used in two ways:

  1. Callback use: Deriving a sub-class and overriding the virtual methods DoOpen() and DoClose(). Iterate() must be called regularly to get necessary actions performed.
  2. Polling use: Instantiating this class and calling OpenAttemptNow() and CloseNow() and (re-)open or close the service accordingly.

Definition at line 2136 of file base.H.

#include "base.H"

Public Member Functions

Initialization and setup ...
 CServiceKeeper ()
 
 CServiceKeeper (TTicks _tDShort, TTicks _tDLong=NEVER, TTicks _tShortToLong=NEVER)
 
 ~CServiceKeeper ()
 
void Setup (TTicks _tDShort, TTicks _tDLong=NEVER, TTicks _tShortToLong=NEVER)
 Setup the retry policy. More...
 
Using the service ...
void Open ()
 Request the service to open. More...
 
void Close ()
 Request the service to close. More...
 
void Refresh ()
 Force retry on next Iterate() and return to short retry intervals.
 
void Iterate ()
 Iterate (callback use); perform all open/close actions as adequate. Not needed for polling use.
 
bool IsOpen ()
 check if the service is actually open.
 
bool ShouldBeOpen ()
 check if the service has been requested to be open.
 
Callbacks (for callback use) ...

These callbacks are always called from Iterate().

virtual void DoOpen ()
 Attempt to open the service in callback use. If this method is overloaded it must call ReportOpenAttempt() to report that the attempt has occurred.
 
virtual void DoClose ()
 Actually close the service. If this method is overloaded it must call ReportClosed() to report that the closing has succeeded. Otherwise, this method will be called again on next call of Iterate().
 
Polling methods (for polling use) ...
bool OpenAttemptNow ()
 Query if the connection should be (re-)opened now. After the attempt, ReportOpenAttempt() must be called to report whether the attempt was successful or not.
 
bool CloseNow ()
 Query if the connection should be closed now. Closing must not fail.
 
Reporting about the service (for callback and polling use) ...
void ReportLost ()
 Report that the service is no longer running.
 
void ReportOpenAttempt (bool success)
 Report an open attempt (either successful or not). This must be called from DoOpen() or after OpenAttemptNow() has returned 'true' to confirm that an open attempt has taken placed.
 
void ReportClosed ()
 Report that the service was actually closed. This must be calld from DoClose() or after CloseNow() has returned 'true' to confirm that the service is actually closed.
 

Member Function Documentation

◆ Setup()

void CServiceKeeper::Setup ( TTicks  _tDShort,
TTicks  _tDLong = NEVER,
TTicks  _tShortToLong = NEVER 
)
inline

Setup the retry policy.

Parameters
_tDShortis the retry interval after the service got lost (e.g. disconnected / closed).
_tDLongis the retry interval after the service was lost for a longer time.
_tShortToLongis the time after which the retry interval is changed from _tDShort to _tDLong.

Definition at line 2146 of file base.H.

◆ Open()

void CServiceKeeper::Open ( )
inline

Request the service to open.

     Actual opening will be deferred until the next call to Iterate().

Definition at line 2155 of file base.H.

◆ Close()

void CServiceKeeper::Close ( )
inline

Request the service to close.

     Actual opening will be deferred until the next call to Iterate().
     To properly close the service, it must be closed explicitely by the caller.
     In callback use, this can be accomplished by calling Iterate() until IsOpen()
     returns 'false'.

Definition at line 2160 of file base.H.


The documentation for this class was generated from the following file: