67 lines
1.6 KiB
C++
67 lines
1.6 KiB
C++
#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);
|
|
}
|
|
|
|
void QPulse::RequestServerInfo()
|
|
{
|
|
//ThreadedMainLoopLock lock(ml);
|
|
|
|
pa_context_get_server_info(c, &QPulse::onGotServerInfoSt, this);
|
|
}
|
|
|
|
void QPulse::RequestCardInfo()
|
|
{
|
|
//ThreadedMainLoopLock lock(ml);
|
|
|
|
pa_context_get_card_info_list(c, &QPulse::onGotCardInfoListSt, this);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
void QPulse::onConnectionStateChangedSt(pa_context*, void *userdata)
|
|
{
|
|
QPulse* qp = static_cast<QPulse*>(userdata);
|
|
//ThreadedMainLoopLock lock(qp->ml);
|
|
|
|
emit qp->ConnectionStateChanged();
|
|
}
|