| 1 |
#ifndef CLICOMM_HH |
| 2 |
#define CLICOMM_HH |
| 3 |
|
| 4 |
#include "stl.hh" |
| 5 |
#include "strCat.hh" |
| 6 |
|
| 7 |
#include <cstdint> |
| 8 |
#include <span> |
| 9 |
#include <string_view> |
| 10 |
#include <utility> |
| 11 |
|
| 12 |
namespace openmsx { |
| 13 |
|
| 14 |
class CliComm |
| 15 |
{ |
| 16 |
public: |
| 17 |
enum class LogLevel : uint8_t { |
| 18 |
INFO, |
| 19 |
WARNING, |
| 20 |
LOGLEVEL_ERROR, |
| 21 |
PROGRESS, |
| 22 |
NUM |
| 23 |
}; |
| 24 |
enum class UpdateType : uint8_t { |
| 25 |
LED, |
| 26 |
SETTING, |
| 27 |
SETTING_INFO, |
| 28 |
HARDWARE, |
| 29 |
PLUG, |
| 30 |
MEDIA, |
| 31 |
STATUS, |
| 32 |
EXTENSION, |
| 33 |
SOUND_DEVICE, |
| 34 |
CONNECTOR, |
| 35 |
DEBUG_UPDT, |
| 36 |
NUM |
| 37 |
}; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
virtual void log(LogLevel level, std::string_view message, float fraction = 0.0f) = 0; |
| 44 |
virtual void update(UpdateType type, std::string_view name, |
| 45 |
std::string_view value) = 0; |
| 46 |
|
| 47 |
|
| 48 |
virtual void updateFiltered(UpdateType type, std::string_view name, |
| 49 |
std::string_view value) = 0; |
| 50 |
|
| 51 |
|
| 52 |
void printInfo (std::string_view message); |
| 53 |
void printWarning (std::string_view message); |
| 54 |
void printError (std::string_view message); |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
void printProgress(std::string_view message, float fraction); |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
void printInfo(const char* message) { |
| 67 |
printInfo(std::string_view(message)); |
| 68 |
} |
| 69 |
void printWarning(const char* message) { |
| 70 |
printWarning(std::string_view(message)); |
| 71 |
} |
| 72 |
void printError(const char* message) { |
| 73 |
printError(std::string_view(message)); |
| 74 |
} |
| 75 |
void printProgress(const char* message, float fraction) { |
| 76 |
printProgress(std::string_view(message), fraction); |
| 77 |
} |
| 78 |
|
| 79 |
template<typename... Args> |
| 80 |
void printInfo(Args&& ...args) { |
| 81 |
auto tmp = tmpStrCat(std::forward<Args>(args)...); |
| 82 |
printInfo(std::string_view(tmp)); |
| 83 |
} |
| 84 |
template<typename... Args> |
| 85 |
void printWarning(Args&& ...args) { |
| 86 |
auto tmp = tmpStrCat(std::forward<Args>(args)...); |
| 87 |
printWarning(std::string_view(tmp)); |
| 88 |
} |
| 89 |
template<typename... Args> |
| 90 |
void printError(Args&& ...args) { |
| 91 |
auto tmp = tmpStrCat(std::forward<Args>(args)...); |
| 92 |
printError(std::string_view(tmp)); |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
[[nodiscard]] static auto getLevelStrings() { |
| 97 |
static constexpr array_with_enum_index<LogLevel, std::string_view> levelStr = { |
| 98 |
"info", "warning", "error", "progress" |
| 99 |
}; |
| 100 |
return std::span{levelStr}; |
| 101 |
} |
| 102 |
[[nodiscard]] static auto getUpdateStrings() { |
| 103 |
static constexpr array_with_enum_index<UpdateType, std::string_view> updateStr = { |
| 104 |
"led", "setting", "setting-info", "hardware", "plug", |
| 105 |
"media", "status", "extension", "sounddevice", "connector", |
| 106 |
"debug" |
| 107 |
}; |
| 108 |
return std::span{updateStr}; |
| 109 |
} |
| 110 |
|
| 111 |
protected: |
| 112 |
CliComm() = default; |
| 113 |
~CliComm() = default; |
| 114 |
}; |
| 115 |
|
| 116 |
[[nodiscard]] inline auto toString(CliComm::LogLevel type) |
| 117 |
{ |
| 118 |
return CliComm::getLevelStrings()[std::to_underlying(type)]; |
| 119 |
} |
| 120 |
|
| 121 |
[[nodiscard]] inline auto toString(CliComm::UpdateType type) |
| 122 |
{ |
| 123 |
return CliComm::getUpdateStrings()[std::to_underlying(type)]; |
| 124 |
} |
| 125 |
|
| 126 |
} |
| 127 |
|
| 128 |
#endif |