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);
|
|
|
|
}
|
|
|
|
|
2018-10-02 06:27:51 +00:00
|
|
|
bool QPulse::RequestServerInfo()
|
2018-10-01 07:00:27 +00:00
|
|
|
{
|
|
|
|
//ThreadedMainLoopLock lock(ml);
|
|
|
|
|
2018-10-02 06:27:51 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-10-02 06:27:51 +00:00
|
|
|
bool QPulse::RequestCardInfo()
|
2018-10-01 07:00:27 +00:00
|
|
|
{
|
|
|
|
//ThreadedMainLoopLock lock(ml);
|
|
|
|
|
2018-10-02 06:27:51 +00:00
|
|
|
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);
|
|
|
|
|
2018-10-02 06:27:25 +00:00
|
|
|
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);
|
|
|
|
|
2018-10-02 06:27:25 +00:00
|
|
|
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();
|
|
|
|
}
|