// // Created by zhaohe on 19-5-31. // #pragma once #include #include #include #include #include #include #include #include #include #include "nlohmann/json.hpp" #include "logger_factory.hpp" #include "spdlog/fmt/ostr.h" #include "spdlog/spdlog.h" extern "C" { #include #include "linux/input-event-codes.h" } namespace zwsd {} // namespace zwsd #define ENABLE_BASIC_TYPE_LOGGER(type) \ template \ static inline OStream &operator<<(OStream &os, const std::list &c) { \ nlohmann::json j = c; \ return os << j.dump(); \ } \ template \ static inline OStream &operator<<(OStream &os, const std::vector &c) { \ nlohmann::json j = c; \ return os << j.dump(); \ } \ template \ static inline OStream &operator<<(OStream &os, const std::set &c) { \ nlohmann::json j = c; \ return os << j.dump(); \ } ENABLE_BASIC_TYPE_LOGGER(std::string) ENABLE_BASIC_TYPE_LOGGER(bool) ENABLE_BASIC_TYPE_LOGGER(uint8_t) ENABLE_BASIC_TYPE_LOGGER(uint16_t) ENABLE_BASIC_TYPE_LOGGER(uint32_t) ENABLE_BASIC_TYPE_LOGGER(uint64_t) ENABLE_BASIC_TYPE_LOGGER(int8_t) ENABLE_BASIC_TYPE_LOGGER(int16_t) ENABLE_BASIC_TYPE_LOGGER(int32_t) ENABLE_BASIC_TYPE_LOGGER(int64_t) ENABLE_BASIC_TYPE_LOGGER(float) ENABLE_BASIC_TYPE_LOGGER(double) #undef ENABLE_BASIC_TYPE_LOGGER // dump input event template static inline OStream &operator<<(OStream &os, struct input_event &event) { return os << fmt::format("input-event {} {} {}", event.type, event.code, event.value); } #define ZCHECK(exptr, info) \ { \ if (!(exptr)) { \ logger->critical("({}:{})ZCHECK failed: {} {}", __FILE__, __LINE__, info, #exptr); \ exit(-1); \ } \ }