OXYGENHUB
◆ main openmsx / src / Connector.hh
2.2 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#ifndef CONNECTOR_HH
2
#define CONNECTOR_HH
3
4
#include "EmuTime.hh"
5
#include "serialize_meta.hh"
6
7
#include "zstring_view.hh"
8
9
#include <memory>
10
11
namespace openmsx {
12
13
class Pluggable;
14
class PluggingController;
15
16
/**
17
 * Represents something you can plug devices into.
18
 * Examples are a joystick port, a printer port, a MIDI port etc.
19
 * When there is not an actual Pluggable plugged in, a dummy Pluggable
20
 * is used.
21
 */
22
class Connector
23
{
24
public:
25
	Connector(const Connector&) = delete;
26
	Connector(Connector&&) = delete;
27
	Connector& operator=(const Connector&) = delete;
28
	Connector& operator=(Connector&&) = delete;
29
30
	/**
31
	 * Name that identifies this connector.
32
	 */
33
	[[nodiscard]] const std::string& getName() const { return name; }
34
35
	/**
36
	 * Get a description for this connector
37
	 */
38
	[[nodiscard]] virtual zstring_view getDescription() const = 0;
39
40
	/**
41
	 * A Connector belong to a certain class.
42
	 * Only Pluggables of this class can be plugged in this Connector.
43
	 */
44
	[[nodiscard]] virtual zstring_view getClass() const = 0;
45
46
	/**
47
	 * This plugs a Pluggable in this Connector.
48
	 * The default implementation is ok.
49
	 * @throw PlugException
50
	 */
51
	virtual void plug(Pluggable& device, EmuTime time);
52
53
	/**
54
	 * This unplugs the currently inserted Pluggable from this Connector.
55
	 * It is replaced by the dummy Pluggable provided by the concrete
56
	 * Connector subclass.
57
	 */
58
	virtual void unplug(EmuTime time);
59
60
	/**
61
	 * Returns the Pluggable currently plugged in.
62
	 */
63
	[[nodiscard]] Pluggable& getPlugged() const { return *plugged; }
64
65
	[[nodiscard]] PluggingController& getPluggingController() const {
66
		return pluggingController;
67
	}
68
69
	template<typename Archive>
70
	void serialize(Archive& ar, unsigned version);
71
72
protected:
73
	/**
74
	 * Creates a new Connector.
75
	 * @param pluggingController PluggingController.
76
	 * @param name Name that identifies this connector.
77
	 * @param dummy Dummy Pluggable whose class matches this Connector.
78
	 */
79
	Connector(PluggingController& pluggingController,
80
	          std::string name, std::unique_ptr<Pluggable> dummy);
81
82
	~Connector();
83
84
private:
85
	PluggingController& pluggingController;
86
	const std::string name;
87
	const std::unique_ptr<Pluggable> dummy;
88
	Pluggable* plugged;
89
};
90
91
REGISTER_BASE_CLASS(Connector, "Connector");
92
93
} // namespace openmsx
94
95
#endif