You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.8 KiB

5 months ago
  1. //
  2. // Created by zhaohe on 19-5-31.
  3. //
  4. #pragma once
  5. #include <fstream>
  6. #include <iostream>
  7. #include <list>
  8. #include <map>
  9. #include <memory>
  10. #include <set>
  11. #include <sstream>
  12. #include <string>
  13. #include <vector>
  14. #include "nlohmann/json.hpp"
  15. #include "logger_factory.hpp"
  16. #include "spdlog/fmt/ostr.h"
  17. #include "spdlog/spdlog.h"
  18. extern "C" {
  19. #include <linux/input.h>
  20. #include "linux/input-event-codes.h"
  21. }
  22. namespace zwsd {} // namespace zwsd
  23. #define ENABLE_BASIC_TYPE_LOGGER(type) \
  24. template <typename OStream> \
  25. static inline OStream &operator<<(OStream &os, const std::list<type> &c) { \
  26. nlohmann::json j = c; \
  27. return os << j.dump(); \
  28. } \
  29. template <typename OStream> \
  30. static inline OStream &operator<<(OStream &os, const std::vector<type> &c) { \
  31. nlohmann::json j = c; \
  32. return os << j.dump(); \
  33. } \
  34. template <typename OStream> \
  35. static inline OStream &operator<<(OStream &os, const std::set<type> &c) { \
  36. nlohmann::json j = c; \
  37. return os << j.dump(); \
  38. }
  39. ENABLE_BASIC_TYPE_LOGGER(std::string)
  40. ENABLE_BASIC_TYPE_LOGGER(bool)
  41. ENABLE_BASIC_TYPE_LOGGER(uint8_t)
  42. ENABLE_BASIC_TYPE_LOGGER(uint16_t)
  43. ENABLE_BASIC_TYPE_LOGGER(uint32_t)
  44. ENABLE_BASIC_TYPE_LOGGER(uint64_t)
  45. ENABLE_BASIC_TYPE_LOGGER(int8_t)
  46. ENABLE_BASIC_TYPE_LOGGER(int16_t)
  47. ENABLE_BASIC_TYPE_LOGGER(int32_t)
  48. ENABLE_BASIC_TYPE_LOGGER(int64_t)
  49. ENABLE_BASIC_TYPE_LOGGER(float)
  50. ENABLE_BASIC_TYPE_LOGGER(double)
  51. #undef ENABLE_BASIC_TYPE_LOGGER
  52. // dump input event
  53. template <typename OStream>
  54. static inline OStream &operator<<(OStream &os, struct input_event &event) {
  55. return os << fmt::format("input-event {} {} {}", event.type, event.code, event.value);
  56. }
  57. #define ZCHECK(exptr, info) \
  58. { \
  59. if (!(exptr)) { \
  60. logger->critical("({}:{})ZCHECK failed: {} {}", __FILE__, __LINE__, info, #exptr); \
  61. exit(-1); \
  62. } \
  63. }