LLDB mainline
ProtocolServerMCP.h
Go to the documentation of this file.
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-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_PLUGINS_PROTOCOL_MCP_PROTOCOLSERVERMCP_H
10#define LLDB_PLUGINS_PROTOCOL_MCP_PROTOCOLSERVERMCP_H
11
13#include "lldb/Host/MainLoop.h"
14#include "lldb/Host/Socket.h"
17#include <map>
18#include <memory>
19#include <thread>
20#include <tuple>
21#include <vector>
22
24
26
27 using ServerUP = std::unique_ptr<lldb_protocol::mcp::Server>;
28
30
31public:
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
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 that
52 // 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
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
70};
71
72} // namespace lldb_private::mcp
73
74#endif
std::unique_ptr< ReadHandle > ReadHandleUP
std::unique_ptr< Socket > m_listener
virtual void Extend(lldb_protocol::mcp::Server &server) const
llvm::Error Start(ProtocolServer::Connection connection) override
Socket * GetSocket() const override
std::unique_ptr< lldb_protocol::mcp::Server > ServerUP
std::vector< ReadHandleUP > m_accept_handles
static lldb::ProtocolServerUP CreateInstance()
llvm::StringRef GetPluginName() override
void AcceptCallback(std::unique_ptr< Socket > socket)
static llvm::StringRef GetPluginNameStatic()
lldb_protocol::mcp::ServerInfoHandle m_server_info_handle
static llvm::StringRef GetPluginDescriptionStatic()
A handle that tracks the server info on disk and cleans up the disk record once it is no longer refer...
Definition Server.h:100
MainLoopPosix MainLoop
Definition MainLoop.h:20
std::unique_ptr< lldb_private::ProtocolServer > ProtocolServerUP