LLDB mainline
lldb_private::transport::Binder< Proto > Class Template Reference

Binder collects a table of functions that handle calls. More...

#include <JSONTransport.h>

Inheritance diagram for lldb_private::transport::Binder< Proto >:
[legend]

Classes

class  ReplyOnce
 Function object to reply to a call. More...

Public Member Functions

 Binder (Transport &transport)
 Binder (const Binder &)=delete
Binderoperator= (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 Result, typename Params, typename Fn, typename... Args>
void BindAsync (llvm::StringLiteral method, Fn &&fn, Args &&...args)
 Bind an asynchronous 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.
void FailPendingRequests (llvm::StringRef reason)
 Fails every in-flight outgoing request, invoking its reply with an error.
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
Transportm_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

Detailed Description

template<typename Proto>
class lldb_private::transport::Binder< Proto >

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.

Binder binder{transport};
binder.bind<int, vector<int>>("adder", [](const vector<int> &params) {
int sum = 0;
for (int v : params)
sum += v;
return sum;
});
Binder(Transport &transport)

A bind of an outgoing request.

binder.bind<int, vector<int>>("add");
call_add({1,2,3}, [](Expected<int> result) {
cout << *result << "\n";
});
typename detail::request_t< R, P >::type OutgoingRequest

Definition at line 488 of file JSONTransport.h.

Member Typedef Documentation

◆ Callback

template<typename Proto>
template<typename T>
using lldb_private::transport::Binder< Proto >::Callback = llvm::unique_function<T>
private

Definition at line 622 of file JSONTransport.h.

◆ Evt

template<typename Proto>
using lldb_private::transport::Binder< Proto >::Evt = typename Proto::Evt
private

Definition at line 491 of file JSONTransport.h.

◆ Id

template<typename Proto>
using lldb_private::transport::Binder< Proto >::Id = typename Proto::Id
private

Definition at line 492 of file JSONTransport.h.

◆ MessageHandler

template<typename Proto>
using lldb_private::transport::Binder< Proto >::MessageHandler = typename Transport::MessageHandler
private

Definition at line 494 of file JSONTransport.h.

◆ Req

template<typename Proto>
using lldb_private::transport::Binder< Proto >::Req = typename Proto::Req
private

Definition at line 489 of file JSONTransport.h.

◆ Resp

template<typename Proto>
using lldb_private::transport::Binder< Proto >::Resp = typename Proto::Resp
private

Definition at line 490 of file JSONTransport.h.

◆ Transport

template<typename Proto>
using lldb_private::transport::Binder< Proto >::Transport = JSONTransport<Proto>
private

Definition at line 493 of file JSONTransport.h.

Constructor & Destructor Documentation

◆ Binder() [1/2]

template<typename Proto>
lldb_private::transport::Binder< Proto >::Binder ( Transport & transport)
inlineexplicit

Definition at line 497 of file JSONTransport.h.

◆ Binder() [2/2]

template<typename Proto>
lldb_private::transport::Binder< Proto >::Binder ( const Binder< Proto > & )
delete

Member Function Documentation

◆ Bind() [1/4]

template<typename Proto>
template<typename Result, typename Params>
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 798 of file JSONTransport.h.

References error(), m_mutex, m_pending_responses, m_seq, m_transport, OnError(), and Parse().

◆ Bind() [2/4]

template<typename Proto>
template<typename Params>
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 866 of file JSONTransport.h.

References error(), m_transport, OnError(), and lldb_private::toJSON().

◆ Bind() [3/4]

template<typename Proto>
template<typename Result, typename Params, typename Fn, typename... Args>
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 711 of file JSONTransport.h.

References m_request_handlers, Parse(), and lldb_private::toJSON().

◆ Bind() [4/4]

template<typename Proto>
template<typename Params, typename Fn, typename... Args>
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 772 of file JSONTransport.h.

References m_event_handlers, OnError(), and Parse().

◆ BindAsync()

template<typename Proto>
template<typename Result, typename Params, typename Fn, typename... Args>
void lldb_private::transport::Binder< Proto >::BindAsync ( llvm::StringLiteral method,
Fn && fn,
Args &&... args )

Bind an asynchronous handler for an incoming request.

The handler receives a Reply to invoke later instead of returning a result. This lets it defer the response, e.g. until a request it forwarded elsewhere is answered. Handler should be e.g. void peek(const PeekParams&, Reply<PeekResult>); PeekParams must be JSON parsable and PeekResult must be serializable.

Definition at line 908 of file JSONTransport.h.

References m_request_handlers, Parse(), and lldb_private::toJSON().

◆ FailPendingRequests()

template<typename Proto>
void lldb_private::transport::Binder< Proto >::FailPendingRequests ( llvm::StringRef reason)
inline

Fails every in-flight outgoing request, invoking its reply with an error.

Call when the connection is going away, so pending replies are satisfied rather than destroyed unanswered.

Definition at line 607 of file JSONTransport.h.

◆ OnClosed()

template<typename Proto>
void lldb_private::transport::Binder< Proto >::OnClosed ( )
inlineoverridevirtual

Called on EOF or client disconnect.

Implements lldb_private::transport::JSONTransport< Proto >::MessageHandler.

Definition at line 589 of file JSONTransport.h.

◆ OnDisconnect()

template<typename Proto>
template<typename Fn, typename... Args>
void lldb_private::transport::Binder< Proto >::OnDisconnect ( Fn && fn,
Args &&... args )

Bind a handler on transport disconnect.

Definition at line 686 of file JSONTransport.h.

References m_disconnect_handler.

◆ OnError() [1/2]

template<typename Proto>
template<typename Fn, typename... Args>
void lldb_private::transport::Binder< Proto >::OnError ( Fn && fn,
Args &&... args )

Bind a handler on error when communicating with the transport.

Definition at line 698 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().

◆ OnError() [2/2]

template<typename Proto>
void lldb_private::transport::Binder< Proto >::OnError ( llvm::Error )
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 583 of file JSONTransport.h.

◆ operator=()

template<typename Proto>
Binder & lldb_private::transport::Binder< Proto >::operator= ( const Binder< Proto > & )
delete

◆ Parse()

template<typename Proto>
template<typename T>
llvm::Expected< T > lldb_private::transport::Binder< Proto >::Parse ( const llvm::json::Value & raw,
llvm::StringRef method )
staticprivate

Definition at line 888 of file JSONTransport.h.

References lldb_private::fromJSON(), and lldb_private::OS.

Referenced by Bind(), Bind(), and BindAsync().

◆ Received() [1/3]

template<typename Proto>
void lldb_private::transport::Binder< Proto >::Received ( const Evt & )
inlineoverridevirtual

Called when an event is received.

Implements lldb_private::transport::JSONTransport< Proto >::MessageHandler.

Definition at line 544 of file JSONTransport.h.

◆ Received() [2/3]

template<typename Proto>
void lldb_private::transport::Binder< Proto >::Received ( const Req & )
inlineoverridevirtual

Called when a request is received.

Implements lldb_private::transport::JSONTransport< Proto >::MessageHandler.

Definition at line 555 of file JSONTransport.h.

◆ Received() [3/3]

template<typename Proto>
void lldb_private::transport::Binder< Proto >::Received ( const Resp & )
inlineoverridevirtual

Called when a response is received.

Implements lldb_private::transport::JSONTransport< Proto >::MessageHandler.

Definition at line 568 of file JSONTransport.h.

Member Data Documentation

◆ m_disconnect_handler

template<typename Proto>
Callback<void()> lldb_private::transport::Binder< Proto >::m_disconnect_handler
private

Definition at line 631 of file JSONTransport.h.

Referenced by OnDisconnect().

◆ m_error_handler

template<typename Proto>
Callback<void(llvm::Error)> lldb_private::transport::Binder< Proto >::m_error_handler
private

◆ m_event_handlers

template<typename Proto>
llvm::StringMap<Callback<void(const Evt &)> > lldb_private::transport::Binder< Proto >::m_event_handlers
private

Definition at line 630 of file JSONTransport.h.

Referenced by Bind().

◆ m_mutex

template<typename Proto>
std::recursive_mutex lldb_private::transport::Binder< Proto >::m_mutex
private

Definition at line 624 of file JSONTransport.h.

Referenced by Bind().

◆ m_pending_responses

template<typename Proto>
std::map<Id, Callback<void(const Resp &)> > lldb_private::transport::Binder< Proto >::m_pending_responses
private

Definition at line 627 of file JSONTransport.h.

Referenced by Bind().

◆ m_request_handlers

template<typename Proto>
llvm::StringMap<Callback<void(const Req &, Callback<void(const Resp &)>)> > lldb_private::transport::Binder< Proto >::m_request_handlers
private

Definition at line 629 of file JSONTransport.h.

Referenced by Bind(), and BindAsync().

◆ m_seq

template<typename Proto>
Id lldb_private::transport::Binder< Proto >::m_seq
private

Definition at line 626 of file JSONTransport.h.

Referenced by Bind().

◆ m_transport

template<typename Proto>
Transport& lldb_private::transport::Binder< Proto >::m_transport
private

Definition at line 625 of file JSONTransport.h.

Referenced by Bind().


The documentation for this class was generated from the following file: