Skip to content

Commit

Permalink
Use setData helper for DirectSpeaker metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
rsjbailey committed Oct 15, 2021
1 parent 9c873c7 commit 156a2d3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ class DirectSpeakersMetadataSender {
void startTimer();
MessageBuffer getMessage();
void handleTimeout(std::error_code ec);
template<typename FunctionT>
void setData(FunctionT&& set) {
std::lock_guard<std::mutex> dataLock{dataMutex_};
data_.set_changed(true);
set(&data_);
}

std::shared_ptr<spdlog::logger> logger_;
nng::PushSocket socket_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,19 @@ void DirectSpeakersMetadataSender::handleTimeout(std::error_code ec) {
}

void DirectSpeakersMetadataSender::routing(int32_t value) {
std::lock_guard<std::mutex> lock(dataMutex_);
data_.set_changed(true);
data_.set_routing(value);
setData([value](auto data) { data->set_routing(value); });
}
void DirectSpeakersMetadataSender::name(const std::string& value) {
std::lock_guard<std::mutex> lock(dataMutex_);
data_.set_name(value);
setData([&value](auto data) { data->set_name(value); });
}
void DirectSpeakersMetadataSender::colour(int value) {
std::lock_guard<std::mutex> lock(dataMutex_);
data_.set_colour(value);
setData([value](auto data) { data->set_colour(value); });
}
void DirectSpeakersMetadataSender::speakerSetupIndex(int value) {
std::lock_guard<std::mutex> lock(dataMutex_);
data_.set_changed(true);
data_.set_allocated_ds_metadata(
proto::convertSpeakerSetupToEpsMetadata(value));
setData([value](auto data) {
data->set_allocated_ds_metadata(
proto::convertSpeakerSetupToEpsMetadata(value));
});
}

} // namespace communication
Expand Down

0 comments on commit 156a2d3

Please sign in to comment.