From c99e05026f918a44dd43ba58ceaa15ecdd9bb7ad Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Sat, 6 Sep 2025 15:41:19 +1000 Subject: plugin: abstract service + ref --- plugin/src/Caelestia/service.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 plugin/src/Caelestia/service.cpp (limited to 'plugin/src/Caelestia/service.cpp') diff --git a/plugin/src/Caelestia/service.cpp b/plugin/src/Caelestia/service.cpp new file mode 100644 index 0000000..9c13421 --- /dev/null +++ b/plugin/src/Caelestia/service.cpp @@ -0,0 +1,39 @@ +#include "service.hpp" + +#include +#include + +namespace caelestia { + +Service::Service(QObject* parent) + : QObject(parent) + , m_refCount(0) {} + +int Service::refCount() const { + return m_refCount; +} + +void Service::ref() { + if (m_refCount == 0) { + start(); + } + + m_refCount++; + emit refCountChanged(); +} + +void Service::unref() { + if (m_refCount == 0) { + qWarning() << "ServiceRef::unref: attempted to unref service with no active refs"; + return; + } + + m_refCount--; + emit refCountChanged(); + + if (m_refCount == 0) { + stop(); + } +} + +} // namespace caelestia -- cgit v1.2.3-freya