================ @@ -54,112 +50,226 @@ class TransportUnhandledContentsError std::string m_unhandled_contents; }; -class TransportInvalidError : public llvm::ErrorInfo<TransportInvalidError> { +/// A transport is responsible for maintaining the connection to a client +/// application, and reading/writing structured messages to it. +/// +/// Transports have limited thread safety requirements: +/// - Messages will not be sent concurrently. +/// - Messages MAY be sent while Run() is reading, or its callback is active. +template <typename Req, typename Resp, typename Evt> class Transport { public: - static char ID; - - TransportInvalidError() = default; + using Message = std::variant<Req, Resp, Evt>; + + virtual ~Transport() = default; + + /// Sends an event, a message that does not require a response. + virtual llvm::Error Event(const Evt &) = 0; + /// Sends a request, a message that expects a response. + virtual llvm::Error Request(const Req &) = 0; + /// Sends a response to a specific request. + virtual llvm::Error Response(const Resp &) = 0; + + /// Implemented to handle incoming messages. (See Run() below). + class MessageHandler { + public: + virtual ~MessageHandler() = default; + /// Called when an event is received. + virtual void OnEvent(const Evt &) = 0; + /// Called when a request is received. + virtual void OnRequest(const Req &) = 0; + /// Called when a response is received. + virtual void OnResponse(const Resp &) = 0; + + /// 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. + virtual void OnError(MainLoopBase &, llvm::Error) = 0; ---------------- labath wrote:
It's kinda weird that this is the only method that takes a mainloop argument. FWICS, this is only needed for the test as the real implementation holds a MainLoop variable anyway. Could the test version do the same? https://github.com/llvm/llvm-project/pull/153121 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits