2017-09-23 00:28:11 +00:00
|
|
|
//
|
|
|
|
// DiskImage.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 21/09/2017.
|
|
|
|
// Copyright © 2017 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef DiskImage_hpp
|
|
|
|
#define DiskImage_hpp
|
|
|
|
|
2017-09-23 02:39:23 +00:00
|
|
|
#include <map>
|
2017-09-23 00:28:11 +00:00
|
|
|
#include <memory>
|
2017-09-23 02:39:23 +00:00
|
|
|
|
|
|
|
#include "../Disk.hpp"
|
|
|
|
#include "../Track/Track.hpp"
|
2017-09-23 00:28:11 +00:00
|
|
|
|
|
|
|
namespace Storage {
|
|
|
|
namespace Disk {
|
|
|
|
|
2018-04-28 03:18:45 +00:00
|
|
|
enum class Error {
|
|
|
|
InvalidFormat = -2,
|
|
|
|
UnknownVersion = -3
|
|
|
|
};
|
|
|
|
|
2017-09-23 00:28:11 +00:00
|
|
|
/*!
|
2017-09-23 02:46:31 +00:00
|
|
|
Models a disk image as a collection of tracks, plus a range of possible track positions.
|
2017-09-23 00:28:11 +00:00
|
|
|
|
|
|
|
The intention is not that tracks necessarily be evenly spaced; a head_position_count of 3 wih track
|
|
|
|
A appearing in positions 0 and 1, and track B appearing in position 2 is an appropriate use of this API
|
|
|
|
if it matches the media.
|
|
|
|
*/
|
|
|
|
class DiskImage {
|
|
|
|
public:
|
|
|
|
virtual ~DiskImage() {}
|
|
|
|
|
|
|
|
/*!
|
2018-05-07 03:17:36 +00:00
|
|
|
@returns the distance at which there stops being any further content.
|
2017-09-23 00:28:11 +00:00
|
|
|
|
|
|
|
This is not necessarily a track count. There is no implicit guarantee that every position will
|
|
|
|
return a distinct track, or — e.g. if the media is holeless — will return any track at all.
|
|
|
|
*/
|
2018-05-07 03:17:36 +00:00
|
|
|
virtual HeadPosition get_maximum_head_position() = 0;
|
2017-09-23 00:28:11 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
@returns the number of heads (and, therefore, impliedly surfaces) available on this disk.
|
|
|
|
*/
|
2017-10-07 01:45:12 +00:00
|
|
|
virtual int get_head_count() { return 1; }
|
2017-09-23 00:28:11 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
@returns the @c Track at @c position underneath @c head if there are any detectable events there;
|
|
|
|
returns @c nullptr otherwise.
|
|
|
|
*/
|
2017-10-07 01:45:12 +00:00
|
|
|
virtual std::shared_ptr<Track> get_track_at_position(Track::Address address) = 0;
|
2017-09-23 00:28:11 +00:00
|
|
|
|
|
|
|
/*!
|
2017-10-07 23:37:36 +00:00
|
|
|
Replaces the Tracks indicated by the map, that maps from physical address to track content.
|
2017-09-23 00:28:11 +00:00
|
|
|
*/
|
2017-10-07 23:37:36 +00:00
|
|
|
virtual void set_tracks(const std::map<Track::Address, std::shared_ptr<Track>> &tracks) {}
|
2017-10-07 01:45:12 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Communicates that it is likely to be a while before any more tracks are written.
|
|
|
|
*/
|
|
|
|
virtual void flush_tracks() {}
|
2017-09-23 00:28:11 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
@returns whether the disk image is read only. Defaults to @c true if not overridden.
|
|
|
|
*/
|
|
|
|
virtual bool get_is_read_only() { return true; }
|
|
|
|
};
|
|
|
|
|
|
|
|
class DiskImageHolderBase: public Disk {
|
|
|
|
protected:
|
2017-10-07 02:07:42 +00:00
|
|
|
std::set<Track::Address> unwritten_tracks_;
|
2017-10-07 01:45:12 +00:00
|
|
|
std::map<Track::Address, std::shared_ptr<Track>> cached_tracks_;
|
2017-09-23 00:28:11 +00:00
|
|
|
std::unique_ptr<Concurrency::AsyncTaskQueue> update_queue_;
|
|
|
|
};
|
|
|
|
|
2017-09-23 02:46:31 +00:00
|
|
|
/*!
|
|
|
|
Provides a wrapper that wraps a DiskImage to make it into a Disk, providing caching and,
|
|
|
|
thereby, an intermediate store for modified tracks so that mutable disk images can either
|
|
|
|
update on the fly or perform a block update on closure, as appropriate.
|
|
|
|
*/
|
2017-09-23 00:28:11 +00:00
|
|
|
template <typename T> class DiskImageHolder: public DiskImageHolderBase {
|
|
|
|
public:
|
|
|
|
template <typename... Ts> DiskImageHolder(Ts&&... args) :
|
|
|
|
disk_image_(args...) {}
|
|
|
|
~DiskImageHolder();
|
|
|
|
|
2018-05-07 03:17:36 +00:00
|
|
|
HeadPosition get_maximum_head_position();
|
2017-10-07 01:45:12 +00:00
|
|
|
int get_head_count();
|
|
|
|
std::shared_ptr<Track> get_track_at_position(Track::Address address);
|
|
|
|
void set_track_at_position(Track::Address address, const std::shared_ptr<Track> &track);
|
|
|
|
void flush_tracks();
|
2017-09-23 00:28:11 +00:00
|
|
|
bool get_is_read_only();
|
|
|
|
|
|
|
|
private:
|
|
|
|
T disk_image_;
|
|
|
|
};
|
|
|
|
|
2017-09-23 02:46:31 +00:00
|
|
|
#include "DiskImageImplementation.hpp"
|
2017-09-23 00:28:11 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* DiskImage_hpp */
|