Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
LordAro committed Nov 15, 2014
1 parent d7200c7 commit 1330462
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 58 deletions.
3 changes: 1 addition & 2 deletions src/audio/audio_sink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ PlayCallbackStepResult AudioSink::PlayCallbackFailure(
Debug() << "Buffer underflow" << std::endl;
memset(out, 0, this->bytes_per_sample * frames_per_buf);
result = std::make_pair(paContinue, frames_per_buf);
}
else {
} else {
// End of input is ok, it means the stream can finish.
result = std::make_pair(paComplete, in.second);
}
Expand Down
6 changes: 3 additions & 3 deletions src/audio/audio_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ AudioSource::DecodeResult AudioSource::Decode()

if (read == 0) {
this->decode_state = DecodeState::END_OF_FILE;
}
else {
} else {
this->decode_state = DecodeState::DECODING;

// Copy only the bit of the buffer occupied by decoded data
// See BytesPerSample() for an explanation of the
// ChannelCount() division.
auto front = this->buffer.begin();
auto read_bytes = (this->BytesPerSample() * read) / this->ChannelCount();
auto read_bytes = (this->BytesPerSample() * read) /
this->ChannelCount();
decoded = DecodeVector(front, front + read_bytes);
}

Expand Down
20 changes: 15 additions & 5 deletions src/errors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ class ConfigError : public Error {
* Constructs an ConfigError.
* @param message The human-readable message of the error.
*/
ConfigError(const std::string &message) : Error(message) {}
ConfigError(const std::string &message) : Error(message)
{
}
};

/**
Expand All @@ -59,7 +61,9 @@ class InternalError : public Error {
* Constructs an InternalError.
* @param message The human-readable message of the error.
*/
InternalError(const std::string &message) : Error(message) {}
InternalError(const std::string &message) : Error(message)
{
}
};

/**
Expand All @@ -71,7 +75,9 @@ class FileError : public Error {
* Constructs a FileError.
* @param message The human-readable message of the error.
*/
FileError(const std::string &message) : Error(message) {}
FileError(const std::string &message) : Error(message)
{
}
};

/**
Expand All @@ -83,7 +89,9 @@ class SeekError : public Error {
* Constructs a SeekError.
* @param message The human-readable message of the error.
*/
SeekError(const std::string &message) : Error(message) {}
SeekError(const std::string &message) : Error(message)
{
}
};

/**
Expand All @@ -95,7 +103,9 @@ class NetError : public Error {
* Constructs a NetError.
* @param message The human-readable message of the error.
*/
NetError(const std::string &message) : Error(message) {}
NetError(const std::string &message) : Error(message)
{
}
};

/** Class for telling the human what playd is doing. */
Expand Down
33 changes: 17 additions & 16 deletions src/io/io_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ void UvListenCallback(uv_stream_t *server, int status)
void UvRespondCallback(uv_write_t *req, int status)
{
if (status) {
Debug() << "UvRespondCallback: got status:" << status << std::endl;
Debug() << "UvRespondCallback: got status:" << status
<< std::endl;
}

WriteReq *wr = reinterpret_cast<WriteReq *>(req);
Expand All @@ -106,7 +107,6 @@ void UvUpdateTimerCallback(uv_timer_t *handle)
if (!running) IoCore::End();
}


//
// ConnectionPool
//
Expand All @@ -130,8 +130,7 @@ void ConnectionPool::Accept(uv_stream_t *server)
this->connections.back().get());

uv_read_start((uv_stream_t *)client, UvAlloc, UvReadCallback);
}
else {
} else {
uv_close((uv_handle_t *)client, UvCloseCallback);
}
}
Expand All @@ -158,7 +157,6 @@ void ConnectionPool::RespondRaw(const std::string &string) const
this->Broadcast(string);
}


//
// IoCore
//
Expand Down Expand Up @@ -214,12 +212,12 @@ void IoCore::RespondRaw(const std::string &string) const
uv_stop(uv_default_loop());
}


//
// Connection
//

Connection::Connection(ConnectionPool &parent, uv_tcp_t *tcp, CommandHandler &handler)
Connection::Connection(ConnectionPool &parent, uv_tcp_t *tcp,
CommandHandler &handler)
: parent(parent), tcp(tcp), tokeniser(), handler(handler)
{
Debug() << "Opening connection from" << Name() << std::endl;
Expand Down Expand Up @@ -255,28 +253,31 @@ std::string Connection::Name()
struct sockaddr_storage s;
int namelen;

if (uv_tcp_getpeername(this->tcp,
(struct sockaddr *) &s,
&namelen) < 0) return "(error)";
if (uv_tcp_getpeername(this->tcp, (struct sockaddr *)&s, &namelen) < 0) {
return "(error)";
}

// Now, split the sockaddr into host and service.
char host[NI_MAXHOST];
char serv[NI_MAXSERV];

// We use NI_NUMERICSERV to ensure a port number comes out.
// Otherwise, we could get a (likely erroneous) string description of what
// Otherwise, we could get a (likely erroneous) string description of
// what
// the network stack *thinks* the port is used for.
if (getnameinfo((struct sockaddr *) &s,
namelen, host, sizeof(host), serv, sizeof(serv),
NI_NUMERICSERV)) return "(error)";
if (getnameinfo((struct sockaddr *)&s, namelen, host, sizeof(host),
serv, sizeof(serv), NI_NUMERICSERV)) {
return "(error)";
}

return std::string(host) + ":" + std::string(serv);
}

void Connection::Read(ssize_t nread, const uv_buf_t *buf)
{
// Did the connection hang up? If so, de-pool it.
// De-pooling the connection will usually lead to the connection being destroyed.
// De-pooling the connection will usually lead to the connection being
// destroyed.
if (nread == UV_EOF) {
this->Depool();
return;
Expand All @@ -285,7 +286,7 @@ void Connection::Read(ssize_t nread, const uv_buf_t *buf)
// Did we hit any other read errors? Also de-pool, but log the error.
if (nread < 0) {
Debug() << "Error on" << Name() << "-" << uv_err_name(nread)
<< std::endl;
<< std::endl;
this->Depool();
return;
}
Expand Down
10 changes: 4 additions & 6 deletions src/io/io_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ extern "C" {
class Player;
class Connection;


/// A pool of TCP connections.
class ConnectionPool : public ResponseSink {
public:
/**
* Constructs a ConnectionPool.
* @param player The player that forms welcome responses for new clients.
* @param player The player that forms welcome responses for new
* clients.
* @param handler The handler to which read commands should be sent.
*/
ConnectionPool(Player &player, CommandHandler &handler);
Expand Down Expand Up @@ -72,7 +72,6 @@ class ConnectionPool : public ResponseSink {
void RespondRaw(const std::string &string) const override;
};


/// A TCP connection from a client.
class Connection : public ResponseSink {
public:
Expand All @@ -82,7 +81,8 @@ class Connection : public ResponseSink {
* @param tcp The underlying libuv TCP stream.
* @param handler The handler to which read commands should be sent.
*/
Connection(ConnectionPool &parent, uv_tcp_t *tcp, CommandHandler &handler);
Connection(ConnectionPool &parent, uv_tcp_t *tcp,
CommandHandler &handler);

/**
* Destructs a Connection.
Expand Down Expand Up @@ -141,7 +141,6 @@ class Connection : public ResponseSink {
void HandleCommand(const std::vector<std::string> &words);
};


/**
* The IO core, which services input, routes responses, and executes the
* Player update routine periodically.
Expand Down Expand Up @@ -202,5 +201,4 @@ class IoCore : public ResponseSink {
void DoUpdateTimer();
};


#endif // PS_IO_CORE_HPP
4 changes: 3 additions & 1 deletion src/io/io_response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ void ResponseSink::RespondArgs(ResponseCode code,
{
std::ostringstream os;
os << RESPONSES[static_cast<int>(code)];
for (auto argument : arguments) os << " " << this->EscapeArgument(argument);
for (auto argument : arguments) {
os << " " << this->EscapeArgument(argument);
}
this->RespondRaw(os.str());
}

Expand Down
9 changes: 3 additions & 6 deletions src/io/tokeniser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ std::vector<Tokeniser::Line> Tokeniser::Feed(const std::string &raw_string)
case QuoteType::SINGLE:
if (c == '\'') {
this->quote_type = QuoteType::NONE;
}
else {
} else {
this->Push(c);
}
break;
Expand All @@ -50,8 +49,7 @@ std::vector<Tokeniser::Line> Tokeniser::Feed(const std::string &raw_string)
break;

case '\\':
this->escape_next =
true;
this->escape_next = true;
break;

default:
Expand All @@ -77,8 +75,7 @@ std::vector<Tokeniser::Line> Tokeniser::Feed(const std::string &raw_string)
break;

case '\\':
this->escape_next =
true;
this->escape_next = true;
break;

default:
Expand Down
17 changes: 9 additions & 8 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ int Playd::Run()
std::string addr = size > 2 ? this->arguments.at(2) : "0.0.0.0";
std::string port = size > 3 ? this->arguments.at(3) : "1350";
try {
this->io = decltype(this->io)(
new IoCore(this->player, this->handler, addr, port));
} catch (NetError &e) {
this->io = decltype(this->io)(new IoCore(
this->player, this->handler, addr, port));
}
catch (NetError &e) {
std::cerr << "Network error: " << e.Message() << std::endl;
std::cerr << "Is " << addr << ":" << port << " available?" << std::endl;
std::cerr << "Is " << addr << ":" << port << " available?"
<< std::endl;
return EXIT_FAILURE;
}

Expand All @@ -84,8 +86,8 @@ int Playd::Run()
// Show the user the valid device IDs they can use.
auto device_list = this->audio.GetDevicesInfo();
for (const auto &device : device_list) {
std::cout << device.first << ": "
<< device.second << std::endl;
std::cout << device.first << ": " << device.second
<< std::endl;
}
return EXIT_FAILURE;
}
Expand All @@ -99,8 +101,7 @@ int Playd::Run()
}
catch (Error &error) {
std::cerr << "Unhandled exception in main loop: "
<< error.Message()
<< std::endl;
<< error.Message() << std::endl;
return EXIT_FAILURE;
}

Expand Down
7 changes: 0 additions & 7 deletions src/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include <string>


//
// Client communications
//
Expand All @@ -22,7 +21,6 @@
#endif
const std::string MSG_OHAI = "playd " PD_VERSION;


//
// Command failure messages
//
Expand All @@ -48,23 +46,20 @@ const std::string MSG_CMD_NEEDS_PLAYING = "Command requires a playing file";
*/
const std::string MSG_CMD_NEEDS_STOPPED = "Command requires a stopped file";


//
// Decoder failures
//

/// Message shown when a bad sample rate is found.
const std::string MSG_DECODE_BADRATE = "Unsupported or invalid sample rate";


//
// Device ID failures
//

/// Message shown when an incorrect device ID is provided.
const std::string MSG_DEV_BADID = "Incorrect device ID";


//
// Load failures
//
Expand All @@ -82,7 +77,6 @@ const std::string MSG_OUTPUT_RINGWRITE = "Ring buffer write error";
/// Message shown when there is an error initialising the ring buffer.
const std::string MSG_OUTPUT_RINGINIT = "Ring buffer init error";


//
// Seek failures
//
Expand All @@ -96,5 +90,4 @@ const std::string MSG_SEEK_INVALID_UNIT = "Invalid time unit: try us, s, m, h";
/// Message shown when a seek command has an invalid time value.
const std::string MSG_SEEK_INVALID_VALUE = "Invalid time: try integer[unit]";


#endif // PS_MESSAGES_H
3 changes: 1 addition & 2 deletions src/player/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ void Player::PlaybackUpdate()
{
if (this->file.IsStopped()) {
this->End();
}
else {
} else {
this->UpdatePosition();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/player/player_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void PlayerFile::Emit(ResponseSink &sink) const

void PlayerFile::Load(const std::string &path)
{
if (this->audio != nullptr) this->Eject();
if (this->audio != nullptr) this->Eject();

this->audio = decltype(this->audio)(this->audio_system.Load(path));

Expand Down
3 changes: 2 additions & 1 deletion src/time_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
std::string unit = seek.first;
MicrosecondPosition num_units = seek.second;

return static_cast<MicrosecondPosition>(TimeParser::UnitMultiplier(unit)) *
return static_cast<MicrosecondPosition>(
TimeParser::UnitMultiplier(unit)) *
num_units;
}

Expand Down

0 comments on commit 1330462

Please sign in to comment.