mirror of
https://github.com/pocoproject/poco.git
synced 2025-12-08 12:19:21 +01:00
* chore(CppParser): 0, NULL --> nullptr * chore(Crypto): 0, NULL --> nullptr * chore(DNSSD): 0, NULL --> nullptr * chore(Encodings): 0, NULL --> nullptr * chore(CppUnit): Correct indentation. * chore(Foundation): 0, NULL --> nullptr * chore(CMake): Always warn about wrong nullptr usage when compiling with GCC or CLang * chore(Net): 0, NULL --> nullptr * chore(Foundation): 0, NULL --> nullptr * chore(Data): 0, NULL --> nullptr * chore(macOS): 0, NULL --> nullptr * chore(XML): 0, NULL --> nullptr * chore(Zip): 0, NULL --> nullptr * chore(Util): 0, NULL --> nullptr * chore(Net/NetSSL): 0, NULL --> nullptr * chore(Bonjour): 0, NULL --> nullptr * chore(MongoDB, Redis): 0, NULL --> nullptr * chore(Poco): 0, NULL --> nullptr * chore(Win32): 0, NULL --> nullptr * chore(CMake): Only warn about nullptr when verbose warnings are enabled. * Potential fix for code scanning alert no. 1634: Guarded Free Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * chore(Net): Fix warning reported by gitlab. * chore(gitlab CI): attempt to clean to gain disk space on the runner. * chore(gitlab CI): Run build with --parallel 4, correct docker cleanup. --------- Co-authored-by: Aleksandar Fabijanic <aleks-f@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
204 lines
3.8 KiB
C++
204 lines
3.8 KiB
C++
//
|
|
// Notifier.cpp
|
|
//
|
|
// Library: Data/SQLite
|
|
// Package: SQLite
|
|
// Module: Notifier
|
|
//
|
|
// Implementation of Notifier
|
|
//
|
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
|
// and Contributors.
|
|
//
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
//
|
|
|
|
|
|
#include "Poco/Data/SQLite/Notifier.h"
|
|
|
|
|
|
namespace Poco {
|
|
namespace Data {
|
|
namespace SQLite {
|
|
|
|
|
|
Notifier::Notifier(const Session& session, EnabledEventType enabled):
|
|
_session(session)
|
|
{
|
|
if (enabled & SQLITE_NOTIFY_UPDATE) enableUpdate();
|
|
if (enabled & SQLITE_NOTIFY_COMMIT) enableCommit();
|
|
if (enabled & SQLITE_NOTIFY_ROLLBACK) enableRollback();
|
|
}
|
|
|
|
|
|
Notifier::Notifier(const Session& session, const Any& value, EnabledEventType enabled):
|
|
_session(session),
|
|
_value(value)
|
|
{
|
|
if (enabled & SQLITE_NOTIFY_UPDATE) enableUpdate();
|
|
if (enabled & SQLITE_NOTIFY_COMMIT) enableCommit();
|
|
if (enabled & SQLITE_NOTIFY_ROLLBACK) enableRollback();
|
|
}
|
|
|
|
|
|
Notifier::~Notifier()
|
|
{
|
|
try
|
|
{
|
|
disableAll();
|
|
}
|
|
catch (...)
|
|
{
|
|
poco_unexpected();
|
|
}
|
|
}
|
|
|
|
|
|
bool Notifier::enableUpdate()
|
|
{
|
|
Poco::Mutex::ScopedLock l(_mutex);
|
|
|
|
if (Utility::registerUpdateHandler(Utility::dbHandle(_session), &sqliteUpdateCallbackFn, this))
|
|
_enabledEvents |= SQLITE_NOTIFY_UPDATE;
|
|
|
|
return updateEnabled();
|
|
}
|
|
|
|
|
|
bool Notifier::disableUpdate()
|
|
{
|
|
Poco::Mutex::ScopedLock l(_mutex);
|
|
|
|
if (Utility::registerUpdateHandler(Utility::dbHandle(_session), (Utility::UpdateCallbackType) nullptr, this))
|
|
_enabledEvents &= ~SQLITE_NOTIFY_UPDATE;
|
|
|
|
return !updateEnabled();
|
|
}
|
|
|
|
|
|
bool Notifier::updateEnabled() const
|
|
{
|
|
return 0 != (_enabledEvents & SQLITE_NOTIFY_UPDATE);
|
|
}
|
|
|
|
|
|
bool Notifier::enableCommit()
|
|
{
|
|
Poco::Mutex::ScopedLock l(_mutex);
|
|
|
|
if (Utility::registerUpdateHandler(Utility::dbHandle(_session), &sqliteCommitCallbackFn, this))
|
|
_enabledEvents |= SQLITE_NOTIFY_COMMIT;
|
|
|
|
return commitEnabled();
|
|
}
|
|
|
|
|
|
bool Notifier::disableCommit()
|
|
{
|
|
Poco::Mutex::ScopedLock l(_mutex);
|
|
|
|
if (Utility::registerUpdateHandler(Utility::dbHandle(_session), (Utility::CommitCallbackType) nullptr, this))
|
|
_enabledEvents &= ~SQLITE_NOTIFY_COMMIT;
|
|
|
|
return !commitEnabled();
|
|
}
|
|
|
|
|
|
bool Notifier::commitEnabled() const
|
|
{
|
|
return 0 != (_enabledEvents & SQLITE_NOTIFY_COMMIT);
|
|
}
|
|
|
|
|
|
bool Notifier::enableRollback()
|
|
{
|
|
Poco::Mutex::ScopedLock l(_mutex);
|
|
|
|
if (Utility::registerUpdateHandler(Utility::dbHandle(_session), &sqliteRollbackCallbackFn, this))
|
|
_enabledEvents |= SQLITE_NOTIFY_ROLLBACK;
|
|
|
|
return rollbackEnabled();
|
|
}
|
|
|
|
|
|
bool Notifier::disableRollback()
|
|
{
|
|
Poco::Mutex::ScopedLock l(_mutex);
|
|
|
|
if (Utility::registerUpdateHandler(Utility::dbHandle(_session), (Utility::RollbackCallbackType) nullptr, this))
|
|
_enabledEvents &= ~SQLITE_NOTIFY_ROLLBACK;
|
|
|
|
return !rollbackEnabled();
|
|
}
|
|
|
|
|
|
bool Notifier::rollbackEnabled() const
|
|
{
|
|
return 0 != (_enabledEvents & SQLITE_NOTIFY_ROLLBACK);
|
|
}
|
|
|
|
|
|
bool Notifier::enableAll()
|
|
{
|
|
return enableUpdate() && enableCommit() && enableRollback();
|
|
}
|
|
|
|
|
|
bool Notifier::disableAll()
|
|
{
|
|
return disableUpdate() && disableCommit() && disableRollback();
|
|
}
|
|
|
|
|
|
void Notifier::sqliteUpdateCallbackFn(void* pVal, int opCode, const char* pDB, const char* pTable, Poco::Int64 row)
|
|
{
|
|
poco_check_ptr(pVal);
|
|
Notifier* pV = reinterpret_cast<Notifier*>(pVal);
|
|
|
|
if (opCode == Utility::OPERATION_INSERT)
|
|
{
|
|
pV->_table = pTable;
|
|
pV->_row = row;
|
|
pV->insert.notify(pV);
|
|
}
|
|
else if (opCode == Utility::OPERATION_UPDATE)
|
|
{
|
|
pV->_table = pTable;
|
|
pV->_row = row;
|
|
pV->update.notify(pV);
|
|
}
|
|
else if (opCode == Utility::OPERATION_DELETE)
|
|
{
|
|
pV->_table = pTable;
|
|
pV->_row = row;
|
|
pV->erase.notify(pV);
|
|
}
|
|
}
|
|
|
|
|
|
int Notifier::sqliteCommitCallbackFn(void* pVal)
|
|
{
|
|
Notifier* pV = reinterpret_cast<Notifier*>(pVal);
|
|
|
|
try
|
|
{
|
|
pV->commit.notify(pV);
|
|
}
|
|
catch (...)
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
void Notifier::sqliteRollbackCallbackFn(void* pVal)
|
|
{
|
|
Notifier* pV = reinterpret_cast<Notifier*>(pVal);
|
|
pV->rollback.notify(pV);
|
|
}
|
|
|
|
|
|
} } } // namespace Poco::Data::SQLite
|