13 #ifndef __PROCESS_EVENT_HPP__ 14 #define __PROCESS_EVENT_HPP__ 35 struct TerminateEvent;
73 explicit IsVisitor(
bool* _result) : result(_result) {}
74 void visit(
const T&)
override { *result =
true; }
84 const T* result =
nullptr;
87 explicit AsVisitor(
const T** _result) : result(_result) {}
88 void visit(
const T& t)
override { *result = &t; }
92 if (result ==
nullptr) {
93 ABORT(
"Attempting to \"cast\" event incorrectly!");
106 : message(
std::move(_message)) {}
111 const std::string&
name,
114 : message{
name, from, to, std::string(data, length)} {}
121 : message{std::move(
name), from, to, std::move(data)} {}
130 visitor->
visit(*
this);
135 consumer->consume(std::move(*
this));
145 std::unique_ptr<http::Request>&& _request,
148 response(
std::move(_response)) {}
165 visitor->
visit(*
this);
170 consumer->consume(std::move(*
this));
184 functionType(_functionType)
194 visitor->
visit(*
this);
199 consumer->consume(std::move(*
this));
203 std::unique_ptr<lambda::CallableOnce<void(ProcessBase*)>>
f;
221 visitor->
visit(*
this);
226 consumer->consume(std::move(*
this));
236 : from(_from), inject(_inject) {}
245 visitor->
visit(*
this);
250 consumer->consume(std::move(*
this));
264 explicit Visitor(
JSON::Object* _object) : object(_object) {}
268 object->values[
"type"] =
"MESSAGE";
270 const Message& message =
event.message;
272 object->values[
"name"] = message.
name;
275 object->values[
"body"] = message.
body;
280 object->values[
"type"] =
"HTTP";
284 object->values[
"method"] = request.
method;
290 object->values[
"type"] =
"DISPATCH";
295 object->values[
"type"] =
"EXITED";
300 object->values[
"type"] =
"TERMINATE";
313 #endif // __PROCESS_EVENT_HPP__
#define ABORT(...)
Definition: abort.hpp:40
void visit(EventVisitor *visitor) const override
Definition: event.hpp:192
virtual void visit(const TerminateEvent &)
Definition: event.hpp:45
Future< Response > request(const Request &request, bool streamedResponse=false)
Asynchronously sends an HTTP request to the process and returns the HTTP response once the entire res...
F && f
Definition: defer.hpp:270
URL url
Definition: http.hpp:544
HttpEvent(std::unique_ptr< http::Request > &&_request, std::unique_ptr< Promise< http::Response >> &&_response)
Definition: event.hpp:144
MessageEvent(const UPID &from, const UPID &to, const std::string &name, const char *data, size_t length)
Definition: event.hpp:108
Definition: event.hpp:142
Definition: message.hpp:22
void consume(EventConsumer *consumer)&&override
Definition: event.hpp:248
Definition: type_utils.hpp:619
std::unique_ptr< Promise< http::Response > > response
Definition: event.hpp:174
Definition: event.hpp:178
Definition: process.hpp:72
~HttpEvent() override
Definition: event.hpp:155
bool is() const
Definition: event.hpp:68
virtual void visit(const MessageEvent &)
Definition: event.hpp:41
UPID pid
Definition: event.hpp:229
void consume(EventConsumer *consumer)&&override
Definition: event.hpp:133
Option< const std::type_info * > functionType
Definition: event.hpp:205
ExitedEvent(const UPID &_pid)
Definition: event.hpp:211
Definition: event.hpp:233
Definition: event.hpp:209
UPID from
Definition: event.hpp:253
UPID to
Definition: message.hpp:26
void consume(EventConsumer *consumer)&&override
Definition: event.hpp:168
UPID from
Definition: message.hpp:25
Message message
Definition: event.hpp:138
An "untyped" PID, used to encapsulate the process ID for lower-layer abstractions (eg...
Definition: pid.hpp:39
void visit(EventVisitor *visitor) const override
Definition: event.hpp:163
Definition: future.hpp:74
void consume(EventConsumer *consumer)&&override
Definition: event.hpp:197
std::unique_ptr< http::Request > request
Definition: event.hpp:173
void visit(EventVisitor *visitor) const override
Definition: event.hpp:219
virtual void visit(const HttpEvent &)
Definition: event.hpp:43
const T & as() const
Definition: event.hpp:82
virtual void consume(MessageEvent &&)
Definition: event.hpp:52
MessageEvent(Message &&_message)
Definition: event.hpp:105
DispatchEvent(std::unique_ptr< lambda::CallableOnce< void(ProcessBase *)>> _f, const Option< const std::type_info * > &_functionType)
Definition: event.hpp:180
virtual ~Event()
Definition: event.hpp:62
virtual void consume(TerminateEvent &&)
Definition: event.hpp:56
virtual void consume(DispatchEvent &&)
Definition: event.hpp:53
std::string method
Definition: http.hpp:538
Definition: executor.hpp:48
virtual void consume(HttpEvent &&)
Definition: event.hpp:54
void visit(EventVisitor *visitor) const override
Definition: event.hpp:128
std::string body
Definition: message.hpp:27
virtual void consume(ExitedEvent &&)
Definition: event.hpp:55
Definition: event.hpp:103
virtual void visit(const DispatchEvent &)
Definition: event.hpp:42
virtual ~EventVisitor()
Definition: event.hpp:40
std::string stringify(int flags)
std::unique_ptr< lambda::CallableOnce< void(ProcessBase *)> > f
Definition: event.hpp:203
bool inject
Definition: event.hpp:254
virtual void visit(const ExitedEvent &)
Definition: event.hpp:44
std::string name
Definition: message.hpp:24
constexpr const char * name
Definition: shell.hpp:41
void visit(EventVisitor *visitor) const override
Definition: event.hpp:243
virtual ~EventConsumer()
Definition: event.hpp:51
MessageEvent(const UPID &from, const UPID &to, std::string &&name, std::string &&data)
Definition: event.hpp:116
void consume(EventConsumer *consumer)&&override
Definition: event.hpp:224
Definition: lambda.hpp:414
TerminateEvent(const UPID &_from, bool _inject)
Definition: event.hpp:235