Added memoryfilesystem and working on c wrapper
This commit is contained in:
99
include/TessesFramework/Filesystem/MemoryFilesystem.hpp
Normal file
99
include/TessesFramework/Filesystem/MemoryFilesystem.hpp
Normal file
@ -0,0 +1,99 @@
|
||||
#pragma once
|
||||
#include "VFS.hpp"
|
||||
#include "VFSFix.hpp"
|
||||
#include "../Threading/Mutex.hpp"
|
||||
#include <atomic>
|
||||
namespace Tesses::Framework::Filesystem
|
||||
{
|
||||
class MemoryEntry {
|
||||
public:
|
||||
std::string name;
|
||||
virtual ~MemoryEntry();
|
||||
};
|
||||
class MemoryFileData {
|
||||
public:
|
||||
MemoryFileData();
|
||||
time_t lastWrite;
|
||||
|
||||
bool canAccess;
|
||||
size_t readers;
|
||||
std::vector<uint8_t> file;
|
||||
};
|
||||
|
||||
class MemoryFile : public MemoryEntry
|
||||
{
|
||||
public:
|
||||
std::shared_ptr<MemoryFileData> data;
|
||||
~MemoryFile();
|
||||
};
|
||||
|
||||
class MemoryDirectory : public MemoryEntry
|
||||
{
|
||||
public:
|
||||
MemoryDirectory();
|
||||
time_t lastWrite;
|
||||
std::vector<MemoryEntry*> entries;
|
||||
~MemoryDirectory();
|
||||
};
|
||||
|
||||
class MemorySymlink : public MemoryEntry
|
||||
{
|
||||
public:
|
||||
time_t lastWrite;
|
||||
VFSPath linkedTo;
|
||||
};
|
||||
|
||||
class MemoryFilesystemStream : public Streams::Stream
|
||||
{
|
||||
public:
|
||||
std::shared_ptr<Tesses::Framework::Threading::Mutex> mtx;
|
||||
std::shared_ptr<MemoryFileData> data;
|
||||
bool canRead;
|
||||
bool canWrite;
|
||||
bool canSeek;
|
||||
int64_t pos;
|
||||
MemoryFilesystemStream(std::shared_ptr<Tesses::Framework::Threading::Mutex> mtx, std::shared_ptr<MemoryFileData> data,bool canRead, bool canWrite, bool canSeek);
|
||||
size_t Read(uint8_t* buff, size_t sz);
|
||||
size_t Write(const uint8_t* buff, size_t sz);
|
||||
bool CanRead();
|
||||
bool CanWrite();
|
||||
bool CanSeek();
|
||||
int64_t GetPosition();
|
||||
void Flush();
|
||||
void Seek(int64_t pos, Streams::SeekOrigin whence);
|
||||
~MemoryFilesystemStream();
|
||||
};
|
||||
|
||||
|
||||
class MemoryFilesystem : public VFS
|
||||
{
|
||||
std::shared_ptr<Tesses::Framework::Threading::Mutex> mtx;
|
||||
MemoryDirectory root;
|
||||
|
||||
MemoryEntry* GetEntry(VFSPath path,bool followSymlink);
|
||||
public:
|
||||
MemoryFilesystem();
|
||||
Tesses::Framework::Streams::Stream* OpenFile(VFSPath path, std::string mode);
|
||||
|
||||
void CreateDirectory(VFSPath path);
|
||||
void DeleteDirectory(VFSPath path);
|
||||
bool RegularFileExists(VFSPath path);
|
||||
bool SymlinkExists(VFSPath path);
|
||||
bool DirectoryExists(VFSPath path);
|
||||
|
||||
void DeleteFile(VFSPath path);
|
||||
void CreateSymlink(VFSPath existingFile, VFSPath symlinkFile);
|
||||
VFSPathEnumerator EnumeratePaths(VFSPath path);
|
||||
void CreateHardlink(VFSPath existingFile, VFSPath newName);
|
||||
|
||||
void MoveFile(VFSPath src, VFSPath dest);
|
||||
|
||||
void MoveDirectory(VFSPath src, VFSPath dest);
|
||||
VFSPath ReadLink(VFSPath path);
|
||||
std::string VFSPathToSystem(VFSPath path);
|
||||
VFSPath SystemToVFSPath(std::string path);
|
||||
void GetDate(VFSPath path, time_t& lastWrite, time_t& lastAccess);
|
||||
void SetDate(VFSPath path, time_t lastWrite, time_t lastAccess);
|
||||
~MemoryFilesystem();
|
||||
};
|
||||
};
|
||||
@ -15,6 +15,7 @@ namespace Tesses::Framework::Streams
|
||||
FileStream(FILE* f, bool owns, std::string mode , bool canSeek=true);
|
||||
size_t Read(uint8_t* buff, size_t sz);
|
||||
size_t Write(const uint8_t* buff, size_t sz);
|
||||
bool EndOfStream();
|
||||
bool CanRead();
|
||||
bool CanWrite();
|
||||
bool CanSeek();
|
||||
|
||||
77
include/TessesFramework/TessesFramework.h
Normal file
77
include/TessesFramework/TessesFramework.h
Normal file
@ -0,0 +1,77 @@
|
||||
#pragma once
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef void string_t;
|
||||
typedef void tf_vfs_t;
|
||||
typedef void tf_stream_t;
|
||||
typedef void tf_thread_t;
|
||||
typedef void tf_mutex_t;
|
||||
typedef void tf_vfs_dir_t;
|
||||
|
||||
typedef void (*tf_action_user_data_t)(void* ptr);
|
||||
|
||||
|
||||
typedef enum {
|
||||
TF_SEEK_BEGIN,
|
||||
TF_SEEK_CURRENT,
|
||||
TF_SEEK_END
|
||||
} TF_WHENCE;
|
||||
|
||||
string_t* string_create();
|
||||
string_t* string_create_from_buff(const void* text, size_t len);
|
||||
string_t* string_create_from_charpointer(const char* text);
|
||||
string_t* string_resize(string_t* str, size_t len);
|
||||
string_t* string_set_char(string_t* str, size_t index, char c);
|
||||
char string_get_char(string_t* str,size_t index);
|
||||
string_t* string_append_char(string_t* str, char c);
|
||||
string_t* string_append_from_buff(string_t* str,const void* text, size_t len);
|
||||
string_t* string_append_from_charpointer(string_t* str,const char* text);
|
||||
string_t* string_append(string_t* str, string_t* toAppend);
|
||||
string_t* string_append_signed(string_t* str, int64_t num);
|
||||
string_t* string_append_unsigned(string_t* str, uint64_t num);
|
||||
string_t* string_append_double(string_t* str, double num);
|
||||
void string_print(string_t* str);
|
||||
void string_println(string_t* str);
|
||||
size_t string_size(string_t* str);
|
||||
const char* string_c_str(string_t* str);
|
||||
void string_free(string_t* str);
|
||||
|
||||
void tf_init();
|
||||
tf_thread_t* tf_create_thread(void* userData, tf_action_user_data_t cb);
|
||||
void tf_join_thread(tf_thread_t* thrd);
|
||||
void tf_detach_thread(tf_thread_t* thrd);
|
||||
|
||||
tf_mutex_t* tf_mutex_create();
|
||||
void tf_mutex_lock(tf_mutex_t* mtx);
|
||||
bool tf_mutex_trylock(tf_mutex_t* mtx);
|
||||
void tf_mutex_unlock(tf_mutex_t* mtx);
|
||||
void tf_mutex_free(tf_mutex_t* mtx);
|
||||
|
||||
bool tf_stream_canread(tf_stream_t* strm);
|
||||
bool tf_stream_canwrite(tf_stream_t* strm);
|
||||
bool tf_stream_canseek(tf_stream_t* strm);
|
||||
bool tf_stream_eof(tf_stream_t* strm);
|
||||
int64_t tf_stream_getlen(tf_stream_t* strm);
|
||||
int64_t tf_stream_getpos(tf_stream_t* strm);
|
||||
void tf_stream_seek(tf_stream_t* strm, int64_t pos, TF_WHENCE whence);
|
||||
size_t tf_stream_read(tf_stream_t* strm, uint8_t* buffer, size_t length);
|
||||
size_t tf_stream_write(tf_stream_t* strm, const uint8_t* buffer, size_t length);
|
||||
size_t tf_stream_readblock(tf_stream_t* strm, uint8_t* buffer, size_t length);
|
||||
void tf_stream_writeblock(tf_stream_t* strm, const uint8_t* buffer, size_t length);
|
||||
void tf_stream_copyto(tf_stream_t* src, tf_stream_t* dest, size_t blockSize);
|
||||
void tf_stream_close(tf_stream_t* strm);
|
||||
void tf_stream_flush(tf_stream_t* strm);
|
||||
int32_t tf_stream_readbyte(tf_stream_t* strm);
|
||||
void tf_stream_writebyte(tf_stream_t* strm, uint8_t val);
|
||||
|
||||
tf_stream_t* tf_stream_fopen(const char* file, const char* mode);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
@ -11,8 +11,10 @@
|
||||
#include "TextStreams/StreamWriter.hpp"
|
||||
#include "Threading/Thread.hpp"
|
||||
#include "Threading/Mutex.hpp"
|
||||
#include "Threading/ThreadPool.hpp"
|
||||
#include "Filesystem/LocalFS.hpp"
|
||||
#include "Filesystem/SubdirFilesystem.hpp"
|
||||
#include "Filesystem/NullFilesystem.hpp"
|
||||
#include "Filesystem/MountableFilesystem.hpp"
|
||||
#include "Filesystem/MemoryFilesystem.hpp"
|
||||
#include "Crypto/ClientTLSStream.hpp"
|
||||
23
include/TessesFramework/Threading/ThreadPool.hpp
Normal file
23
include/TessesFramework/Threading/ThreadPool.hpp
Normal file
@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
#include <functional>
|
||||
#include "Thread.hpp"
|
||||
#include "Mutex.hpp"
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
|
||||
namespace Tesses::Framework::Threading
|
||||
{
|
||||
|
||||
class ThreadPool
|
||||
{
|
||||
std::vector<Thread*> threads;
|
||||
std::queue<std::function<void()>> callbacks;
|
||||
Mutex mtx;
|
||||
volatile bool isRunning;
|
||||
public:
|
||||
static size_t GetNumberOfCores();
|
||||
ThreadPool(size_t threads);
|
||||
void Schedule(std::function<void()> cb);
|
||||
~ThreadPool();
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user