Expose API to notify about variable value change

This commit is contained in:
WarmUpTill 2026-06-13 23:24:21 +02:00
parent 89ffa6611c
commit 28a0ca8fcf
2 changed files with 20 additions and 8 deletions

View File

@ -108,16 +108,20 @@ std::optional<int> Variable::IntValue() const
void Variable::SetValue(const std::string &value)
{
std::lock_guard<std::mutex> lock(_mutex);
_previousValue = _value;
_value = value;
{
std::lock_guard<std::mutex> lock(_mutex);
_previousValue = _value;
_value = value;
UpdateLastUsed();
if (_previousValue != _value) {
_lastChanged = std::chrono::high_resolution_clock::now();
++_valueChangeCount;
UpdateLastUsed();
if (_previousValue != _value) {
_lastChanged =
std::chrono::high_resolution_clock::now();
++_valueChangeCount;
}
setLastVariableChangeTime();
}
setLastVariableChangeTime();
_cv.notify_all();
}
void Variable::SetValue(double value)

View File

@ -3,6 +3,7 @@
#include "item-selection-helpers.hpp"
#include "resizing-text-edit.hpp"
#include <condition_variable>
#include <mutex>
#include <obs-data.h>
#include <optional>
@ -43,6 +44,11 @@ public:
std::optional<uint64_t> GetSecondsSinceLastUse() const;
std::optional<uint64_t> GetSecondsSinceLastChange() const;
void MarkAsUsed() const;
EXPORT std::condition_variable &GetCV() { return _cv; }
EXPORT std::unique_lock<std::mutex> GetCVLock()
{
return std::unique_lock<std::mutex>(_cvMutex);
}
private:
SaveAction _saveAction = SaveAction::DONT_SAVE;
@ -53,6 +59,8 @@ private:
mutable std::chrono::high_resolution_clock::time_point _lastUsed;
mutable std::chrono::high_resolution_clock::time_point _lastChanged;
mutable std::mutex _mutex;
std::mutex _cvMutex;
std::condition_variable _cv;
void UpdateLastUsed() const;