brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · e0f2a6c Raw
75 lines · c
1//===- ProtocolServerMCP.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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLDB_PLUGINS_PROTOCOL_MCP_PROTOCOLSERVERMCP_H10#define LLDB_PLUGINS_PROTOCOL_MCP_PROTOCOLSERVERMCP_H11 12#include "lldb/Core/ProtocolServer.h"13#include "lldb/Host/MainLoop.h"14#include "lldb/Host/Socket.h"15#include "lldb/Protocol/MCP/Server.h"16#include "lldb/Protocol/MCP/Transport.h"17#include <map>18#include <memory>19#include <thread>20#include <tuple>21#include <vector>22 23namespace lldb_private::mcp {24 25class ProtocolServerMCP : public ProtocolServer {26 27  using ServerUP = std::unique_ptr<lldb_protocol::mcp::Server>;28 29  using ReadHandleUP = MainLoop::ReadHandleUP;30 31public:32  ProtocolServerMCP();33  ~ProtocolServerMCP() override;34 35  llvm::Error Start(ProtocolServer::Connection connection) override;36  llvm::Error Stop() override;37 38  static void Initialize();39  static void Terminate();40 41  static llvm::StringRef GetPluginNameStatic() { return "MCP"; }42  static llvm::StringRef GetPluginDescriptionStatic();43 44  static lldb::ProtocolServerUP CreateInstance();45 46  llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }47 48  Socket *GetSocket() const override { return m_listener.get(); }49 50protected:51  // This adds tools and resource providers that52  // are specific to this server. Overridable by the unit tests.53  virtual void Extend(lldb_protocol::mcp::Server &server) const;54 55private:56  void AcceptCallback(std::unique_ptr<Socket> socket);57 58  bool m_running = false;59 60  lldb_private::MainLoop m_loop;61  std::thread m_loop_thread;62  std::mutex m_mutex;63  size_t m_client_count = 0;64 65  std::unique_ptr<Socket> m_listener;66  std::vector<ReadHandleUP> m_accept_handles;67 68  ServerUP m_server;69  lldb_protocol::mcp::ServerInfoHandle m_server_info_handle;70};71 72} // namespace lldb_private::mcp73 74#endif75