CppZmqZoltanExt 0.0.1
Loading...
Searching...
No Matches
signal.h
Go to the documentation of this file.
1/*
2MIT License
3
4Copyright (c) 2025 Luan Young
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in all
14copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE.
23*/
56#pragma once
57
58#include <array>
59#include <optional>
60#include <zmq.hpp>
61
62#include "cppzmqzoltanext/czze_export.h"
63
64namespace zmqzext {
65
77class CZZE_EXPORT signal_t {
78public:
86 enum class type_t : uint8_t {
87 success = 1,
88 failure = 2,
89 stop = 3,
90 };
91
99 type_t type() const noexcept { return _type; }
100
109 bool is_success() const noexcept { return _type == type_t::success; }
110
119 bool is_failure() const noexcept { return _type == type_t::failure; }
120
129 bool is_stop() const noexcept { return _type == type_t::stop; }
130
141 static zmq::message_t create_success();
142
153 static zmq::message_t create_failure();
154
165 static zmq::message_t create_stop();
166
183 static std::optional<signal_t> check_signal(const zmq::message_t& msg) noexcept;
184
185private:
186 explicit signal_t(type_t type) noexcept : _type(type) {}
187 type_t _type;
188};
189
190} // namespace zmqzext
Class representing signals for ZMQ communication.
Definition: signal.h:77
type_t
Enumeration of possible signal types.
Definition: signal.h:86
bool is_stop() const noexcept
Check if this signal is a stop signal.
Definition: signal.h:129
bool is_success() const noexcept
Check if this signal is a success signal.
Definition: signal.h:109
type_t type() const noexcept
Get the type of the signal.
Definition: signal.h:99
bool is_failure() const noexcept
Check if this signal is a failure signal.
Definition: signal.h:119