diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ec4b36..7446fbd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -154,6 +154,13 @@ google_binary(cartographer_compute_relations_metrics cartographer/ground_truth/compute_relations_metrics_main.cc ) +if(${BUILD_GRPC}) + google_binary(cartographer_grpc_server + SRCS + cartographer_grpc/map_builder_server_main.cc + ) +endif() + foreach(ABS_FIL ${ALL_TESTS}) file(RELATIVE_PATH REL_FIL ${PROJECT_SOURCE_DIR} ${ABS_FIL}) get_filename_component(DIR ${REL_FIL} DIRECTORY) @@ -195,6 +202,9 @@ target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC # TODO(hrapp): This should not explicitly list pthread and use # PROTOBUF_LIBRARIES, but that failed on first try. target_link_libraries(${PROJECT_NAME} PUBLIC ${PROTOBUF_LIBRARY} pthread) +if(${BUILD_GRPC}) + target_link_libraries(${PROJECT_NAME} PUBLIC grpc++) +endif() # Add the binary directory first, so that port.h is included after it has # been generated. diff --git a/cartographer_grpc/map_builder_server_main.cc b/cartographer_grpc/map_builder_server_main.cc new file mode 100644 index 0000000..4a2b6bb --- /dev/null +++ b/cartographer_grpc/map_builder_server_main.cc @@ -0,0 +1,58 @@ +/* + * Copyright 2017 The Cartographer Authors + * + * 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 "cartographer_grpc/map_builder_server.h" +#include "cartographer_grpc/map_builder_server_options.h" +#include "gflags/gflags.h" +#include "glog/logging.h" + +DEFINE_string(configuration_directory, "", + "First directory in which configuration files are searched, " + "second is always the Cartographer installation to allow " + "including files from there."); +DEFINE_string(configuration_basename, "", + "Basename, i.e. not containing any directory prefix, of the " + "configuration file."); + +namespace cartographer_grpc { + +void Run(const std::string& configuration_directory, + const std::string& configuration_basename) { + proto::MapBuilderServerOptions map_builder_server_options = + LoadMapBuilderServerOptions(configuration_directory, + configuration_basename); + MapBuilderServer map_builder_server(map_builder_server_options); + map_builder_server.Start(); + map_builder_server.WaitForShutdown(); +} + +} // namespace cartographer_grpc + +int main(int argc, char** argv) { + google::InitGoogleLogging(argv[0]); + FLAGS_logtostderr = true; + google::SetUsageMessage( + "\n\n" + "This program offers a MapBuilder service via a gRPC interface.\n"); + google::ParseCommandLineFlags(&argc, &argv, true); + if (FLAGS_configuration_directory.empty() || + FLAGS_configuration_basename.empty()) { + google::ShowUsageWithFlagsRestrict(argv[0], "cartographer_grpc_server"); + return EXIT_FAILURE; + } + cartographer_grpc::Run(FLAGS_configuration_directory, + FLAGS_configuration_basename); +} diff --git a/cartographer_grpc/map_builder_server_options.cc b/cartographer_grpc/map_builder_server_options.cc index 853704d..308c189 100644 --- a/cartographer_grpc/map_builder_server_options.cc +++ b/cartographer_grpc/map_builder_server_options.cc @@ -30,7 +30,8 @@ proto::MapBuilderServerOptions CreateMapBuilderServerOptions( map_builder_server_options.set_num_grpc_threads( lua_parameter_dictionary->GetInt("num_grpc_threads")); *map_builder_server_options.mutable_map_builder_options() = - cartographer::mapping::CreateMapBuilderOptions(lua_parameter_dictionary); + cartographer::mapping::CreateMapBuilderOptions( + lua_parameter_dictionary->GetDictionary("map_builder").get()); return map_builder_server_options; } diff --git a/configuration_files/map_builder_server.lua b/configuration_files/map_builder_server.lua new file mode 100644 index 0000000..da965f1 --- /dev/null +++ b/configuration_files/map_builder_server.lua @@ -0,0 +1,23 @@ +-- Copyright 2017 The Cartographer Authors +-- +-- 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 "map_builder.lua" + +options = { + server_address = "0.0.0.0:50051", + num_grpc_threads = 4, + map_builder = MAP_BUILDER, +} + +return options