MostlyHarmless 0.0.1
 
Loading...
Searching...
No Matches
mostly_harmless::data::DatabasePropertyWatcher< T > Class Template Referencefinal

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 >
 

Detailed Description

template<DatabaseStorageType T>
class mostly_harmless::data::DatabasePropertyWatcher< T >

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.

Template Parameters
TAny type satisfying DatabaseStorageType

Constructor & Destructor Documentation

◆ DatabasePropertyWatcher() [1/2]

template<DatabaseStorageType T>
mostly_harmless::data::DatabasePropertyWatcher< T >::DatabasePropertyWatcher ( const DatabasePropertyWatcher< T > & )
delete

Non copyable

◆ DatabasePropertyWatcher() [2/2]

template<DatabaseStorageType T>
mostly_harmless::data::DatabasePropertyWatcher< T >::DatabasePropertyWatcher ( DatabasePropertyWatcher< T > && )
deletenoexcept

Non moveable

Member Function Documentation

◆ operator=() [1/2]

template<DatabaseStorageType T>
auto mostly_harmless::data::DatabasePropertyWatcher< T >::operator= ( const DatabasePropertyWatcher< T > & ) -> DatabasePropertyWatcher=delete
delete

Non copyable

◆ operator=() [2/2]

template<DatabaseStorageType T>
auto mostly_harmless::data::DatabasePropertyWatcher< T >::operator= ( DatabasePropertyWatcher< T > && ) -> DatabasePropertyWatcher=delete
deletenoexcept

Non moveable

◆ tryCreate()

template<DatabaseStorageType T>
static auto mostly_harmless::data::DatabasePropertyWatcher< T >::tryCreate ( const DatabaseState & databaseState,
std::string_view propertyName,
int pollFrequencyMs,
std::function< void(const T &)> && callback ) -> std::unique_ptr<DatabasePropertyWatcher>
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.

Parameters
databaseStateA const reference to the database connection to duplicate for this PropertyWatcher.
propertyNameThe name of the property to watch.
pollFrequencyMsThe interval in milliseconds to poll the database for changes at.
callbackA lambda to be invoked from a background timer thread on property value change.
Returns
A DatabasePropertyWatcher for the given property name if successful, nullptr otherwise.

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