summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2016-12-29 23:23:28 +0100
committerMax Kellermann <max@musicpd.org>2016-12-29 23:28:54 +0100
commit4484411a77fe3f01fc450e525729a2c6f5911024 (patch)
treea2989f7cde4734d01f781ded4e8fbff20d8764e9
parent61a151c803b2794804a73b7810136b5f43940d04 (diff)
output/Internal: add various trivial getter methods
-rw-r--r--src/mixer/MixerAll.cxx4
-rw-r--r--src/output/Finish.cxx2
-rw-r--r--src/output/Internal.hxx24
-rw-r--r--src/output/MultipleOutputs.cxx16
-rw-r--r--src/output/OutputPrint.cxx2
-rw-r--r--src/output/OutputState.cxx3
6 files changed, 38 insertions, 13 deletions
diff --git a/src/mixer/MixerAll.cxx b/src/mixer/MixerAll.cxx
index f82d940f6..ae423f089 100644
--- a/src/mixer/MixerAll.cxx
+++ b/src/mixer/MixerAll.cxx
@@ -45,7 +45,7 @@ output_mixer_get_volume(const AudioOutput &ao)
} catch (const std::runtime_error &e) {
FormatError(e,
"Failed to read mixer for '%s'",
- ao.name);
+ ao.GetName());
return -1;
}
}
@@ -88,7 +88,7 @@ output_mixer_set_volume(AudioOutput &ao, unsigned volume)
} catch (const std::runtime_error &e) {
FormatError(e,
"Failed to set mixer for '%s'",
- ao.name);
+ ao.GetName());
return false;
}
}
diff --git a/src/output/Finish.cxx b/src/output/Finish.cxx
index 13c1c82bc..350330193 100644
--- a/src/output/Finish.cxx
+++ b/src/output/Finish.cxx
@@ -42,7 +42,7 @@ AudioOutput::~AudioOutput()
void
audio_output_free(AudioOutput *ao)
{
- assert(!ao->open);
+ assert(!ao->IsOpen());
assert(!ao->fail_timer.IsDefined());
assert(!ao->thread.IsDefined());
diff --git a/src/output/Internal.hxx b/src/output/Internal.hxx
index a5b56edda..ae030bc8f 100644
--- a/src/output/Internal.hxx
+++ b/src/output/Internal.hxx
@@ -288,15 +288,39 @@ public:
void BeginDestroy();
void FinishDestroy();
+ const char *GetName() const {
+ return name;
+ }
+
+ /**
+ * Caller must lock the mutex.
+ */
+ bool IsEnabled() const {
+ return enabled;
+ }
+
+ /**
+ * Caller must lock the mutex.
+ */
bool IsOpen() const {
return open;
}
+ /**
+ * Caller must lock the mutex.
+ */
bool IsCommandFinished() const {
return command == Command::NONE;
}
/**
+ * Caller must lock the mutex.
+ */
+ const std::exception_ptr &GetLastError() const {
+ return last_error;
+ }
+
+ /**
* Waits for command completion.
*
* Caller must lock the mutex.
diff --git a/src/output/MultipleOutputs.cxx b/src/output/MultipleOutputs.cxx
index 10b918d30..e56fe2f2a 100644
--- a/src/output/MultipleOutputs.cxx
+++ b/src/output/MultipleOutputs.cxx
@@ -76,9 +76,9 @@ MultipleOutputs::Configure(EventLoop &event_loop,
auto output = LoadOutput(event_loop, replay_gain_config,
mixer_listener,
client, *param);
- if (FindByName(output->name) != nullptr)
+ if (FindByName(output->GetName()) != nullptr)
throw FormatRuntimeError("output devices with identical "
- "names: %s", output->name);
+ "names: %s", output->GetName());
outputs.push_back(output);
}
@@ -97,7 +97,7 @@ AudioOutput *
MultipleOutputs::FindByName(const char *name) const
{
for (auto i : outputs)
- if (strcmp(i->name, name) == 0)
+ if (strcmp(i->GetName(), name) == 0)
return i;
return nullptr;
@@ -217,13 +217,13 @@ MultipleOutputs::Open(const AudioFormat audio_format,
for (auto ao : outputs) {
const ScopeLock lock(ao->mutex);
- if (ao->enabled)
+ if (ao->IsEnabled())
enabled = true;
- if (ao->open)
+ if (ao->IsOpen())
ret = true;
- else if (ao->last_error && !first_error)
- first_error = ao->last_error;
+ else if (!first_error)
+ first_error = ao->GetLastError();
}
if (!enabled) {
@@ -265,7 +265,7 @@ MultipleOutputs::ClearTailChunk(const MusicChunk *chunk,
/* this mutex will be unlocked by the caller when it's
ready */
ao->mutex.lock();
- locked[i] = ao->open;
+ locked[i] = ao->IsOpen();
if (!locked[i]) {
ao->mutex.unlock();
diff --git a/src/output/OutputPrint.cxx b/src/output/OutputPrint.cxx
index 9ddb67d1e..9a8f5b745 100644
--- a/src/output/OutputPrint.cxx
+++ b/src/output/OutputPrint.cxx
@@ -37,6 +37,6 @@ printAudioDevices(Response &r, const MultipleOutputs &outputs)
r.Format("outputid: %i\n"
"outputname: %s\n"
"outputenabled: %i\n",
- i, ao.name, ao.enabled);
+ i, ao.GetName(), ao.IsEnabled());
}
}
diff --git a/src/output/OutputState.cxx b/src/output/OutputState.cxx
index ca6d4de5f..981bb024a 100644
--- a/src/output/OutputState.cxx
+++ b/src/output/OutputState.cxx
@@ -45,7 +45,8 @@ audio_output_state_save(BufferedOutputStream &os,
const AudioOutput &ao = outputs.Get(i);
const ScopeLock lock(ao.mutex);
- os.Format(AUDIO_DEVICE_STATE "%d:%s\n", ao.enabled, ao.name);
+ os.Format(AUDIO_DEVICE_STATE "%d:%s\n",
+ ao.IsEnabled(), ao.GetName());
}
}