refactor(pulseaudio): remove wait timeout, fix indents

This commit is contained in:
NBonaparte 2017-10-07 20:19:06 -07:00
parent 6e8b9dea29
commit 1792090d66
3 changed files with 10 additions and 12 deletions

View file

@ -33,7 +33,7 @@ class pulseaudio {
const string& get_name(); const string& get_name();
bool wait(int timeout = -1); bool wait();
int process_events(); int process_events();
int get_volume(); int get_volume();

View file

@ -18,7 +18,7 @@ pulseaudio::pulseaudio(string&& sink_name) : spec_s_name(sink_name) {
pa_threaded_mainloop_free(m_mainloop); pa_threaded_mainloop_free(m_mainloop);
throw pulseaudio_error("Could not create pulseaudio context."); throw pulseaudio_error("Could not create pulseaudio context.");
} }
pa_context_set_state_callback(m_context, context_state_callback, this); pa_context_set_state_callback(m_context, context_state_callback, this);
if (pa_context_connect(m_context, nullptr, PA_CONTEXT_NOFLAGS, nullptr) < 0) { if (pa_context_connect(m_context, nullptr, PA_CONTEXT_NOFLAGS, nullptr) < 0) {
@ -94,11 +94,9 @@ const string& pulseaudio::get_name() {
} }
/** /**
* Wait for events (timeout in ms) * Wait for events
*/ */
bool pulseaudio::wait(int timeout) { bool pulseaudio::wait() {
// TODO wait for specified timeout
(void) timeout;
return m_events.size() > 0; return m_events.size() > 0;
} }
@ -122,11 +120,11 @@ int pulseaudio::process_events() {
break; break;
// get volume // get volume
case evtype::CHANGE: case evtype::CHANGE:
// doesn't do anything // doesn't do anything
o = pa_context_get_sink_info_by_index(m_context, m_index, get_sink_volume_callback, this); o = pa_context_get_sink_info_by_index(m_context, m_index, get_sink_volume_callback, this);
wait_loop(o, m_mainloop); wait_loop(o, m_mainloop);
break; break;
// get default sink // get default sink
case evtype::REMOVE: case evtype::REMOVE:
o = pa_context_get_server_info(m_context, get_default_sink_callback, this); o = pa_context_get_server_info(m_context, get_default_sink_callback, this);
wait_loop(o, m_mainloop); wait_loop(o, m_mainloop);
@ -252,7 +250,7 @@ void pulseaudio::subscribe_callback(pa_context *, pa_subscription_event_type_t t
switch(t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) { switch(t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) {
case PA_SUBSCRIPTION_EVENT_NEW: case PA_SUBSCRIPTION_EVENT_NEW:
This->m_events.emplace(evtype::NEW); This->m_events.emplace(evtype::NEW);
break; break;
case PA_SUBSCRIPTION_EVENT_CHANGE: case PA_SUBSCRIPTION_EVENT_CHANGE:
if (idx == This->m_index) if (idx == This->m_index)
This->m_events.emplace(evtype::CHANGE); This->m_events.emplace(evtype::CHANGE);
@ -282,7 +280,7 @@ void pulseaudio::simple_callback(pa_context *, int success, void *userdata) {
void pulseaudio::get_default_sink_callback(pa_context *, const pa_server_info *info, void *userdata) { void pulseaudio::get_default_sink_callback(pa_context *, const pa_server_info *info, void *userdata) {
pulseaudio *This = static_cast<pulseaudio *>(userdata); pulseaudio *This = static_cast<pulseaudio *>(userdata);
if (info->default_sink_name) { if (info->default_sink_name) {
This->def_s_name = info->default_sink_name; This->def_s_name = info->default_sink_name;
This->s_name = info->default_sink_name; This->s_name = info->default_sink_name;
} else } else
This->def_s_name = ""s; This->def_s_name = ""s;

View file

@ -49,7 +49,7 @@ namespace modules {
bool pulseaudio_module::has_event() { bool pulseaudio_module::has_event() {
// Poll for mixer and control events // Poll for mixer and control events
try { try {
if (m_pulseaudio->wait(25)) if (m_pulseaudio->wait())
return true; return true;
} catch (const pulseaudio_error& e) { } catch (const pulseaudio_error& e) {
m_log.err("%s: %s", name(), e.what()); m_log.err("%s: %s", name(), e.what());
@ -146,7 +146,7 @@ namespace modules {
} else { } else {
return false; return false;
} }
if (m_pulseaudio->wait(0)) { if (m_pulseaudio->wait()) {
m_pulseaudio->process_events(); m_pulseaudio->process_events();
} }
} }