/usr/include/Poco/Data/SQLite/Notifier.h is in libpoco-dev 1.8.0.1-1ubuntu4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | //
// Notifier.h
//
// Library: Data/SQLite
// Package: SQLite
// Module: Notifier
//
// Definition of Notifier.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef SQLite_Notifier_INCLUDED
#define SQLite_Notifier_INCLUDED
#include "Poco/Data/SQLite/SQLite.h"
#include "Poco/Data/SQLite/Utility.h"
#include "Poco/Data/Session.h"
#include "Poco/Mutex.h"
#include "Poco/Types.h"
#include "Poco/Dynamic/Var.h"
#include "Poco/BasicEvent.h"
#include <map>
namespace Poco {
namespace Data {
namespace SQLite {
class SQLite_API Notifier
/// Notifier is a wrapper for SQLite callback calls. It supports event callbacks
/// for insert, update, delete, commit and rollback events. While (un)registering
/// callbacks is thread-safe, execution of the callbacks themselves are not;
/// it is the user's responsibility to ensure the thread-safey of the functions
/// they provide as callback target. Additionally, commit callbacks may prevent
/// database transactions from succeeding (see sqliteCommitCallbackFn documentation
/// for details).
///
/// There can be only one set of callbacks per session (i.e. registering a new
/// callback automatically unregisters the previous one). All callbacks are
/// registered and enabled at Notifier contruction time and can be disabled
/// at a later point time.
{
public:
typedef unsigned char EnabledEventType;
/// A type definition for events-enabled bitmap.
typedef Poco::BasicEvent<void> Event;
//
// Events
//
Event update;
Event insert;
Event erase;
Event commit;
Event rollback;
// Event types.
static const EnabledEventType SQLITE_NOTIFY_UPDATE = 1;
static const EnabledEventType SQLITE_NOTIFY_COMMIT = 2;
static const EnabledEventType SQLITE_NOTIFY_ROLLBACK = 4;
Notifier(const Session& session,
EnabledEventType enabled = SQLITE_NOTIFY_UPDATE | SQLITE_NOTIFY_COMMIT | SQLITE_NOTIFY_ROLLBACK);
/// Creates a Notifier and enables all callbacks.
Notifier(const Session& session,
const Any& value,
EnabledEventType enabled = SQLITE_NOTIFY_UPDATE | SQLITE_NOTIFY_COMMIT | SQLITE_NOTIFY_ROLLBACK);
/// Creates a Notifier, assigns the value to the internal storage and and enables all callbacks.
~Notifier();
/// Disables all callbacks and destroys the Notifier.
bool enableUpdate();
/// Enables update callbacks.
bool disableUpdate();
/// Disables update callbacks.
bool updateEnabled() const;
/// Returns true if update callbacks are enabled, false otherwise.
bool enableCommit();
/// Enables commit callbacks.
bool disableCommit();
/// Disables commit callbacks.
bool commitEnabled() const;
/// Returns true if update callbacks are enabled, false otherwise.
bool enableRollback();
/// Enables rollback callbacks.
bool disableRollback();
/// Disables rollback callbacks.
bool rollbackEnabled() const;
/// Returns true if rollback callbacks are enabled, false otherwise.
bool enableAll();
/// Enables all callbacks.
bool disableAll();
/// Disables all callbacks.
static void sqliteUpdateCallbackFn(void* pVal, int opCode, const char* pDB, const char* pTable, Poco::Int64 row);
/// Update callback event dispatcher. Determines the type of the event, updates the row number
/// and triggers the event.
static int sqliteCommitCallbackFn(void* pVal);
/// Commit callback event dispatcher. If an exception occurs, it is catched inside this function,
/// non-zero value is returned, which causes SQLite engine to turn commit into a rollback.
/// Therefore, callers should check for return value - if it is zero, callback completed succesfuly
/// and transaction was committed.
static void sqliteRollbackCallbackFn(void* pVal);
/// Rollback callback event dispatcher.
bool operator == (const Notifier& other) const;
/// Equality operator. Compares value, row and database handles and
/// returns true iff all are equal.
Poco::Int64 getRow() const;
/// Returns the row number.
void setRow(Poco::Int64 row);
/// Sets the row number.
const Poco::Dynamic::Var& getValue() const;
/// Returns the value.
template <typename T>
inline void setValue(const T& val)
/// Sets the value.
{
_value = val;
}
private:
Notifier();
Notifier(const Notifier&);
Notifier& operator=(const Notifier&);
const Session& _session;
Poco::Dynamic::Var _value;
Poco::Int64 _row;
EnabledEventType _enabledEvents;
Poco::Mutex _mutex;
};
//
// inlines
//
inline bool Notifier::operator == (const Notifier& other) const
{
return _value == other._value &&
_row == other._row &&
Utility::dbHandle(_session) == Utility::dbHandle(other._session);
}
inline Poco::Int64 Notifier::getRow() const
{
return _row;
}
inline void Notifier::setRow(Poco::Int64 row)
/// Sets the row number.
{
_row = row;
}
inline const Poco::Dynamic::Var& Notifier::getValue() const
{
return _value;
}
} } } // namespace Poco::Data::SQLite
#endif // SQLite_Notifier_INCLUDED
|