major msg -> obj file transfer refactor
mostly done, some things are hacky or not done
This commit is contained in:
77
solanaceae/tox_messages/backends/tox_ft_filesystem.cpp
Normal file
77
solanaceae/tox_messages/backends/tox_ft_filesystem.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
#include "./tox_ft_filesystem.hpp"
|
||||
|
||||
#include <solanaceae/object_store/meta_components.hpp>
|
||||
#include <solanaceae/object_store/meta_components_file.hpp>
|
||||
|
||||
#include <solanaceae/file/file2_std.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace Backends {
|
||||
|
||||
ToxFTFilesystem::ToxFTFilesystem(
|
||||
ObjectStore2& os
|
||||
) : StorageBackendI::StorageBackendI(os) {
|
||||
}
|
||||
|
||||
ToxFTFilesystem::~ToxFTFilesystem(void) {
|
||||
}
|
||||
|
||||
ObjectHandle ToxFTFilesystem::newObject(ByteSpan id) {
|
||||
ObjectHandle o{_os.registry(), _os.registry().create()};
|
||||
|
||||
o.emplace<ObjComp::Ephemeral::Backend>(this);
|
||||
o.emplace<ObjComp::ID>(std::vector<uint8_t>{id});
|
||||
//o.emplace<ObjComp::Ephemeral::FilePath>(object_file_path.generic_u8string());
|
||||
|
||||
_os.throwEventConstruct(o);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
std::unique_ptr<File2I> ToxFTFilesystem::file2(Object ov, FILE2_FLAGS flags) {
|
||||
if (flags & FILE2_RAW) {
|
||||
std::cerr << "TFTF error: does not support raw modes\n";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (flags == FILE2_NONE) {
|
||||
std::cerr << "TFTF error: no file mode set\n";
|
||||
assert(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (flags & FILE2_WRITE) {
|
||||
std::cerr << "TFTF error: opening file in write mode not supported\n";
|
||||
}
|
||||
|
||||
ObjectHandle o{_os.registry(), ov};
|
||||
|
||||
if (!static_cast<bool>(o)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// will this do if we go and support enc?
|
||||
// use ObjComp::Ephemeral::FilePath instead??
|
||||
if (!o.all_of<ObjComp::F::SingleInfoLocal>()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const auto& file_path = o.get<ObjComp::F::SingleInfoLocal>().file_path;
|
||||
if (file_path.empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// read only
|
||||
auto res = std::make_unique<File2RFile>(file_path);
|
||||
|
||||
if (!res || !res->isGood()) {
|
||||
std::cerr << "TFTF error: failed constructing file '" << file_path << "'\n";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
} // Backends
|
||||
|
19
solanaceae/tox_messages/backends/tox_ft_filesystem.hpp
Normal file
19
solanaceae/tox_messages/backends/tox_ft_filesystem.hpp
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <solanaceae/object_store/object_store.hpp>
|
||||
|
||||
namespace Backends {
|
||||
|
||||
struct ToxFTFilesystem : public StorageBackendI {
|
||||
ToxFTFilesystem(
|
||||
ObjectStore2& os
|
||||
);
|
||||
~ToxFTFilesystem(void);
|
||||
|
||||
ObjectHandle newObject(ByteSpan id) override;
|
||||
|
||||
std::unique_ptr<File2I> file2(Object o, FILE2_FLAGS flags) override;
|
||||
};
|
||||
|
||||
} // Backends
|
||||
|
Reference in New Issue
Block a user