summaryrefslogtreecommitdiff
path: root/modules/remote-filesystem
diff options
context:
space:
mode:
authorClaudius 'keldu' Holeksa <mail@keldu.de>2024-07-18 19:07:53 +0200
committerClaudius 'keldu' Holeksa <mail@keldu.de>2024-07-18 19:07:53 +0200
commit14dbb72f6c6043b442c5a74299fbe55b9f199ca6 (patch)
tree09f1dbf37ab555c4be3a734af43ac860da027194 /modules/remote-filesystem
parentf1223709e193c4513047293a1a42b55b9e8874b8 (diff)
wip
Diffstat (limited to 'modules/remote-filesystem')
-rw-r--r--modules/remote-filesystem/.nix/derivation.nix43
-rw-r--r--modules/remote-filesystem/SConstruct83
-rw-r--r--modules/remote-filesystem/c++/SConscript38
-rw-r--r--modules/remote-filesystem/c++/remote.hpp59
-rw-r--r--modules/remote-filesystem/examples/SConscript32
-rw-r--r--modules/remote-filesystem/tests/SConscript31
6 files changed, 286 insertions, 0 deletions
diff --git a/modules/remote-filesystem/.nix/derivation.nix b/modules/remote-filesystem/.nix/derivation.nix
new file mode 100644
index 0000000..f1d4421
--- /dev/null
+++ b/modules/remote-filesystem/.nix/derivation.nix
@@ -0,0 +1,43 @@
+{ lib
+, stdenv
+, scons
+, clang-tools
+, version
+, forstio
+, build_examples ? "false"
+}:
+
+stdenv.mkDerivation {
+ pname = "forstio-remote-filesystem";
+ inherit version;
+ src = ./..;
+
+ enableParallelBuilding = true;
+
+ nativeBuildInputs = [
+ scons
+ clang-tools
+ ];
+
+ buildInputs = [
+ forstio.core
+ forstio.async
+ forstio.io
+ forstio.codec
+ forstio.remote
+ forstio.io_codec
+ ];
+
+ outputs = [
+ "out"
+ "dev"
+ ];
+
+ buildPhase = ''
+ scons build_examples=${build_examples}
+ '';
+
+ installPhase = ''
+ scons prefix=$out build_examples=${build_examples} install
+ '';
+}
diff --git a/modules/remote-filesystem/SConstruct b/modules/remote-filesystem/SConstruct
new file mode 100644
index 0000000..5e94c0b
--- /dev/null
+++ b/modules/remote-filesystem/SConstruct
@@ -0,0 +1,83 @@
+#!/usr/bin/env python3
+
+import sys
+import os
+import os.path
+import glob
+import re
+
+
+if sys.version_info < (3,):
+ def isbasestring(s):
+ return isinstance(s,basestring)
+else:
+ def isbasestring(s):
+ return isinstance(s, (str,bytes))
+
+def add_kel_source_files(self, sources, filetype, lib_env=None, shared=False, target_post=""):
+
+ if isbasestring(filetype):
+ dir_path = self.Dir('.').abspath
+ filetype = sorted(glob.glob(dir_path+"/"+filetype))
+
+ for path in filetype:
+ target_name = re.sub( r'(.*?)(\.cpp|\.c\+\+)', r'\1' + target_post, path )
+ if shared:
+ target_name+='.os'
+ sources.append( self.SharedObject( target=target_name, source=path ) )
+ else:
+ target_name+='.o'
+ sources.append( self.StaticObject( target=target_name, source=path ) )
+ pass
+
+def isAbsolutePath(key, dirname, env):
+ assert os.path.isabs(dirname), "%r must have absolute path syntax" % (key,)
+
+env_vars = Variables(
+ args=ARGUMENTS
+)
+
+env_vars.Add(
+ BoolVariable('build_examples',
+ help='Build examples',
+ default=False
+ )
+);
+
+env_vars.Add('prefix',
+ help='Installation target location of build results and headers',
+ default='/usr/local/',
+ validator=isAbsolutePath
+);
+
+env=Environment(ENV=os.environ, variables=env_vars, CPPPATH=[],
+ CXX=['c++'],
+ CPPDEFINES=['SAW_UNIX'],
+ CXXFLAGS=['-std=c++20','-g','-Wall','-Wextra'],
+ LIBS=[
+ 'forstio-core'
+ ,'forstio-async'
+ ,'forstio-io'
+ ,'forstio-codec'
+ ,'forstio-io_codec'
+ ,'forstio-remote'
+ ]
+);
+env.__class__.add_source_files = add_kel_source_files
+env.Tool('compilation_db');
+env.cdb = env.CompilationDatabase('compile_commands.json');
+
+env.objects = [];
+env.sources = [];
+env.headers = [];
+env.targets = [];
+
+Export('env')
+SConscript('c++/SConscript')
+SConscript('examples/SConscript')
+
+env.Alias('cdb', env.cdb);
+env.Alias('all', [env.targets]);
+env.Default('all');
+
+env.Alias('install', '$prefix')
diff --git a/modules/remote-filesystem/c++/SConscript b/modules/remote-filesystem/c++/SConscript
new file mode 100644
index 0000000..2bf03be
--- /dev/null
+++ b/modules/remote-filesystem/c++/SConscript
@@ -0,0 +1,38 @@
+#!/bin/false
+
+import os
+import os.path
+import glob
+
+
+Import('env')
+
+dir_path = Dir('.').abspath
+
+# Environment for base library
+remote-filesystem_env = env.Clone();
+
+remote-filesystem_env.sources = sorted(glob.glob(dir_path + "/*.cpp"))
+remote-filesystem_env.headers = sorted(glob.glob(dir_path + "/*.hpp"))
+
+env.sources += remote-filesystem_env.sources;
+env.headers += remote-filesystem_env.headers;
+
+## Shared lib
+objects_shared = []
+remote-filesystem_env.add_source_files(objects_shared, remote-filesystem_env.sources, shared=True);
+env.library_shared = remote-filesystem_env.SharedLibrary('#build/forstio-remote-filesystem', [objects_shared]);
+
+## Static lib
+objects_static = []
+remote-filesystem_env.add_source_files(objects_static, remote-filesystem_env.sources, shared=False);
+env.library_static = remote-filesystem_env.StaticLibrary('#build/forstio-remote-filesystem', [objects_static]);
+
+# Set Alias
+env.Alias('library_remote-filesystem', [env.library_shared, env.library_static]);
+
+env.targets += ['library_remote-filesystem'];
+
+# Install
+env.Install('$prefix/lib/', [env.library_shared, env.library_static]);
+env.Install('$prefix/include/forstio/remote/filesystem/', [remote-filesystem_env.headers]);
diff --git a/modules/remote-filesystem/c++/remote.hpp b/modules/remote-filesystem/c++/remote.hpp
new file mode 100644
index 0000000..42cdd03
--- /dev/null
+++ b/modules/remote-filesystem/c++/remote.hpp
@@ -0,0 +1,59 @@
+#pragma once
+
+#include <filesystem>
+
+#include <forstio/remote/remote.hpp>
+
+namespace saw {
+namespace rmt {
+struct FileSystem {};
+}
+
+template<>
+class remote_address<rmt::FileSystem> {
+private:
+ std::filesystem::path path_;
+public:
+ remote_address(const std::filesystem::path& path__):
+ path_{path__}
+ {}
+};
+
+template<typename Iface, typename Encoding, typename Storage>
+class rpc_client<Iface, Encoding, Storage, rmt::FileSystem> {
+private:
+ ptr<remote_address<rmt::FileSystem>> addr_;
+public:
+ rpc_client(ptr<remote_address<rmt::FileSystem>> addr__):
+ addr_{addr__}
+ {}
+};
+
+template<typename Iface, typename Encoding, typename Storage>
+class rpc_server<Iface, Encoding, Storage, rmt::FileSystem> {
+private:
+ ptr<remote_address<rmt::FileSystem>> addr_;
+public:
+ rpc_server(ptr<remote_address<rmt::FileSystem>> addr__):
+ addr_{addr__}
+ {}
+};
+
+template<>
+class remote<rmt::FileSystem> {
+private:
+ SAW_FORBID_COPY(remote);
+ SAW_FORBID_MOVE(remote);
+
+
+public:
+ error_or<own<remote_address<rmt::FileSystem>>> parse_address(const std::string_view& path_v){
+ return heap<remote_address<rmt::FileSystem>>(path_v);
+ }
+
+ template<typename Iface, typename Encoding, typename Storage>
+ rpc_server<Iface, Encoding, Storage, rmt::FileSystem> listen(const remote_address<rmt::FileSystem>& addr, typename rpc_server<Iface,Encoding,Storage,rmt::FileSystem>::InterfaceT iface){
+ return {addr, std::move(iface)};
+ }
+};
+}
diff --git a/modules/remote-filesystem/examples/SConscript b/modules/remote-filesystem/examples/SConscript
new file mode 100644
index 0000000..df8e0c6
--- /dev/null
+++ b/modules/remote-filesystem/examples/SConscript
@@ -0,0 +1,32 @@
+#!/bin/false
+
+import os
+import os.path
+import glob
+
+
+Import('env')
+
+dir_path = Dir('.').abspath
+
+# Environment for base library
+examples_env = env.Clone();
+
+examples_env.sources = sorted(glob.glob(dir_path + "/*.cpp"))
+examples_env.headers = sorted(glob.glob(dir_path + "/*.hpp"))
+
+env.sources += examples_env.sources;
+env.headers += examples_env.headers;
+
+objects_static = []
+
+# Set Alias
+env.examples = [
+#, examples_env.echo_server
+];
+env.Alias('examples', env.examples);
+
+if env["build_examples"]:
+ env.targets += ['examples'];
+ env.Install('$prefix/bin/', env.examples);
+#endif
diff --git a/modules/remote-filesystem/tests/SConscript b/modules/remote-filesystem/tests/SConscript
new file mode 100644
index 0000000..f8ffc92
--- /dev/null
+++ b/modules/remote-filesystem/tests/SConscript
@@ -0,0 +1,31 @@
+#!/bin/false
+
+import os
+import os.path
+import glob
+
+
+Import('env')
+
+dir_path = Dir('.').abspath
+
+# Environment for base library
+test_cases_env = env.Clone();
+
+test_cases_env.Append(LIBS=['forstio-test']);
+
+test_cases_env.sources = sorted(glob.glob(dir_path + "/*.cpp"))
+test_cases_env.headers = sorted(glob.glob(dir_path + "/*.hpp"))
+
+env.sources += test_cases_env.sources;
+env.headers += test_cases_env.headers;
+
+objects_static = []
+test_cases_env.add_source_files(objects_static, test_cases_env.sources, shared=False);
+test_cases_env.program = test_cases_env.Program('#bin/tests', [objects_static, env.library_static]);
+
+# Set Alias
+env.Alias('test', test_cases_env.program);
+env.Alias('check', test_cases_env.program);
+
+env.targets += ['test','check'];