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 "EventListener.hh"
6#include "Socket.hh"
7#include "CliComm.hh"
9#include "Poller.hh"
10#include <array>
11#include <mutex>
12#include <string>
13#include <thread>
14
15namespace openmsx {
16
17class CommandController;
18class EventDistributor;
19
21{
22public:
23 void setUpdateEnable(CliComm::UpdateType type, bool value) {
24 updateEnabled[type] = value;
25 }
26 [[nodiscard]] bool getUpdateEnable(CliComm::UpdateType type) const {
27 return updateEnabled[type];
28 }
29
35 void start();
36
37protected:
38 CliConnection(CommandController& commandController,
39 EventDistributor& eventDistributor);
40 ~CliConnection() override;
41
42 virtual void output(std::string_view message) = 0;
43
48 void end();
49
53 virtual void close() = 0;
54
60 void startOutput();
61
64
65private:
66 virtual void run() = 0;
67
68 void execute(const std::string& command);
69
70 // CliListener
71 void log(CliComm::LogLevel level, std::string_view message, float fraction) noexcept override;
72 void update(CliComm::UpdateType type, std::string_view machine,
73 std::string_view name, std::string_view value) noexcept override;
74
75 // EventListener
76 int signalEvent(const Event& event) override;
77
78 CommandController& commandController;
79 EventDistributor& eventDistributor;
80
81 std::thread thread;
82
83 std::array<bool, CliComm::NUM_UPDATES> updateEnabled;
84};
85
86class StdioConnection final : public CliConnection
87{
88public:
89 StdioConnection(CommandController& commandController,
90 EventDistributor& eventDistributor);
91 ~StdioConnection() override;
92
93 void output(std::string_view message) override;
94
95private:
96 void close() override;
97 void run() override;
98};
99
100#ifdef _WIN32
101class PipeConnection final : public CliConnection
102{
103public:
104 PipeConnection(CommandController& commandController,
105 EventDistributor& eventDistributor,
106 std::string_view name);
107 ~PipeConnection() override;
108
109 void output(std::string_view message) override;
110
111private:
112 void close() override;
113 void run() override;
114
115 HANDLE pipeHandle;
116 HANDLE shutdownEvent;
117};
118#endif
119
120class SocketConnection final : public CliConnection
121{
122public:
123 SocketConnection(CommandController& commandController,
124 EventDistributor& eventDistributor,
125 SOCKET sd);
126 ~SocketConnection() override;
127
128 void output(std::string_view message) override;
129
130private:
131 void close() override;
132 void run() override;
133 void closeSocket();
134
135 std::mutex sdMutex;
136 SOCKET sd;
137 bool established = false;
138};
139
140} // namespace openmsx
141
142#endif
void end()
End this connection by sending the closing tag and then closing the stream.
virtual void close()=0
Close the connection.
void start()
Starts the helper thread.
void setUpdateEnable(CliComm::UpdateType type, bool value)
AdhocCliCommParser parser
void startOutput()
Send opening XML tag, should be called exactly once by a subclass shortly after opening a connection.
virtual void output(std::string_view message)=0
bool getUpdateEnable(CliComm::UpdateType type) const
Polls for events on a given file descriptor.
Definition Poller.hh:15
void output(std::string_view message) override
void output(std::string_view message) override
This file implemented 3 utility functions:
Definition Autofire.cc:9
std::variant< KeyUpEvent, KeyDownEvent, MouseMotionEvent, MouseButtonUpEvent, MouseButtonDownEvent, MouseWheelEvent, JoystickAxisMotionEvent, JoystickHatEvent, JoystickButtonUpEvent, JoystickButtonDownEvent, OsdControlReleaseEvent, OsdControlPressEvent, WindowEvent, TextEvent, FileDropEvent, QuitEvent, FinishFrameEvent, CliCommandEvent, GroupEvent, BootEvent, FrameDrawnEvent, BreakEvent, SwitchRendererEvent, TakeReverseSnapshotEvent, AfterTimedEvent, MachineLoadedEvent, MachineActivatedEvent, MachineDeactivatedEvent, MidiInReaderEvent, MidiInWindowsEvent, MidiInCoreMidiEvent, MidiInCoreMidiVirtualEvent, MidiInALSAEvent, Rs232TesterEvent, Rs232NetEvent, ImGuiDelayedActionEvent, ImGuiActiveEvent > Event
Definition Event.hh:454
int SOCKET
Definition Socket.hh:25