openMSX
CliComm.hh
Go to the documentation of this file.
1 #ifndef CLICOMM_HH
2 #define CLICOMM_HH
3 
4 #include "span.hh"
5 #include "strCat.hh"
6 #include <string_view>
7 
8 namespace openmsx {
9 
10 class CliComm
11 {
12 public:
13  enum LogLevel {
16  LOGLEVEL_ERROR, // ERROR may give preprocessor name clashes
18  NUM_LEVELS // must be last
19  };
20  enum UpdateType {
21  LED,
31  NUM_UPDATES // must be last
32  };
33 
34  virtual void log(LogLevel level, std::string_view message) = 0;
35  virtual void update(UpdateType type, std::string_view name,
36  std::string_view value) = 0;
37 
38  // convenience methods (shortcuts for log())
39  void printInfo (std::string_view message);
40  void printWarning (std::string_view message);
41  void printError (std::string_view message);
42  void printProgress(std::string_view message);
43 
44  // These overloads are (only) needed for efficiency, because otherwise
45  // the templated overload below is a better match than the 'string_view'
46  // overload above (and we don't want to construct a temp string).
47  void printInfo(const char* message) {
48  printInfo(std::string_view(message));
49  }
50  void printWarning(const char* message) {
51  printWarning(std::string_view(message));
52  }
53  void printError(const char* message) {
54  printError(std::string_view(message));
55  }
56  void printProgress(const char* message) {
57  printProgress(std::string_view(message));
58  }
59 
60  template<typename... Args>
61  void printInfo(Args&& ...args) {
62  printInfo(std::string_view(strCat(std::forward<Args>(args)...)));
63  }
64  template<typename... Args>
65  void printWarning(Args&& ...args) {
66  printWarning(std::string_view(strCat(std::forward<Args>(args)...)));
67  }
68  template<typename... Args>
69  void printError(Args&& ...args) {
70  printError(std::string_view(strCat(std::forward<Args>(args)...)));
71  }
72  template<typename... Args>
73  void printProgress(Args&& ...args) {
74  printProgress(std::string_view(strCat(std::forward<Args>(args)...)));
75  }
76 
77  // string representations of the LogLevel and UpdateType enums
79  static constexpr const char* const levelStr [NUM_LEVELS] = {
80  "info", "warning", "error", "progress"
81  };
82  return levelStr;
83  }
85  static constexpr const char* const updateStr[NUM_UPDATES] = {
86  "led", "setting", "setting-info", "hardware", "plug",
87  "media", "status", "extension", "sounddevice", "connector"
88  };
89  return updateStr;
90  }
91 
92 protected:
93  CliComm() = default;
94  ~CliComm() = default;
95 };
96 
97 } // namespace openmsx
98 
99 #endif
openmsx::CliComm::getLevelStrings
static span< const char *const > getLevelStrings()
Definition: CliComm.hh:78
openmsx::CliComm::printProgress
void printProgress(Args &&...args)
Definition: CliComm.hh:73
openmsx::CliComm::printProgress
void printProgress(std::string_view message)
Definition: CliComm.cc:20
openmsx::CliComm::UpdateType
UpdateType
Definition: CliComm.hh:20
openmsx::CliComm::EXTENSION
Definition: CliComm.hh:28
openmsx::CliComm::WARNING
Definition: CliComm.hh:15
openmsx::CliComm::LOGLEVEL_ERROR
Definition: CliComm.hh:16
openmsx::CliComm::update
virtual void update(UpdateType type, std::string_view name, std::string_view value)=0
openmsx::CliComm::printInfo
void printInfo(Args &&...args)
Definition: CliComm.hh:61
openmsx::CliComm::SETTINGINFO
Definition: CliComm.hh:23
openmsx::CliComm::printInfo
void printInfo(std::string_view message)
Definition: CliComm.cc:5
openmsx::CliComm::LogLevel
LogLevel
Definition: CliComm.hh:13
openmsx::CliComm::printWarning
void printWarning(const char *message)
Definition: CliComm.hh:50
span
Definition: span.hh:34
openmsx::CliComm::NUM_LEVELS
Definition: CliComm.hh:18
openmsx::CliComm::STATUS
Definition: CliComm.hh:27
openmsx::CliComm::printWarning
void printWarning(std::string_view message)
Definition: CliComm.cc:10
openmsx::CliComm::NUM_UPDATES
Definition: CliComm.hh:31
openmsx::CliComm::CliComm
CliComm()=default
openmsx::CliComm::MEDIA
Definition: CliComm.hh:26
openmsx::CliComm::getUpdateStrings
static span< const char *const > getUpdateStrings()
Definition: CliComm.hh:84
openmsx::CliComm::printInfo
void printInfo(const char *message)
Definition: CliComm.hh:47
openmsx::CliComm::PLUG
Definition: CliComm.hh:25
openmsx::CliComm::LED
Definition: CliComm.hh:21
span.hh
openmsx::CliComm::printWarning
void printWarning(Args &&...args)
Definition: CliComm.hh:65
openmsx::CliComm::CONNECTOR
Definition: CliComm.hh:30
openmsx::CliComm::log
virtual void log(LogLevel level, std::string_view message)=0
openmsx::CliComm::printProgress
void printProgress(const char *message)
Definition: CliComm.hh:56
strCat.hh
openmsx::CliComm::~CliComm
~CliComm()=default
openmsx::CliComm::printError
void printError(std::string_view message)
Definition: CliComm.cc:15
openmsx::CliComm::printError
void printError(const char *message)
Definition: CliComm.hh:53
openmsx::CliComm
Definition: CliComm.hh:10
openmsx::CliComm::INFO
Definition: CliComm.hh:14
openmsx::CliComm::SETTING
Definition: CliComm.hh:22
openmsx::CliComm::PROGRESS
Definition: CliComm.hh:17
openmsx::CliComm::SOUNDDEVICE
Definition: CliComm.hh:29
strCat
std::string strCat(Ts &&...ts)
Definition: strCat.hh:573
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
openmsx::CliComm::HARDWARE
Definition: CliComm.hh:24
openmsx::CliComm::printError
void printError(Args &&...args)
Definition: CliComm.hh:69