diff --git a/include/libnetwrk/net/core/client/client.hpp b/include/libnetwrk/net/core/client/client.hpp index 4a7af7d..3356623 100644 --- a/include/libnetwrk/net/core/client/client.hpp +++ b/include/libnetwrk/net/core/client/client.hpp @@ -55,10 +55,10 @@ namespace libnetwrk { Connect to service. */ bool connect(const std::string& host, const uint16_t port) { - if (m_context.status != service_status::stopped) + if (m_context.status != to_underlying(service_status::stopped)) return false; - m_context.status = service_status::starting; + m_context.status = to_underlying(service_status::starting); bool connected = connect_impl(host, port); @@ -66,10 +66,10 @@ namespace libnetwrk { if (m_context.cb_connect) m_context.cb_connect(m_comp_connection.connection); - m_context.status = service_status::started; + m_context.status = to_underlying(service_status::started); } else { - m_context.status = service_status::stopped; + m_context.status = to_underlying(service_status::stopped); } return connected; @@ -79,10 +79,10 @@ namespace libnetwrk { Disconnect the client and clean up. */ void disconnect() { - if (m_context.status != service_status::started) + if (m_context.status != to_underlying(service_status::started)) return; - m_context.status = service_status::stopping; + m_context.status = to_underlying(service_status::stopping); this->teardown(); if (m_context.cb_disconnect) @@ -90,7 +90,7 @@ namespace libnetwrk { LIBNETWRK_INFO(m_context.name, "Disconnected."); - m_context.status = service_status::stopped; + m_context.status = to_underlying(service_status::stopped); } void send(message_t& message, libnetwrk::send_flags flags = libnetwrk::send_flags::none) { diff --git a/include/libnetwrk/net/core/service/service.hpp b/include/libnetwrk/net/core/service/service.hpp index 3dbd10c..20b6061 100644 --- a/include/libnetwrk/net/core/service/service.hpp +++ b/include/libnetwrk/net/core/service/service.hpp @@ -55,10 +55,10 @@ namespace libnetwrk { } bool start(const std::string& host, const uint16_t port) { - if (m_context.status != service_status::stopped) + if (m_context.status != to_underlying(service_status::stopped)) return false; - m_context.status = service_status::starting; + m_context.status = to_underlying(service_status::starting); bool started = start_impl(host, port); @@ -66,24 +66,24 @@ namespace libnetwrk { if (m_context.cb_start) m_context.cb_start(); - m_context.status = service_status::started; + m_context.status = to_underlying(service_status::started); } else { - m_context.status = service_status::stopped; + m_context.status = to_underlying(service_status::stopped); } return started; } void stop() { - if (m_context.status != service_status::started) + if (m_context.status != to_underlying(service_status::started)) return; - m_context.status = service_status::stopping; + m_context.status = to_underlying(service_status::stopping); this->teardown(); - m_context.status = service_status::stopped; + m_context.status = to_underlying(service_status::stopped); if (m_context.cb_stop) m_context.cb_stop(); diff --git a/include/libnetwrk/net/core/shared/shared_comp_message.hpp b/include/libnetwrk/net/core/shared/shared_comp_message.hpp index d46d192..d52d762 100644 --- a/include/libnetwrk/net/core/shared/shared_comp_message.hpp +++ b/include/libnetwrk/net/core/shared/shared_comp_message.hpp @@ -218,7 +218,7 @@ namespace libnetwrk { } void process_messages_loop() { - while (m_context.status == service_status::started) { + while (m_context.status == to_underlying(service_status::started)) { bool wait = false; { @@ -231,7 +231,7 @@ namespace libnetwrk { m_cv.wait(lock); } - if (m_context.status != service_status::started) + if (m_context.status != to_underlying(service_status::started)) break; invoke_processing_callbacks(); diff --git a/include/libnetwrk/net/core/shared/shared_context.hpp b/include/libnetwrk/net/core/shared/shared_context.hpp index 71bfd66..a3c88ca 100644 --- a/include/libnetwrk/net/core/shared/shared_context.hpp +++ b/include/libnetwrk/net/core/shared/shared_context.hpp @@ -38,7 +38,7 @@ namespace libnetwrk { public: std::string name = ""; - std::atomic_uint8_t status = libnetwrk::service_status::stopped; + std::atomic_uint8_t status = to_underlying(libnetwrk::service_status::stopped); io_context_t io_context; cb_message_t cb_message; @@ -50,7 +50,7 @@ namespace libnetwrk { public: bool is_running() const { - return status == service_status::started; + return status == to_underlying(service_status::started); } void start_io_context() { diff --git a/include/libnetwrk/net/tcp/tcp_client.hpp b/include/libnetwrk/net/tcp/tcp_client.hpp index 80a3a21..057cc5f 100644 --- a/include/libnetwrk/net/tcp/tcp_client.hpp +++ b/include/libnetwrk/net/tcp/tcp_client.hpp @@ -24,7 +24,7 @@ namespace libnetwrk::tcp { : base_t(name) {} virtual ~tcp_client() { - this->m_context.status = service_status::stopping; + this->m_context.status = to_underlying(service_status::stopping); this->teardown(); }; diff --git a/include/libnetwrk/net/tcp/tcp_service.hpp b/include/libnetwrk/net/tcp/tcp_service.hpp index fdab39f..c8794c2 100644 --- a/include/libnetwrk/net/tcp/tcp_service.hpp +++ b/include/libnetwrk/net/tcp/tcp_service.hpp @@ -25,7 +25,7 @@ namespace libnetwrk::tcp { : base_t(name), m_acceptor(this->m_context.io_context) {}; virtual ~tcp_service() { - this->m_context.status = service_status::stopping; + this->m_context.status = to_underlying(service_status::stopping); this->teardown(); }