Storage initial
This commit is contained in:
parent
bd1a6a44db
commit
d5dfb1c304
14 changed files with 551 additions and 2 deletions
98
Storage/public/LocalStorage.hpp
Normal file
98
Storage/public/LocalStorage.hpp
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
#pragma once
|
||||
|
||||
#include "Storage.hpp"
|
||||
|
||||
namespace tp {
|
||||
|
||||
class FileSystemHandle;
|
||||
|
||||
class FileLocation {
|
||||
String mLocation;
|
||||
public:
|
||||
FileLocation() : mLocation("tmp") {};
|
||||
explicit FileLocation(const String& location) : mLocation(location) {}
|
||||
void setLocation(const String& location) { mLocation = location; }
|
||||
[[nodiscard]] const String& getLocation() const { return mLocation; }
|
||||
};
|
||||
|
||||
class FileConnectionType {
|
||||
public:
|
||||
enum HandleType {
|
||||
READ,
|
||||
WRITE,
|
||||
NONE,
|
||||
};
|
||||
|
||||
private:
|
||||
HandleType mHandleType;
|
||||
|
||||
public:
|
||||
FileConnectionType() : mHandleType(NONE) {}
|
||||
explicit FileConnectionType(bool read) : mHandleType((HandleType) read) {}
|
||||
explicit FileConnectionType(HandleType handleType) : mHandleType(handleType) {}
|
||||
[[nodiscard]] HandleType getType() const { return mHandleType; }
|
||||
[[nodiscard]] bool isRead() const { return mHandleType == READ; }
|
||||
[[nodiscard]] bool isWrite() const { return mHandleType == WRITE; }
|
||||
};
|
||||
|
||||
class FileConnectionStatus {
|
||||
public:
|
||||
enum Status {
|
||||
NONE,
|
||||
OPENED,
|
||||
CLOSED,
|
||||
DENIED,
|
||||
INVALID,
|
||||
};
|
||||
|
||||
private:
|
||||
Status mStatus = NONE;
|
||||
|
||||
public:
|
||||
FileConnectionStatus() = default;
|
||||
[[nodiscard]] Status getStatus() const { return mStatus; }
|
||||
void setStatus(Status status) { mStatus = status; }
|
||||
[[nodiscard]] bool isOpened() const { return mStatus == OPENED; }
|
||||
};
|
||||
|
||||
class File {
|
||||
typedef ualni SizeBytes;
|
||||
typedef ualni BytePointer;
|
||||
typedef int1 Byte;
|
||||
|
||||
private:
|
||||
FileSystemHandle* mHandle = nullptr;
|
||||
|
||||
FileLocation mLocation;
|
||||
FileConnectionType mConnectionType;
|
||||
FileConnectionStatus mStatus;
|
||||
|
||||
BytePointer mPointer = 0;
|
||||
|
||||
public:
|
||||
File() {
|
||||
MODULE_SANITY_CHECK(gModuleStorage)
|
||||
};
|
||||
|
||||
virtual ~File() {
|
||||
File::disconnect();
|
||||
}
|
||||
|
||||
public:
|
||||
virtual bool connect(const FileLocation& location, const FileConnectionType& connectionInfo);
|
||||
virtual bool disconnect();
|
||||
|
||||
public:
|
||||
virtual const FileConnectionStatus& getConnectionStatus() { return mStatus; }
|
||||
virtual const FileConnectionType& getConnectionType() { return mConnectionType; }
|
||||
virtual const FileLocation& getLocation() { return mLocation; }
|
||||
|
||||
public:
|
||||
virtual bool setPointer(BytePointer pointer);
|
||||
virtual bool readBytes(Byte* bytes, SizeBytes size);
|
||||
virtual bool writeBytes(const Byte* bytes, SizeBytes size);
|
||||
|
||||
public:
|
||||
virtual SizeBytes size();
|
||||
};
|
||||
}
|
||||
14
Storage/public/RemoteStorage.hpp
Normal file
14
Storage/public/RemoteStorage.hpp
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include "Storage.hpp"
|
||||
|
||||
namespace tp {
|
||||
class Client : public Storage {
|
||||
// same as local storage file but transfers all commands to server
|
||||
};
|
||||
|
||||
class Server {
|
||||
// opens local storage and transfers all client command to it
|
||||
// manages multiple clients
|
||||
};
|
||||
}
|
||||
53
Storage/public/Storage.hpp
Normal file
53
Storage/public/Storage.hpp
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
#pragma once
|
||||
|
||||
#include "Strings.hpp"
|
||||
|
||||
namespace tp {
|
||||
|
||||
extern ModuleManifest gModuleStorage;
|
||||
|
||||
class StorageLocation {
|
||||
public:
|
||||
StorageLocation() = default;
|
||||
virtual ~StorageLocation() = default;
|
||||
};
|
||||
|
||||
class ConnectionType {
|
||||
public:
|
||||
ConnectionType() = default;
|
||||
virtual ~ConnectionType() = default;
|
||||
};
|
||||
|
||||
class ConnectionStatus {
|
||||
public:
|
||||
ConnectionStatus() = default;
|
||||
virtual ~ConnectionStatus() = default;
|
||||
};
|
||||
|
||||
class Storage {
|
||||
typedef ualni SizeBytes;
|
||||
typedef ualni BytePointer;
|
||||
typedef int1 Byte;
|
||||
|
||||
private:
|
||||
StorageLocation mLocation;
|
||||
ConnectionType mConnectionType;
|
||||
ConnectionStatus mStatus;
|
||||
|
||||
public:
|
||||
Storage() = default;
|
||||
virtual ~Storage() = default;
|
||||
|
||||
public:
|
||||
virtual bool connect(const StorageLocation& location, const ConnectionType& connectionInfo) = 0;
|
||||
virtual bool disconnect() = 0;
|
||||
virtual const ConnectionStatus& getConnectionStatus() = 0;
|
||||
|
||||
public:
|
||||
virtual bool readBytes(BytePointer pointer, Byte* bytes, SizeBytes size) = 0;
|
||||
virtual bool writeBytes(BytePointer pointer, const Byte* bytes, SizeBytes size) = 0;
|
||||
|
||||
public:
|
||||
virtual SizeBytes size() = 0;
|
||||
};
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue