CatapultServer
v0.5.0.1 (Elephant)
|
Go to the documentation of this file.
37 template<
typename TFuncTraits,
typename... TArgs>
39 auto pPromise = std::make_shared<thread::promise<typename TFuncTraits::ResultType>>();
40 auto future = pPromise->get_future();
41 auto packetPayload = TFuncTraits::CreateRequestPacketPayload(std::forward<TArgs>(args)...);
42 send(traits, packetPayload, [pPromise](
auto result,
auto&& value) {
44 pPromise->set_value(std::move(value));
57 template<
typename TFuncTraits,
typename TCallback>
59 using ResultType =
typename TFuncTraits::ResultType;
60 m_io.
write(packetPayload, [traits, callback, &io =
m_io](
auto code) {
61 if (ionet::SocketOperationCode::Success != code)
64 io.read([traits, callback](
auto readCode,
const auto* pResponsePacket) {
65 if (ionet::SocketOperationCode::Success != readCode)
70 <<
"received packet of type " << pResponsePacket->Type
71 <<
" but expected type " << TFuncTraits::Packet_Type;
72 return callback(RemoteChainResult::Malformed_Packet, ResultType());
76 if (!traits.tryParseResult(*pResponsePacket, result)) {
78 <<
"unable to parse " << pResponsePacket->Type
79 <<
" packet (size = " << pResponsePacket->Size <<
")";
99 return "write to remote node failed";
101 return "read from remote node failed";
103 return "remote node returned malformed packet";
#define CATAPULT_LOG(SEV)
Writes a log entry to the default logger with SEV severity.
Definition: Logging.h:340
static constexpr const char * GetErrorMessage(RemoteChainResult result)
Definition: RemoteRequestDispatcher.h:96
def warning(*args)
Definition: colorPrint.py:10
Exception class that is thrown when a catapult api operation produces an error.
Definition: ApiTypes.h:27
RemoteRequestDispatcher(ionet::PacketIo &io)
Creates a remote request dispatcher around io.
Definition: RemoteRequestDispatcher.h:32
static constexpr auto Friendly_Name
Definition: RemoteNodeApi.cpp:34
static constexpr auto Packet_Type
Definition: RemoteNodeApi.cpp:33
An interface for reading and writing packets.
Definition: PacketIo.h:31
Provides a way to access the result of an asynchronous operation.
Definition: Future.h:29
thread::future< typename TFuncTraits::ResultType > dispatch(const TFuncTraits &traits, TArgs &&... args)
Dispatches args to the underlying io.
Definition: RemoteRequestDispatcher.h:38
void send(const TFuncTraits &traits, const ionet::PacketPayload &packetPayload, const TCallback &callback)
Definition: RemoteRequestDispatcher.h:58
Dispatches requests to a remote node.
Definition: RemoteRequestDispatcher.h:29
virtual void write(const PacketPayload &payload, const WriteCallback &callback)=0
Writes payload and calls callback on completion.
RemoteChainResult
Definition: RemoteRequestDispatcher.h:89
A packet payload that can be written.
Definition: PacketPayload.h:29
Definition: AddressExtractionExtension.cpp:28
ionet::PacketIo & m_io
Definition: RemoteRequestDispatcher.h:108