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_SOURCE_PLUGINS_PROTOCOL_MCP_PROTOCOLSERVERMCP_H
10#define LLDB_SOURCE_PLUGINS_PROTOCOL_MCP_PROTOCOLSERVERMCP_H
11
13#include "lldb/Host/MainLoop.h"
14#include "lldb/Host/Socket.h"
16#include "llvm/ADT/StringRef.h"
17#include "llvm/Support/Error.h"
18#include <cstddef>
19#include <memory>
20#include <mutex>
21#include <thread>
22#include <vector>
23
25
27
28 using ServerUP = std::unique_ptr<lldb_protocol::mcp::Server>;
29
31
32public:
34 ~ProtocolServerMCP() override;
35
36 llvm::Error Start(ProtocolServer::Connection connection) override;
37 llvm::Error Stop() override;
38
39 static void Initialize();
40 static void Terminate();
41
42 static llvm::StringRef GetPluginNameStatic() { return "MCP"; }
43 static llvm::StringRef GetPluginDescriptionStatic();
44
46
47 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
48
49 Socket *GetSocket() const override { return m_listener.get(); }
50
51protected:
52 // This adds tools and resource providers that
53 // are specific to this server. Overridable by the unit tests.
54 virtual void Extend(lldb_protocol::mcp::Server &server) const;
55
56private:
57 void AcceptCallback(std::unique_ptr<Socket> socket);
58
59 bool m_running = false;
60
62 std::thread m_loop_thread;
63 std::mutex m_mutex;
64 size_t m_client_count = 0;
65
66 std::unique_ptr<Socket> m_listener;
67 std::vector<ReadHandleUP> m_accept_handles;
68
71};
72
73} // namespace lldb_private::mcp
74
75#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