You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.7 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2023 Jon Evans <jon@craftyjon.com>
  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. #include <tuple>
  21. #include <api/api_handler_common.h>
  22. #include <build_version.h>
  23. #include <google/protobuf/empty.pb.h>
  24. #include <pgm_base.h>
  25. #include <project/net_settings.h>
  26. #include <project/project_file.h>
  27. #include <settings/settings_manager.h>
  28. #include <wx/string.h>
  29. using namespace kiapi::common::commands;
  30. using namespace kiapi::common::types;
  31. using google::protobuf::Empty;
  32. API_HANDLER_COMMON::API_HANDLER_COMMON() :
  33. API_HANDLER()
  34. {
  35. registerHandler<commands::GetVersion, GetVersionResponse>( &API_HANDLER_COMMON::handleGetVersion );
  36. registerHandler<GetNetClasses, NetClassesResponse>( &API_HANDLER_COMMON::handleGetNetClasses );
  37. registerHandler<Ping, Empty>( &API_HANDLER_COMMON::handlePing );
  38. }
  39. HANDLER_RESULT<GetVersionResponse> API_HANDLER_COMMON::handleGetVersion( commands::GetVersion&,
  40. const HANDLER_CONTEXT& )
  41. {
  42. GetVersionResponse reply;
  43. reply.mutable_version()->set_full_version( GetBuildVersion().ToStdString() );
  44. std::tuple<int, int, int> version = GetMajorMinorPatchTuple();
  45. reply.mutable_version()->set_major( std::get<0>( version ) );
  46. reply.mutable_version()->set_minor( std::get<1>( version ) );
  47. reply.mutable_version()->set_patch( std::get<2>( version ) );
  48. return reply;
  49. }
  50. HANDLER_RESULT<NetClassesResponse> API_HANDLER_COMMON::handleGetNetClasses( GetNetClasses& aMsg,
  51. const HANDLER_CONTEXT& aCtx )
  52. {
  53. NetClassesResponse reply;
  54. std::shared_ptr<NET_SETTINGS>& netSettings =
  55. Pgm().GetSettingsManager().Prj().GetProjectFile().m_NetSettings;
  56. for( const auto& [name, netClass] : netSettings->m_NetClasses )
  57. {
  58. reply.add_net_classes()->set_name( name.ToStdString() );
  59. }
  60. return reply;
  61. }
  62. HANDLER_RESULT<Empty> API_HANDLER_COMMON::handlePing( Ping& aMsg, const HANDLER_CONTEXT& aCtx )
  63. {
  64. return Empty();
  65. }