-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some steps towards defining a general datastore API.
- Loading branch information
1 parent
0beac3c
commit 6a48592
Showing
4 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#include "lib/globals.h" | ||
#include "lib/image.h" | ||
#include "lib/flux.h" | ||
#include "lib/layout.h" | ||
#include "globals.h" | ||
#include "datastore.h" | ||
|
||
class DatastoreImpl : public Datastore | ||
{ | ||
W_OBJECT(DatastoreImpl); | ||
|
||
public: | ||
DatastoreImpl( | ||
std::shared_ptr<Encoder>& encoder, std::shared_ptr<Decoder>& decoder): | ||
_encoder(encoder), | ||
_decoder(decoder) | ||
{ | ||
} | ||
|
||
public: | ||
void setDiskData(std::shared_ptr<const DiskFlux> diskData) override {} | ||
|
||
void setTrackData(std::shared_ptr<const TrackFlux> trackData) override { | ||
key_t key = {trackData->trackInfo->physicalTrack, trackData->trackInfo->physicalSide}; | ||
_tracks[key] = trackData; | ||
} | ||
|
||
void setImageData(std::shared_ptr<const Image> imageData) override { | ||
clear(); | ||
_loadedSectors = *imageData; | ||
} | ||
|
||
void clear() override | ||
{ | ||
_loadedSectors.clear(); | ||
_changedSectors.clear(); | ||
_tracks.clear(); | ||
} | ||
|
||
public: | ||
std::shared_ptr<const Sector> get( | ||
unsigned track, unsigned side, unsigned sectorId) override | ||
{ | ||
auto it = _changedSectors.get(track, side, sectorId); | ||
if (it) | ||
return it; | ||
|
||
return _loadedSectors.get(track, side, sectorId); | ||
} | ||
|
||
std::shared_ptr<Sector> put( | ||
unsigned track, unsigned side, unsigned sectorId) override | ||
{ | ||
return _changedSectors.put(track, side, sectorId); | ||
} | ||
|
||
virtual bool isReadOnly() override | ||
{ | ||
return false; | ||
} | ||
|
||
bool needsFlushing() override | ||
{ | ||
return !_changedSectors.empty(); | ||
} | ||
|
||
private: | ||
std::shared_ptr<Encoder> _encoder; | ||
std::shared_ptr<Decoder> _decoder; | ||
Image _loadedSectors; | ||
Image _changedSectors; | ||
|
||
typedef std::pair<unsigned, unsigned> key_t; | ||
std::map<key_t, std::shared_ptr<const TrackFlux>> _tracks; | ||
}; | ||
|
||
W_OBJECT_IMPL(Datastore); | ||
W_OBJECT_IMPL(DatastoreImpl); | ||
|
||
Datastore* Datastore::create( | ||
std::shared_ptr<Encoder>& encoder, std::shared_ptr<Decoder>& decoder) | ||
{ | ||
return new DatastoreImpl(encoder, decoder); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
|
||
#include "lib/vfs/sectorinterface.h" | ||
|
||
class Datastore : public SectorInterface, public QObject | ||
{ | ||
W_OBJECT(Datastore); | ||
|
||
public: | ||
virtual void setDiskData(std::shared_ptr<const DiskFlux> diskData) = 0; | ||
W_SLOT(setDiskData) | ||
|
||
virtual void setTrackData(std::shared_ptr<const TrackFlux> trackData) = 0; | ||
W_SLOT(setTrackData) | ||
|
||
virtual void setImageData(std::shared_ptr<const Image> imageData) = 0; | ||
W_SLOT(setImageData) | ||
|
||
virtual void clear() = 0; | ||
W_SLOT(clear) | ||
|
||
public: | ||
static Datastore* create( | ||
std::shared_ptr<Encoder>& encoder, std::shared_ptr<Decoder>& decoder); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters