summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2017-10-25 17:40:22 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2017-10-25 17:40:30 +0100
commit3bd7165aba79f098d96e7fed292c12002d807d0f (patch)
tree77f4259517dc0e8e569fbfd71941242d4befe4a6
parentExclude default untestable functions from coverage reports (diff)
downloadnetfs-3bd7165aba79f098d96e7fed292c12002d807d0f.tar.bz2
netfs-3bd7165aba79f098d96e7fed292c12002d807d0f.tar.xz
netfs-3bd7165aba79f098d96e7fed292c12002d807d0f.zip
Greatly simplify the mess of fuse_operations initialisation and remove the now redundent fuseCall wrapper
-rw-r--r--netfs/fuse/fuseAppBase.cpp2
-rw-r--r--netfs/fuse/fuseAppBase.h143
-rw-r--r--netfs/unittests/testCore.cpp12
3 files changed, 83 insertions, 74 deletions
diff --git a/netfs/fuse/fuseAppBase.cpp b/netfs/fuse/fuseAppBase.cpp
index 87275c6..fc6fa14 100644
--- a/netfs/fuse/fuseAppBase.cpp
+++ b/netfs/fuse/fuseAppBase.cpp
@@ -224,7 +224,7 @@ FuseAppBase::runint(int argc, char ** argv)
fuseApp = this;
struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
if (fuse_opt_parse(&args, fuseApp, fuse_opts,
- fuseCall<void *, const char *, int, struct fuse_args *>::helper<&FuseAppBase::opt_parse>) == -1) {
+ &helper<decltype(&FuseAppBase::opt_parse), &FuseAppBase::opt_parse>) == -1) {
exit(1);
}
return args;
diff --git a/netfs/fuse/fuseAppBase.h b/netfs/fuse/fuseAppBase.h
index 63763d9..4128c6b 100644
--- a/netfs/fuse/fuseAppBase.h
+++ b/netfs/fuse/fuseAppBase.h
@@ -65,51 +65,51 @@ class DLL_PUBLIC FuseAppBase {
virtual int fuse_opt_parse(struct fuse_args *args, void *data, const struct fuse_opt opts[], fuse_opt_proc_t proc) = 0;
virtual int main(int, char **, const struct fuse_operations *) = 0;
-#define GetHelper(func) getHelper<&FuseAppBase::func>(typeid(&FuseAppBase::func) != typeid(&FuseApp::func))
+#define GetHelper(func) getHelper<decltype(&FuseAppBase::func), decltype(&FuseApp::func), &FuseAppBase::func>(&FuseAppBase::func)
template <typename FuseApp>
static int run(int argc, char ** argv, FuseApp * fa)
{
auto args = fa->runint(argc, argv);
struct fuse_operations operations = {
- fuseCall<const char *, struct stat *>::GetHelper(getattr),
- fuseCall<const char *, char *, size_t>::GetHelper(readlink),
+ GetHelper(getattr),
+ GetHelper(readlink),
NULL, // getdir deprecated
- fuseCall<const char *, mode_t, dev_t>::GetHelper(mknod),
- fuseCall<const char *, mode_t>::GetHelper(mkdir),
- fuseCall<const char *>::GetHelper(unlink),
- fuseCall<const char *>::GetHelper(rmdir),
- fuseCall<const char *, const char *>::GetHelper(symlink),
- fuseCall<const char *, const char *>::GetHelper(rename),
- fuseCall<const char *, const char *>::GetHelper(link),
- fuseCall<const char *, mode_t>::GetHelper(chmod),
- fuseCall<const char *, uid_t, gid_t>::GetHelper(chown),
- fuseCall<const char *, off_t>::GetHelper(truncate),
+ GetHelper(mknod),
+ GetHelper(mkdir),
+ GetHelper(unlink),
+ GetHelper(rmdir),
+ GetHelper(symlink),
+ GetHelper(rename),
+ GetHelper(link),
+ GetHelper(chmod),
+ GetHelper(chown),
+ GetHelper(truncate),
NULL, // utime deprecated
- fuseCall<const char *, struct fuse_file_info *>::GetHelper(open),
- fuseCall<const char *, char *, size_t, off_t, struct fuse_file_info *>::GetHelper(read),
- fuseCall<const char *, const char *, size_t, off_t, struct fuse_file_info *>::GetHelper(write),
- fuseCall<const char *, struct statvfs *>::GetHelper(statfs),
- fuseCall<const char *, struct fuse_file_info *>::GetHelper(flush),
- fuseCall<const char *, struct fuse_file_info *>::GetHelper(release),
- fuseCall<const char *, int, struct fuse_file_info *>::GetHelper(fsync),
- fuseCall<const char *, const char *, const char *, size_t, int>::GetHelper(setxattr),
- fuseCall<const char *, const char *, char *, size_t>::GetHelper(getxattr),
- fuseCall<const char *, char *, size_t>::GetHelper(listxattr),
- fuseCall<const char *, const char *>::GetHelper(removexattr),
- fuseCall<const char *, struct fuse_file_info *>::GetHelper(opendir),
- fuseCall<const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *>::GetHelper(readdir),
- fuseCall<const char *, struct fuse_file_info *>::GetHelper(releasedir),
- fuseCall<const char *, int, struct fuse_file_info *>::GetHelper(fsyncdir),
+ GetHelper(open),
+ GetHelper(read),
+ GetHelper(write),
+ GetHelper(statfs),
+ GetHelper(flush),
+ GetHelper(release),
+ GetHelper(fsync),
+ GetHelper(setxattr),
+ GetHelper(getxattr),
+ GetHelper(listxattr),
+ GetHelper(removexattr),
+ GetHelper(opendir),
+ GetHelper(readdir),
+ GetHelper(releasedir),
+ GetHelper(fsyncdir),
fuseInit,
fuseDestroy,
- fuseCall<const char *, int>::GetHelper(access),
- fuseCall<const char *, mode_t, struct fuse_file_info *>::GetHelper(create),
- fuseCall<const char *, off_t, struct fuse_file_info *>::GetHelper(ftruncate),
- fuseCall<const char *, struct stat *, struct fuse_file_info *>::GetHelper(fgetattr),
+ GetHelper(access),
+ GetHelper(create),
+ GetHelper(ftruncate),
+ GetHelper(fgetattr),
#if (FUSE_MINOR_VERSION >= 6)
- fuseCall<const char *, struct fuse_file_info *, int, struct flock *>::GetHelper(lock),
- fuseCall<const char *, const struct timespec [2]>::GetHelper(utimens),
- fuseCall<const char *, size_t, uint64_t *>::GetHelper(bmap),
+ GetHelper(lock),
+ GetHelper(utimens),
+ GetHelper(bmap),
#if (FUSE_MINOR_VERSION >= 8)
0, // flag_nullpath_ok
#if (FUSE_MINOR_VERSION >= 9)
@@ -117,13 +117,13 @@ class DLL_PUBLIC FuseAppBase {
0, // flag_utime_omit_ok
#endif
0, // flag_reserved
- fuseCall<const char *, int, void *, struct fuse_file_info *, unsigned int, void *>::GetHelper(ioctl),
- fuseCall<const char *, struct fuse_file_info *, struct fuse_pollhandle *, unsigned *>::GetHelper(poll),
+ GetHelper(ioctl),
+ GetHelper(poll),
#if (FUSE_MINOR_VERSION >= 9)
- fuseCall<const char *, struct fuse_bufvec *, off_t, struct fuse_file_info *>::GetHelper(write_buf),
- fuseCall<const char *, struct fuse_bufvec **, size_t, off_t, struct fuse_file_info *>::GetHelper(read_buf),
- fuseCall<const char *, struct fuse_file_info *, int>::GetHelper(flock),
- fuseCall<const char *, int, off_t, off_t, struct fuse_file_info *>::GetHelper(fallocate),
+ GetHelper(write_buf),
+ GetHelper(read_buf),
+ GetHelper(flock),
+ GetHelper(fallocate),
#endif
#endif
#endif
@@ -136,41 +136,40 @@ class DLL_PUBLIC FuseAppBase {
static void * fuseInit(struct fuse_conn_info *conn);
static void fuseDestroy(void *);
- template <typename... Args>
- class DLL_PRIVATE fuseCall {
- public:
- typedef int (*WrapperFunc)(Args...);
- template <int (FuseAppBase::*b)(Args...)>
- static WrapperFunc getHelper(bool implemented)
- {
- auto func = &helper<b>;
- return implemented ? func : NULL;
+ template <typename BFunc, typename IFunc, BFunc bfunc, typename ... Args>
+ static typename std::enable_if<!std::is_same<BFunc, IFunc>::value, int(*)(Args...)>::type getHelper(int(FuseAppBase::*)(Args...))
+ {
+ return &helper<BFunc, bfunc, Args...>;
+ }
+ template <typename BFunc, typename IFunc, BFunc bfunc, typename ... Args>
+ static typename std::enable_if<std::is_same<BFunc, IFunc>::value, int(*)(Args...)>::type getHelper(int(FuseAppBase::*)(Args...))
+ {
+ return nullptr;
+ }
+ template <typename Func, Func f, typename ... Args>
+ static int helper(Args ... a)
+ {
+ for (int t = 0; ; ++t) {
+ try {
+ return (fuseApp->*f)(a...);
}
- template <int (FuseAppBase::*f)(Args...)>
- static int helper(Args ... a)
- {
- for (int t = 0; ; ++t) {
- try {
- return (fuseApp->*f)(a...);
- }
- catch (const std::exception & ex) {
- if (t < 10) {
- if (int rtn = fuseApp->onError(ex)) {
- return rtn;
- }
- }
- else {
- fuseApp->logf(LOG_ERR, "Retries expired with %s calling %s", ex.what(), typeid(f).name());
- return -EIO;
- }
- }
- catch (...) {
- fuseApp->logf(LOG_ERR, "Unknown exception calling %s", typeid(f).name());
- return -EIO;
+ catch (const std::exception & ex) {
+ if (t < 10) {
+ if (int rtn = fuseApp->onError(ex)) {
+ return rtn;
}
}
+ else {
+ fuseApp->logf(LOG_ERR, "Retries expired with %s calling %s", ex.what(), typeid(f).name());
+ return -EIO;
+ }
}
- };
+ catch (...) {
+ fuseApp->logf(LOG_ERR, "Unknown exception calling %s", typeid(f).name());
+ return -EIO;
+ }
+ }
+ }
static FuseAppBase * fuseApp;
};
diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp
index ff5a352..880a503 100644
--- a/netfs/unittests/testCore.cpp
+++ b/netfs/unittests/testCore.cpp
@@ -51,7 +51,17 @@ class Core {
const fuse_operations * fuse;
};
-BOOST_FIXTURE_TEST_SUITE( NetfsCore, Core )
+BOOST_FIXTURE_TEST_SUITE( NetfsCore, Core );
+
+BOOST_AUTO_TEST_CASE(fuse_operations_correct)
+{
+ // open should be defined
+ BOOST_REQUIRE(fuse->open);
+ // getdir should not be defined (Not supported)
+ BOOST_REQUIRE(!fuse->getdir);
+ // fsync should not be defined (Not implemented)
+ BOOST_REQUIRE(!fuse->fsync);
+}
BOOST_AUTO_TEST_CASE ( daemonInitialised )
{