openMSX
DiskChanger.hh
Go to the documentation of this file.
1 #ifndef DISKCHANGER_HH
2 #define DISKCHANGER_HH
3 
4 #include "DiskContainer.hh"
5 #include "StateChangeListener.hh"
6 #include "serialize_meta.hh"
7 #include "span.hh"
8 #include <functional>
9 #include <memory>
10 #include <string>
11 
12 namespace openmsx {
13 
14 class CommandController;
15 class StateChangeDistributor;
16 class Scheduler;
17 class MSXMotherBoard;
18 class Reactor;
19 class Disk;
20 class DiskCommand;
21 class TclObject;
22 class DiskName;
23 
24 class DiskChanger final : public DiskContainer, private StateChangeListener
25 {
26 public:
28  std::string driveName,
29  bool createCmd = true,
30  bool doubleSidedDrive = true,
31  std::function<void()> preChangeCallback = {});
32  DiskChanger(Reactor& reactor,
33  std::string driveName); // for virtual_drive
34  ~DiskChanger() override;
35 
36  void createCommand();
37 
38  [[nodiscard]] const std::string& getDriveName() const { return driveName; }
39  [[nodiscard]] const DiskName& getDiskName() const;
40  [[nodiscard]] bool peekDiskChanged() const { return diskChangedFlag; }
41  void forceDiskChange() { diskChangedFlag = true; }
42  [[nodiscard]] Disk& getDisk() { return *disk; }
43 
44  // DiskContainer
45  [[nodiscard]] SectorAccessibleDisk* getSectorAccessibleDisk() override;
46  [[nodiscard]] const std::string& getContainerName() const override;
47  bool diskChanged() override;
48  int insertDisk(std::string_view filename) override;
49 
50  // for NowindCommand
51  void changeDisk(std::unique_ptr<Disk> newDisk);
52 
53  // for DirAsDSK
54  [[nodiscard]] Scheduler* getScheduler() const { return scheduler; }
55  [[nodiscard]] bool isDoubleSidedDrive() const { return doubleSidedDrive; }
56 
57  template<typename Archive>
58  void serialize(Archive& ar, unsigned version);
59 
60 private:
61  void init(const std::string& prefix, bool createCmd);
63  void ejectDisk();
64  void sendChangeDiskEvent(span<std::string> args);
65 
66  // StateChangeListener
67  void signalStateChange(const std::shared_ptr<StateChange>& event) override;
68  void stopReplay(EmuTime::param time) override;
69 
70 private:
71  Reactor& reactor;
72  CommandController& controller;
73  StateChangeDistributor* stateChangeDistributor;
74  Scheduler* scheduler;
75  std::function<void()> preChangeCallback;
76 
77  const std::string driveName;
78  std::unique_ptr<Disk> disk;
79 
80  friend class DiskCommand;
81  std::unique_ptr<DiskCommand> diskCommand; // must come after driveName
82  const bool doubleSidedDrive; // for DirAsDSK
83 
84  bool diskChangedFlag;
85 };
87 
88 } // namespace openmsx
89 
90 #endif
DiskContainer.hh
openmsx::SectorAccessibleDisk
Definition: SectorAccessibleDisk.hh:16
openmsx::Scheduler
Definition: Scheduler.hh:34
openmsx::DiskChanger::getScheduler
Scheduler * getScheduler() const
Definition: DiskChanger.hh:54
openmsx::CommandController
Definition: CommandController.hh:18
openmsx::DiskChanger::serialize
void serialize(Archive &ar, unsigned version)
Definition: DiskChanger.cc:313
openmsx::DiskContainer
Definition: DiskContainer.hh:15
StateChangeListener.hh
openmsx::DiskChanger::getDisk
Disk & getDisk()
Definition: DiskChanger.hh:42
openmsx::DiskChanger::getSectorAccessibleDisk
SectorAccessibleDisk * getSectorAccessibleDisk() override
Definition: DiskChanger.cc:114
serialize_meta.hh
openmsx::DiskName
DiskName
Definition: DiskName.cc:45
openmsx::DiskChanger::peekDiskChanged
bool peekDiskChanged() const
Definition: DiskChanger.hh:40
openmsx::DiskChanger
Definition: DiskChanger.hh:25
openmsx::DiskChanger::changeDisk
void changeDisk(std::unique_ptr< Disk > newDisk)
Definition: DiskChanger.cc:190
openmsx::StateChangeDistributor
Definition: StateChangeDistributor.hh:15
openmsx::Disk
Definition: Disk.hh:13
openmsx::DiskChanger::insertDisk
int insertDisk(std::string_view filename) override
Definition: DiskChanger.cc:160
span
Definition: span.hh:126
openmsx::Reactor
Contains the main loop of openMSX.
Definition: Reactor.hh:67
openmsx::SERIALIZE_CLASS_VERSION
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
openmsx::DiskChanger::getDiskName
const DiskName & getDiskName() const
Definition: DiskChanger.cc:102
openmsx::DiskName
Definition: DiskName.hh:9
openmsx::DiskChanger::DiskChanger
DiskChanger(MSXMotherBoard &board, std::string driveName, bool createCmd=true, bool doubleSidedDrive=true, std::function< void()> preChangeCallback={})
Definition: DiskChanger.cc:49
openmsx::DiskChanger::createCommand
void createCommand()
Definition: DiskChanger.cc:87
openmsx::MSXMotherBoard
Definition: MSXMotherBoard.hh:61
openmsx::filename
constexpr const char *const filename
Definition: FirmwareSwitch.cc:10
openmsx::DiskChanger::getDriveName
const std::string & getDriveName() const
Definition: DiskChanger.hh:38
span.hh
openmsx::DiskCommand
Definition: DiskChanger.cc:36
openmsx::DiskChanger::getContainerName
const std::string & getContainerName() const override
Definition: DiskChanger.cc:122
openmsx::DiskChanger::diskChanged
bool diskChanged() override
Definition: DiskChanger.cc:107
openmsx::Scheduler
Scheduler
Definition: Scheduler.cc:132
openmsx::DiskChanger::forceDiskChange
void forceDiskChange()
Definition: DiskChanger.hh:41
openmsx::DiskChanger::~DiskChanger
~DiskChanger() override
Definition: DiskChanger.cc:93
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5
openmsx::StateChangeListener
Definition: StateChangeListener.hh:12
openmsx::DiskChanger::isDoubleSidedDrive
bool isDoubleSidedDrive() const
Definition: DiskChanger.hh:55