#ifndef SINGLETONPROCESS_H #define SINGLETONPROCESS_H #include #include #include #include #include class SingletonProcess { public: using MessageHandler = boost::signals2::signal; using MessageHandlerSlot = MessageHandler::slot_type; SingletonProcess(const std::string_view &name); bool alreadyRun() const; MessageHandler messageHandler; ~SingletonProcess(); bool sendMessage(const char *data, size_t size); protected: void run(); private: #if WIN32 void *m_handle{nullptr}; // windows HANDLE #else int m_handle{-1}; #endif bool m_alreadyRun{false}; std::unique_ptr m_messageQueue; std::unique_ptr m_thread; std::condition_variable m_conditionVariable; std::mutex m_mutex; bool m_exit{false}; }; #endif // SINGLETONPROCESS_H