KiCad PCB EDA Suite
Loading...
Searching...
No Matches
api_handler_common.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2023 Jon Evans <[email protected]>
5 * Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <tuple>
22
24#include <build_version.h>
25#include <google/protobuf/empty.pb.h>
26#include <pgm_base.h>
30#include <wx/string.h>
31
32using namespace kiapi::common::commands;
33using namespace kiapi::common::types;
34using google::protobuf::Empty;
35
36
39{
40 registerHandler<commands::GetVersion, GetVersionResponse>( &API_HANDLER_COMMON::handleGetVersion );
41 registerHandler<GetNetClasses, NetClassesResponse>( &API_HANDLER_COMMON::handleGetNetClasses );
42 registerHandler<Ping, Empty>( &API_HANDLER_COMMON::handlePing );
43}
44
45
47 const HANDLER_CONTEXT& )
48{
49 GetVersionResponse reply;
50
51 reply.mutable_version()->set_full_version( GetBuildVersion().ToStdString() );
52
53 std::tuple<int, int, int> version = GetMajorMinorPatchTuple();
54 reply.mutable_version()->set_major( std::get<0>( version ) );
55 reply.mutable_version()->set_minor( std::get<1>( version ) );
56 reply.mutable_version()->set_patch( std::get<2>( version ) );
57
58 return reply;
59}
60
61
63 const HANDLER_CONTEXT& aCtx )
64{
65 NetClassesResponse reply;
66
67 std::shared_ptr<NET_SETTINGS>& netSettings =
69
70 for( const auto& [name, netClass] : netSettings->GetNetclasses() )
71 {
72 reply.add_net_classes()->set_name( name.ToStdString() );
73 }
74
75 return reply;
76}
77
78
80{
81 return Empty();
82}
const char * name
Definition: DXF_plotter.cpp:57
tl::expected< T, ApiResponseStatus > HANDLER_RESULT
Definition: api_handler.h:45
const std::tuple< int, int, int > & GetMajorMinorPatchTuple()
Get the build version numbers as a tuple.
wxString GetBuildVersion()
Get the full KiCad version string.
HANDLER_RESULT< commands::GetVersionResponse > handleGetVersion(commands::GetVersion &aMsg, const HANDLER_CONTEXT &aCtx)
HANDLER_RESULT< commands::NetClassesResponse > handleGetNetClasses(commands::GetNetClasses &aMsg, const HANDLER_CONTEXT &aCtx)
HANDLER_RESULT< Empty > handlePing(commands::Ping &aMsg, const HANDLER_CONTEXT &aCtx)
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:142
std::shared_ptr< NET_SETTINGS > m_NetSettings
Net settings for this project (owned here)
Definition: project_file.h:178
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:200
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1060
see class PGM_BASE