File indexing completed on 2024-07-14 05:24:23

0001 /*
0002     SPDX-FileCopyrightText: 2018 Nicolas Fella <nicolas.fella@gmx.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #include "canberracontext.h"
0008 
0009 namespace QPulseAudio
0010 {
0011 CanberraContext *CanberraContext::s_context = nullptr;
0012 
0013 CanberraContext *CanberraContext::instance()
0014 {
0015     if (!s_context) {
0016         s_context = new CanberraContext;
0017     }
0018     return s_context;
0019 }
0020 
0021 CanberraContext::CanberraContext(QObject *parent)
0022     : QObject(parent)
0023 {
0024     ca_context_create(&m_canberra);
0025 }
0026 
0027 CanberraContext::~CanberraContext()
0028 {
0029     if (m_canberra) {
0030         ca_context_destroy(m_canberra);
0031     }
0032 }
0033 
0034 ca_context *CanberraContext::canberra()
0035 {
0036     return m_canberra;
0037 }
0038 
0039 void CanberraContext::ref()
0040 {
0041     ++m_references;
0042 }
0043 
0044 void CanberraContext::unref()
0045 {
0046     if (--m_references == 0) {
0047         delete this;
0048         s_context = nullptr;
0049     }
0050 }
0051 }