From e03f17d40415fb1bac6f9167c34073bed49fb231 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 17 Apr 2022 12:50:08 +0100 Subject: Simplified constexpr operations map --- netfs/fuse/fuseApp.cpp | 3 -- netfs/fuse/fuseAppBase.h | 105 ++++++++++++++++++++++--------------------- netfs/unittests/testCore.cpp | 3 ++ 3 files changed, 58 insertions(+), 53 deletions(-) diff --git a/netfs/fuse/fuseApp.cpp b/netfs/fuse/fuseApp.cpp index f9b6884..cfd9689 100644 --- a/netfs/fuse/fuseApp.cpp +++ b/netfs/fuse/fuseApp.cpp @@ -20,9 +20,6 @@ namespace AdHoc { template class CallCacheable; } -static_assert(NetFS::FuseApp::operations.access); -static_assert(!NetFS::FuseApp::operations.destroy); - NetFS::FuseApp::FuseApp(Ice::StringSeq && a) : iceArgs(std::move(a)) { } NetFS::FuseApp::~FuseApp() diff --git a/netfs/fuse/fuseAppBase.h b/netfs/fuse/fuseAppBase.h index e4c1c62..7d8edce 100644 --- a/netfs/fuse/fuseAppBase.h +++ b/netfs/fuse/fuseAppBase.h @@ -74,15 +74,67 @@ public: protected: static FuseAppBase * fuseApp; + + template + constexpr static auto + getInternalHelper() + { + if constexpr (Implemented) { + return [](auto... a) { + SharedLock(fuseApp->_lock); + return (fuseApp->*bfunc)(a...); + }; + } + else { + return nullptr; + } + } + + template + constexpr static auto + getHelper() + { + if constexpr (Implemented) { + return [](auto... a) -> decltype((fuseApp->*bfunc)(a...)) { + for (int t = 0;; ++t) { + try { + fuseApp->beforeOperation(); + SharedLock(fuseApp->_lock); + return (fuseApp->*bfunc)(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(bfunc).name()); + return -EIO; + } + } + catch (...) { + fuseApp->logf(LOG_ERR, "Unknown exception calling %s", typeid(bfunc).name()); + return -EIO; + } + } + }; + } + else { + return nullptr; + } + } }; template class FuseAppBaseT : public FuseAppBase { +private: public: #define GetIntHelper(func) \ - getInternalHelper(&FuseAppBase::func) + getInternalHelper, &FuseAppBase::func>() #define GetHelper(func) \ - getHelper(&FuseAppBase::func) - constexpr static fuse_operations operations { + getHelper, &FuseAppBase::func>() + constexpr const static fuse_operations operations { GetHelper(getattr), GetHelper(readlink), GetHelper(mknod), @@ -129,53 +181,6 @@ public: #undef GetHelper #undef GetIntHelper -private: - template - constexpr static auto - getInternalHelper(Rtn (FuseAppBase::*)(Args...)) -> Rtn (*)(Args...) - { - if constexpr (!std::is_same::value) { - return [](Args... a) { - SharedLock(fuseApp->_lock); - return (fuseApp->*bfunc)(a...); - }; - } - return nullptr; - } - template - constexpr static auto - getHelper(Rtn (FuseAppBase::*)(Args...)) -> Rtn (*)(Args...) - { - if constexpr (!std::is_same::value) { - return [](Args... a) -> Rtn { - for (int t = 0;; ++t) { - try { - fuseApp->beforeOperation(); - SharedLock(fuseApp->_lock); - return (fuseApp->*bfunc)(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(bfunc).name()); - return -EIO; - } - } - catch (...) { - fuseApp->logf(LOG_ERR, "Unknown exception calling %s", typeid(bfunc).name()); - return -EIO; - } - } - }; - } - return nullptr; - } - protected: template static int diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp index 717cc16..385b826 100644 --- a/netfs/unittests/testCore.cpp +++ b/netfs/unittests/testCore.cpp @@ -86,6 +86,9 @@ BOOST_FIXTURE_TEST_SUITE(NetfsCore, Core); BOOST_AUTO_TEST_CASE(fuse_operations_correct) { + BOOST_CHECK(NetFS::FuseApp::operations.access); + BOOST_CHECK(!NetFS::FuseApp::operations.destroy); + // open should be defined BOOST_REQUIRE(fuse->open); // bmap should not be defined (Not supported) -- cgit v1.2.3