pa-card-profile-tray/qpulse.cpp

77 lines
1.8 KiB
C++
Raw Normal View History

2018-10-01 07:00:27 +00:00
#include "qpulse.h"
#include "threadedmainlooplock.h"
QPulse::QPulse(QObject *parent) :
QObject(parent),
ml(pa_threaded_mainloop_new()),
c(nullptr)
{
pa_threaded_mainloop_start(ml);
c = pa_context_new( pa_threaded_mainloop_get_api(ml), "pa-card-profile-tray");
pa_context_set_state_callback(c, &QPulse::onConnectionStateChangedSt, this);
pa_context_connect(c, nullptr, PA_CONTEXT_NOFLAGS, nullptr);
}
QPulse::~QPulse()
{
pa_context_disconnect(c);
pa_threaded_mainloop_stop(ml);
pa_threaded_mainloop_free(ml);
}
pa_context_state_t QPulse::ConnectionState()
{
//ThreadedMainLoopLock lock(ml);
return pa_context_get_state(c);
}
bool QPulse::RequestServerInfo()
2018-10-01 07:00:27 +00:00
{
//ThreadedMainLoopLock lock(ml);
pa_operation* o = pa_context_get_server_info(c, &QPulse::onGotServerInfoSt, this);
if (! o) {
return false;
}
pa_operation_unref(o);
2018-10-01 07:00:27 +00:00
}
bool QPulse::RequestCardInfo()
2018-10-01 07:00:27 +00:00
{
//ThreadedMainLoopLock lock(ml);
pa_operation* o = pa_context_get_card_info_list(c, &QPulse::onGotCardInfoListSt, this);
if (! o) {
return false;
}
pa_operation_unref(o);
2018-10-01 07:00:27 +00:00
}
void QPulse::onGotCardInfoListSt(pa_context*, const pa_card_info *i, int eol, void *userdata)
{
QPulse* qp = static_cast<QPulse*>(userdata);
//ThreadedMainLoopLock lock(qp->ml);
emit qp->GotCardInfoList(*i, eol);
2018-10-01 07:00:27 +00:00
}
void QPulse::onGotServerInfoSt(pa_context*, const pa_server_info *i, void *userdata)
{
QPulse* qp = static_cast<QPulse*>(userdata);
//ThreadedMainLoopLock lock(qp->ml);
emit qp->GotServerInfo(*i);
2018-10-01 07:00:27 +00:00
}
void QPulse::onConnectionStateChangedSt(pa_context*, void *userdata)
{
QPulse* qp = static_cast<QPulse*>(userdata);
//ThreadedMainLoopLock lock(qp->ml);
emit qp->ConnectionStateChanged();
}