openMSX
HD.hh
Go to the documentation of this file.
1 #ifndef HD_HH
2 #define HD_HH
3 
4 #include "Filename.hh"
5 #include "File.hh"
7 #include "DiskContainer.hh"
8 #include "TigerTree.hh"
9 #include "serialize_meta.hh"
10 #include <bitset>
11 #include <string>
12 #include <memory>
13 
14 namespace openmsx {
15 
16 class MSXMotherBoard;
17 class HDCommand;
18 class DeviceConfig;
19 
20 class HD : public SectorAccessibleDisk, public DiskContainer
21  , public TTData
22 {
23 public:
24  explicit HD(const DeviceConfig& config);
25  ~HD() override;
26 
27  [[nodiscard]] const std::string& getName() const { return name; }
28  [[nodiscard]] const Filename& getImageName() const { return filename; }
29  void switchImage(const Filename& filename);
30 
31  [[nodiscard]] std::string getTigerTreeHash();
32 
33  template<typename Archive>
34  void serialize(Archive& ar, unsigned version);
35 
36  [[nodiscard]] MSXMotherBoard& getMotherBoard() const { return motherBoard; }
37 
38 private:
39  // SectorAccessibleDisk:
40  void readSectorsImpl(
41  SectorBuffer* buffers, size_t startSector, size_t num) override;
42  void writeSectorImpl(size_t sector, const SectorBuffer& buf) override;
43  [[nodiscard]] size_t getNbSectorsImpl() const override;
44  [[nodiscard]] bool isWriteProtectedImpl() const override;
45  [[nodiscard]] Sha1Sum getSha1SumImpl(FilePool& filePool) override;
46 
47  // Diskcontainer:
48  [[nodiscard]] SectorAccessibleDisk* getSectorAccessibleDisk() override;
49  [[nodiscard]] std::string_view getContainerName() const override;
50  [[nodiscard]] bool diskChanged() override;
51  int insertDisk(const std::string& newFilename) override;
52 
53  // TTData
54  [[nodiscard]] uint8_t* getData(size_t offset, size_t size) override;
55  [[nodiscard]] bool isCacheStillValid(time_t& time) override;
56 
57  void showProgress(size_t position, size_t maxPosition);
58 
59 private:
60  MSXMotherBoard& motherBoard;
61  std::string name;
62  std::unique_ptr<HDCommand> hdCommand;
63  std::unique_ptr<TigerTree> tigerTree;
64 
65  File file;
66  Filename filename;
67  size_t filesize;
68 
69  static constexpr unsigned MAX_HD = 26;
70  using HDInUse = std::bitset<MAX_HD>;
71  std::shared_ptr<HDInUse> hdInUse;
72 
73  uint64_t lastProgressTime;
74  bool everDidProgress;
75 };
76 
79 
80 } // namespace openmsx
81 
82 #endif
This class represents a filename.
Definition: Filename.hh:18
const std::string & getName() const
Definition: HD.hh:27
void switchImage(const Filename &filename)
Definition: HD.cc:85
~HD() override
Definition: HD.cc:76
HD(const DeviceConfig &config)
Definition: HD.cc:24
std::string getTigerTreeHash()
Definition: HD.cc:148
MSXMotherBoard & getMotherBoard() const
Definition: HD.hh:36
const Filename & getImageName() const
Definition: HD.hh:28
void serialize(Archive &ar, unsigned version)
Definition: HD.cc:211
This class represents the result of a sha1 calculation (a 160-bit value).
Definition: sha1.hh:22
The TigerTree class will query the to-be-hashed data via this abstract interface.
Definition: TigerTree.hh:44
This file implemented 3 utility functions:
Definition: Autofire.cc:9
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
REGISTER_BASE_CLASS(Connector, "Connector")
size_t size(std::string_view utf8)