DatabaseActivityMonitor
The DatabaseActivityMonitor class is used to notify WinCC OA about the state of the connection between the backend and the
database.
This class contains the following functions:
- setConnectionEstablishedCallback - This sets up a callback function that will be triggered when notifyActivity() is called, but only after notifyConnectionFailure() has been called first.
- setConnectionLostCallback - This sets up a callback function that will be triggered when notifyConnectionFailure() is called, but only after notifyActivity() has been called first.
- notifyActivity - This method triggers the onConnectionEstablished callback, but only if the most recent callback that was called was onConnectionLost. Use this method when there are no errors with the database connection. - Calls the onConnectionEstablished callback if the last called callback was onConnectionLost. Call this method if there are no database connection errors.
- notifyConnectionFailure - This method triggers the onConnectionLost callback, but only if the most recent callback that was called was onConnectionEstablished. Use this method whenever there are errors with the database connection.
- hasTimeoutExpired - Checks the timeout of the last update of the database connection state.
- resetTimeout - Resets the timeout of the last update of the database connection state.
- setNewTimeout - Sets the new value of timeout of the last update of the database connection state.
Example
DatabaseActivityMonitor databaseActivityMonitor(activityMonitorTimeout);
databaseActivityMonitor.setConnectionEstablishedCallback([&]()
{
if (doExit)
{
return;
}
sendMonitoringUpdateForDatabaseConnectionState(configChannelHandler, DatabaseActivityMonitor::DatabaseConnectionState::Established);
logger.logDebug("[Backend] Backend has established/restored connection with database");
});
databaseActivityMonitor.setConnectionLostCallback([&]()
{
if (doExit)
{
return;
}
logger.logWarning("[Backend] The connection to the database has been lost.");
sendMonitoringUpdateForDatabaseConnectionState(configChannelHandler, DatabaseActivityMonitor::DatabaseConnectionState::Lost);
});
if(pingDatabase())
{
databaseActivityMonitor.notifyActivity();
}
else
{
databaseActivityMonitor.notifyConnectionFailure();
}
