diff --git a/include/wrapper/DeriveBaseClass.hpp b/include/wrapper/DeriveBaseClass.hpp index 9f59348..e0f3e94 100644 --- a/include/wrapper/DeriveBaseClass.hpp +++ b/include/wrapper/DeriveBaseClass.hpp @@ -9,28 +9,35 @@ namespace client { template class FluidSCWrapper; namespace impl { - + +template struct ChooseRTOrNRT; + +template<> +struct ChooseRTOrNRT +{ + template + using type = NonRealTime; +}; + +template<> +struct ChooseRTOrNRT +{ + template + using type = RealTime; +}; + + template struct BaseChooser { - templatestruct Choose - { - using type = NonRealTime; - }; - - template<> - struct Choose - { - using type = RealTime; - }; - using RT = typename Client::isRealTime; static constexpr bool UseRealTime = RT::value && !IsModel_t::value; - using type = typename Choose::type; + using type = typename ChooseRTOrNRT::template type; }; + template using BaseChooser_t = typename BaseChooser::type; diff --git a/include/wrapper/NonRealtime.hpp b/include/wrapper/NonRealtime.hpp index 7eaca7a..90b75a2 100644 --- a/include/wrapper/NonRealtime.hpp +++ b/include/wrapper/NonRealtime.hpp @@ -44,13 +44,16 @@ namespace impl { using CacheEntryPointer = std::shared_ptr; using WeakCacheEntryPointer = std::weak_ptr; //could use weak_type in 17 + + public: using Cache = std::map; - + static Cache mCache; + private: static bool isNull(WeakCacheEntryPointer const& weak) { return !weak.owner_before(WeakCacheEntryPointer{}) && !WeakCacheEntryPointer{}.owner_before(weak); } - static Cache mCache; + public: static WeakCacheEntryPointer get(index id) @@ -201,27 +204,20 @@ namespace impl { { using NRTCommand::NRTCommand; - - template - struct CancelCheck{ - void operator()(index id) + void cancelCheck(std::false_type, index id) + { + if(auto ptr = get(id).lock()) { - if(auto ptr = get(id).lock()) - { - auto& client = ptr->mClient; - if(!client.synchronous() && client.state() == ProcessState::kProcessing) - std::cout << Wrapper::getName() - << ": Processing cancelled" - << std::endl; - } + auto& client = ptr->mClient; + if(!client.synchronous() && client.state() == ProcessState::kProcessing) + std::cout << Wrapper::getName() + << ": Processing cancelled" + << std::endl; } - }; + } + + void cancelCheck(std::true_type, index){} - template<> - struct CancelCheck{ - void operator()(index) - {} - }; static const char* name() { @@ -231,7 +227,7 @@ namespace impl { bool stage2(World*) { - CancelCheck()(NRTCommand::mID); + cancelCheck(IsRTQueryModel_t(),NRTCommand::mID); remove(NRTCommand::mID); NRTCommand::sendReply(name(), true); return true; @@ -759,7 +755,7 @@ namespace impl { if(auto ptr = get(mID).lock()) { - bool trigger = (mPreviousTrigger <= 0) && mTrigger > 0; + bool trigger = (!mPreviousTrigger) && mTrigger; mPreviousTrigger = mTrigger; mTrigger = 0; auto& client = ptr->mClient; @@ -784,8 +780,8 @@ namespace impl { } private: - bool mPreviousTrigger{0}; - bool mTrigger{0}; + bool mPreviousTrigger{false}; + bool mTrigger{false}; Result mResult; impl::FloatControlsIter mControlsIterator; index mID; @@ -941,25 +937,19 @@ namespace impl { } }; - FifoMsg mFifoMsg; - char* mCompletionMessage = nullptr; - void* mReplyAddr = nullptr; - const char* mName = nullptr; - index checkThreadInterval; - index pollCounter{0}; - index mPreviousTrigger{0}; - + FifoMsg mFifoMsg; + char* mCompletionMessage = nullptr; + void* mReplyAddr = nullptr; + const char* mName = nullptr; + index checkThreadInterval; + index pollCounter{0}; + index mPreviousTrigger{0}; bool mSynchronous{true}; - Wrapper* mWrapper{static_cast(this)}; Result mResult; }; - //initialize static cache - template - using Cache = typename NonRealTime::Cache; - template - Cache NonRealTime::mCache{}; + typename NonRealTime::Cache NonRealTime::mCache{}; } }