From c28bbc2c15ee0bcba3203c3b5011c3e86213bffd Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 15 Feb 2015 16:13:47 +0000 Subject: Refactor to make more testable --- libfusepp/Jamfile.jam | 5 -- libfusepp/fuseAppBase.cpp | 214 ++++++++++++++++++++++++++++++++++++++++++++++ libfusepp/fuseAppBase.h | 162 +++++++++++++++++++++++++++++++++++ libfusepp/fuseapp.cpp | 214 ---------------------------------------------- libfusepp/fuseapp.h | 162 ----------------------------------- 5 files changed, 376 insertions(+), 381 deletions(-) delete mode 100644 libfusepp/Jamfile.jam create mode 100644 libfusepp/fuseAppBase.cpp create mode 100644 libfusepp/fuseAppBase.h delete mode 100644 libfusepp/fuseapp.cpp delete mode 100644 libfusepp/fuseapp.h (limited to 'libfusepp') diff --git a/libfusepp/Jamfile.jam b/libfusepp/Jamfile.jam deleted file mode 100644 index 1ba4a26..0000000 --- a/libfusepp/Jamfile.jam +++ /dev/null @@ -1,5 +0,0 @@ -project - : usage-requirements - . - ; - diff --git a/libfusepp/fuseAppBase.cpp b/libfusepp/fuseAppBase.cpp new file mode 100644 index 0000000..4d9ca97 --- /dev/null +++ b/libfusepp/fuseAppBase.cpp @@ -0,0 +1,214 @@ +#include "fuseAppBase.h" +#include +#include +#include +#include +#include +#include + +FuseAppBase * FuseAppBase::fuseApp; + +FuseAppBase::FuseAppBase() +{ +} +FuseAppBase::~FuseAppBase() +{ +} +void * FuseAppBase::init(fuse_conn_info*) +{ + return NULL; +} +int FuseAppBase::opt_parse(void*, const char *, int, fuse_args*) +{ + return 1; +} +int FuseAppBase::access(const char *, int) +{ + return -ENOSYS; +} +int FuseAppBase::chmod(const char *, mode_t) +{ + return -ENOSYS; +} +int FuseAppBase::chown(const char *, uid_t, gid_t) +{ + return -ENOSYS; +} +int FuseAppBase::create(const char *, mode_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::fgetattr(const char *, struct stat *, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::flush(const char *, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::fsync(const char *, int, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::fsyncdir(const char *, int, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::ftruncate(const char *, off_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::getattr(const char *, struct stat *) +{ + return -ENOSYS; +} +int FuseAppBase::getxattr(const char *, const char *, char *, size_t) +{ + return -ENOSYS; +} +int FuseAppBase::link(const char *, const char *) +{ + return -ENOSYS; +} +int FuseAppBase::listxattr(const char *, char *, size_t) +{ + return -ENOSYS; +} +int FuseAppBase::mkdir(const char *, mode_t) +{ + return -ENOSYS; +} +int FuseAppBase::mknod(const char *, mode_t, dev_t) +{ + return -ENOSYS; +} +int FuseAppBase::open(const char *, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::opendir(const char *, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::read(const char *, char *, size_t, off_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::readdir(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::readlink(const char *, char *, size_t) +{ + return -ENOSYS; +} +int FuseAppBase::release(const char *, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::releasedir(const char *, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::removexattr(const char *, const char *) +{ + return -ENOSYS; +} +int FuseAppBase::rename(const char *, const char *) +{ + return -ENOSYS; +} +int FuseAppBase::rmdir(const char *) +{ + return -ENOSYS; +} +int FuseAppBase::setxattr(const char *, const char *, const char *, size_t, int) +{ + return -ENOSYS; +} +int FuseAppBase::statfs(const char *, struct statvfs *) +{ + return -ENOSYS; +} +int FuseAppBase::symlink(const char *, const char *) +{ + return -ENOSYS; +} +int FuseAppBase::truncate(const char *, off_t) +{ + return -ENOSYS; +} +int FuseAppBase::unlink(const char *) +{ + return -ENOSYS; +} +int FuseAppBase::write(const char *, const char *, size_t, off_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::lock(const char *, struct fuse_file_info *, int, struct flock *) +{ + return -ENOSYS; +} +int FuseAppBase::utimens(const char *, const struct timespec[2]) +{ + return -ENOSYS; +} +int FuseAppBase::bmap(const char *, size_t, uint64_t *) +{ + return -ENOSYS; +} +int FuseAppBase::ioctl(const char *, int, void *, struct fuse_file_info *, unsigned int, void *) +{ + return -ENOSYS; +} +int FuseAppBase::poll(const char *, struct fuse_file_info *, struct fuse_pollhandle *, unsigned *) +{ + return -ENOSYS; +} +int FuseAppBase::write_buf(const char *, struct fuse_bufvec *, off_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::read_buf(const char *, struct fuse_bufvec **, size_t, off_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::flock(const char *, struct fuse_file_info *, int) +{ + return -ENOSYS; +} +int FuseAppBase::fallocate(const char *, int, off_t, off_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::onError(const std::exception & e) throw() +{ + fprintf(stderr, "Unknown exception calling (what: %s)\n", e.what()); + return -ENOSYS; +} + +void * FuseAppBase::fuseInit (struct fuse_conn_info *conn) +{ + return fuseApp->init(conn); +} +void FuseAppBase::fuseDestroy(void *) +{ + delete fuseApp; +} + +struct fuse_args +FuseAppBase::runint(int & argc, char** & argv, FuseAppBase * fa) +{ + struct fuse_opt fuse_opts[] = { + { NULL, 0, 0 } + }; + fuseApp = fa; + struct fuse_args args = FUSE_ARGS_INIT(argc, argv); + if (fuse_opt_parse(&args, fuseApp, fuse_opts, + fuseCall::helper<&FuseAppBase::opt_parse>) == -1) { + exit(1); + } + return args; +} + diff --git a/libfusepp/fuseAppBase.h b/libfusepp/fuseAppBase.h new file mode 100644 index 0000000..a320d36 --- /dev/null +++ b/libfusepp/fuseAppBase.h @@ -0,0 +1,162 @@ +#ifndef FUSEAPP_H +#define FUSEAPP_H + +#define FUSE_USE_VERSION 26 +#include +#include +#include +#include +#include + +class FuseAppBase { + public: + FuseAppBase(); + virtual ~FuseAppBase() = 0; + virtual void * init (struct fuse_conn_info * info); + virtual int opt_parse(void *, const char * arg, int key, struct fuse_args *); + virtual int access(const char *, int); + virtual int chmod(const char *, mode_t); + virtual int chown(const char *, uid_t, gid_t); + virtual int create(const char *, mode_t, struct fuse_file_info *); + virtual int fgetattr(const char *, struct stat *, struct fuse_file_info *); + virtual int flush(const char *, struct fuse_file_info *); + virtual int fsync(const char *, int, struct fuse_file_info *); + virtual int fsyncdir(const char *, int, struct fuse_file_info *); + virtual int ftruncate(const char *, off_t, struct fuse_file_info *); + virtual int getattr(const char *, struct stat *); + virtual int getxattr(const char *, const char *, char *, size_t); + virtual int link(const char *, const char *); + virtual int listxattr(const char *, char *, size_t); + virtual int mkdir(const char *, mode_t); + virtual int mknod(const char *, mode_t, dev_t); + virtual int open(const char *, struct fuse_file_info *); + virtual int opendir(const char *, struct fuse_file_info *); + virtual int read(const char *, char *, size_t, off_t, struct fuse_file_info *); + virtual int readdir(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *); + virtual int readlink(const char *, char *, size_t); + virtual int release(const char *, struct fuse_file_info *); + virtual int releasedir(const char *, struct fuse_file_info *); + virtual int removexattr(const char *, const char *); + virtual int rename(const char *, const char *); + virtual int rmdir(const char *); + virtual int setxattr(const char *, const char *, const char *, size_t, int); + virtual int statfs(const char *, struct statvfs *); + virtual int symlink(const char *, const char *); + virtual int truncate(const char *, off_t); + virtual int unlink(const char *); + virtual int write(const char *, const char *, size_t, off_t, struct fuse_file_info *); + virtual int lock(const char *, struct fuse_file_info *, int cmd, struct flock *); + virtual int utimens(const char *, const struct timespec tv[2]); + virtual int bmap(const char *, size_t blocksize, uint64_t *idx); + virtual int ioctl(const char *, int cmd, void *arg, struct fuse_file_info *, unsigned int flags, void * data); + virtual int poll(const char *, struct fuse_file_info *, struct fuse_pollhandle *, unsigned *); + virtual int write_buf(const char *, struct fuse_bufvec *buf, off_t off, struct fuse_file_info *); + virtual int read_buf(const char *, struct fuse_bufvec **bufp, size_t size, off_t off, struct fuse_file_info *); + virtual int flock(const char *, struct fuse_file_info *, int op); + virtual int fallocate(const char *, int, off_t, off_t, struct fuse_file_info *); + virtual int onError(const std::exception & err) throw(); + +#define GetHelper(func) getHelper<&FuseAppBase::func>(typeid(&FuseAppBase::func) != typeid(&FuseApp::func)) + template + static int run(int & argc, char** & argv, FuseApp * fa) + { + auto args = runint(argc, argv, fa); + struct fuse_operations operations = { + fuseCall::GetHelper(getattr), + fuseCall::GetHelper(readlink), + NULL, // getdir deprecated + fuseCall::GetHelper(mknod), + fuseCall::GetHelper(mkdir), + fuseCall::GetHelper(unlink), + fuseCall::GetHelper(rmdir), + fuseCall::GetHelper(symlink), + fuseCall::GetHelper(rename), + fuseCall::GetHelper(link), + fuseCall::GetHelper(chmod), + fuseCall::GetHelper(chown), + fuseCall::GetHelper(truncate), + NULL, // utime deprecated + fuseCall::GetHelper(open), + fuseCall::GetHelper(read), + fuseCall::GetHelper(write), + fuseCall::GetHelper(statfs), + fuseCall::GetHelper(flush), + fuseCall::GetHelper(release), + fuseCall::GetHelper(fsync), + fuseCall::GetHelper(setxattr), + fuseCall::GetHelper(getxattr), + fuseCall::GetHelper(listxattr), + fuseCall::GetHelper(removexattr), + fuseCall::GetHelper(opendir), + fuseCall::GetHelper(readdir), + fuseCall::GetHelper(releasedir), + fuseCall::GetHelper(fsyncdir), + fuseInit, + fuseDestroy, + fuseCall::GetHelper(access), + fuseCall::GetHelper(create), + fuseCall::GetHelper(ftruncate), + fuseCall::GetHelper(fgetattr), +#if (FUSE_MINOR_VERSION >= 6) + fuseCall::GetHelper(lock), + fuseCall::GetHelper(utimens), + fuseCall::GetHelper(bmap), +#if (FUSE_MINOR_VERSION >= 8) + 0, // flag_nullpath_ok +#if (FUSE_MINOR_VERSION >= 9) + 0, // flag_nopath + 0, // flag_utime_omit_ok +#endif + 0, // flag_reserved + fuseCall::GetHelper(ioctl), + fuseCall::GetHelper(poll), +#if (FUSE_MINOR_VERSION >= 9) + fuseCall::GetHelper(write_buf), + fuseCall::GetHelper(read_buf), + fuseCall::GetHelper(flock), + fuseCall::GetHelper(fallocate), +#endif +#endif +#endif + }; + return fuse_main(args.argc, args.argv, &operations, fa); + } + private: + static struct fuse_args runint(int &, char ** &, FuseAppBase *); + static void * fuseInit(struct fuse_conn_info *conn); + static void fuseDestroy(void *); + + template + class fuseCall { + public: + typedef int (*WrapperFunc)(Args...); + template + static WrapperFunc getHelper(bool implemented) + { + auto func = &helper; + return implemented ? func : NULL; + } + template + static int helper(Args ... a) + { + try { + return (fuseApp->*f)(a...); + } + catch (const std::exception & ex) { + if (int rtn = fuseApp->onError(ex)) { + return rtn; + } + return helper(a...); + } + catch (...) { + fprintf(stderr, "Unknown exception calling %s\n", typeid(f).name()); + return -ENOSYS; + } + } + }; + + static FuseAppBase * fuseApp; +}; + +#endif + diff --git a/libfusepp/fuseapp.cpp b/libfusepp/fuseapp.cpp deleted file mode 100644 index 1a6494a..0000000 --- a/libfusepp/fuseapp.cpp +++ /dev/null @@ -1,214 +0,0 @@ -#include "fuseapp.h" -#include -#include -#include -#include -#include -#include - -FuseAppBase * FuseAppBase::fuseApp; - -FuseAppBase::FuseAppBase() -{ -} -FuseAppBase::~FuseAppBase() -{ -} -void * FuseAppBase::init(fuse_conn_info*) -{ - return NULL; -} -int FuseAppBase::opt_parse(void*, const char *, int, fuse_args*) -{ - return 1; -} -int FuseAppBase::access(const char *, int) -{ - return -ENOSYS; -} -int FuseAppBase::chmod(const char *, mode_t) -{ - return -ENOSYS; -} -int FuseAppBase::chown(const char *, uid_t, gid_t) -{ - return -ENOSYS; -} -int FuseAppBase::create(const char *, mode_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::fgetattr(const char *, struct stat *, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::flush(const char *, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::fsync(const char *, int, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::fsyncdir(const char *, int, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::ftruncate(const char *, off_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::getattr(const char *, struct stat *) -{ - return -ENOSYS; -} -int FuseAppBase::getxattr(const char *, const char *, char *, size_t) -{ - return -ENOSYS; -} -int FuseAppBase::link(const char *, const char *) -{ - return -ENOSYS; -} -int FuseAppBase::listxattr(const char *, char *, size_t) -{ - return -ENOSYS; -} -int FuseAppBase::mkdir(const char *, mode_t) -{ - return -ENOSYS; -} -int FuseAppBase::mknod(const char *, mode_t, dev_t) -{ - return -ENOSYS; -} -int FuseAppBase::open(const char *, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::opendir(const char *, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::read(const char *, char *, size_t, off_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::readdir(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::readlink(const char *, char *, size_t) -{ - return -ENOSYS; -} -int FuseAppBase::release(const char *, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::releasedir(const char *, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::removexattr(const char *, const char *) -{ - return -ENOSYS; -} -int FuseAppBase::rename(const char *, const char *) -{ - return -ENOSYS; -} -int FuseAppBase::rmdir(const char *) -{ - return -ENOSYS; -} -int FuseAppBase::setxattr(const char *, const char *, const char *, size_t, int) -{ - return -ENOSYS; -} -int FuseAppBase::statfs(const char *, struct statvfs *) -{ - return -ENOSYS; -} -int FuseAppBase::symlink(const char *, const char *) -{ - return -ENOSYS; -} -int FuseAppBase::truncate(const char *, off_t) -{ - return -ENOSYS; -} -int FuseAppBase::unlink(const char *) -{ - return -ENOSYS; -} -int FuseAppBase::write(const char *, const char *, size_t, off_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::lock(const char *, struct fuse_file_info *, int, struct flock *) -{ - return -ENOSYS; -} -int FuseAppBase::utimens(const char *, const struct timespec[2]) -{ - return -ENOSYS; -} -int FuseAppBase::bmap(const char *, size_t, uint64_t *) -{ - return -ENOSYS; -} -int FuseAppBase::ioctl(const char *, int, void *, struct fuse_file_info *, unsigned int, void *) -{ - return -ENOSYS; -} -int FuseAppBase::poll(const char *, struct fuse_file_info *, struct fuse_pollhandle *, unsigned *) -{ - return -ENOSYS; -} -int FuseAppBase::write_buf(const char *, struct fuse_bufvec *, off_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::read_buf(const char *, struct fuse_bufvec **, size_t, off_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::flock(const char *, struct fuse_file_info *, int) -{ - return -ENOSYS; -} -int FuseAppBase::fallocate(const char *, int, off_t, off_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::onError(const std::exception & e) throw() -{ - fprintf(stderr, "Unknown exception calling (what: %s)\n", e.what()); - return -ENOSYS; -} - -void * FuseAppBase::fuseInit (struct fuse_conn_info *conn) -{ - return fuseApp->init(conn); -} -void FuseAppBase::fuseDestroy(void *) -{ - delete fuseApp; -} - -struct fuse_args -FuseAppBase::runint(int & argc, char** & argv, FuseAppBase * fa) -{ - struct fuse_opt fuse_opts[] = { - { NULL, 0, 0 } - }; - fuseApp = fa; - struct fuse_args args = FUSE_ARGS_INIT(argc, argv); - if (fuse_opt_parse(&args, fuseApp, fuse_opts, - fuseCall::helper<&FuseAppBase::opt_parse>) == -1) { - exit(1); - } - return args; -} - diff --git a/libfusepp/fuseapp.h b/libfusepp/fuseapp.h deleted file mode 100644 index a320d36..0000000 --- a/libfusepp/fuseapp.h +++ /dev/null @@ -1,162 +0,0 @@ -#ifndef FUSEAPP_H -#define FUSEAPP_H - -#define FUSE_USE_VERSION 26 -#include -#include -#include -#include -#include - -class FuseAppBase { - public: - FuseAppBase(); - virtual ~FuseAppBase() = 0; - virtual void * init (struct fuse_conn_info * info); - virtual int opt_parse(void *, const char * arg, int key, struct fuse_args *); - virtual int access(const char *, int); - virtual int chmod(const char *, mode_t); - virtual int chown(const char *, uid_t, gid_t); - virtual int create(const char *, mode_t, struct fuse_file_info *); - virtual int fgetattr(const char *, struct stat *, struct fuse_file_info *); - virtual int flush(const char *, struct fuse_file_info *); - virtual int fsync(const char *, int, struct fuse_file_info *); - virtual int fsyncdir(const char *, int, struct fuse_file_info *); - virtual int ftruncate(const char *, off_t, struct fuse_file_info *); - virtual int getattr(const char *, struct stat *); - virtual int getxattr(const char *, const char *, char *, size_t); - virtual int link(const char *, const char *); - virtual int listxattr(const char *, char *, size_t); - virtual int mkdir(const char *, mode_t); - virtual int mknod(const char *, mode_t, dev_t); - virtual int open(const char *, struct fuse_file_info *); - virtual int opendir(const char *, struct fuse_file_info *); - virtual int read(const char *, char *, size_t, off_t, struct fuse_file_info *); - virtual int readdir(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *); - virtual int readlink(const char *, char *, size_t); - virtual int release(const char *, struct fuse_file_info *); - virtual int releasedir(const char *, struct fuse_file_info *); - virtual int removexattr(const char *, const char *); - virtual int rename(const char *, const char *); - virtual int rmdir(const char *); - virtual int setxattr(const char *, const char *, const char *, size_t, int); - virtual int statfs(const char *, struct statvfs *); - virtual int symlink(const char *, const char *); - virtual int truncate(const char *, off_t); - virtual int unlink(const char *); - virtual int write(const char *, const char *, size_t, off_t, struct fuse_file_info *); - virtual int lock(const char *, struct fuse_file_info *, int cmd, struct flock *); - virtual int utimens(const char *, const struct timespec tv[2]); - virtual int bmap(const char *, size_t blocksize, uint64_t *idx); - virtual int ioctl(const char *, int cmd, void *arg, struct fuse_file_info *, unsigned int flags, void * data); - virtual int poll(const char *, struct fuse_file_info *, struct fuse_pollhandle *, unsigned *); - virtual int write_buf(const char *, struct fuse_bufvec *buf, off_t off, struct fuse_file_info *); - virtual int read_buf(const char *, struct fuse_bufvec **bufp, size_t size, off_t off, struct fuse_file_info *); - virtual int flock(const char *, struct fuse_file_info *, int op); - virtual int fallocate(const char *, int, off_t, off_t, struct fuse_file_info *); - virtual int onError(const std::exception & err) throw(); - -#define GetHelper(func) getHelper<&FuseAppBase::func>(typeid(&FuseAppBase::func) != typeid(&FuseApp::func)) - template - static int run(int & argc, char** & argv, FuseApp * fa) - { - auto args = runint(argc, argv, fa); - struct fuse_operations operations = { - fuseCall::GetHelper(getattr), - fuseCall::GetHelper(readlink), - NULL, // getdir deprecated - fuseCall::GetHelper(mknod), - fuseCall::GetHelper(mkdir), - fuseCall::GetHelper(unlink), - fuseCall::GetHelper(rmdir), - fuseCall::GetHelper(symlink), - fuseCall::GetHelper(rename), - fuseCall::GetHelper(link), - fuseCall::GetHelper(chmod), - fuseCall::GetHelper(chown), - fuseCall::GetHelper(truncate), - NULL, // utime deprecated - fuseCall::GetHelper(open), - fuseCall::GetHelper(read), - fuseCall::GetHelper(write), - fuseCall::GetHelper(statfs), - fuseCall::GetHelper(flush), - fuseCall::GetHelper(release), - fuseCall::GetHelper(fsync), - fuseCall::GetHelper(setxattr), - fuseCall::GetHelper(getxattr), - fuseCall::GetHelper(listxattr), - fuseCall::GetHelper(removexattr), - fuseCall::GetHelper(opendir), - fuseCall::GetHelper(readdir), - fuseCall::GetHelper(releasedir), - fuseCall::GetHelper(fsyncdir), - fuseInit, - fuseDestroy, - fuseCall::GetHelper(access), - fuseCall::GetHelper(create), - fuseCall::GetHelper(ftruncate), - fuseCall::GetHelper(fgetattr), -#if (FUSE_MINOR_VERSION >= 6) - fuseCall::GetHelper(lock), - fuseCall::GetHelper(utimens), - fuseCall::GetHelper(bmap), -#if (FUSE_MINOR_VERSION >= 8) - 0, // flag_nullpath_ok -#if (FUSE_MINOR_VERSION >= 9) - 0, // flag_nopath - 0, // flag_utime_omit_ok -#endif - 0, // flag_reserved - fuseCall::GetHelper(ioctl), - fuseCall::GetHelper(poll), -#if (FUSE_MINOR_VERSION >= 9) - fuseCall::GetHelper(write_buf), - fuseCall::GetHelper(read_buf), - fuseCall::GetHelper(flock), - fuseCall::GetHelper(fallocate), -#endif -#endif -#endif - }; - return fuse_main(args.argc, args.argv, &operations, fa); - } - private: - static struct fuse_args runint(int &, char ** &, FuseAppBase *); - static void * fuseInit(struct fuse_conn_info *conn); - static void fuseDestroy(void *); - - template - class fuseCall { - public: - typedef int (*WrapperFunc)(Args...); - template - static WrapperFunc getHelper(bool implemented) - { - auto func = &helper; - return implemented ? func : NULL; - } - template - static int helper(Args ... a) - { - try { - return (fuseApp->*f)(a...); - } - catch (const std::exception & ex) { - if (int rtn = fuseApp->onError(ex)) { - return rtn; - } - return helper(a...); - } - catch (...) { - fprintf(stderr, "Unknown exception calling %s\n", typeid(f).name()); - return -ENOSYS; - } - } - }; - - static FuseAppBase * fuseApp; -}; - -#endif - -- cgit v1.2.3