A convenience class for responding to changes in a databaseState, potentially fired from other processes. Watches a given property's field corresponding to type T for changes, and fires a callback on change. Note that callback will run on a background timer thread, so if you need thread safety, be sure to utilise ISharedState::callOnMessageThread
from your callback lambda.
More...
#include <mostlyharmless_DatabasePropertyWatcher.h>
Public Member Functions | |
DatabasePropertyWatcher (const DatabasePropertyWatcher &)=delete | |
DatabasePropertyWatcher (DatabasePropertyWatcher &&) noexcept=delete | |
auto | operator= (const DatabasePropertyWatcher &) -> DatabasePropertyWatcher=delete |
auto | operator= (DatabasePropertyWatcher &&) noexcept -> DatabasePropertyWatcher=delete |
Static Public Member Functions | |
static auto | tryCreate (const DatabaseState &databaseState, std::string_view propertyName, int pollFrequencyMs, std::function< void(const T &)> &&callback) -> std::unique_ptr< DatabasePropertyWatcher > |
A convenience class for responding to changes in a databaseState, potentially fired from other processes. Watches a given property's field corresponding to type T for changes, and fires a callback on change. Note that callback will run on a background timer thread, so if you need thread safety, be sure to utilise ISharedState::callOnMessageThread
from your callback lambda.
T | Any type satisfying DatabaseStorageType |
|
delete |
Non copyable
|
deletenoexcept |
Non moveable
|
delete |
Non copyable
|
deletenoexcept |
Non moveable
|
inlinestatic |
Attempts to create a DatabasePropertyWatcher for the given property name. As sqlite requires database access across different processes to each have their own unique connection, we first call DatabaseState::duplicate
to create a new connection specifically for this thread.
databaseState | A const reference to the database connection to duplicate for this PropertyWatcher. |
propertyName | The name of the property to watch. |
pollFrequencyMs | The interval in milliseconds to poll the database for changes at. |
callback | A lambda to be invoked from a background timer thread on property value change. |