LLDB mainline
|
Binder collects a table of functions that handle calls. More...
#include <JSONTransport.h>
Classes | |
class | ReplyOnce |
Function object to reply to a call. More... |
Public Member Functions | |
Binder (Transport &transport) | |
Binder (const Binder &)=delete | |
Binder & | operator= (const Binder &)=delete |
template<typename Fn, typename... Args> | |
void | OnDisconnect (Fn &&fn, Args &&...args) |
Bind a handler on transport disconnect. | |
template<typename Fn, typename... Args> | |
void | OnError (Fn &&fn, Args &&...args) |
Bind a handler on error when communicating with the transport. | |
template<typename Result, typename Params, typename Fn, typename... Args> | |
void | Bind (llvm::StringLiteral method, Fn &&fn, Args &&...args) |
Bind a handler for an incoming request. | |
template<typename Params, typename Fn, typename... Args> | |
void | Bind (llvm::StringLiteral method, Fn &&fn, Args &&...args) |
Bind a handler for an incoming event. | |
template<typename Result, typename Params> | |
OutgoingRequest< Result, Params > | Bind (llvm::StringLiteral method) |
Bind a function object to be used for outgoing requests. | |
template<typename Params> | |
OutgoingEvent< Params > | Bind (llvm::StringLiteral method) |
Bind a function object to be used for outgoing events. | |
void | Received (const Evt &evt) override |
Called when an event is received. | |
void | Received (const Req &req) override |
Called when a request is received. | |
void | Received (const Resp &resp) override |
Called when a response is received. | |
void | OnError (llvm::Error err) override |
Called when an error occurs while reading from the transport. | |
void | OnClosed () override |
Called on EOF or client disconnect. | |
Public Member Functions inherited from lldb_private::transport::JSONTransport< Proto >::MessageHandler | |
virtual | ~MessageHandler ()=default |
Private Types | |
using | Req = typename Proto::Req |
using | Resp = typename Proto::Resp |
using | Evt = typename Proto::Evt |
using | Id = typename Proto::Id |
using | Transport = JSONTransport<Proto> |
using | MessageHandler = typename Transport::MessageHandler |
template<typename T> | |
using | Callback = llvm::unique_function<T> |
Static Private Member Functions | |
template<typename T> | |
static llvm::Expected< T > | Parse (const llvm::json::Value &raw, llvm::StringRef method) |
Private Attributes | |
std::recursive_mutex | m_mutex |
Transport & | m_transport |
Id | m_seq |
std::map< Id, Callback< void(const Resp &)> > | m_pending_responses |
llvm::StringMap< Callback< void(const Req &, Callback< void(const Resp &)>)> > | m_request_handlers |
llvm::StringMap< Callback< void(const Evt &)> > | m_event_handlers |
Callback< void()> | m_disconnect_handler |
Callback< void(llvm::Error)> | m_error_handler |
Binder collects a table of functions that handle calls.
The wrapper takes care of parsing/serializing responses.
This allows a JSONTransport to handle incoming and outgoing requests and events.
A bind of an incoming request to a lambda.
A bind of an outgoing request.
Definition at line 487 of file JSONTransport.h.
|
private |
Definition at line 591 of file JSONTransport.h.
|
private |
Definition at line 490 of file JSONTransport.h.
|
private |
Definition at line 491 of file JSONTransport.h.
|
private |
Definition at line 493 of file JSONTransport.h.
|
private |
Definition at line 488 of file JSONTransport.h.
|
private |
Definition at line 489 of file JSONTransport.h.
|
private |
Definition at line 492 of file JSONTransport.h.
|
inlineexplicit |
Definition at line 496 of file JSONTransport.h.
|
delete |
OutgoingRequest< Result, Params > lldb_private::transport::Binder< Proto >::Bind | ( | llvm::StringLiteral | method | ) |
Bind a function object to be used for outgoing requests.
e.g. OutgoingRequest<Params, Result> Edit = bind("edit"); Params must be JSON-serializable, Result must be parsable.
Definition at line 767 of file JSONTransport.h.
References error(), m_mutex, m_pending_responses, m_seq, m_transport, OnError(), and Parse().
OutgoingEvent< Params > lldb_private::transport::Binder< Proto >::Bind | ( | llvm::StringLiteral | method | ) |
Bind a function object to be used for outgoing events.
e.g. OutgoingEvent<LogParams> Log = bind("log"); LogParams must be JSON-serializable.
Definition at line 835 of file JSONTransport.h.
References error(), m_transport, OnError(), and lldb_private::toJSON().
void lldb_private::transport::Binder< Proto >::Bind | ( | llvm::StringLiteral | method, |
Fn && | fn, | ||
Args &&... | args ) |
Bind a handler for an incoming request.
e.g. bind("peek", &ThisModule::peek, this);. Handler should be e.g. Expected<PeekResult> peek(const PeekParams&); PeekParams must be JSON parsable and PeekResult must be serializable.
Definition at line 680 of file JSONTransport.h.
References m_request_handlers, Parse(), and lldb_private::toJSON().
void lldb_private::transport::Binder< Proto >::Bind | ( | llvm::StringLiteral | method, |
Fn && | fn, | ||
Args &&... | args ) |
Bind a handler for an incoming event.
e.g. bind("peek", &ThisModule::peek, this); Handler should be e.g. void peek(const PeekParams&); PeekParams must be JSON parsable.
Definition at line 741 of file JSONTransport.h.
References m_event_handlers, OnError(), and Parse().
|
inlineoverridevirtual |
Called on EOF or client disconnect.
Implements lldb_private::transport::JSONTransport< Proto >::MessageHandler.
Definition at line 580 of file JSONTransport.h.
void lldb_private::transport::Binder< Proto >::OnDisconnect | ( | Fn && | fn, |
Args &&... | args ) |
Bind a handler on transport disconnect.
Definition at line 655 of file JSONTransport.h.
References m_disconnect_handler.
void lldb_private::transport::Binder< Proto >::OnError | ( | Fn && | fn, |
Args &&... | args ) |
Bind a handler on error when communicating with the transport.
Definition at line 667 of file JSONTransport.h.
References error(), and m_error_handler.
Referenced by Bind(), Bind(), lldb_private::transport::Binder< ProtocolDescriptor >::Received(), and lldb_private::transport::Binder< ProtocolDescriptor >::Received().
|
inlineoverridevirtual |
Called when an error occurs while reading from the transport.
NOTE: This does NOT indicate that a specific request failed, but that there was an error in the underlying transport.
Implements lldb_private::transport::JSONTransport< Proto >::MessageHandler.
Definition at line 574 of file JSONTransport.h.
|
delete |
|
staticprivate |
Definition at line 857 of file JSONTransport.h.
References lldb_private::fromJSON(), and lldb_private::OS.
|
inlineoverridevirtual |
Called when an event is received.
Implements lldb_private::transport::JSONTransport< Proto >::MessageHandler.
Definition at line 535 of file JSONTransport.h.
|
inlineoverridevirtual |
Called when a request is received.
Implements lldb_private::transport::JSONTransport< Proto >::MessageHandler.
Definition at line 546 of file JSONTransport.h.
|
inlineoverridevirtual |
Called when a response is received.
Implements lldb_private::transport::JSONTransport< Proto >::MessageHandler.
Definition at line 559 of file JSONTransport.h.
|
private |
Definition at line 600 of file JSONTransport.h.
Referenced by lldb_private::transport::Binder< ProtocolDescriptor >::OnClosed(), and OnDisconnect().
|
private |
Definition at line 601 of file JSONTransport.h.
Referenced by OnError(), and lldb_private::transport::Binder< ProtocolDescriptor >::OnError().
|
private |
Definition at line 599 of file JSONTransport.h.
Referenced by Bind().
|
private |
Definition at line 593 of file JSONTransport.h.
Referenced by Bind().
|
private |
Definition at line 596 of file JSONTransport.h.
Referenced by Bind().
|
private |
Definition at line 598 of file JSONTransport.h.
Referenced by Bind().
|
private |
Definition at line 595 of file JSONTransport.h.
Referenced by Bind().
|
private |
Definition at line 594 of file JSONTransport.h.
Referenced by Bind().