openMSX
Pluggable.cc
Go to the documentation of this file.
1 #include "Pluggable.hh"
2 #include "PlugException.hh"
3 #include "Connector.hh"
4 #include "unreachable.hh"
5 #include <cassert>
6 
7 using std::string;
8 
9 namespace openmsx {
10 
12 {
13  setConnector(nullptr);
14 }
15 
16 const string& Pluggable::getName() const
17 {
18  static const string name;
19  return name;
20 }
21 
22 void Pluggable::plug(Connector& newConnector, EmuTime::param time)
23 {
24  assert(getClass() == newConnector.getClass());
25 
26  if (connector) {
27  throw PlugException(getName(), " already plugged in ",
28  connector->getName(), '.');
29  }
30  plugHelper(newConnector, time);
31  setConnector(&newConnector);
32 }
33 
34 void Pluggable::unplug(EmuTime::param time)
35 {
36  try {
37  unplugHelper(time);
38  } catch (MSXException&) {
40  }
41  setConnector(nullptr);
42 }
43 
44 } // namespace openmsx
Represents something you can plug devices into.
Definition: Connector.hh:20
void setConnector(Connector *conn)
Definition: Pluggable.hh:58
virtual string_view getClass() const =0
A Connector belong to a certain class.
virtual string_view getClass() const =0
A pluggable belongs to a certain class.
const std::string & getName() const
Name that identifies this connector.
Definition: Connector.hh:29
virtual void unplugHelper(EmuTime::param time)=0
void unplug(EmuTime::param time)
This method is called when this pluggable is removed from a conector.
Definition: Pluggable.cc:34
void plug(Connector &connector, EmuTime::param time)
This method is called when this pluggable is inserted in a connector.
Definition: Pluggable.cc:22
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
virtual const std::string & getName() const
Name used to identify this pluggable.
Definition: Pluggable.cc:16
virtual void plugHelper(Connector &newConnector, EmuTime::param time)=0
Thrown when a plug action fails.
#define UNREACHABLE
Definition: unreachable.hh:38