Reformat code with clang 10

This commit is contained in:
badaix 2020-11-27 21:29:34 +01:00
parent 59763f03c1
commit 3ac9245d00
24 changed files with 174 additions and 155 deletions

View file

@ -281,6 +281,8 @@ IF(CLANG_FORMAT)
server/*.[ch]pp
)
list(REMOVE_ITEM CHECK_CXX_SOURCE_FILES "${CMAKE_SOURCE_DIR}/common/json.hpp")
ADD_CUSTOM_TARGET(
reformat
COMMAND

View file

@ -176,9 +176,10 @@ bool BrowseBonjour::browse(const string& serviceName, mDNSResult& result, int /*
deque<mDNSReply> replyCollection;
{
DNSServiceHandle service(new DNSServiceRef(NULL));
CHECKED(DNSServiceBrowse(service.get(), 0, 0, serviceName.c_str(), "local.",
[](DNSServiceRef /*service*/, DNSServiceFlags /*flags*/, uint32_t /*interfaceIndex*/, DNSServiceErrorType errorCode,
const char* serviceName, const char* regtype, const char* replyDomain, void* context) {
CHECKED(DNSServiceBrowse(
service.get(), 0, 0, serviceName.c_str(), "local.",
[](DNSServiceRef /*service*/, DNSServiceFlags /*flags*/, uint32_t /*interfaceIndex*/, DNSServiceErrorType errorCode, const char* serviceName,
const char* regtype, const char* replyDomain, void* context) {
auto replyCollection = static_cast<deque<mDNSReply>*>(context);
CHECKED(errorCode);
@ -194,10 +195,10 @@ bool BrowseBonjour::browse(const string& serviceName, mDNSResult& result, int /*
{
DNSServiceHandle service(new DNSServiceRef(NULL));
for (auto& reply : replyCollection)
CHECKED(DNSServiceResolve(service.get(), 0, 0, reply.name.c_str(), reply.regtype.c_str(), reply.domain.c_str(),
[](DNSServiceRef /*service*/, DNSServiceFlags /*flags*/, uint32_t /*interfaceIndex*/, DNSServiceErrorType errorCode,
const char* /*fullName*/, const char* hosttarget, uint16_t port, uint16_t /*txtLen*/,
const unsigned char* /*txtRecord*/, void* context) {
CHECKED(DNSServiceResolve(
service.get(), 0, 0, reply.name.c_str(), reply.regtype.c_str(), reply.domain.c_str(),
[](DNSServiceRef /*service*/, DNSServiceFlags /*flags*/, uint32_t /*interfaceIndex*/, DNSServiceErrorType errorCode, const char* /*fullName*/,
const char* hosttarget, uint16_t port, uint16_t /*txtLen*/, const unsigned char* /*txtRecord*/, void* context) {
auto resultCollection = static_cast<deque<mDNSResolve>*>(context);
CHECKED(errorCode);
@ -216,9 +217,10 @@ bool BrowseBonjour::browse(const string& serviceName, mDNSResult& result, int /*
for (auto& resolve : resolveCollection)
{
resultCollection[i].port = resolve.port;
CHECKED(DNSServiceGetAddrInfo(service.get(), kDNSServiceFlagsLongLivedQuery, 0, kDNSServiceProtocol_IPv4, resolve.fullName.c_str(),
[](DNSServiceRef /*service*/, DNSServiceFlags /*flags*/, uint32_t interfaceIndex, DNSServiceErrorType /*errorCode*/,
const char* hostname, const sockaddr* address, uint32_t /*ttl*/, void* context) {
CHECKED(DNSServiceGetAddrInfo(
service.get(), kDNSServiceFlagsLongLivedQuery, 0, kDNSServiceProtocol_IPv4, resolve.fullName.c_str(),
[](DNSServiceRef /*service*/, DNSServiceFlags /*flags*/, uint32_t interfaceIndex, DNSServiceErrorType /*errorCode*/, const char* hostname,
const sockaddr* address, uint32_t /*ttl*/, void* context) {
auto result = static_cast<mDNSResult*>(context);
result->host = string(hostname);
@ -227,8 +229,7 @@ bool BrowseBonjour::browse(const string& serviceName, mDNSResult& result, int /*
char hostIP[NI_MAXHOST];
char hostService[NI_MAXSERV];
if (getnameinfo(address, sizeof(*address), hostIP, sizeof(hostIP), hostService, sizeof(hostService),
NI_NUMERICHOST | NI_NUMERICSERV) == 0)
if (getnameinfo(address, sizeof(*address), hostIP, sizeof(hostIP), hostService, sizeof(hostService), NI_NUMERICHOST | NI_NUMERICSERV) == 0)
result->ip = string(hostIP);
else
return;

View file

@ -260,8 +260,8 @@ void Controller::getNextMessage()
void Controller::sendTimeSyncMessage(int quick_syncs)
{
auto timeReq = std::make_shared<msg::Time>();
clientConnection_->sendRequest<msg::Time>(timeReq, 2s, [this, quick_syncs](const boost::system::error_code& ec,
const std::unique_ptr<msg::Time>& response) mutable {
clientConnection_->sendRequest<msg::Time>(
timeReq, 2s, [this, quick_syncs](const boost::system::error_code& ec, const std::unique_ptr<msg::Time>& response) mutable {
if (ec)
{
LOG(ERROR, LOG_TAG) << "Time sync request failed: " << ec.message() << "\n";
@ -277,7 +277,8 @@ void Controller::sendTimeSyncMessage(int quick_syncs)
if (quick_syncs > 0)
{
if (--quick_syncs == 0)
LOG(INFO, LOG_TAG) << "diff to server [ms]: " << (float)TimeProvider::getInstance().getDiffToServer<chronos::usec>().count() / 1000.f << "\n";
LOG(INFO, LOG_TAG) << "diff to server [ms]: " << (float)TimeProvider::getInstance().getDiffToServer<chronos::usec>().count() / 1000.f
<< "\n";
next = 100us;
}
timer_.expires_after(next);

View file

@ -368,7 +368,8 @@ void AlsaPlayer::initAlsa()
unsigned int period_time;
snd_pcm_hw_params_get_period_time(params, &period_time, nullptr);
snd_pcm_hw_params_get_period_size(params, &frames_, nullptr);
LOG(INFO, LOG_TAG) << "rate: " << rate << ", channels: " << channels << ", buffer time: " << buffer_time << " us, periods: " << periods << ", period time: " << period_time << " us, period frames: " << frames_ << "\n";
LOG(INFO, LOG_TAG) << "rate: " << rate << ", channels: " << channels << ", buffer time: " << buffer_time << " us, periods: " << periods
<< ", period time: " << period_time << " us, period frames: " << frames_ << "\n";
// Allocate buffer to hold single period
snd_pcm_sw_params_t* swparams;

View file

@ -93,7 +93,8 @@ bool PulsePlayer::getHardwareVolume(double& volume, bool& muted)
void PulsePlayer::triggerVolumeUpdate()
{
pa_context_get_sink_input_info(pa_ctx_, pa_stream_get_index(playstream_),
pa_context_get_sink_input_info(
pa_ctx_, pa_stream_get_index(playstream_),
[](pa_context* ctx, const pa_sink_input_info* info, int eol, void* userdata) {
std::ignore = ctx;
LOG(DEBUG, LOG_TAG) << "pa_context_get_sink_info_by_index info: " << (info != nullptr) << ", eol: " << eol << "\n";
@ -247,7 +248,8 @@ void PulsePlayer::start()
// modify the variable to 1 so we know when we have a connection and it's
// ready.
// If there's an error, the callback will set pa_ready to 2
pa_context_set_state_callback(pa_ctx_,
pa_context_set_state_callback(
pa_ctx_,
[](pa_context* c, void* userdata) {
auto self = static_cast<PulsePlayer*>(userdata);
self->stateCallback(c);
@ -276,7 +278,8 @@ void PulsePlayer::start()
if (settings_.mixer.mode == ClientSettings::Mixer::Mode::hardware)
{
pa_context_set_subscribe_callback(pa_ctx_,
pa_context_set_subscribe_callback(
pa_ctx_,
[](pa_context* ctx, pa_subscription_event_type_t event_type, uint32_t idx, void* userdata) {
auto self = static_cast<PulsePlayer*>(userdata);
self->subscribeCallback(ctx, event_type, idx);
@ -284,7 +287,8 @@ void PulsePlayer::start()
this);
const pa_subscription_mask_t mask = static_cast<pa_subscription_mask_t>(PA_SUBSCRIPTION_MASK_SINK_INPUT);
pa_context_subscribe(pa_ctx_, mask,
pa_context_subscribe(
pa_ctx_, mask,
[](pa_context* ctx, int success, void* userdata) {
std::ignore = ctx;
if (success)
@ -296,14 +300,16 @@ void PulsePlayer::start()
this);
}
pa_stream_set_write_callback(playstream_,
pa_stream_set_write_callback(
playstream_,
[](pa_stream* stream, size_t length, void* userdata) {
auto self = static_cast<PulsePlayer*>(userdata);
self->writeCallback(stream, length);
},
this);
pa_stream_set_underflow_callback(playstream_,
pa_stream_set_underflow_callback(
playstream_,
[](pa_stream* stream, void* userdata) {
auto self = static_cast<PulsePlayer*>(userdata);
self->underflowCallback(stream);

View file

@ -42,6 +42,6 @@ inline int64_t swap(const int64_t& val)
{
return SWAP_64(val);
}
}
} // namespace endian
#endif

View file

@ -58,7 +58,7 @@ public:
msg["muted"] = muted;
}
};
}
} // namespace msg
#endif

View file

@ -106,7 +106,7 @@ public:
return id;
}
};
}
} // namespace msg
#endif

View file

@ -80,7 +80,7 @@ public:
msg["muted"] = muted;
}
};
}
} // namespace msg
#endif

View file

@ -67,7 +67,7 @@ public:
~StreamTags() override = default;
};
}
} // namespace msg
#endif

View file

@ -53,7 +53,7 @@ protected:
writeVal(stream, latency.usec);
}
};
}
} // namespace msg
#endif

View file

@ -111,7 +111,7 @@ static float strtof(const char* str, char** endptr)
return std::strtof(str, endptr);
#endif
}
}
} // namespace cpt
#endif

View file

@ -152,8 +152,9 @@ ControlSessionHttp::~ControlSessionHttp()
void ControlSessionHttp::start()
{
http::async_read(socket_, buffer_, req_, boost::asio::bind_executor(strand_, [ this, self = shared_from_this() ](
boost::system::error_code ec, std::size_t bytes) { on_read(ec, bytes); }));
http::async_read(
socket_, buffer_, req_,
boost::asio::bind_executor(strand_, [this, self = shared_from_this()](boost::system::error_code ec, std::size_t bytes) { on_read(ec, bytes); }));
}

View file

@ -803,7 +803,8 @@ inline void Error::parse_json(const Json& json)
inline Json Error::to_json() const
{
Json j = {
{"code", code_}, {"message", message_},
{"code", code_},
{"message", message_},
};
if (!data_.is_null())
@ -1065,7 +1066,8 @@ inline void Response::parse_json(const Json& json)
inline Json Response::to_json() const
{
Json j = {
{"jsonrpc", "2.0"}, {"id", id_.to_json()},
{"jsonrpc", "2.0"},
{"id", id_.to_json()},
};
if (error_)
@ -1129,7 +1131,8 @@ inline void Notification::parse_json(const Json& json)
inline Json Notification::to_json() const
{
Json json = {
{"jsonrpc", "2.0"}, {"method", method_},
{"jsonrpc", "2.0"},
{"method", method_},
};
if (params_)

View file

@ -24,7 +24,8 @@
static constexpr auto LOG_TAG = "Bonjour";
typedef union {
typedef union
{
unsigned char b[2];
unsigned short NotAnInteger;
} Opaque16;

View file

@ -77,8 +77,9 @@ std::string StreamSessionWebsocket::getIP()
void StreamSessionWebsocket::sendAsync(const shared_const_buffer& buffer, const WriteHandler& handler)
{
LOG(TRACE, LOG_TAG) << "sendAsync: " << buffer.message().type << "\n";
ws_.async_write(buffer, boost::asio::bind_executor(strand_, [ self = shared_from_this(), buffer, handler ](boost::system::error_code ec,
std::size_t length) { handler(ec, length); }));
ws_.async_write(buffer, boost::asio::bind_executor(strand_, [self = shared_from_this(), buffer, handler](boost::system::error_code ec, std::size_t length) {
handler(ec, length);
}));
}

View file

@ -192,7 +192,9 @@ json PcmStream::toJson() const
state = "disabled";
json j = {
{"uri", uri_.toJson()}, {"id", getId()}, {"status", state},
{"uri", uri_.toJson()},
{"id", getId()},
{"status", state},
};
if (meta_)

View file

@ -147,4 +147,4 @@ std::string StreamUri::getQuery(const std::string& key, const std::string& def)
return iter->second;
return def;
}
}
} // namespace streamreader