Path: blob/main/contrib/llvm-project/lldb/source/Core/ProtocolServer.cpp
213764 views
//===-- ProtocolServer.cpp ------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/Core/ProtocolServer.h"9#include "lldb/Core/PluginManager.h"1011using namespace lldb_private;12using namespace lldb;1314ProtocolServer *ProtocolServer::GetOrCreate(llvm::StringRef name) {15static std::mutex g_mutex;16static llvm::StringMap<ProtocolServerUP> g_protocol_server_instances;1718std::lock_guard<std::mutex> guard(g_mutex);1920auto it = g_protocol_server_instances.find(name);21if (it != g_protocol_server_instances.end())22return it->second.get();2324if (ProtocolServerCreateInstance create_callback =25PluginManager::GetProtocolCreateCallbackForPluginName(name)) {26auto pair =27g_protocol_server_instances.try_emplace(name, create_callback());28return pair.first->second.get();29}3031return nullptr;32}3334std::vector<llvm::StringRef> ProtocolServer::GetSupportedProtocols() {35std::vector<llvm::StringRef> supported_protocols;36size_t i = 0;3738for (llvm::StringRef protocol_name =39PluginManager::GetProtocolServerPluginNameAtIndex(i++);40!protocol_name.empty();41protocol_name = PluginManager::GetProtocolServerPluginNameAtIndex(i++)) {42supported_protocols.push_back(protocol_name);43}4445return supported_protocols;46}474849