summaryrefslogtreecommitdiff
path: root/plugin/src/Caelestia/service.cpp
blob: 9c13421d7fe4cef561cecd9bad5be1a5e1a1bd6e (plain)
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
#include "service.hpp"

#include <QDebug>
#include <QObject>

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