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

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

View file

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

File diff suppressed because it is too large Load diff

View file

@ -16,16 +16,17 @@
/// http://patorjk.com/software/taag/#p=display&f=Graceful&t=JSONRPC%2B%2B /// http://patorjk.com/software/taag/#p=display&f=Graceful&t=JSONRPC%2B%2B
/// checked with clang-tidy: /// checked with clang-tidy:
/// run-clang-tidy-3.8.py -header-filter='jsonrpcpp.hpp' -checks='*,-misc-definitions-in-headers,-google-readability-braces-around-statements,-readability-braces-around-statements,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-google-build-using-namespace,-google-build-using-namespace,-modernize-pass-by-value,-google-explicit-constructor' /// run-clang-tidy-3.8.py -header-filter='jsonrpcpp.hpp'
/// -checks='*,-misc-definitions-in-headers,-google-readability-braces-around-statements,-readability-braces-around-statements,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-google-build-using-namespace,-google-build-using-namespace,-modernize-pass-by-value,-google-explicit-constructor'
#ifndef JSON_RPC_H #ifndef JSON_RPC_H
#define JSON_RPC_H #define JSON_RPC_H
#include "json.hpp"
#include <cstring> #include <cstring>
#include <exception>
#include <string> #include <string>
#include <vector> #include <vector>
#include "json.hpp"
#include <exception>
using Json = nlohmann::json; using Json = nlohmann::json;
@ -93,8 +94,6 @@ protected:
class NullableEntity : public Entity class NullableEntity : public Entity
{ {
public: public:
@ -116,8 +115,6 @@ protected:
class Id : public Entity class Id : public Entity
{ {
public: public:
@ -166,8 +163,6 @@ protected:
class Parameter : public NullableEntity class Parameter : public NullableEntity
{ {
public: public:
@ -180,10 +175,8 @@ public:
Parameter(std::nullptr_t); Parameter(std::nullptr_t);
Parameter(const Json& json = nullptr); Parameter(const Json& json = nullptr);
Parameter(const std::string& key1, const Json& value1, Parameter(const std::string& key1, const Json& value1, const std::string& key2 = "", const Json& value2 = nullptr, const std::string& key3 = "",
const std::string& key2 = "", const Json& value2 = nullptr, const Json& value3 = nullptr, const std::string& key4 = "", const Json& value4 = nullptr);
const std::string& key3 = "", const Json& value3 = nullptr,
const std::string& key4 = "", const Json& value4 = nullptr);
Json to_json() const override; Json to_json() const override;
void parse_json(const Json& json) override; void parse_json(const Json& json) override;
@ -232,8 +225,6 @@ public:
class Error : public NullableEntity class Error : public NullableEntity
{ {
public: public:
@ -304,8 +295,6 @@ protected:
class RpcException : public std::exception class RpcException : public std::exception
{ {
public: public:
@ -417,8 +406,6 @@ public:
class Response : public Entity class Response : public Entity
{ {
public: public:
@ -455,8 +442,6 @@ protected:
class Notification : public Entity class Notification : public Entity
{ {
public: public:
@ -484,7 +469,6 @@ protected:
typedef std::function<void(const Parameter& params)> notification_callback; typedef std::function<void(const Parameter& params)> notification_callback;
typedef std::function<jsonrpcpp::response_ptr(const Id& id, const Parameter& params)> request_callback; typedef std::function<jsonrpcpp::response_ptr(const Id& id, const Parameter& params)> request_callback;
@ -519,8 +503,6 @@ private:
class Batch : public Entity class Batch : public Entity
{ {
public: public:
@ -545,7 +527,6 @@ public:
/////////////////////////// Entity implementation ///////////////////////////// /////////////////////////// Entity implementation /////////////////////////////
inline Entity::Entity(entity_t type) : entity(type) inline Entity::Entity(entity_t type) : entity(type)
@ -653,8 +634,6 @@ inline std::string Entity::type_str() const
/////////////////////////// NullableEntity implementation ///////////////////// /////////////////////////// NullableEntity implementation /////////////////////
inline NullableEntity::NullableEntity(entity_t type) : Entity(type), isNull(false) inline NullableEntity::NullableEntity(entity_t type) : Entity(type), isNull(false)
@ -668,8 +647,6 @@ inline NullableEntity::NullableEntity(entity_t type, std::nullptr_t) : Entity(ty
/////////////////////////// Id implementation ///////////////////////////////// /////////////////////////// Id implementation /////////////////////////////////
inline Id::Id() : Entity(entity_t::id), type_(value_t::null), int_id_(0), string_id_("") inline Id::Id() : Entity(entity_t::id), type_(value_t::null), int_id_(0), string_id_("")
@ -733,8 +710,6 @@ inline Json Id::to_json() const
//////////////////////// Error implementation ///////////////////////////////// //////////////////////// Error implementation /////////////////////////////////
inline Parameter::Parameter(std::nullptr_t) : NullableEntity(entity_t::id, nullptr), type(value_t::null) inline Parameter::Parameter(std::nullptr_t) : NullableEntity(entity_t::id, nullptr), type(value_t::null)
@ -749,10 +724,9 @@ inline Parameter::Parameter(const Json& json) : NullableEntity(entity_t::id), ty
} }
inline Parameter::Parameter(const std::string& key1, const Json& value1, inline Parameter::Parameter(const std::string& key1, const Json& value1, const std::string& key2, const Json& value2, const std::string& key3,
const std::string& key2, const Json& value2, const Json& value3, const std::string& key4, const Json& value4)
const std::string& key3, const Json& value3, : NullableEntity(entity_t::id), type(value_t::map)
const std::string& key4, const Json& value4) : NullableEntity(entity_t::id), type(value_t::map)
{ {
param_map[key1] = value1; param_map[key1] = value1;
if (!key2.empty()) if (!key2.empty())
@ -839,8 +813,6 @@ inline Json Parameter::get(size_t idx) const
//////////////////////// Error implementation ///////////////////////////////// //////////////////////// Error implementation /////////////////////////////////
inline Error::Error(const Json& json) : Error("Internal error", -32603, nullptr) inline Error::Error(const Json& json) : Error("Internal error", -32603, nullptr)
@ -889,8 +861,7 @@ inline void Error::parse_json(const Json& json)
inline Json Error::to_json() const inline Json Error::to_json() const
{ {
Json j = { Json j = {
{"code", code_}, {"code", code_}, {"message", message_},
{"message", message_},
}; };
if (!data_.is_null()) if (!data_.is_null())
@ -900,8 +871,6 @@ inline Json Error::to_json() const
////////////////////// Request implementation ///////////////////////////////// ////////////////////// Request implementation /////////////////////////////////
inline Request::Request(const Json& json) : Entity(entity_t::request), method_(""), id_() inline Request::Request(const Json& json) : Entity(entity_t::request), method_(""), id_()
@ -964,11 +933,7 @@ inline void Request::parse_json(const Json& json)
inline Json Request::to_json() const inline Json Request::to_json() const
{ {
Json json = { Json json = {{"jsonrpc", "2.0"}, {"method", method_}, {"id", id_.to_json()}};
{"jsonrpc", "2.0"},
{"method", method_},
{"id", id_.to_json()}
};
if (params_) if (params_)
json["params"] = params_.to_json(); json["params"] = params_.to_json();
@ -993,7 +958,6 @@ inline const char* RpcException::what() const noexcept
inline RpcEntityException::RpcEntityException(const Error& error) : RpcException(error.message()), Entity(entity_t::exception), error_(error) inline RpcEntityException::RpcEntityException(const Error& error) : RpcException(error.message()), Entity(entity_t::exception), error_(error)
{ {
} }
@ -1014,37 +978,26 @@ inline ParseErrorException::ParseErrorException(const std::string& data) : Parse
inline Json ParseErrorException::to_json() const inline Json ParseErrorException::to_json() const
{ {
Json response = { Json response = {{"jsonrpc", "2.0"}, {"error", error_.to_json()}, {"id", nullptr}};
{"jsonrpc", "2.0"},
{"error", error_.to_json()},
{"id", nullptr}
};
return response; return response;
} }
inline RequestException::RequestException(const Error& error, const Id& requestId) : RpcEntityException(error), id_(requestId) inline RequestException::RequestException(const Error& error, const Id& requestId) : RpcEntityException(error), id_(requestId)
{ {
} }
inline Json RequestException::to_json() const inline Json RequestException::to_json() const
{ {
Json response = { Json response = {{"jsonrpc", "2.0"}, {"error", error_.to_json()}, {"id", id_.to_json()}};
{"jsonrpc", "2.0"},
{"error", error_.to_json()},
{"id", id_.to_json()}
};
return response; return response;
} }
inline InvalidRequestException::InvalidRequestException(const Id& requestId) : RequestException(Error("Invalid request", -32600), requestId) inline InvalidRequestException::InvalidRequestException(const Id& requestId) : RequestException(Error("Invalid request", -32600), requestId)
{ {
} }
@ -1053,7 +1006,8 @@ inline InvalidRequestException::InvalidRequestException(const Request& request)
{ {
} }
inline InvalidRequestException::InvalidRequestException(const char* data, const Id& requestId) : RequestException(Error("Invalid request", -32600, data), requestId) inline InvalidRequestException::InvalidRequestException(const char* data, const Id& requestId)
: RequestException(Error("Invalid request", -32600, data), requestId)
{ {
} }
@ -1071,7 +1025,8 @@ inline MethodNotFoundException::MethodNotFoundException(const Request& request)
{ {
} }
inline MethodNotFoundException::MethodNotFoundException(const char* data, const Id& requestId) : RequestException(Error("Method not found", -32601, data), requestId) inline MethodNotFoundException::MethodNotFoundException(const char* data, const Id& requestId)
: RequestException(Error("Method not found", -32601, data), requestId)
{ {
} }
@ -1089,7 +1044,8 @@ inline InvalidParamsException::InvalidParamsException(const Request& request) :
{ {
} }
inline InvalidParamsException::InvalidParamsException(const char* data, const Id& requestId) : RequestException(Error("Invalid params", -32602, data), requestId) inline InvalidParamsException::InvalidParamsException(const char* data, const Id& requestId)
: RequestException(Error("Invalid params", -32602, data), requestId)
{ {
} }
@ -1107,7 +1063,8 @@ inline InternalErrorException::InternalErrorException(const Request& request) :
{ {
} }
inline InternalErrorException::InternalErrorException(const char* data, const Id& requestId) : RequestException(Error("Internal error", -32603, data), requestId) inline InternalErrorException::InternalErrorException(const char* data, const Id& requestId)
: RequestException(Error("Internal error", -32603, data), requestId)
{ {
} }
@ -1186,8 +1143,7 @@ inline void Response::parse_json(const Json& json)
inline Json Response::to_json() const inline Json Response::to_json() const
{ {
Json j = { Json j = {
{"jsonrpc", "2.0"}, {"jsonrpc", "2.0"}, {"id", id_.to_json()},
{"id", id_.to_json()},
}; };
if (error_) if (error_)
@ -1200,8 +1156,6 @@ inline Json Response::to_json() const
///////////////// Notification implementation ///////////////////////////////// ///////////////// Notification implementation /////////////////////////////////
inline Notification::Notification(const Json& json) : Entity(entity_t::notification) inline Notification::Notification(const Json& json) : Entity(entity_t::notification)
@ -1258,8 +1212,7 @@ inline void Notification::parse_json(const Json& json)
inline Json Notification::to_json() const inline Json Notification::to_json() const
{ {
Json json = { Json json = {
{"jsonrpc", "2.0"}, {"jsonrpc", "2.0"}, {"method", method_},
{"method", method_},
}; };
if (params_) if (params_)
@ -1270,8 +1223,6 @@ inline Json Notification::to_json() const
//////////////////////// Batch implementation ///////////////////////////////// //////////////////////// Batch implementation /////////////////////////////////
inline Batch::Batch(const Json& json) : Entity(entity_t::batch) inline Batch::Batch(const Json& json) : Entity(entity_t::batch)
@ -1327,7 +1278,6 @@ inline Json Batch::to_json() const
//////////////////////// Parser implementation //////////////////////////////// //////////////////////// Parser implementation ////////////////////////////////
inline void Parser::register_notification_callback(const std::string& notification, notification_callback callback) inline void Parser::register_notification_callback(const std::string& notification, notification_callback callback)

View file

@ -161,7 +161,8 @@ void PublishAvahi::create_services(AvahiClient* c)
} }
/// Add an additional (hypothetic) subtype /// 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)) NULL, "_magic._sub._printer._tcp") < 0))
{ {
fprintf(stderr, "Failed to add subtype _magic._sub._printer._tcp: %s\n", avahi_strerror(ret)); 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; DNSServiceFlags flags = 0;
Opaque16 registerPort = {{static_cast<unsigned char>(service.port_ >> 8), static_cast<unsigned char>(service.port_ & 0xFF)}}; Opaque16 registerPort = {{static_cast<unsigned char>(service.port_ >> 8), static_cast<unsigned char>(service.port_ & 0xFF)}};
DNSServiceRef client = NULL; DNSServiceRef client = NULL;
// DNSServiceRegister(&client, flags, kDNSServiceInterfaceIndexAny, serviceName_.c_str(), service.name_.c_str(), NULL, NULL, // DNSServiceRegister(&client, flags, kDNSServiceInterfaceIndexAny, serviceName_.c_str(), service.name_.c_str(), NULL, NULL, registerPort.NotAnInteger,
//registerPort.NotAnInteger, service.txt_.size(), service.txt_.empty()?NULL:service.txt_.c_str(), reg_reply, this); // 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, DNSServiceRegister(&client, flags, kDNSServiceInterfaceIndexAny, serviceName_.c_str(), service.name_.c_str(), NULL, NULL, registerPort.NotAnInteger, 0,
NULL, reg_reply, this); NULL, reg_reply, this);
clients.push_back(client); clients.push_back(client);

View file

@ -16,12 +16,12 @@
#ifndef TINY_PROCESS_LIBRARY_HPP_ #ifndef TINY_PROCESS_LIBRARY_HPP_
#define TINY_PROCESS_LIBRARY_HPP_ #define TINY_PROCESS_LIBRARY_HPP_
#include <string>
#include <mutex>
#include <sys/wait.h>
#include <cstdlib> #include <cstdlib>
#include <unistd.h> #include <mutex>
#include <signal.h> #include <signal.h>
#include <string>
#include <sys/wait.h>
#include <unistd.h>
// Forked from: https://github.com/eidheim/tiny-process-library // Forked from: https://github.com/eidheim/tiny-process-library
// Copyright (c) 2015-2016 Ole Christian Eidheim // Copyright (c) 2015-2016 Ole Christian Eidheim
@ -31,7 +31,8 @@
/// Thus, at the moment, if read_stdout==nullptr, read_stderr==nullptr and open_stdin==false, /// 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. /// 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. /// Compile with -DMSYS_PROCESS_USE_SH to run command using "sh -c [command]" on Windows as well.
class Process { class Process
{
public: public:
typedef int fd_type; typedef int fd_type;
@ -236,8 +237,6 @@ private:
close(stderr_fd); close(stderr_fd);
} }
} }
}; };
#endif // TINY_PROCESS_LIBRARY_HPP_ #endif // TINY_PROCESS_LIBRARY_HPP_