| 1 | //===-- ResponseHandler.h -------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLDB_TOOLS_LLDB_DAP_HANDLER_RESPONSEHANDLER_H |
| 10 | #define LLDB_TOOLS_LLDB_DAP_HANDLER_RESPONSEHANDLER_H |
| 11 | |
| 12 | #include "llvm/ADT/StringRef.h" |
| 13 | #include "llvm/Support/JSON.h" |
| 14 | #include <cstdint> |
| 15 | |
| 16 | namespace lldb_dap { |
| 17 | struct DAP; |
| 18 | |
| 19 | /// Handler for responses to reverse requests. |
| 20 | class ResponseHandler { |
| 21 | public: |
| 22 | ResponseHandler(llvm::StringRef command, int64_t id) |
| 23 | : m_command(command), m_id(id) {} |
| 24 | |
| 25 | /// ResponseHandlers are not copyable. |
| 26 | /// @{ |
| 27 | ResponseHandler(const ResponseHandler &) = delete; |
| 28 | ResponseHandler &operator=(const ResponseHandler &) = delete; |
| 29 | /// @} |
| 30 | |
| 31 | virtual ~ResponseHandler() = default; |
| 32 | |
| 33 | virtual void operator()(llvm::Expected<llvm::json::Value> value) const = 0; |
| 34 | |
| 35 | protected: |
| 36 | llvm::StringRef m_command; |
| 37 | int64_t m_id; |
| 38 | }; |
| 39 | |
| 40 | /// Response handler used for unknown responses. |
| 41 | class UnknownResponseHandler : public ResponseHandler { |
| 42 | public: |
| 43 | using ResponseHandler::ResponseHandler; |
| 44 | void operator()(llvm::Expected<llvm::json::Value> value) const override; |
| 45 | }; |
| 46 | |
| 47 | /// Response handler which logs to stderr in case of a failure. |
| 48 | class LogFailureResponseHandler : public ResponseHandler { |
| 49 | public: |
| 50 | using ResponseHandler::ResponseHandler; |
| 51 | void operator()(llvm::Expected<llvm::json::Value> value) const override; |
| 52 | }; |
| 53 | |
| 54 | } // namespace lldb_dap |
| 55 | |
| 56 | #endif |
| 57 | |