24#include <api/common/envelope.pb.h>
29#include <fmt/format.h>
36static bool sendRequest(
const std::string& aUrl,
const google::protobuf::Message& aRequest )
40 if( !client.
Connect( wxString::FromUTF8( aUrl ) ) )
43 wxString::Format( wxS(
"crossprobe: failed to connect to %s" ), wxString::FromUTF8( aUrl ) ) );
47 kiapi::common::ApiResponse response;
52 wxString::Format( wxS(
"crossprobe: failed to send to %s" ), wxString::FromUTF8( aUrl ) ) );
56 return response.status().status() == kiapi::common::AS_OK;
62 std::optional<std::string> targetUrl;
65 std::lock_guard<std::mutex> lock(
s_mutex );
67 if(
s_peers.contains( aTarget ) )
68 targetUrl =
s_peers.at( aTarget );
89 wxLogTrace(
traceApi, wxS(
"crossprobe: API server is not running, cannot announce" ) );
96 if( primaryUrl == ourUrl )
99 kiapi::common::commands::CrossProbeAnnounce announce;
100 announce.set_frame_type(
static_cast<kiapi::common::types::FrameType
>( aFrameType ) );
101 announce.set_socket_path( ourUrl );
102 announce.set_api_token( server.
Token() );
106 if( !client.
Connect( wxString::FromUTF8( primaryUrl ) ) )
108 wxLogTrace(
traceApi, wxString::Format( wxS(
"crossprobe: failed to connect to primary at %s" ),
109 wxString::FromUTF8( primaryUrl ) ) );
115 wxLogTrace(
traceApi, wxString::Format( wxS(
"crossprobe: announced frame %d to primary at %s" ), aFrameType,
116 wxString::FromUTF8( primaryUrl ) ) );
123 std::lock_guard<std::mutex> lock(
s_mutex );
124 s_peers[aFrameType] = aSocketPath;
static bool IsOnStandardSocketPath()
static void RegisterPeer(FRAME_T aFrameType, const std::string &aSocketPath)
static bool SendToFrame(FRAME_T aTarget, const google::protobuf::Message &aRequest)
static std::mutex s_mutex
static std::map< FRAME_T, std::string > s_peers
static void AnnounceToPrimary(FRAME_T aFrameType)
bool Connect(const wxString &aSocketUrl)
bool Send(const google::protobuf::Message &aRequest, kiapi::common::ApiResponse &aResponse, const std::string &aClientName="kicad")
Send a protobuf request to the KiCad API server and wait for a response.
const std::string & Token() const
std::string SocketPath() const
static std::string StandardSocketUrl()
Return the default API socket URL (including the ipc:// scheme).
KICAD_API_SERVER & GetApiServer()
static bool sendRequest(const std::string &aUrl, const google::protobuf::Message &aRequest)
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
const wxChar *const traceApi
Flag to enable debug output related to the IPC API and its plugin system.
const KICOMMON_API std::string StandaloneCrossProbeClientName
PGM_BASE & Pgm()
The global program "get" accessor.