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
11#include "stl.hh"
12
13#include <array>
14#include <mutex>
15#include <string>
16#include <thread>
17
18namespace openmsx {
19
20class CommandController;
21class EventDistributor;
22
24{
25public:
26 void setUpdateEnable(CliComm::UpdateType type, bool value) {
27 updateEnabled[type] = value;
28 }
29 [[nodiscard]] bool getUpdateEnable(CliComm::UpdateType type) const {
30 return updateEnabled[type];
31 }
32
38 void start();
39
40protected:
41 CliConnection(CommandController& commandController,
42 EventDistributor& eventDistributor);
43 ~CliConnection() override;
44
45 virtual void output(std::string_view message) = 0;
46
51 void end();
52
56 virtual void close() = 0;
57
63 void startOutput();
64
67
68private:
69 virtual void run() = 0;
70
71 void execute(const std::string& command);
72
73 // CliListener
74 void log(CliComm::LogLevel level, std::string_view message, float fraction) noexcept override;
75 void update(CliComm::UpdateType type, std::string_view machine,
76 std::string_view name, std::string_view value) noexcept override;
77
78 // EventListener
79 bool signalEvent(const Event& event) override;
80
81 CommandController& commandController;
82 EventDistributor& eventDistributor;
83
84 std::thread thread;
85
87};
88
89class StdioConnection final : public CliConnection
90{
91public:
92 StdioConnection(CommandController& commandController,
93 EventDistributor& eventDistributor);
94 ~StdioConnection() override;
95
96 void output(std::string_view message) override;
97
98private:
99 void close() override;
100 void run() override;
101};
102
103#ifdef _WIN32
104class PipeConnection final : public CliConnection
105{
106public:
107 PipeConnection(CommandController& commandController,
108 EventDistributor& eventDistributor,
109 std::string_view name);
110 ~PipeConnection() override;
111
112 void output(std::string_view message) override;
113
114private:
115 void close() override;
116 void run() override;
117
118 HANDLE pipeHandle;
119 HANDLE shutdownEvent;
120};
121#endif
122
123class SocketConnection final : public CliConnection
124{
125public:
126 SocketConnection(CommandController& commandController,
127 EventDistributor& eventDistributor,
128 SOCKET sd);
129 ~SocketConnection() override;
130
131 void output(std::string_view message) override;
132
133private:
134 void close() override;
135 void run() override;
136 void closeSocket();
137
138 std::mutex sdMutex;
139 SOCKET sd;
140 bool established = false;
141};
142
143} // namespace openmsx
144
145#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:11
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:445
int SOCKET
Definition Socket.hh:25