Files
microReticulum/src/Utilities/OS.cpp
T
Chad Attermann 1b1beab4fa WIP: Work toward removing platform-specifics
Moved LoRa and UDP test code into `examples` folder.
Moved `main.cpp` test app to `examples` folder.
Removed platform-specific filesystem code and replaced with an interface
to be implemeneted by the consumer.
2024-05-26 17:28:51 -06:00

63 lines
1.7 KiB
C++

#include "OS.h"
#include "../Log.h"
using namespace RNS;
using namespace RNS::Utilities;
/*static*/ Filesystem OS::filesystem = {Type::NONE};
/*static*/ void OS::register_filesystem(Filesystem& filesystem) {
extreme("Registering filesystem......");
OS::filesystem = filesystem;
}
/*static*/ void OS::deregister_filesystem() {
extreme("Deregistering filesystem......");
OS::filesystem = {Type::NONE};
}
/*static*/ bool OS::file_exists(const char* file_path) {
extreme("file_exists: checking for filesystem");
if (!filesystem) {
warning("file_exists: filesystem not registered");
throw std::runtime_error("Filesystem has not been registered");
}
return filesystem.do_file_exists(file_path);
}
/*static*/ const Bytes OS::read_file(const char* file_path) {
if (!filesystem) {
throw std::runtime_error("Filesystem has not been registered");
}
return filesystem.do_read_file(file_path);
}
/*static*/ bool OS::write_file(const Bytes& data, const char* file_path) {
if (!filesystem) {
throw std::runtime_error("Filesystem has not been registered");
}
return filesystem.do_write_file(data, file_path);
}
/*static*/ bool OS::remove_file(const char* file_path) {
if (!filesystem) {
throw std::runtime_error("Filesystem has not been registered");
}
return filesystem.do_remove_file(file_path);
}
/*static*/ bool OS::rename_file(const char* from_file_path, const char* to_file_path) {
if (!filesystem) {
throw std::runtime_error("Filesystem has not been registered");
}
return filesystem.do_rename_file(from_file_path, to_file_path);
}
/*static*/ bool OS::create_directory(const char* directory_path) {
if (!filesystem) {
throw std::runtime_error("Filesystem has not been registered");
}
return filesystem.do_create_directory(directory_path);
}