Program Listing for File netio3_evloop.hpp

Return to documentation for file (network/netio3_evloop.hpp)

#ifndef FELIX_NETIO3_EVLOOP_H_
#define FELIX_NETIO3_EVLOOP_H_

#include <thread>
#include <memory>

#include "netio3-backend/EventLoop/BaseEventLoop.hpp"

template<typename EventLoopType>
concept Netio3EventLoopType = std::is_base_of<netio3::BaseEventLoop, EventLoopType>::value;

class Netio3EventLoop
{
    public:
        template<Netio3EventLoopType EventLoopType>
        struct type_tag {};
        template <Netio3EventLoopType EventLoopType>
        explicit Netio3EventLoop(type_tag<EventLoopType>)
            : m_evloop(std::make_shared<EventLoopType>()) {}
        Netio3EventLoop(const Netio3EventLoop &) = delete;
        Netio3EventLoop(Netio3EventLoop &&) = delete;
        Netio3EventLoop &operator=(const Netio3EventLoop &) = delete;
        Netio3EventLoop &operator=(Netio3EventLoop &&) = delete;
        ~Netio3EventLoop() { stop(); }
        void start_thread(const std::string& thread_name);
        void start();
        void stop();

        std::shared_ptr<netio3::BaseEventLoop> get_evloop() { return m_evloop; }

    private:
        std::thread m_evloop_thread;
        void run(const std::string& thread_name);
        std::shared_ptr<netio3::BaseEventLoop> m_evloop;
};


#endif /* FELIX_NETIO3_EVLOOP_H_ */