Skip to content

Commit

Permalink
Some steps towards defining a general datastore API.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgiven committed Jan 22, 2024
1 parent 0beac3c commit 6a48592
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/gui2/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ def uic(self, name, src: Target = None, dest=None):
"./fluxvisualiserwidget.cc",
"./imagevisualiserwidget.cc",
"./scene.cc",
"./datastore.cc",
"./globals.h",
"./mainwindow.h",
"./drivecomponent.h",
"./formatcomponent.h",
"./datastore.h",
],
cflags=["-fPIC"],
ldflags=["$(QT5_EXTRA_LIBS)"],
Expand Down
84 changes: 84 additions & 0 deletions src/gui2/datastore.cc
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);
}
25 changes: 25 additions & 0 deletions src/gui2/datastore.h
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);
};
2 changes: 2 additions & 0 deletions src/gui2/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@

class TrackFlux;
class DiskFlux;
class Image;

Q_DECLARE_METATYPE(const ConfigProto*)
W_REGISTER_ARGTYPE(std::shared_ptr<const TrackFlux>)
W_REGISTER_ARGTYPE(std::shared_ptr<const DiskFlux>)
W_REGISTER_ARGTYPE(std::shared_ptr<const Image>)

extern QThreadPool workerThreadPool;

Expand Down

0 comments on commit 6a48592

Please sign in to comment.