1//===-- ProtocolServer.cpp ------------------------------------------------===//
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#include "lldb/Core/ProtocolServer.h"
10#include "lldb/Core/PluginManager.h"
11
12using namespace lldb_private;
13using namespace lldb;
14
15ProtocolServer *ProtocolServer::GetOrCreate(llvm::StringRef name) {
16 static std::mutex g_mutex;
17 static llvm::StringMap<ProtocolServerUP> g_protocol_server_instances;
18
19 std::lock_guard<std::mutex> guard(g_mutex);
20
21 auto it = g_protocol_server_instances.find(Key: name);
22 if (it != g_protocol_server_instances.end())
23 return it->second.get();
24
25 if (ProtocolServerCreateInstance create_callback =
26 PluginManager::GetProtocolCreateCallbackForPluginName(name)) {
27 auto pair =
28 g_protocol_server_instances.try_emplace(Key: name, Args: create_callback());
29 return pair.first->second.get();
30 }
31
32 return nullptr;
33}
34
35std::vector<llvm::StringRef> ProtocolServer::GetSupportedProtocols() {
36 std::vector<llvm::StringRef> supported_protocols;
37 size_t i = 0;
38
39 for (llvm::StringRef protocol_name =
40 PluginManager::GetProtocolServerPluginNameAtIndex(idx: i++);
41 !protocol_name.empty();
42 protocol_name = PluginManager::GetProtocolServerPluginNameAtIndex(idx: i++)) {
43 supported_protocols.push_back(x: protocol_name);
44 }
45
46 return supported_protocols;
47}
48

source code of lldb/source/Core/ProtocolServer.cpp