openMSX
GlobalCliComm.hh
Go to the documentation of this file.
1 #ifndef GLOBALCLICOMM_HH
2 #define GLOBALCLICOMM_HH
3 
4 #include "CliComm.hh"
5 #include "hash_map.hh"
6 #include "xxhash.hh"
7 #include <memory>
8 #include <mutex>
9 #include <vector>
10 
11 namespace openmsx {
12 
13 class CliListener;
14 
15 class GlobalCliComm final : public CliComm
16 {
17 public:
18  GlobalCliComm(const GlobalCliComm&) = delete;
20 
21  GlobalCliComm() = default;
23 
24  void addListener(std::unique_ptr<CliListener> listener);
25  std::unique_ptr<CliListener> removeListener(CliListener& listener);
26 
27  // Before this method has been called commands send over external
28  // connections are not yet processed (but they keep pending).
30 
31  // CliComm
32  void log(LogLevel level, std::string_view message) override;
33  void update(UpdateType type, std::string_view name,
34  std::string_view value) override;
35 
36 private:
37  void updateHelper(UpdateType type, std::string_view machine,
38  std::string_view name, std::string_view value);
39 
41 
42  std::vector<std::unique_ptr<CliListener>> listeners; // unordered
43  std::mutex mutex; // lock access to listeners member
44  bool delivering = false;
45  bool allowExternalCommands = false;
46 
47  friend class MSXCliComm;
48 };
49 
50 } // namespace openmsx
51 
52 #endif
openmsx::GlobalCliComm::GlobalCliComm
GlobalCliComm()=default
xxhash.hh
openmsx::CliComm::UpdateType
UpdateType
Definition: CliComm.hh:20
openmsx::CliListener
Definition: CliListener.hh:9
openmsx::GlobalCliComm::log
void log(LogLevel level, std::string_view message) override
Definition: GlobalCliComm.cc:55
openmsx::CliComm::LogLevel
LogLevel
Definition: CliComm.hh:13
openmsx::GlobalCliComm
Definition: GlobalCliComm.hh:16
openmsx::CliComm::NUM_UPDATES
@ NUM_UPDATES
Definition: CliComm.hh:31
openmsx::GlobalCliComm::~GlobalCliComm
~GlobalCliComm()
Definition: GlobalCliComm.cc:13
openmsx::GlobalCliComm::GlobalCliComm
GlobalCliComm(const GlobalCliComm &)=delete
openmsx::GlobalCliComm::update
void update(UpdateType type, std::string_view name, std::string_view value) override
Definition: GlobalCliComm.cc:83
openmsx::GlobalCliComm::operator=
GlobalCliComm & operator=(const GlobalCliComm &)=delete
hash_map.hh
openmsx::MSXCliComm
Definition: MSXCliComm.hh:14
openmsx::GlobalCliComm::setAllowExternalCommands
void setAllowExternalCommands()
Definition: GlobalCliComm.cc:44
openmsx::GlobalCliComm::removeListener
std::unique_ptr< CliListener > removeListener(CliListener &listener)
Definition: GlobalCliComm.cc:32
openmsx::CliComm
Definition: CliComm.hh:11
CliComm.hh
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
openmsx::GlobalCliComm::addListener
void addListener(std::unique_ptr< CliListener > listener)
Definition: GlobalCliComm.cc:19
hash_map< std::string, std::string, XXHasher >