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]] std::string_view getContainerName() const override;
47  bool diskChanged() override;
48  int insertDisk(const std::string& 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(std::string_view 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) noexcept 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
bool peekDiskChanged() const
Definition: DiskChanger.hh:40
Scheduler * getScheduler() const
Definition: DiskChanger.hh:54
const DiskName & getDiskName() const
Definition: DiskChanger.cc:103
~DiskChanger() override
Definition: DiskChanger.cc:94
int insertDisk(const std::string &filename) override
Definition: DiskChanger.cc:161
const std::string & getDriveName() const
Definition: DiskChanger.hh:38
std::string_view getContainerName() const override
Definition: DiskChanger.cc:123
void serialize(Archive &ar, unsigned version)
Definition: DiskChanger.cc:315
DiskChanger(MSXMotherBoard &board, std::string driveName, bool createCmd=true, bool doubleSidedDrive=true, std::function< void()> preChangeCallback={})
Definition: DiskChanger.cc:50
bool isDoubleSidedDrive() const
Definition: DiskChanger.hh:55
void changeDisk(std::unique_ptr< Disk > newDisk)
Definition: DiskChanger.cc:191
SectorAccessibleDisk * getSectorAccessibleDisk() override
Definition: DiskChanger.cc:115
bool diskChanged() override
Definition: DiskChanger.cc:108
Contains the main loop of openMSX.
Definition: Reactor.hh:67
Definition: span.hh:126
This file implemented 3 utility functions:
Definition: Autofire.cc:9
constexpr const char *const filename
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)