reformat code

This commit is contained in:
badaix 2019-09-24 22:52:31 +02:00
parent b20add3815
commit 88b49ad2a0
11 changed files with 2051 additions and 2406 deletions

View file

@ -178,7 +178,7 @@ void ClientConnection::getNextMessage()
socketRead(&buffer[0], baseMsgSize);
baseMessage.deserialize(&buffer[0]);
// LOG(DEBUG) << "getNextMessage: " << baseMessage.type << ", size: " << baseMessage.size << ", id: " << baseMessage.id << ", refers: " <<
//baseMessage.refersTo << "\n";
// baseMessage.refersTo << "\n";
if (baseMessage.size > buffer.size())
buffer.resize(baseMessage.size);
// {
@ -191,7 +191,7 @@ void ClientConnection::getNextMessage()
{
std::unique_lock<std::mutex> lock(pendingRequestsMutex_);
// LOG(DEBUG) << "got lock - getNextMessage: " << baseMessage.type << ", size: " << baseMessage.size << ", id: " << baseMessage.id << ",
//refers: " << baseMessage.refersTo << "\n";
// refers: " << baseMessage.refersTo << "\n";
{
for (auto req : pendingRequests_)
{

View file

@ -370,8 +370,8 @@ else if (miniBuffer_.full() && (cs::usec(abs(miniBuffer_.median())) > cs::msec(5
shortMedian_ = shortBuffer_.median();
LOG(INFO) << "Chunk: " << age.count() / 100 << "\t" << miniBuffer_.median() / 100 << "\t" << shortMedian_ / 100 << "\t" << median_ / 100 << "\t"
<< buffer_.size() << "\t" << cs::duration<cs::msec>(outputBufferDacTime) << "\n";
// LOG(INFO) << "Chunk: " << age.count()/1000 << "\t" << miniBuffer_.median()/1000 << "\t" << shortMedian_/1000 << "\t" << median_/1000 << "\t"
//<< buffer_.size() << "\t" << cs::duration<cs::msec>(outputBufferDacTime) << "\n";
// LOG(INFO) << "Chunk: " << age.count()/1000 << "\t" << miniBuffer_.median()/1000 << "\t" << shortMedian_/1000 << "\t" << median_/1000 << "\t" <<
// buffer_.size() << "\t" << cs::duration<cs::msec>(outputBufferDacTime) << "\n";
}
return (abs(cs::duration<cs::msec>(age)) < 500);
}

View file

@ -4,13 +4,13 @@
#include <cstdint>
#ifdef IS_BIG_ENDIAN
# define SWAP_16(x) (__builtin_bswap16(x))
# define SWAP_32(x) (__builtin_bswap32(x))
# define SWAP_64(x) (__builtin_bswap64(x))
#define SWAP_16(x) (__builtin_bswap16(x))
#define SWAP_32(x) (__builtin_bswap32(x))
#define SWAP_64(x) (__builtin_bswap64(x))
#else
# define SWAP_16(x) x
# define SWAP_32(x) x
# define SWAP_64(x) x
#define SWAP_16(x) x
#define SWAP_32(x) x
#define SWAP_64(x) x
#endif
namespace endian
@ -22,28 +22,26 @@ T swap(const T&);
template <>
inline int8_t swap(const int8_t& val)
{
return val;
return val;
}
template <>
inline int16_t swap(const int16_t& val)
{
return SWAP_16(val);
return SWAP_16(val);
}
template <>
inline int32_t swap(const int32_t& val)
{
return SWAP_32(val);
return SWAP_32(val);
}
template <>
inline int64_t swap(const int64_t& val)
{
return SWAP_64(val);
return SWAP_64(val);
}
}
#endif

File diff suppressed because it is too large Load diff

View file

@ -71,8 +71,8 @@ void FlacEncoder::encode(const msg::PcmChunk* chunk)
{
int samples = chunk->getSampleCount();
int frames = chunk->getFrameCount();
// LOG(INFO) << "payload: " << chunk->payloadSize << "\tframes: " << frames << "\tsamples: " << samples << "\tduration: " <<
//chunk->duration<chronos::msec>().count() << "\n";
// LOG(INFO) << "payload: " << chunk->payloadSize << "\tframes: " << frames << "\tsamples: " << samples << "\tduration: " <<
// chunk->duration<chronos::msec>().count() << "\n";
if (pcmBufferSize_ < samples)
{

File diff suppressed because it is too large Load diff

View file

@ -161,7 +161,8 @@ void PublishAvahi::create_services(AvahiClient* c)
}
/// Add an additional (hypothetic) subtype
/* if ((ret = avahi_entry_group_add_service_subtype(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, AvahiPublishFlags(0), name, "_printer._tcp",
/* if ((ret = avahi_entry_group_add_service_subtype(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, AvahiPublishFlags(0), name,
"_printer._tcp",
NULL, "_magic._sub._printer._tcp") < 0))
{
fprintf(stderr, "Failed to add subtype _magic._sub._printer._tcp: %s\n", avahi_strerror(ret));

View file

@ -150,8 +150,8 @@ void PublishBonjour::publish(const std::vector<mDNSService>& services)
DNSServiceFlags flags = 0;
Opaque16 registerPort = {{static_cast<unsigned char>(service.port_ >> 8), static_cast<unsigned char>(service.port_ & 0xFF)}};
DNSServiceRef client = NULL;
// DNSServiceRegister(&client, flags, kDNSServiceInterfaceIndexAny, serviceName_.c_str(), service.name_.c_str(), NULL, NULL,
//registerPort.NotAnInteger, service.txt_.size(), service.txt_.empty()?NULL:service.txt_.c_str(), reg_reply, this);
// DNSServiceRegister(&client, flags, kDNSServiceInterfaceIndexAny, serviceName_.c_str(), service.name_.c_str(), NULL, NULL, registerPort.NotAnInteger,
// service.txt_.size(), service.txt_.empty()?NULL:service.txt_.c_str(), reg_reply, this);
DNSServiceRegister(&client, flags, kDNSServiceInterfaceIndexAny, serviceName_.c_str(), service.name_.c_str(), NULL, NULL, registerPort.NotAnInteger, 0,
NULL, reg_reply, this);
clients.push_back(client);

View file

@ -578,8 +578,8 @@ void StreamServer::onMessageReceived(ControlSession* controlSession, const std::
void StreamServer::onMessageReceived(StreamSession* streamSession, const msg::BaseMessage& baseMessage, char* buffer)
{
// LOG(DEBUG) << "onMessageReceived: " << baseMessage.type << ", size: " << baseMessage.size << ", id: " << baseMessage.id << ", refers: " <<
//baseMessage.refersTo << ", sent: " << baseMessage.sent.sec << "," << baseMessage.sent.usec << ", recv: " << baseMessage.received.sec << "," <<
//baseMessage.received.usec << "\n";
// baseMessage.refersTo << ", sent: " << baseMessage.sent.sec << "," << baseMessage.sent.usec << ", recv: " << baseMessage.received.sec << "," <<
// baseMessage.received.usec << "\n";
if (baseMessage.type == message_type::kTime)
{
auto timeMsg = make_shared<msg::Time>();

View file

@ -190,7 +190,7 @@ void StreamSession::getNextMessage()
}
// LOG(INFO) << "getNextMessage: " << baseMessage.type << ", size: " << baseMessage.size << ", id: " << baseMessage.id << ", refers: " <<
//baseMessage.refersTo << "\n";
// baseMessage.refersTo << "\n";
if (baseMessage.size > buffer.size())
buffer.resize(baseMessage.size);
// {

View file

@ -16,228 +16,227 @@
#ifndef TINY_PROCESS_LIBRARY_HPP_
#define TINY_PROCESS_LIBRARY_HPP_
#include <string>
#include <mutex>
#include <sys/wait.h>
#include <cstdlib>
#include <unistd.h>
#include <mutex>
#include <signal.h>
#include <string>
#include <sys/wait.h>
#include <unistd.h>
// Forked from: https://github.com/eidheim/tiny-process-library
// Copyright (c) 2015-2016 Ole Christian Eidheim
// Thanks, Christian :-)
///Create a new process given command and run path.
///Thus, at the moment, if read_stdout==nullptr, read_stderr==nullptr and open_stdin==false,
///the stdout, stderr and stdin are sent to the parent process instead.
///Compile with -DMSYS_PROCESS_USE_SH to run command using "sh -c [command]" on Windows as well.
class Process {
/// Create a new process given command and run path.
/// Thus, at the moment, if read_stdout==nullptr, read_stderr==nullptr and open_stdin==false,
/// the stdout, stderr and stdin are sent to the parent process instead.
/// Compile with -DMSYS_PROCESS_USE_SH to run command using "sh -c [command]" on Windows as well.
class Process
{
public:
typedef int fd_type;
typedef int fd_type;
Process(const std::string &command, const std::string &path = "") : closed(true)
{
open(command, path);
}
Process(const std::string& command, const std::string& path = "") : closed(true)
{
open(command, path);
}
~Process()
{
close_fds();
}
~Process()
{
close_fds();
}
///Get the process id of the started process.
pid_t getPid()
{
return pid;
}
/// Get the process id of the started process.
pid_t getPid()
{
return pid;
}
///Write to stdin. Convenience function using write(const char *, size_t).
bool write(const std::string &data)
{
return write(data.c_str(), data.size());
}
/// Write to stdin. Convenience function using write(const char *, size_t).
bool write(const std::string& data)
{
return write(data.c_str(), data.size());
}
///Wait until process is finished, and return exit status.
int get_exit_status()
{
if (pid <= 0)
return -1;
/// Wait until process is finished, and return exit status.
int get_exit_status()
{
if (pid <= 0)
return -1;
int exit_status;
waitpid(pid, &exit_status, 0);
{
std::lock_guard<std::mutex> lock(close_mutex);
closed=true;
}
close_fds();
int exit_status;
waitpid(pid, &exit_status, 0);
{
std::lock_guard<std::mutex> lock(close_mutex);
closed = true;
}
close_fds();
if (exit_status >= 256)
exit_status = exit_status>>8;
if (exit_status >= 256)
exit_status = exit_status >> 8;
return exit_status;
}
return exit_status;
}
///Write to stdin.
bool write(const char *bytes, size_t n)
{
std::lock_guard<std::mutex> lock(stdin_mutex);
if (::write(stdin_fd, bytes, n)>=0)
return true;
else
return false;
}
/// Write to stdin.
bool write(const char* bytes, size_t n)
{
std::lock_guard<std::mutex> lock(stdin_mutex);
if (::write(stdin_fd, bytes, n) >= 0)
return true;
else
return false;
}
///Close stdin. If the process takes parameters from stdin, use this to notify that all parameters have been sent.
void close_stdin()
{
std::lock_guard<std::mutex> lock(stdin_mutex);
if (pid > 0)
close(stdin_fd);
}
/// Close stdin. If the process takes parameters from stdin, use this to notify that all parameters have been sent.
void close_stdin()
{
std::lock_guard<std::mutex> lock(stdin_mutex);
if (pid > 0)
close(stdin_fd);
}
///Kill the process.
void kill(bool force=false)
{
std::lock_guard<std::mutex> lock(close_mutex);
if (pid > 0 && !closed)
{
if(force)
::kill(-pid, SIGTERM);
else
::kill(-pid, SIGINT);
}
}
/// Kill the process.
void kill(bool force = false)
{
std::lock_guard<std::mutex> lock(close_mutex);
if (pid > 0 && !closed)
{
if (force)
::kill(-pid, SIGTERM);
else
::kill(-pid, SIGINT);
}
}
///Kill a given process id. Use kill(bool force) instead if possible.
static void kill(pid_t id, bool force=false)
{
if (id <= 0)
return;
if (force)
::kill(-id, SIGTERM);
else
::kill(-id, SIGINT);
}
/// Kill a given process id. Use kill(bool force) instead if possible.
static void kill(pid_t id, bool force = false)
{
if (id <= 0)
return;
if (force)
::kill(-id, SIGTERM);
else
::kill(-id, SIGINT);
}
fd_type getStdout()
{
return stdout_fd;
}
fd_type getStdout()
{
return stdout_fd;
}
fd_type getStderr()
{
return stderr_fd;
}
fd_type getStderr()
{
return stderr_fd;
}
fd_type getStdin()
{
return stdin_fd;
}
fd_type getStdin()
{
return stdin_fd;
}
private:
pid_t pid;
bool closed;
std::mutex close_mutex;
std::mutex stdin_mutex;
pid_t pid;
bool closed;
std::mutex close_mutex;
std::mutex stdin_mutex;
fd_type stdout_fd, stderr_fd, stdin_fd;
fd_type stdout_fd, stderr_fd, stdin_fd;
void closePipe(int pipefd[2])
{
close(pipefd[0]);
close(pipefd[1]);
}
void closePipe(int pipefd[2])
{
close(pipefd[0]);
close(pipefd[1]);
}
pid_t open(const std::string &command, const std::string &path)
{
int stdin_p[2], stdout_p[2], stderr_p[2];
pid_t open(const std::string& command, const std::string& path)
{
int stdin_p[2], stdout_p[2], stderr_p[2];
if (pipe(stdin_p) != 0)
return -1;
if (pipe(stdin_p) != 0)
return -1;
if (pipe(stdout_p) != 0)
{
closePipe(stdin_p);
return -1;
}
if (pipe(stdout_p) != 0)
{
closePipe(stdin_p);
return -1;
}
if (pipe(stderr_p) != 0)
{
closePipe(stdin_p);
closePipe(stdout_p);
return -1;
}
if (pipe(stderr_p) != 0)
{
closePipe(stdin_p);
closePipe(stdout_p);
return -1;
}
pid = fork();
pid = fork();
if (pid < 0)
{
closePipe(stdin_p);
closePipe(stdout_p);
closePipe(stderr_p);
return pid;
}
else if (pid == 0)
{
dup2(stdin_p[0], 0);
dup2(stdout_p[1], 1);
dup2(stderr_p[1], 2);
if (pid < 0)
{
closePipe(stdin_p);
closePipe(stdout_p);
closePipe(stderr_p);
return pid;
}
else if (pid == 0)
{
dup2(stdin_p[0], 0);
dup2(stdout_p[1], 1);
dup2(stderr_p[1], 2);
closePipe(stdin_p);
closePipe(stdout_p);
closePipe(stderr_p);
closePipe(stdin_p);
closePipe(stdout_p);
closePipe(stderr_p);
//Based on http://stackoverflow.com/a/899533/3808293
int fd_max = sysconf(_SC_OPEN_MAX);
for (int fd=3; fd<fd_max; fd++)
close(fd);
// Based on http://stackoverflow.com/a/899533/3808293
int fd_max = sysconf(_SC_OPEN_MAX);
for (int fd = 3; fd < fd_max; fd++)
close(fd);
setpgid(0, 0);
setpgid(0, 0);
if (!path.empty())
{
auto path_escaped = path;
size_t pos=0;
//Based on https://www.reddit.com/r/cpp/comments/3vpjqg/a_new_platform_independent_process_library_for_c11/cxsxyb7
while ((pos = path_escaped.find('\'', pos)) != std::string::npos)
{
path_escaped.replace(pos, 1, "'\\''");
pos += 4;
}
execl("/bin/sh", "sh", "-c", ("cd '" + path_escaped + "' && " + command).c_str(), NULL);
}
else
execl("/bin/sh", "sh", "-c", command.c_str(), NULL);
if (!path.empty())
{
auto path_escaped = path;
size_t pos = 0;
// Based on https://www.reddit.com/r/cpp/comments/3vpjqg/a_new_platform_independent_process_library_for_c11/cxsxyb7
while ((pos = path_escaped.find('\'', pos)) != std::string::npos)
{
path_escaped.replace(pos, 1, "'\\''");
pos += 4;
}
execl("/bin/sh", "sh", "-c", ("cd '" + path_escaped + "' && " + command).c_str(), NULL);
}
else
execl("/bin/sh", "sh", "-c", command.c_str(), NULL);
_exit(EXIT_FAILURE);
}
_exit(EXIT_FAILURE);
}
close(stdin_p[0]);
close(stdout_p[1]);
close(stderr_p[1]);
close(stdin_p[0]);
close(stdout_p[1]);
close(stderr_p[1]);
stdin_fd = stdin_p[1];
stdout_fd = stdout_p[0];
stderr_fd = stderr_p[0];
stdin_fd = stdin_p[1];
stdout_fd = stdout_p[0];
stderr_fd = stderr_p[0];
closed = false;
return pid;
}
closed = false;
return pid;
}
void close_fds()
{
close_stdin();
if (pid > 0)
{
close(stdout_fd);
close(stderr_fd);
}
}
void close_fds()
{
close_stdin();
if (pid > 0)
{
close(stdout_fd);
close(stderr_fd);
}
}
};
#endif // TINY_PROCESS_LIBRARY_HPP_
#endif // TINY_PROCESS_LIBRARY_HPP_