openMSX
CliConnection.hh
Go to the documentation of this file.
1 #ifndef CLICONNECTION_HH
2 #define CLICONNECTION_HH
3 
4 #include "CliListener.hh"
5 #include "Thread.hh"
6 #include "Semaphore.hh"
7 #include "EventListener.hh"
8 #include "Socket.hh"
9 #include "CliComm.hh"
10 #include "AdhocCliCommParser.hh"
11 #include <string>
12 
13 namespace openmsx {
14 
15 class CommandController;
16 class EventDistributor;
17 
18 class CliConnection : public CliListener, private EventListener,
19  protected Runnable
20 {
21 public:
22  virtual ~CliConnection();
23 
24  void setUpdateEnable(CliComm::UpdateType type, bool value) {
25  updateEnabled[type] = value;
26  }
28  return updateEnabled[type];
29  }
30 
36  void start();
37 
38 protected:
39  CliConnection(CommandController& commandController,
40  EventDistributor& eventDistributor);
41 
42  virtual void output(string_ref message) = 0;
43 
48  void end();
49 
53  virtual void close() = 0;
54 
60  void startOutput();
61 
63  Thread thread; // TODO: Possible to make this private?
64 
65 private:
66  void execute(const std::string& command);
67 
68  // CliListener
69  virtual void log(CliComm::LogLevel level, string_ref message);
70  virtual void update(CliComm::UpdateType type, string_ref machine,
71  string_ref name, string_ref value);
72 
73  // EventListener
74  virtual int signalEvent(const std::shared_ptr<const Event>& event);
75 
76  CommandController& commandController;
77  EventDistributor& eventDistributor;
78 
79  bool updateEnabled[CliComm::NUM_UPDATES];
80 };
81 
83 {
84 public:
87  virtual ~StdioConnection();
88 
89  virtual void output(string_ref message);
90 
91 private:
92  virtual void close();
93  virtual void run();
94 
95  bool ok;
96 };
97 
98 #ifdef _WIN32
99 class PipeConnection : public CliConnection
100 {
101 public:
102  PipeConnection(CommandController& commandController,
104  string_ref name);
105  virtual ~PipeConnection();
106 
107  virtual void output(string_ref message);
108 
109 private:
110  virtual void close();
111  virtual void run();
112 
113  HANDLE pipeHandle;
114  HANDLE shutdownEvent;
115 };
116 #endif
117 
119 {
120 public:
123  SOCKET sd);
124  virtual ~SocketConnection();
125 
126  virtual void output(string_ref message);
127 
128 private:
129  virtual void close();
130  virtual void run();
131 
132  Semaphore sem;
133  SOCKET sd;
134  bool established;
135 };
136 
137 } // namespace openmsx
138 
139 #endif
virtual void output(string_ref message)=0
AdhocCliCommParser parser
This class implements a subset of the proposal for std::string_ref (proposed for the next c++ standar...
Definition: string_ref.hh:18
void start()
Starts the helper thread.
int SOCKET
Definition: Socket.hh:22
StdioConnection(CommandController &commandController, EventDistributor &eventDistributor)
bool getUpdateEnable(CliComm::UpdateType type) const
virtual void output(string_ref message)
virtual void close()=0
Close the connection.
CliConnection(CommandController &commandController, EventDistributor &eventDistributor)
virtual void output(string_ref message)
void end()
End this connection by sending the closing tag and then closing the stream.
SocketConnection(CommandController &commandController, EventDistributor &eventDistributor, SOCKET sd)
eventDistributor(eventDistributor_)
commandController(commandController_)
void startOutput()
Send opening XML tag, should be called exactly once by a subclass shortly after opening a connection...
void setUpdateEnable(CliComm::UpdateType type, bool value)