Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
Add package version API (#22)
Browse files Browse the repository at this point in the history
* Add package version API

* Fix message type

* Fix ament index

* Modify api name
  • Loading branch information
isamu-takagi authored Oct 20, 2021
1 parent 9b06833 commit 22fc3a8
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
2 changes: 2 additions & 0 deletions autoware_iv_external_api_adaptor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ ament_auto_add_library(${PROJECT_NAME} SHARED
src/engage.cpp
src/initial_pose.cpp
src/map.cpp
src/metadata_packages.cpp
src/operator.cpp
src/route.cpp
src/service.cpp
Expand All @@ -35,6 +36,7 @@ rclcpp_components_register_nodes(${PROJECT_NAME} "external_api::Engage")
rclcpp_components_register_nodes(${PROJECT_NAME} "external_api::InitialPose")
rclcpp_components_register_nodes(${PROJECT_NAME} "external_api::Map")
rclcpp_components_register_nodes(${PROJECT_NAME} "external_api::Operator")
rclcpp_components_register_nodes(${PROJECT_NAME} "external_api::MetadataPackages")
rclcpp_components_register_nodes(${PROJECT_NAME} "external_api::Route")
rclcpp_components_register_nodes(${PROJECT_NAME} "external_api::Service")
rclcpp_components_register_nodes(${PROJECT_NAME} "external_api::Start")
Expand Down
1 change: 1 addition & 0 deletions autoware_iv_external_api_adaptor/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<depend>autoware_external_api_msgs</depend>
<depend>autoware_system_msgs</depend>
<depend>autoware_vehicle_msgs</depend>
<depend>nlohmann-json-dev</depend>
<depend>rclcpp</depend>
<depend>rclcpp_components</depend>
<depend>std_srvs</depend>
Expand Down
59 changes: 59 additions & 0 deletions autoware_iv_external_api_adaptor/src/metadata_packages.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2021 Tier IV, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "metadata_packages.hpp"
#include <string>
#include "ament_index_cpp/get_resources.hpp"
#include "ament_index_cpp/get_resource.hpp"
#include "nlohmann/json.hpp"

namespace external_api
{

MetadataPackages::MetadataPackages(const rclcpp::NodeOptions & options)
: Node("external_api_metadata_packages", options)
{
using namespace std::placeholders;
autoware_api_utils::ServiceProxyNodeInterface proxy(this);

const auto resources = ament_index_cpp::get_resources("autoware_metadata_packages");
nlohmann::json json = nlohmann::json::object();
for (const auto & resource : resources) {
const std::string & package = resource.first;
std::string content;
ament_index_cpp::get_resource("autoware_metadata_packages", package, content);
json[package] = nlohmann::json::parse(content);
}
metadata_.format = "1";
metadata_.json = json.dump();

group_ = create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
srv_ = proxy.create_service<autoware_external_api_msgs::srv::GetMetadataPackages>(
"/api/external/get/metadata/packages",
std::bind(&MetadataPackages::getVersions, this, _1, _2),
rmw_qos_profile_services_default, group_);
}

void MetadataPackages::getVersions(
const autoware_external_api_msgs::srv::GetMetadataPackages::Request::SharedPtr,
const autoware_external_api_msgs::srv::GetMetadataPackages::Response::SharedPtr response)
{
response->metadata = metadata_;
response->status = autoware_api_utils::response_success();
}

} // namespace external_api

#include "rclcpp_components/register_node_macro.hpp"
RCLCPP_COMPONENTS_REGISTER_NODE(external_api::MetadataPackages)
46 changes: 46 additions & 0 deletions autoware_iv_external_api_adaptor/src/metadata_packages.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2021 Tier IV, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef PACKAGE_VERSIONS_HPP_
#define PACKAGE_VERSIONS_HPP_

#include "rclcpp/rclcpp.hpp"
#include "autoware_api_utils/autoware_api_utils.hpp"
#include "autoware_external_api_msgs/srv/get_metadata_packages.hpp"

namespace external_api
{

class MetadataPackages : public rclcpp::Node
{
public:
explicit MetadataPackages(const rclcpp::NodeOptions & options);

private:
// ros interface
rclcpp::CallbackGroup::SharedPtr group_;
autoware_api_utils::Service<autoware_external_api_msgs::srv::GetMetadataPackages>::SharedPtr srv_;

// ros callback
void getVersions(
const autoware_external_api_msgs::srv::GetMetadataPackages::Request::SharedPtr request,
const autoware_external_api_msgs::srv::GetMetadataPackages::Response::SharedPtr response);

// data
autoware_external_api_msgs::msg::MetadataPackages metadata_;
};

} // namespace external_api

#endif // PACKAGE_VERSIONS_HPP_

0 comments on commit 22fc3a8

Please sign in to comment.