Commit ff60a5f8 authored by Dominik Charousset's avatar Dominik Charousset

Migrate to latest upstream CAF API

parent 43e2750b
...@@ -20,10 +20,6 @@ caf_incubator_add_component( ...@@ -20,10 +20,6 @@ caf_incubator_add_component(
HEADERS HEADERS
${CAF_NET_HEADERS} ${CAF_NET_HEADERS}
SOURCES SOURCES
src/basp/connection_state_strings.cpp
src/basp/ec_strings.cpp
src/basp/message_type_strings.cpp
src/basp/operation_strings.cpp
src/convert_ip_endpoint.cpp src/convert_ip_endpoint.cpp
src/datagram_socket.cpp src/datagram_socket.cpp
src/defaults.cpp src/defaults.cpp
...@@ -35,6 +31,10 @@ caf_incubator_add_component( ...@@ -35,6 +31,10 @@ caf_incubator_add_component(
src/multiplexer.cpp src/multiplexer.cpp
src/net/abstract_actor_shell.cpp src/net/abstract_actor_shell.cpp
src/net/actor_shell.cpp src/net/actor_shell.cpp
src/net/basp/connection_state_strings.cpp
src/net/basp/ec_strings.cpp
src/net/basp/message_type_strings.cpp
src/net/basp/operation_strings.cpp
src/net/middleman.cpp src/net/middleman.cpp
src/net/middleman_backend.cpp src/net/middleman_backend.cpp
src/net/packet_writer.cpp src/net/packet_writer.cpp
......
...@@ -4,14 +4,20 @@ ...@@ -4,14 +4,20 @@
#pragma once #pragma once
#include <cstdint>
#include <string> #include <string>
#include <type_traits>
#include "caf/default_enum_inspect.hpp"
#include "caf/detail/net_export.hpp"
#include "caf/fwd.hpp"
namespace caf::net::basp { namespace caf::net::basp {
/// @addtogroup BASP /// @addtogroup BASP
/// Stores the state of a connection in a `basp::application`. /// Stores the state of a connection in a `basp::application`.
enum class connection_state { enum class connection_state : uint8_t {
/// Initial state for any connection to wait for the peer's handshake. /// Initial state for any connection to wait for the peer's handshake.
await_handshake_header, await_handshake_header,
/// Indicates that the header for the peer's handshake arrived and BASP /// Indicates that the header for the peer's handshake arrived and BASP
...@@ -28,7 +34,20 @@ enum class connection_state { ...@@ -28,7 +34,20 @@ enum class connection_state {
}; };
/// @relates connection_state /// @relates connection_state
std::string to_string(connection_state x); CAF_NET_EXPORT std::string to_string(connection_state x);
/// @relates connection_state
CAF_NET_EXPORT bool from_string(string_view, connection_state&);
/// @relates connection_state
CAF_NET_EXPORT bool from_integer(std::underlying_type_t<connection_state>,
connection_state&);
/// @relates connection_state
template <class Inspector>
bool inspect(Inspector& f, connection_state& x) {
return default_enum_inspect(f, x);
}
/// @} /// @}
......
...@@ -7,7 +7,9 @@ ...@@ -7,7 +7,9 @@
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include "caf/default_enum_inspect.hpp"
#include "caf/detail/net_export.hpp" #include "caf/detail/net_export.hpp"
#include "caf/fwd.hpp"
#include "caf/is_error_code_enum.hpp" #include "caf/is_error_code_enum.hpp"
namespace caf::net::basp { namespace caf::net::basp {
...@@ -33,6 +35,18 @@ enum class ec : uint8_t { ...@@ -33,6 +35,18 @@ enum class ec : uint8_t {
/// @relates ec /// @relates ec
CAF_NET_EXPORT std::string to_string(ec x); CAF_NET_EXPORT std::string to_string(ec x);
/// @relates ec
CAF_NET_EXPORT bool from_string(string_view, ec&);
/// @relates ec
CAF_NET_EXPORT bool from_integer(std::underlying_type_t<ec>, ec&);
/// @relates ec
template <class Inspector>
bool inspect(Inspector& f, ec& x) {
return default_enum_inspect(f, x);
}
} // namespace caf::net::basp } // namespace caf::net::basp
CAF_ERROR_CODE_ENUM(caf::net::basp::ec) CAF_ERROR_CODE_ENUM(caf::net::basp::ec)
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "caf/meta/type_name.hpp" #include "caf/meta/type_name.hpp"
#include "caf/net/basp/constants.hpp" #include "caf/net/basp/constants.hpp"
#include "caf/net/basp/message_type.hpp" #include "caf/net/basp/message_type.hpp"
#include "caf/type_id.hpp"
namespace caf::net::basp { namespace caf::net::basp {
...@@ -78,3 +79,12 @@ bool inspect(Inspector& f, header& x) { ...@@ -78,3 +79,12 @@ bool inspect(Inspector& f, header& x) {
/// @} /// @}
} // namespace caf::net::basp } // namespace caf::net::basp
namespace caf {
template <>
struct type_name<net::basp::header> {
static constexpr string_view value = "caf::net::basp::header";
};
} // namespace caf
...@@ -6,6 +6,12 @@ ...@@ -6,6 +6,12 @@
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include <type_traits>
#include "caf/default_enum_inspect.hpp"
#include "caf/detail/net_export.hpp"
#include "caf/fwd.hpp"
#include "caf/is_error_code_enum.hpp"
namespace caf::net::basp { namespace caf::net::basp {
...@@ -55,7 +61,20 @@ enum class message_type : uint8_t { ...@@ -55,7 +61,20 @@ enum class message_type : uint8_t {
}; };
/// @relates message_type /// @relates message_type
std::string to_string(message_type); CAF_NET_EXPORT std::string to_string(message_type x);
/// @relates message_type
CAF_NET_EXPORT bool from_string(string_view, message_type&);
/// @relates message_type
CAF_NET_EXPORT bool from_integer(std::underlying_type_t<message_type>,
message_type&);
/// @relates message_type
template <class Inspector>
bool inspect(Inspector& f, message_type& x) {
return default_enum_inspect(f, x);
}
/// @} /// @}
......
...@@ -4,7 +4,14 @@ ...@@ -4,7 +4,14 @@
#pragma once #pragma once
#include <cstdint>
#include <string> #include <string>
#include <type_traits>
#include "caf/default_enum_inspect.hpp"
#include "caf/detail/net_export.hpp"
#include "caf/fwd.hpp"
#include "caf/is_error_code_enum.hpp"
namespace caf::net { namespace caf::net {
...@@ -17,22 +24,39 @@ enum class operation { ...@@ -17,22 +24,39 @@ enum class operation {
shutdown = 0x04, shutdown = 0x04,
}; };
/// @relates operation
constexpr operation operator|(operation x, operation y) { constexpr operation operator|(operation x, operation y) {
return static_cast<operation>(static_cast<int>(x) | static_cast<int>(y)); return static_cast<operation>(static_cast<int>(x) | static_cast<int>(y));
} }
/// @relates operation
constexpr operation operator&(operation x, operation y) { constexpr operation operator&(operation x, operation y) {
return static_cast<operation>(static_cast<int>(x) & static_cast<int>(y)); return static_cast<operation>(static_cast<int>(x) & static_cast<int>(y));
} }
/// @relates operation
constexpr operation operator^(operation x, operation y) { constexpr operation operator^(operation x, operation y) {
return static_cast<operation>(static_cast<int>(x) ^ static_cast<int>(y)); return static_cast<operation>(static_cast<int>(x) ^ static_cast<int>(y));
} }
/// @relates operation
constexpr operation operator~(operation x) { constexpr operation operator~(operation x) {
return static_cast<operation>(~static_cast<int>(x)); return static_cast<operation>(~static_cast<int>(x));
} }
std::string to_string(operation x); /// @relates operation
CAF_NET_EXPORT std::string to_string(operation x);
/// @relates operation
CAF_NET_EXPORT bool from_string(string_view, operation&);
/// @relates operation
CAF_NET_EXPORT bool from_integer(std::underlying_type_t<operation>, operation&);
/// @relates operation
template <class Inspector>
bool inspect(Inspector& f, operation& x) {
return default_enum_inspect(f, x);
}
} // namespace caf::net } // namespace caf::net
// clang-format off // clang-format off
// DO NOT EDIT: this file is auto-generated by caf-generate-enum-strings. // DO NOT EDIT: this file is auto-generated by caf-generate-enum-strings.
// Run the target update-enum-strings if this file is out of sync. // Run the target update-enum-strings if this file is out of sync.
#include "caf/config.hpp"
#include "caf/string_view.hpp"
CAF_PUSH_DEPRECATED_WARNING
#include "caf/net/basp/connection_state.hpp" #include "caf/net/basp/connection_state.hpp"
#include <string> #include <string>
...@@ -26,6 +31,45 @@ std::string to_string(connection_state x) { ...@@ -26,6 +31,45 @@ std::string to_string(connection_state x) {
}; };
} }
bool from_string(string_view in, connection_state& out) {
if (in == "await_handshake_header") {
out = connection_state::await_handshake_header;
return true;
} else if (in == "await_handshake_payload") {
out = connection_state::await_handshake_payload;
return true;
} else if (in == "await_header") {
out = connection_state::await_header;
return true;
} else if (in == "await_payload") {
out = connection_state::await_payload;
return true;
} else if (in == "shutdown") {
out = connection_state::shutdown;
return true;
} else {
return false;
}
}
bool from_integer(std::underlying_type_t<connection_state> in,
connection_state& out) {
auto result = static_cast<connection_state>(in);
switch(result) {
default:
return false;
case connection_state::await_handshake_header:
case connection_state::await_handshake_payload:
case connection_state::await_header:
case connection_state::await_payload:
case connection_state::shutdown:
out = result;
return true;
};
}
} // namespace basp } // namespace basp
} // namespace net } // namespace net
} // namespace caf } // namespace caf
CAF_POP_WARNINGS
// clang-format off // clang-format off
// DO NOT EDIT: this file is auto-generated by caf-generate-enum-strings. // DO NOT EDIT: this file is auto-generated by caf-generate-enum-strings.
// Run the target update-enum-strings if this file is out of sync. // Run the target update-enum-strings if this file is out of sync.
#include "caf/config.hpp"
#include "caf/string_view.hpp"
CAF_PUSH_DEPRECATED_WARNING
#include "caf/net/basp/ec.hpp" #include "caf/net/basp/ec.hpp"
#include <string> #include <string>
...@@ -44,6 +49,81 @@ std::string to_string(ec x) { ...@@ -44,6 +49,81 @@ std::string to_string(ec x) {
}; };
} }
bool from_string(string_view in, ec& out) {
if (in == "invalid_magic_number") {
out = ec::invalid_magic_number;
return true;
} else if (in == "unexpected_number_of_bytes") {
out = ec::unexpected_number_of_bytes;
return true;
} else if (in == "unexpected_payload") {
out = ec::unexpected_payload;
return true;
} else if (in == "missing_payload") {
out = ec::missing_payload;
return true;
} else if (in == "illegal_state") {
out = ec::illegal_state;
return true;
} else if (in == "invalid_handshake") {
out = ec::invalid_handshake;
return true;
} else if (in == "missing_handshake") {
out = ec::missing_handshake;
return true;
} else if (in == "unexpected_handshake") {
out = ec::unexpected_handshake;
return true;
} else if (in == "version_mismatch") {
out = ec::version_mismatch;
return true;
} else if (in == "unimplemented") {
out = ec::unimplemented;
return true;
} else if (in == "app_identifiers_mismatch") {
out = ec::app_identifiers_mismatch;
return true;
} else if (in == "invalid_payload") {
out = ec::invalid_payload;
return true;
} else if (in == "invalid_scheme") {
out = ec::invalid_scheme;
return true;
} else if (in == "invalid_locator") {
out = ec::invalid_locator;
return true;
} else {
return false;
}
}
bool from_integer(std::underlying_type_t<ec> in,
ec& out) {
auto result = static_cast<ec>(in);
switch(result) {
default:
return false;
case ec::invalid_magic_number:
case ec::unexpected_number_of_bytes:
case ec::unexpected_payload:
case ec::missing_payload:
case ec::illegal_state:
case ec::invalid_handshake:
case ec::missing_handshake:
case ec::unexpected_handshake:
case ec::version_mismatch:
case ec::unimplemented:
case ec::app_identifiers_mismatch:
case ec::invalid_payload:
case ec::invalid_scheme:
case ec::invalid_locator:
out = result;
return true;
};
}
} // namespace basp } // namespace basp
} // namespace net } // namespace net
} // namespace caf } // namespace caf
CAF_POP_WARNINGS
// clang-format off // clang-format off
// DO NOT EDIT: this file is auto-generated by caf-generate-enum-strings. // DO NOT EDIT: this file is auto-generated by caf-generate-enum-strings.
// Run the target update-enum-strings if this file is out of sync. // Run the target update-enum-strings if this file is out of sync.
#include "caf/config.hpp"
#include "caf/string_view.hpp"
CAF_PUSH_DEPRECATED_WARNING
#include "caf/net/basp/message_type.hpp" #include "caf/net/basp/message_type.hpp"
#include <string> #include <string>
...@@ -30,6 +35,53 @@ std::string to_string(message_type x) { ...@@ -30,6 +35,53 @@ std::string to_string(message_type x) {
}; };
} }
bool from_string(string_view in, message_type& out) {
if (in == "handshake") {
out = message_type::handshake;
return true;
} else if (in == "actor_message") {
out = message_type::actor_message;
return true;
} else if (in == "resolve_request") {
out = message_type::resolve_request;
return true;
} else if (in == "resolve_response") {
out = message_type::resolve_response;
return true;
} else if (in == "monitor_message") {
out = message_type::monitor_message;
return true;
} else if (in == "down_message") {
out = message_type::down_message;
return true;
} else if (in == "heartbeat") {
out = message_type::heartbeat;
return true;
} else {
return false;
}
}
bool from_integer(std::underlying_type_t<message_type> in,
message_type& out) {
auto result = static_cast<message_type>(in);
switch(result) {
default:
return false;
case message_type::handshake:
case message_type::actor_message:
case message_type::resolve_request:
case message_type::resolve_response:
case message_type::monitor_message:
case message_type::down_message:
case message_type::heartbeat:
out = result;
return true;
};
}
} // namespace basp } // namespace basp
} // namespace net } // namespace net
} // namespace caf } // namespace caf
CAF_POP_WARNINGS
// clang-format off
// DO NOT EDIT: this file is auto-generated by caf-generate-enum-strings.
// Run the target update-enum-strings if this file is out of sync.
#include "caf/config.hpp"
#include "caf/string_view.hpp"
CAF_PUSH_DEPRECATED_WARNING
#include "caf/net/operation.hpp"
#include <string>
namespace caf {
namespace net {
std::string to_string(operation x) {
switch(x) {
default:
return "???";
case operation::none:
return "none";
case operation::read:
return "read";
case operation::write:
return "write";
case operation::read_write:
return "read_write";
case operation::shutdown:
return "shutdown";
};
}
bool from_string(string_view in, operation& out) {
if (in == "none") {
out = operation::none;
return true;
} else if (in == "read") {
out = operation::read;
return true;
} else if (in == "write") {
out = operation::write;
return true;
} else if (in == "read_write") {
out = operation::read_write;
return true;
} else if (in == "shutdown") {
out = operation::shutdown;
return true;
} else {
return false;
}
}
bool from_integer(std::underlying_type_t<operation> in,
operation& out) {
auto result = static_cast<operation>(in);
switch(result) {
default:
return false;
case operation::none:
case operation::read:
case operation::write:
case operation::read_write:
case operation::shutdown:
out = result;
return true;
};
}
} // namespace net
} // namespace caf
CAF_POP_WARNINGS
...@@ -40,5 +40,6 @@ CAF_TEST(serialization) { ...@@ -40,5 +40,6 @@ CAF_TEST(serialization) {
CAF_TEST(to_string) { CAF_TEST(to_string) {
basp::header x{basp::message_type::handshake, 42, 4}; basp::header x{basp::message_type::handshake, 42, 4};
CAF_CHECK_EQUAL(deep_to_string(x), "basp::header(handshake, 42, 4)"); CAF_CHECK_EQUAL(deep_to_string(x),
"caf::net::basp::header(handshake, 42, 4)");
} }
...@@ -80,10 +80,10 @@ struct app_t { ...@@ -80,10 +80,10 @@ struct app_t {
auto sub_res = consume(down, buf.subspan(1), {}); auto sub_res = consume(down, buf.subspan(1), {});
return sub_res >= 0 ? sub_res + 1 : sub_res; return sub_res >= 0 ? sub_res + 1 : sub_res;
} }
// Deserialize config value from received line.
auto num_bytes = std::distance(buf.begin(), i) + 1; auto num_bytes = std::distance(buf.begin(), i) + 1;
string_view line{reinterpret_cast<const char*>(buf.data()), string_view line{reinterpret_cast<const char*>(buf.data()),
static_cast<size_t>(num_bytes) - 1}; static_cast<size_t>(num_bytes) - 1};
CAF_MESSAGE("deserialize config value from : " << line);
config_value val; config_value val;
if (auto parsed_res = config_value::parse(line)) { if (auto parsed_res = config_value::parse(line)) {
val = std::move(*parsed_res); val = std::move(*parsed_res);
...@@ -91,13 +91,7 @@ struct app_t { ...@@ -91,13 +91,7 @@ struct app_t {
down->abort_reason(std::move(parsed_res.error())); down->abort_reason(std::move(parsed_res.error()));
return -1; return -1;
} }
if (!holds_alternative<settings>(val)) { CAF_MESSAGE("deserialize message from: " << val);
down->abort_reason(
make_error(pec::type_mismatch,
"expected a dictionary, got a "s + val.type_name()));
return -1;
}
// Deserialize message from received dictionary.
config_value_reader reader{&val}; config_value_reader reader{&val};
caf::message msg; caf::message msg;
if (!reader.apply(msg)) { if (!reader.apply(msg)) {
...@@ -190,7 +184,7 @@ struct fixture : host_fixture, test_coordinator_fixture<> { ...@@ -190,7 +184,7 @@ struct fixture : host_fixture, test_coordinator_fixture<> {
}; };
constexpr std::string_view input = R"__( constexpr std::string_view input = R"__(
{ values = [ { "@type" : "int32_t", value: 123 } ] } [{"@type": "int32_t", "value": 123}]
)__"; )__";
} // namespace } // namespace
......
...@@ -94,12 +94,6 @@ struct app_t { ...@@ -94,12 +94,6 @@ struct app_t {
down->abort_reason(std::move(parsed_res.error())); down->abort_reason(std::move(parsed_res.error()));
return -1; return -1;
} }
if (!holds_alternative<settings>(val)) {
down->abort_reason(
make_error(pec::type_mismatch,
"expected a dictionary, got a "s + val.type_name()));
return -1;
}
// Deserialize message from received dictionary. // Deserialize message from received dictionary.
config_value_reader reader{&val}; config_value_reader reader{&val};
caf::message msg; caf::message msg;
...@@ -193,7 +187,7 @@ struct fixture : host_fixture, test_coordinator_fixture<> { ...@@ -193,7 +187,7 @@ struct fixture : host_fixture, test_coordinator_fixture<> {
}; };
constexpr std::string_view input = R"__( constexpr std::string_view input = R"__(
{ values = [ { "@type" : "int32_t", value: 123 } ] } [ { "@type" : "int32_t", value: 123 } ]
)__"; )__";
} // namespace } // namespace
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment