|
Wt
4.14.1
|
Class for sending and listening for notification trough a database. More...
#include <Wt/Dbo/NotificationListener.h>
Public Member Functions | |
| NotificationListener () | |
| Create a NotificationListener. | |
| NotificationListener (std::unique_ptr< SqlConnection > connection) | |
| Create and connect a NotificationListener. | |
| ~NotificationListener () | |
| Destroy the NotificationListener. | |
| void | connect (std::unique_ptr< SqlConnection > connection) |
| Connect the NotificationListener to a database. | |
| void | disconnect () |
| Disconnect the NotificationListener. | |
| void | notify (const std::string &channel, const std::string &message="") |
| Send a notification. | |
| template<class C > | |
| void | notify (const ptr< C > &obj) |
| Send a notification. | |
| void | setCallback (const std::string &channel, const std::function< void(const std::string &, const std::string &)> &callback) |
| Sets a function to be called when a notification is received. | |
| void | removeCallback (const std::string &channel) |
| Removes the callback for the given channel. | |
Class for sending and listening for notification trough a database.
A NotificationListener send notification trough a database and listen for notification from the database it is connected to. Each notification is send trough a 'channel' and for each notification recieved on a channel, the NotificationListener will emit a signal which is unique for each channel.
subscribe , notify , getNextNotify , setupNotify and stopListen must be implemented for the specific database. This can be done by inheriting from the connection to the specific database and overriding those functions.
|
explicit |
Create and connect a NotificationListener.
Create a new NotificationListener and directly connect it to the database usig the given connection.
| void Wt::Dbo::NotificationListener::connect | ( | std::unique_ptr< SqlConnection > | connection | ) |
Connect the NotificationListener to a database.
Connect the NotificationListener to the database using the given connection. The connection will be used exclusively by this NotificationListener.
Calling this function will destroy any connection already used by the NotificationListener.
| void Wt::Dbo::NotificationListener::disconnect | ( | ) |
Disconnect the NotificationListener.
Disconnect the NotificationListener from the database it is connected to.
Send a notification.
Helper function that sends a notification on the channel with the name of the table the object of the pointer belogns to, and with the id of the object as the message.
| void Wt::Dbo::NotificationListener::notify | ( | const std::string & | channel, |
| const std::string & | message = "" |
||
| ) |
Send a notification.
Sends a notification with the given message on the given channel. If no message is given, en empty string will be sent as message.
Removes the callback for the given channel.
This removes the callback function for the given channel.
| void Wt::Dbo::NotificationListener::setCallback | ( | const std::string & | channel, |
| const std::function< void(const std::string &, const std::string &)> & | callback | ||
| ) |
Sets a function to be called when a notification is received.
This sets the function callback as the function to be called when a notification is received on the given channel. The callback function will take two strings as arguments. The first string is the message received and the second string is the name of the channel the notification was sent on.