| | |
| | | #include <nng/nng.h> |
| | | |
| | | namespace nng_wrap { |
| | | template <class... T> struct make_void{typedef void type;}; |
| | | template <class... T> using void_t = typename make_void<T...>::type; |
| | | template <class T, typename = void> struct is_default_c : std::false_type{}; |
| | | template <class T> struct is_default_c<T, void_t<decltype(T())>> : std::true_type{}; |
| | | template<class T> using is_function_t = typename std::is_function<typename std::remove_pointer<typename std::remove_reference<T>::type>::type>::type; |
| | | template <bool, class T> struct is_callable_h : is_function_t<T>{}; |
| | | template <class T> struct is_callable_h<true, T>{ |
| | | private: |
| | | struct FB{void operator()();}; |
| | | struct D : T, FB{}; |
| | | template<typename U, U> struct c; |
| | | template<class> static std::true_type t(...); |
| | | template<class C> static std::false_type t(c<void(FB::*)(), &C::operator()>*); |
| | | public: |
| | | using type = decltype(t<D>(nullptr)); |
| | | }; |
| | | template <class T> using is_callable = typename is_callable_h<std::is_class<typename std::remove_reference<T>::type>::value, typename std::remove_reference<T>::type>::type; |
| | | |
| | | static thread_local std::string verbose_info{}; |
| | | #ifndef PRNTVITAG |
| | |
| | | return {}; |
| | | } |
| | | |
| | | template <class... T> struct make_void{typedef void type;}; |
| | | template <class... T> using void_t = typename make_void<T...>::type; |
| | | template <class T, typename = void> struct is_default_c : std::false_type{}; |
| | | template <class T> struct is_default_c<T, void_t<decltype(T()),decltype(std::declval<T>().operator()())>> : std::true_type{}; |
| | | template<class T> using is_function_t = typename std::is_function<typename std::remove_pointer<typename std::remove_reference<T>::type>::type>::type; |
| | | template <bool, class T> struct is_callable_h : is_function_t<T>{}; |
| | | template <class T> struct is_callable_h<true, T>{ |
| | | private: |
| | | struct FB{void operator()();}; |
| | | struct D : T, FB{}; |
| | | template<typename U, U> struct c; |
| | | template<class> static std::true_type t(...); |
| | | template<class C> static std::false_type t(c<void(FB::*)(), &C::operator()>*); |
| | | public: |
| | | using type = decltype(t<D>(nullptr)); |
| | | }; |
| | | template <class T> using is_callable = typename is_callable_h<std::is_class<typename std::remove_reference<T>::type>::value, typename std::remove_reference<T>::type>::type; |
| | | |
| | | static constexpr int timeout_req_rep = 5162; |
| | | |
| | | inline void remove_exist(const std::string& url){ |
| | |
| | | public: |
| | | DISABLE_COPY_AND_ASSIGN(_ps); |
| | | _ps()=default; |
| | | int operator()(){return msg_.size();} |
| | | virtual ~_ps(){ |
| | | t_quit_.store(true, std::memory_order_relaxed); |
| | | if (t_.joinable()) t_.join(); |
| | |
| | | DISABLE_COPY_AND_ASSIGN(_ps_sub); |
| | | _ps_sub()=default; |
| | | ~_ps_sub()=default; |
| | | |
| | | std::mutex& operator()(){return mtx_topics_;} |
| | | std::unordered_set<std::string> topics_{}; |
| | | std::mutex mtx_topics_{}; |
| | | std::unordered_set<std::string> failed_topics_{}; |
| | |
| | | public: |
| | | DISABLE_COPY_AND_ASSIGN(_sv); |
| | | _sv()=default; |
| | | std::deque<std::string> operator()(){return {fixed_msg_};} |
| | | ~_sv(){ |
| | | t_quit_.store(true, std::memory_order_relaxed); |
| | | if (t_.joinable()) t_.join(); |
| | |
| | | public: |
| | | DISABLE_COPY_AND_ASSIGN(_rr); |
| | | _rr()=default; |
| | | std::tuple<uint64_t&,std::unordered_map<uint64_t, std::string>&> operator()(){return std::tie(work_index_, msg_);} |
| | | ~_rr(){ |
| | | if(std::get<0>(socks_).id > 0) nng_close(std::get<0>(socks_)); |
| | | if(std::get<0>(std::get<1>(socks_)).id > 0) nng_close(std::get<0>(std::get<1>(socks_))); |
| | |
| | | |
| | | }; |
| | | |
| | | template<class T, typename std::enable_if<is_default_c<T>::value, int>::type=0> inline T* singleton(){ static auto t = std::make_unique<T>(); return t.get(); } |
| | | |
| | | template <class T, class... Args, typename std::enable_if<is_callable<T>::value, int>::type=0> |
| | | inline std::thread get_thread(T&& t, Args&&... args){ |
| | | return std::thread(std::forward<T>(t), std::forward<Args>(args)...); |
| | | } |
| | | template<class T, typename std::enable_if<is_default_c<T>::value, int>::type=0> |
| | | inline T* singleton(){ static auto t = std::make_unique<T>(); return t.get(); } |
| | | template <class T, class... Args, typename std::enable_if<is_callable<T>::value&&sizeof...(Args)==1, int>::type=0> |
| | | inline std::thread get_thread(T&& t, Args&&... args){return std::thread(std::forward<T>(t), std::forward<Args>(args)...);} |
| | | |
| | | } |
| | | #endif |