modernize with clang-tidy

This commit is contained in:
badaix 2019-09-25 19:02:33 +02:00
parent e0d25d02ab
commit 8b231c7cc6
54 changed files with 182 additions and 196 deletions

View file

@ -27,10 +27,10 @@
#include <time.h>
static AvahiSimplePoll* simple_poll = NULL;
static AvahiSimplePoll* simple_poll = nullptr;
BrowseAvahi::BrowseAvahi() : client_(NULL), sb_(NULL)
BrowseAvahi::BrowseAvahi() : client_(nullptr), sb_(nullptr)
{
}
@ -45,15 +45,15 @@ void BrowseAvahi::cleanUp()
{
if (sb_)
avahi_service_browser_free(sb_);
sb_ = NULL;
sb_ = nullptr;
if (client_)
avahi_client_free(client_);
client_ = NULL;
client_ = nullptr;
if (simple_poll)
avahi_simple_poll_free(simple_poll);
simple_poll = NULL;
simple_poll = nullptr;
}
@ -180,7 +180,7 @@ bool BrowseAvahi::browse(const std::string& serviceName, mDNSResult& result, int
/* Create the service browser */
if (!(sb_ =
avahi_service_browser_new(client_, AVAHI_IF_UNSPEC, AVAHI_PROTO_INET, serviceName.c_str(), NULL, (AvahiLookupFlags)0, browse_callback, this)))
avahi_service_browser_new(client_, AVAHI_IF_UNSPEC, AVAHI_PROTO_INET, serviceName.c_str(), nullptr, (AvahiLookupFlags)0, browse_callback, this)))
throw SnapException("BrowseAvahi - Failed to create service browser: " + std::string(avahi_strerror(avahi_client_errno(client_))));
result_.valid = false;

View file

@ -29,7 +29,7 @@ using namespace std;
ClientConnection::ClientConnection(MessageReceiver* receiver, const std::string& host, size_t port)
: socket_(nullptr), active_(false), connected_(false), messageReceiver_(receiver), reqId_(1), host_(host), port_(port), readerThread_(NULL),
: socket_(nullptr), active_(false), connected_(false), messageReceiver_(receiver), reqId_(1), host_(host), port_(port), readerThread_(nullptr),
sumTimeout_(chronos::msec(0))
{
}
@ -116,7 +116,7 @@ void ClientConnection::stop()
catch (...)
{
}
readerThread_ = NULL;
readerThread_ = nullptr;
socket_.reset();
LOG(DEBUG) << "readerThread terminated\n";
}
@ -142,7 +142,7 @@ bool ClientConnection::send(const msg::BaseMessage* message) const
shared_ptr<msg::SerializedMessage> ClientConnection::sendRequest(const msg::BaseMessage* message, const chronos::msec& timeout)
{
shared_ptr<msg::SerializedMessage> response(NULL);
shared_ptr<msg::SerializedMessage> response(nullptr);
if (++reqId_ >= 10000)
reqId_ = 1;
message->id = reqId_;
@ -209,7 +209,7 @@ void ClientConnection::getNextMessage()
}
}
if (messageReceiver_ != NULL)
if (messageReceiver_ != nullptr)
messageReceiver_->onMessageReceived(this, baseMessage, &buffer[0]);
}
@ -226,7 +226,7 @@ void ClientConnection::reader()
}
catch (const std::exception& e)
{
if (messageReceiver_ != NULL)
if (messageReceiver_ != nullptr)
messageReceiver_->onException(this, make_shared<SnapException>(e.what()));
}
catch (...)

View file

@ -40,7 +40,7 @@ class ClientConnection;
/// Used to synchronize server requests (wait for server response)
struct PendingRequest
{
PendingRequest(uint16_t reqId) : id(reqId), response(NULL){};
PendingRequest(uint16_t reqId) : id(reqId), response(nullptr){};
uint16_t id;
std::shared_ptr<msg::SerializedMessage> response;
@ -87,7 +87,7 @@ public:
{
std::shared_ptr<msg::SerializedMessage> reply = sendRequest(message, timeout);
if (!reply)
return NULL;
return nullptr;
std::shared_ptr<T> msg(new T);
msg->deserialize(reply->message, reply->buffer);
return msg;

View file

@ -57,7 +57,7 @@ void Controller::onMessageReceived(ClientConnection* connection, const msg::Base
{
if (stream_ && decoder_)
{
msg::PcmChunk* pcmChunk = new msg::PcmChunk(sampleFormat_, 0);
auto* pcmChunk = new msg::PcmChunk(sampleFormat_, 0);
pcmChunk->deserialize(baseMessage, buffer);
// LOG(DEBUG) << "chunk: " << pcmChunk->payloadSize << ", sampleFormat: " << sampleFormat_.rate << "\n";
if (decoder_->decode(pcmChunk))

View file

@ -54,11 +54,11 @@ public:
/// Implementation of MessageReceiver.
/// ClientConnection passes messages from the server through these callbacks
virtual void onMessageReceived(ClientConnection* connection, const msg::BaseMessage& baseMessage, char* buffer);
void onMessageReceived(ClientConnection* connection, const msg::BaseMessage& baseMessage, char* buffer) override;
/// Implementation of MessageReceiver.
/// Used for async exception reporting
virtual void onException(ClientConnection* connection, shared_exception_ptr exception);
void onException(ClientConnection* connection, shared_exception_ptr exception) override;
private:
void worker();

View file

@ -28,7 +28,7 @@ class Decoder
{
public:
Decoder(){};
virtual ~Decoder(){};
virtual ~Decoder()= default;;
virtual bool decode(msg::PcmChunk* chunk) = 0;
virtual SampleFormat setHeader(msg::CodecHeader* chunk) = 0;

View file

@ -35,11 +35,11 @@ static void metadata_callback(const FLAC__StreamDecoder* decoder, const FLAC__St
static void error_callback(const FLAC__StreamDecoder* decoder, FLAC__StreamDecoderErrorStatus status, void* client_data);
static msg::CodecHeader* flacHeader = NULL;
static msg::PcmChunk* flacChunk = NULL;
static msg::PcmChunk* pcmChunk = NULL;
static msg::CodecHeader* flacHeader = nullptr;
static msg::PcmChunk* flacChunk = nullptr;
static msg::PcmChunk* pcmChunk = nullptr;
static SampleFormat sampleFormat;
static FLAC__StreamDecoder* decoder = NULL;
static FLAC__StreamDecoder* decoder = nullptr;
@ -101,11 +101,11 @@ SampleFormat FlacDecoder::setHeader(msg::CodecHeader* chunk)
flacHeader = chunk;
FLAC__StreamDecoderInitStatus init_status;
if ((decoder = FLAC__stream_decoder_new()) == NULL)
if ((decoder = FLAC__stream_decoder_new()) == nullptr)
throw SnapException("ERROR: allocating decoder");
// (void)FLAC__stream_decoder_set_md5_checking(decoder, true);
init_status = FLAC__stream_decoder_init_stream(decoder, read_callback, NULL, NULL, NULL, NULL, write_callback, metadata_callback, error_callback, this);
init_status = FLAC__stream_decoder_init_stream(decoder, read_callback, nullptr, nullptr, nullptr, nullptr, write_callback, metadata_callback, error_callback, this);
if (init_status != FLAC__STREAM_DECODER_INIT_STATUS_OK)
throw SnapException("ERROR: initializing decoder: " + string(FLAC__StreamDecoderInitStatusString[init_status]));
@ -120,13 +120,13 @@ SampleFormat FlacDecoder::setHeader(msg::CodecHeader* chunk)
FLAC__StreamDecoderReadStatus read_callback(const FLAC__StreamDecoder* decoder, FLAC__byte buffer[], size_t* bytes, void* client_data)
{
if (flacHeader != NULL)
if (flacHeader != nullptr)
{
*bytes = flacHeader->payloadSize;
memcpy(buffer, flacHeader->payload, *bytes);
flacHeader = NULL;
flacHeader = nullptr;
}
else if (flacChunk != NULL)
else if (flacChunk != nullptr)
{
// cerr << "read_callback: " << *bytes << ", avail: " << flacChunk->payloadSize << "\n";
static_cast<FlacDecoder*>(client_data)->cacheInfo_.isCachedChunk_ = false;
@ -150,7 +150,7 @@ FLAC__StreamDecoderWriteStatus write_callback(const FLAC__StreamDecoder* decoder
{
(void)decoder;
if (pcmChunk != NULL)
if (pcmChunk != nullptr)
{
size_t bytes = frame->header.blocksize * sampleFormat.frameSize;
@ -162,7 +162,7 @@ FLAC__StreamDecoderWriteStatus write_callback(const FLAC__StreamDecoder* decoder
for (size_t channel = 0; channel < sampleFormat.channels; ++channel)
{
if (buffer[channel] == NULL)
if (buffer[channel] == nullptr)
{
SLOG(ERROR) << "ERROR: buffer[" << channel << "] is NULL\n";
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;

View file

@ -50,9 +50,9 @@ class FlacDecoder : public Decoder
{
public:
FlacDecoder();
virtual ~FlacDecoder();
virtual bool decode(msg::PcmChunk* chunk);
virtual SampleFormat setHeader(msg::CodecHeader* chunk);
~FlacDecoder() override;
bool decode(msg::PcmChunk* chunk) override;
SampleFormat setHeader(msg::CodecHeader* chunk) override;
CacheInfo cacheInfo_;
std::unique_ptr<FLAC__StreamDecoderErrorStatus> lastError_;

View file

@ -30,9 +30,9 @@ class OggDecoder : public Decoder
{
public:
OggDecoder();
virtual ~OggDecoder();
virtual bool decode(msg::PcmChunk* chunk);
virtual SampleFormat setHeader(msg::CodecHeader* chunk);
~OggDecoder() override;
bool decode(msg::PcmChunk* chunk) override;
SampleFormat setHeader(msg::CodecHeader* chunk) override;
private:
bool decodePayload(msg::PcmChunk* chunk);

View file

@ -25,8 +25,8 @@ class PcmDecoder : public Decoder
{
public:
PcmDecoder();
virtual bool decode(msg::PcmChunk* chunk);
virtual SampleFormat setHeader(msg::CodecHeader* chunk);
bool decode(msg::PcmChunk* chunk) override;
SampleFormat setHeader(msg::CodecHeader* chunk) override;
};

View file

@ -93,7 +93,7 @@ class MetaStderrAdapter : public MetadataAdapter
public:
using MetadataAdapter::push;
int push()
int push() override
{
std::cerr << serialize() << "\n";
return 0;

View file

@ -26,7 +26,7 @@
using namespace std;
AlsaPlayer::AlsaPlayer(const PcmDevice& pcmDevice, std::shared_ptr<Stream> stream) : Player(pcmDevice, stream), handle_(NULL), buff_(NULL)
AlsaPlayer::AlsaPlayer(const PcmDevice& pcmDevice, std::shared_ptr<Stream> stream) : Player(pcmDevice, stream), handle_(nullptr), buff_(nullptr)
{
}
@ -105,18 +105,18 @@ void AlsaPlayer::initAlsa()
if ((pcm = snd_pcm_hw_params_set_channels(handle_, params, channels)) < 0)
throw SnapException("Can't set channels number: " + string(snd_strerror(pcm)));
if ((pcm = snd_pcm_hw_params_set_rate_near(handle_, params, &rate, 0)) < 0)
if ((pcm = snd_pcm_hw_params_set_rate_near(handle_, params, &rate, nullptr)) < 0)
throw SnapException("Can't set rate: " + string(snd_strerror(pcm)));
unsigned int period_time;
snd_pcm_hw_params_get_period_time_max(params, &period_time, 0);
snd_pcm_hw_params_get_period_time_max(params, &period_time, nullptr);
if (period_time > PERIOD_TIME)
period_time = PERIOD_TIME;
unsigned int buffer_time = 4 * period_time;
snd_pcm_hw_params_set_period_time_near(handle_, params, &period_time, 0);
snd_pcm_hw_params_set_buffer_time_near(handle_, params, &buffer_time, 0);
snd_pcm_hw_params_set_period_time_near(handle_, params, &period_time, nullptr);
snd_pcm_hw_params_set_buffer_time_near(handle_, params, &buffer_time, nullptr);
// long unsigned int periodsize = stream_->format.msRate() * 50;//2*rate/50;
// if ((pcm = snd_pcm_hw_params_set_buffer_size_near(pcm_handle, params, &periodsize)) < 0)
@ -132,17 +132,17 @@ void AlsaPlayer::initAlsa()
snd_pcm_hw_params_get_channels(params, &tmp);
LOG(DEBUG) << "channels: " << tmp << "\n";
snd_pcm_hw_params_get_rate(params, &tmp, 0);
snd_pcm_hw_params_get_rate(params, &tmp, nullptr);
LOG(DEBUG) << "rate: " << tmp << " bps\n";
/* Allocate buffer to hold single period */
snd_pcm_hw_params_get_period_size(params, &frames_, 0);
snd_pcm_hw_params_get_period_size(params, &frames_, nullptr);
LOG(INFO) << "frames: " << frames_ << "\n";
buff_size = frames_ * format.frameSize; // channels * 2 /* 2 -> sample size */;
buff_ = (char*)malloc(buff_size);
snd_pcm_hw_params_get_period_time(params, &tmp, NULL);
snd_pcm_hw_params_get_period_time(params, &tmp, nullptr);
LOG(DEBUG) << "period time: " << tmp << "\n";
snd_pcm_sw_params_t* swparams;
@ -158,17 +158,17 @@ void AlsaPlayer::initAlsa()
void AlsaPlayer::uninitAlsa()
{
if (handle_ != NULL)
if (handle_ != nullptr)
{
snd_pcm_drain(handle_);
snd_pcm_close(handle_);
handle_ = NULL;
handle_ = nullptr;
}
if (buff_ != NULL)
if (buff_ != nullptr)
{
free(buff_);
buff_ = NULL;
buff_ = nullptr;
}
}
@ -201,7 +201,7 @@ void AlsaPlayer::worker()
while (active_)
{
if (handle_ == NULL)
if (handle_ == nullptr)
{
try
{
@ -240,7 +240,7 @@ void AlsaPlayer::worker()
while (active_ && !stream_->waitForChunk(100))
{
LOG(DEBUG) << "Waiting for chunk\n";
if ((handle_ != NULL) && (chronos::getTickCount() - lastChunkTick > 5000))
if ((handle_ != nullptr) && (chronos::getTickCount() - lastChunkTick > 5000))
{
LOG(NOTICE) << "No chunk received for 5000ms. Closing ALSA.\n";
uninitAlsa();
@ -253,7 +253,7 @@ void AlsaPlayer::worker()
vector<PcmDevice> AlsaPlayer::pcm_list(void)
vector<PcmDevice> AlsaPlayer::pcm_list()
{
void **hints, **n;
char *name, *descr, *io;
@ -264,15 +264,15 @@ vector<PcmDevice> AlsaPlayer::pcm_list(void)
return result;
n = hints;
size_t idx(0);
while (*n != NULL)
while (*n != nullptr)
{
name = snd_device_name_get_hint(*n, "NAME");
descr = snd_device_name_get_hint(*n, "DESC");
io = snd_device_name_get_hint(*n, "IOID");
if (io != NULL && strcmp(io, "Output") != 0)
if (io != nullptr && strcmp(io, "Output") != 0)
goto __end;
pcmDevice.name = name;
if (descr == NULL)
if (descr == nullptr)
{
pcmDevice.description = "";
}
@ -284,11 +284,11 @@ vector<PcmDevice> AlsaPlayer::pcm_list(void)
result.push_back(pcmDevice);
__end:
if (name != NULL)
if (name != nullptr)
free(name);
if (descr != NULL)
if (descr != nullptr)
free(descr);
if (io != NULL)
if (io != nullptr)
free(io);
n++;
}

View file

@ -31,17 +31,17 @@ class AlsaPlayer : public Player
{
public:
AlsaPlayer(const PcmDevice& pcmDevice, std::shared_ptr<Stream> stream);
virtual ~AlsaPlayer();
~AlsaPlayer() override;
/// Set audio volume in range [0..1]
virtual void start();
virtual void stop();
void start() override;
void stop() override;
/// List the system's audio output devices
static std::vector<PcmDevice> pcm_list(void);
protected:
virtual void worker();
void worker() override;
private:
void initAlsa();

View file

@ -262,7 +262,7 @@ bool Stream::getPlayerChunk(void* outputBuffer, const cs::usec& outputBufferDacT
if (!chunks_.try_pop(chunk_, outputBufferDacTime))
{
LOG(INFO) << "no chunks available\n";
chunk_ = NULL;
chunk_ = nullptr;
sleep_ = cs::usec(0);
return false;
}
@ -362,7 +362,7 @@ else if (miniBuffer_.full() && (cs::usec(abs(miniBuffer_.median())) > cs::msec(5
updateBuffers(age.count());
// print sync stats
time_t now = time(NULL);
time_t now = time(nullptr);
if (now != lastUpdate_)
{
lastUpdate_ = now;

View file

@ -35,18 +35,18 @@ public:
payload = (char*)malloc(size);
}
virtual ~CodecHeader()
~CodecHeader() override
{
free(payload);
}
virtual void read(std::istream& stream)
void read(std::istream& stream) override
{
readVal(stream, codec);
readVal(stream, &payload, payloadSize);
}
virtual uint32_t getSize() const
uint32_t getSize() const override
{
return sizeof(uint32_t) + codec.size() + sizeof(uint32_t) + payloadSize;
}
@ -56,7 +56,7 @@ public:
std::string codec;
protected:
virtual void doserialize(std::ostream& stream) const
void doserialize(std::ostream& stream) const override
{
writeVal(stream, codec);
writeVal(stream, payload, payloadSize);

View file

@ -48,9 +48,8 @@ public:
msg["SnapStreamProtocolVersion"] = 2;
}
virtual ~Hello()
{
}
~Hello() override
= default;
std::string getMacAddress() const
{

View file

@ -36,18 +36,17 @@ public:
{
}
virtual ~JsonMessage()
{
}
~JsonMessage() override
= default;
virtual void read(std::istream& stream)
void read(std::istream& stream) override
{
std::string s;
readVal(stream, s);
msg = json::parse(s);
}
virtual uint32_t getSize() const
uint32_t getSize() const override
{
return sizeof(uint32_t) + msg.dump().size();
}
@ -56,7 +55,7 @@ public:
protected:
virtual void doserialize(std::ostream& stream) const
void doserialize(std::ostream& stream) const override
{
writeVal(stream, msg.dump());
}

View file

@ -127,8 +127,7 @@ struct BaseMessage
}
virtual ~BaseMessage()
{
}
= default;
virtual void read(std::istream& stream)
{

View file

@ -48,9 +48,8 @@ public:
{
}
virtual ~PcmChunk()
{
}
~PcmChunk() override
= default;
int readFrames(void* outputBuffer, size_t frameCount)
{
@ -60,7 +59,7 @@ public:
result = (payloadSize / format.frameSize) - idx_;
// logd << ", from: " << format.frameSize*idx << ", to: " << format.frameSize*idx + format.frameSize*result;
if (outputBuffer != NULL)
if (outputBuffer != nullptr)
memcpy((char*)outputBuffer, (char*)(payload) + format.frameSize * idx_, format.frameSize * result);
idx_ += result;
@ -82,7 +81,7 @@ public:
}
virtual chronos::time_point_clk start() const
chronos::time_point_clk start() const override
{
return chronos::time_point_clk(chronos::sec(timestamp.sec) + chronos::usec(timestamp.usec) +
chronos::usec((chronos::usec::rep)(1000000. * ((double)idx_ / (double)format.rate))));

View file

@ -36,9 +36,8 @@ public:
setMuted(false);
}
virtual ~ServerSettings()
{
}
~ServerSettings() override
= default;
int32_t getBufferMs()
{

View file

@ -65,9 +65,8 @@ public:
{
}
virtual ~StreamTags()
{
}
~StreamTags() override
= default;
};
}

View file

@ -31,17 +31,16 @@ public:
{
}
virtual ~Time()
{
}
~Time() override
= default;
virtual void read(std::istream& stream)
void read(std::istream& stream) override
{
readVal(stream, latency.sec);
readVal(stream, latency.usec);
}
virtual uint32_t getSize() const
uint32_t getSize() const override
{
return sizeof(tv);
}
@ -49,7 +48,7 @@ public:
tv latency;
protected:
virtual void doserialize(std::ostream& stream) const
void doserialize(std::ostream& stream) const override
{
writeVal(stream, latency.sec);
writeVal(stream, latency.usec);

View file

@ -50,19 +50,19 @@ public:
memcpy(payload, wireChunk.payload, payloadSize);
}
virtual ~WireChunk()
~WireChunk() override
{
free(payload);
}
virtual void read(std::istream& stream)
void read(std::istream& stream) override
{
readVal(stream, timestamp.sec);
readVal(stream, timestamp.usec);
readVal(stream, &payload, payloadSize);
}
virtual uint32_t getSize() const
uint32_t getSize() const override
{
return sizeof(tv) + sizeof(int32_t) + payloadSize;
}
@ -77,7 +77,7 @@ public:
char* payload;
protected:
virtual void doserialize(std::ostream& stream) const
void doserialize(std::ostream& stream) const override
{
writeVal(stream, timestamp.sec);
writeVal(stream, timestamp.usec);

View file

@ -31,8 +31,7 @@ using namespace std;
SampleFormat::SampleFormat()
{
}
= default;
SampleFormat::SampleFormat(const std::string& format)

View file

@ -43,12 +43,12 @@ public:
{
}
virtual ~SnapException() throw()
~SnapException() throw() override
{
delete[] text_;
}
virtual const char* what() const noexcept
const char* what() const noexcept override
{
return text_;
}
@ -72,9 +72,8 @@ public:
}
virtual ~AsyncSnapException() throw()
{
}
~AsyncSnapException() throw() override
= default;
};

View file

@ -47,7 +47,7 @@ inline static void timeofday(struct timeval* tv)
inline static void systemtimeofday(struct timeval* tv)
{
gettimeofday(tv, NULL);
gettimeofday(tv, nullptr);
// timeofday<std::chrono::system_clock>(tv);
}

View file

@ -69,7 +69,7 @@ static std::string execGetOutput(const std::string& cmd)
std::string result = "";
while (!feof(pipe.get()))
{
if (fgets(buffer, 1024, pipe.get()) != NULL)
if (fgets(buffer, 1024, pipe.get()) != nullptr)
result += buffer;
}
return strutils::trim(result);
@ -182,7 +182,7 @@ static std::string generateUUID()
static bool initialized(false);
if (!initialized)
{
std::srand(std::time(0));
std::srand(std::time(nullptr));
initialized = true;
}
std::stringstream ss;

View file

@ -54,7 +54,7 @@ static void do_chown(const std::string& file_path, const std::string& user_name,
if (!user_name.empty())
{
struct passwd* pwd = getpwnam(user_name.c_str());
if (pwd == NULL)
if (pwd == nullptr)
throw std::runtime_error("Failed to get uid");
uid = pwd->pw_uid;
}
@ -62,7 +62,7 @@ static void do_chown(const std::string& file_path, const std::string& user_name,
if (!group_name.empty())
{
struct group* grp = getgrnam(group_name.c_str());
if (grp == NULL)
if (grp == nullptr)
throw std::runtime_error("Failed to get gid");
gid = grp->gr_gid;
}

View file

@ -46,7 +46,7 @@ void Config::init(const std::string& root_directory, const std::string& user, co
string dir;
if (!root_directory.empty())
dir = root_directory;
else if (getenv("HOME") == NULL)
else if (getenv("HOME") == nullptr)
dir = "/var/lib/snapserver/";
else
dir = getenv("HOME");
@ -97,10 +97,10 @@ void Config::init(const std::string& root_directory, const std::string& user, co
if (j.count("ConfigVersion"))
{
json jGroups = j["Groups"];
for (auto it = jGroups.begin(); it != jGroups.end(); ++it)
for (auto & jGroup : jGroups)
{
GroupPtr group = make_shared<Group>();
group->fromJson(*it);
group->fromJson(jGroup);
// if (client->id.empty() || getClientInfo(client->id))
// continue;
groups.push_back(group);

View file

@ -161,8 +161,7 @@ struct Snapcast
}
virtual ~Snapcast()
{
}
= default;
virtual void fromJson(const json& j)
{
@ -200,13 +199,13 @@ struct Snapserver : public Snapcast
{
}
virtual void fromJson(const json& j)
void fromJson(const json& j) override
{
Snapcast::fromJson(j);
controlProtocolVersion = jGet<int>(j, "controlProtocolVersion", 1);
}
virtual json toJson()
json toJson() override
{
json j = Snapcast::toJson();
j["controlProtocolVersion"] = controlProtocolVersion;

View file

@ -94,7 +94,7 @@ void ControlServer::onMessageReceived(ControlSession* connection, const std::str
}
else
{
if (controlMessageReceiver_ != NULL)
if (controlMessageReceiver_ != nullptr)
controlMessageReceiver_->onMessageReceived(connection, message);
}
}

View file

@ -46,17 +46,17 @@ typedef std::shared_ptr<tcp::socket> socket_ptr;
class ControlServer : public ControlMessageReceiver
{
public:
ControlServer(asio::io_service* io_service, size_t port, ControlMessageReceiver* controlMessageReceiver = NULL);
ControlServer(asio::io_service* io_service, size_t port, ControlMessageReceiver* controlMessageReceiver = nullptr);
virtual ~ControlServer();
void start();
void stop();
/// Send a message to all connceted clients
void send(const std::string& message, const ControlSession* excludeSession = NULL);
void send(const std::string& message, const ControlSession* excludeSession = nullptr);
/// Clients call this when they receive a message. Implementation of MessageReceiver::onMessageReceived
virtual void onMessageReceived(ControlSession* connection, const std::string& message);
void onMessageReceived(ControlSession* connection, const std::string& message) override;
private:
void startAccept();

View file

@ -82,7 +82,7 @@ void ControlSession::stop()
catch (...)
{
}
socket_ = NULL;
socket_ = nullptr;
LOG(DEBUG) << "ControlSession ControlSession stopped\n";
}
@ -137,7 +137,7 @@ void ControlSession::reader()
if ((len >= 2) && line[len - 2] == '\r')
--len;
line.resize(len);
if ((messageReceiver_ != NULL) && !line.empty())
if ((messageReceiver_ != nullptr) && !line.empty())
messageReceiver_->onMessageReceived(this, line);
}
message.str("");

View file

@ -50,13 +50,12 @@ class Encoder
{
public:
/// ctor. Codec options (E.g. compression level) are passed as string and are codec dependend
Encoder(const std::string& codecOptions = "") : headerChunk_(NULL), codecOptions_(codecOptions)
Encoder(const std::string& codecOptions = "") : headerChunk_(nullptr), codecOptions_(codecOptions)
{
}
virtual ~Encoder()
{
}
= default;
/// The listener will receive the encoded stream
virtual void init(EncoderListener* listener, const SampleFormat& format)

View file

@ -26,7 +26,7 @@
using namespace std;
FlacEncoder::FlacEncoder(const std::string& codecOptions) : Encoder(codecOptions), encoder_(NULL), pcmBufferSize_(0), encodedSamples_(0)
FlacEncoder::FlacEncoder(const std::string& codecOptions) : Encoder(codecOptions), encoder_(nullptr), pcmBufferSize_(0), encodedSamples_(0)
{
flacChunk_ = new msg::PcmChunk();
headerChunk_.reset(new msg::CodecHeader("flac"));
@ -36,7 +36,7 @@ FlacEncoder::FlacEncoder(const std::string& codecOptions) : Encoder(codecOptions
FlacEncoder::~FlacEncoder()
{
if (encoder_ != NULL)
if (encoder_ != nullptr)
{
FLAC__stream_encoder_finish(encoder_);
FLAC__metadata_object_delete(metadata_[0]);
@ -163,7 +163,7 @@ void FlacEncoder::initEncoder()
FLAC__StreamMetadata_VorbisComment_Entry entry;
// allocate the encoder
if ((encoder_ = FLAC__stream_encoder_new()) == NULL)
if ((encoder_ = FLAC__stream_encoder_new()) == nullptr)
throw SnapException("error allocating encoder");
ok &= FLAC__stream_encoder_set_verify(encoder_, true);
@ -181,8 +181,8 @@ void FlacEncoder::initEncoder()
throw SnapException("error setting up encoder");
// now add some metadata; we'll add some tags and a padding block
if ((metadata_[0] = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT)) == NULL ||
(metadata_[1] = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING)) == NULL ||
if ((metadata_[0] = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT)) == nullptr ||
(metadata_[1] = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING)) == nullptr ||
// there are many tag (vorbiscomment) functions but these are convenient for this particular use:
!FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair(&entry, "TITLE", "SnapStream") ||
!FLAC__metadata_object_vorbiscomment_append_comment(metadata_[0], entry, false) ||
@ -196,7 +196,7 @@ void FlacEncoder::initEncoder()
throw SnapException("error setting meta data");
// initialize encoder
init_status = FLAC__stream_encoder_init_stream(encoder_, ::write_callback, NULL, NULL, NULL, this);
init_status = FLAC__stream_encoder_init_stream(encoder_, ::write_callback, nullptr, nullptr, nullptr, this);
if (init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK)
throw SnapException("ERROR: initializing encoder: " + string(FLAC__StreamEncoderInitStatusString[init_status]));
}

View file

@ -31,17 +31,17 @@ class FlacEncoder : public Encoder
{
public:
FlacEncoder(const std::string& codecOptions = "");
~FlacEncoder();
virtual void encode(const msg::PcmChunk* chunk);
virtual std::string getAvailableOptions() const;
virtual std::string getDefaultOptions() const;
virtual std::string name() const;
~FlacEncoder() override;
void encode(const msg::PcmChunk* chunk) override;
std::string getAvailableOptions() const override;
std::string getDefaultOptions() const override;
std::string name() const override;
FLAC__StreamEncoderWriteStatus write_callback(const FLAC__StreamEncoder* encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples,
unsigned current_frame);
protected:
virtual void initEncoder();
void initEncoder() override;
FLAC__StreamEncoder* encoder_;
FLAC__StreamMetadata* metadata_[2];

View file

@ -86,7 +86,7 @@ void OggEncoder::encode(const msg::PcmChunk* chunk)
/* tell the library how much we actually submitted */
vorbis_analysis_wrote(&vd_, frames);
msg::PcmChunk* oggChunk = new msg::PcmChunk(chunk->format, 0);
auto* oggChunk = new msg::PcmChunk(chunk->format, 0);
/* vorbis does some data preanalysis, then divvies up blocks for
more involved (potentially parallel) processing. Get a single
@ -95,7 +95,7 @@ void OggEncoder::encode(const msg::PcmChunk* chunk)
while (vorbis_analysis_blockout(&vd_, &vb_) == 1)
{
/* analysis, assume we want to use bitrate management */
vorbis_analysis(&vb_, NULL);
vorbis_analysis(&vb_, nullptr);
vorbis_bitrate_addblock(&vb_);
while (vorbis_bitrate_flushpacket(&vd_, &op_))
@ -219,7 +219,7 @@ void OggEncoder::initEncoder()
/* set up our packet->stream encoder */
/* pick a random serial number; that way we can more likely build
chained streams just by concatenation */
srand(time(NULL));
srand(time(nullptr));
ogg_stream_init(&os_, rand());
/* Vorbis streams begin with three headers; the initial header (with

View file

@ -26,13 +26,13 @@ class OggEncoder : public Encoder
{
public:
OggEncoder(const std::string& codecOptions = "");
virtual void encode(const msg::PcmChunk* chunk);
virtual std::string getAvailableOptions() const;
virtual std::string getDefaultOptions() const;
virtual std::string name() const;
void encode(const msg::PcmChunk* chunk) override;
std::string getAvailableOptions() const override;
std::string getDefaultOptions() const override;
std::string name() const override;
protected:
virtual void initEncoder();
void initEncoder() override;
private:
ogg_stream_state os_; /// take physical pages, weld into a logical stream of packets

View file

@ -35,7 +35,7 @@ PcmEncoder::PcmEncoder(const std::string& codecOptions) : Encoder(codecOptions)
void PcmEncoder::encode(const msg::PcmChunk* chunk)
{
msg::PcmChunk* pcmChunk = new msg::PcmChunk(*chunk);
auto* pcmChunk = new msg::PcmChunk(*chunk);
listener_->onChunkEncoded(this, pcmChunk, pcmChunk->duration<chronos::msec>().count());
}

View file

@ -25,11 +25,11 @@ class PcmEncoder : public Encoder
{
public:
PcmEncoder(const std::string& codecOptions = "");
virtual void encode(const msg::PcmChunk* chunk);
virtual std::string name() const;
void encode(const msg::PcmChunk* chunk) override;
std::string name() const override;
protected:
virtual void initEncoder();
void initEncoder() override;
template <typename T>
void assign(void* pointer, T val)

View file

@ -27,10 +27,10 @@ static AvahiEntryGroup* group;
static AvahiSimplePoll* simple_poll;
static char* name;
PublishAvahi::PublishAvahi(const std::string& serviceName) : PublishmDNS(serviceName), client_(NULL), active_(false)
PublishAvahi::PublishAvahi(const std::string& serviceName) : PublishmDNS(serviceName), client_(nullptr), active_(false)
{
group = NULL;
simple_poll = NULL;
group = nullptr;
simple_poll = nullptr;
name = avahi_strdup(serviceName_.c_str());
}
@ -85,7 +85,7 @@ PublishAvahi::~PublishAvahi()
void PublishAvahi::entry_group_callback(AvahiEntryGroup* g, AvahiEntryGroupState state, AVAHI_GCC_UNUSED void* userdata)
{
assert(g == group || group == NULL);
assert(g == group || group == nullptr);
group = g;
/// Called whenever the entry group state changes
@ -149,7 +149,7 @@ void PublishAvahi::create_services(AvahiClient* c)
/// We will now add two services and one subtype to the entry group
for (const auto& service : services_)
{
if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, AvahiPublishFlags(0), name, service.name_.c_str(), NULL, NULL,
if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, AvahiPublishFlags(0), name, service.name_.c_str(), nullptr, nullptr,
service.port_, NULL)) < 0)
{
if (ret == AVAHI_ERR_COLLISION)

View file

@ -41,8 +41,8 @@ class PublishAvahi : public PublishmDNS
{
public:
PublishAvahi(const std::string& serviceName);
virtual ~PublishAvahi();
virtual void publish(const std::vector<mDNSService>& services);
~PublishAvahi() override;
void publish(const std::vector<mDNSService>& services) override;
private:
static void entry_group_callback(AvahiEntryGroup* g, AvahiEntryGroupState state, AVAHI_GCC_UNUSED void* userdata);

View file

@ -24,8 +24,7 @@ public:
}
virtual ~PublishmDNS()
{
}
= default;
virtual void publish(const std::vector<mDNSService>& services) = 0;

View file

@ -36,8 +36,7 @@ StreamServer::StreamServer(asio::io_service* io_service, const StreamServerSetti
StreamServer::~StreamServer()
{
}
= default;
void StreamServer::onMetaChanged(const PcmStream* pcmStream)
@ -57,7 +56,7 @@ void StreamServer::onMetaChanged(const PcmStream* pcmStream)
LOG(INFO) << "onMetaChanged (" << pcmStream->getName() << ")\n";
json notification = jsonrpcpp::Notification("Stream.OnMetadata", jsonrpcpp::Parameter("id", pcmStream->getId(), "meta", meta->msg)).to_json();
controlServer_->send(notification.dump(), NULL);
controlServer_->send(notification.dump(), nullptr);
////cout << "Notification: " << notification.dump() << "\n";
}
@ -69,7 +68,7 @@ void StreamServer::onStateChanged(const PcmStream* pcmStream, const ReaderState&
LOG(INFO) << "onStateChanged (" << pcmStream->getName() << "): " << state << "\n";
// LOG(INFO) << pcmStream->toJson().dump(4);
json notification = jsonrpcpp::Notification("Stream.OnUpdate", jsonrpcpp::Parameter("id", pcmStream->getId(), "stream", pcmStream->toJson())).to_json();
controlServer_->send(notification.dump(), NULL);
controlServer_->send(notification.dump(), nullptr);
////cout << "Notification: " << notification.dump() << "\n";
}

View file

@ -79,17 +79,17 @@ public:
// void send(const msg::BaseMessage* message);
/// Clients call this when they receive a message. Implementation of MessageReceiver::onMessageReceived
virtual void onMessageReceived(StreamSession* connection, const msg::BaseMessage& baseMessage, char* buffer);
virtual void onDisconnect(StreamSession* connection);
void onMessageReceived(StreamSession* connection, const msg::BaseMessage& baseMessage, char* buffer) override;
void onDisconnect(StreamSession* connection) override;
/// Implementation of ControllMessageReceiver::onMessageReceived, called by ControlServer::onMessageReceived
virtual void onMessageReceived(ControlSession* connection, const std::string& message);
void onMessageReceived(ControlSession* connection, const std::string& message) override;
/// Implementation of PcmListener
virtual void onMetaChanged(const PcmStream* pcmStream);
virtual void onStateChanged(const PcmStream* pcmStream, const ReaderState& state);
virtual void onChunkRead(const PcmStream* pcmStream, msg::PcmChunk* chunk, double duration);
virtual void onResync(const PcmStream* pcmStream, double ms);
void onMetaChanged(const PcmStream* pcmStream) override;
void onStateChanged(const PcmStream* pcmStream, const ReaderState& state) override;
void onChunkRead(const PcmStream* pcmStream, msg::PcmChunk* chunk, double duration) override;
void onResync(const PcmStream* pcmStream, double ms) override;
private:
void startAccept();

View file

@ -200,7 +200,7 @@ void StreamSession::getNextMessage()
tv t;
baseMessage.received = t;
if (active_ && (messageReceiver_ != NULL))
if (active_ && (messageReceiver_ != nullptr))
messageReceiver_->onMessageReceived(this, baseMessage, &buffer[0]);
}
@ -219,7 +219,7 @@ void StreamSession::reader()
SLOG(ERROR) << "Exception in StreamSession::reader(): " << e.what() << endl;
}
if (active_ && (messageReceiver_ != NULL))
if (active_ && (messageReceiver_ != nullptr))
messageReceiver_->onDisconnect(this);
}
@ -238,7 +238,7 @@ void StreamSession::writer()
if (bufferMs_ > 0)
{
const msg::WireChunk* wireChunk = dynamic_cast<const msg::WireChunk*>(message.get());
if (wireChunk != NULL)
if (wireChunk != nullptr)
{
chronos::time_point_clk now = chronos::clk::now();
size_t age = 0;
@ -258,6 +258,6 @@ void StreamSession::writer()
SLOG(ERROR) << "Exception in StreamSession::writer(): " << e.what() << endl;
}
if (active_ && (messageReceiver_ != NULL))
if (active_ && (messageReceiver_ != nullptr))
messageReceiver_->onDisconnect(this);
}

View file

@ -28,7 +28,7 @@ using namespace std;
static string hex2str(string input)
{
typedef unsigned char byte;
unsigned long x = strtoul(input.c_str(), 0, 16);
unsigned long x = strtoul(input.c_str(), nullptr, 16);
byte a[] = {byte(x >> 24), byte(x >> 16), byte(x >> 8), byte(x), 0};
return string((char*)a);
}

View file

@ -57,7 +57,7 @@ class AirplayStream : public ProcessStream
public:
/// ctor. Encoded PCM data is passed to the PipeListener
AirplayStream(PcmListener* pcmListener, const StreamUri& uri);
virtual ~AirplayStream();
~AirplayStream() override;
protected:
#ifdef HAS_EXPAT
@ -74,8 +74,8 @@ protected:
void push();
#endif
virtual void onStderrMsg(const char* buffer, size_t n);
virtual void initExeAndPath(const std::string& filename);
void onStderrMsg(const char* buffer, size_t n) override;
void initExeAndPath(const std::string& filename) override;
size_t port_;
std::string pipePath_;
std::string params_wo_port_;

View file

@ -34,10 +34,10 @@ class FileStream : public PcmStream
public:
/// ctor. Encoded PCM data is passed to the PipeListener
FileStream(PcmListener* pcmListener, const StreamUri& uri);
virtual ~FileStream();
~FileStream() override;
protected:
virtual void worker();
void worker() override;
std::ifstream ifs;
};

View file

@ -75,7 +75,7 @@ public:
virtual void stop();
/// Implementation of EncoderListener::onChunkEncoded
virtual void onChunkEncoded(const Encoder* encoder, msg::PcmChunk* chunk, double duration);
void onChunkEncoded(const Encoder* encoder, msg::PcmChunk* chunk, double duration) override;
virtual std::shared_ptr<msg::CodecHeader> getHeader();
virtual const StreamUri& getUri() const;

View file

@ -34,10 +34,10 @@ class PipeStream : public PcmStream
public:
/// ctor. Encoded PCM data is passed to the PipeListener
PipeStream(PcmListener* pcmListener, const StreamUri& uri);
virtual ~PipeStream();
~PipeStream() override;
protected:
virtual void worker();
void worker() override;
int fd_;
};

View file

@ -37,10 +37,10 @@ class ProcessStream : public PcmStream
public:
/// ctor. Encoded PCM data is passed to the PipeListener
ProcessStream(PcmListener* pcmListener, const StreamUri& uri);
virtual ~ProcessStream();
~ProcessStream() override;
virtual void start();
virtual void stop();
void start() override;
void stop() override;
protected:
std::string exe_;
@ -50,7 +50,7 @@ protected:
std::thread stderrReaderThread_;
bool logStderr_;
virtual void worker();
void worker() override;
virtual void stderrReader();
virtual void onStderrMsg(const char* buffer, size_t n);
virtual void initExeAndPath(const std::string& filename);

View file

@ -64,8 +64,7 @@ SpotifyStream::SpotifyStream(PcmListener* pcmListener, const StreamUri& uri) : P
SpotifyStream::~SpotifyStream()
{
}
= default;
void SpotifyStream::initExeAndPath(const std::string& filename)

View file

@ -36,16 +36,16 @@ class SpotifyStream : public ProcessStream, WatchdogListener
public:
/// ctor. Encoded PCM data is passed to the PipeListener
SpotifyStream(PcmListener* pcmListener, const StreamUri& uri);
virtual ~SpotifyStream();
~SpotifyStream() override;
protected:
std::unique_ptr<Watchdog> watchdog_;
virtual void stderrReader();
virtual void onStderrMsg(const char* buffer, size_t n);
virtual void initExeAndPath(const std::string& filename);
void stderrReader() override;
void onStderrMsg(const char* buffer, size_t n) override;
void initExeAndPath(const std::string& filename) override;
virtual void onTimeout(const Watchdog* watchdog, size_t ms);
void onTimeout(const Watchdog* watchdog, size_t ms) override;
};