Simplify Handler registration. (#865)
parent
708e7fc57d
commit
9aecf23a37
|
@ -57,7 +57,6 @@ class RpcHandler : public RpcHandlerInterface {
|
||||||
private:
|
private:
|
||||||
const std::weak_ptr<Rpc> rpc_;
|
const std::weak_ptr<Rpc> rpc_;
|
||||||
};
|
};
|
||||||
|
|
||||||
void SetExecutionContext(ExecutionContext* execution_context) override {
|
void SetExecutionContext(ExecutionContext* execution_context) override {
|
||||||
execution_context_ = execution_context;
|
execution_context_ = execution_context;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,12 @@ class Rpc;
|
||||||
class RpcHandlerInterface {
|
class RpcHandlerInterface {
|
||||||
public:
|
public:
|
||||||
virtual ~RpcHandlerInterface() = default;
|
virtual ~RpcHandlerInterface() = default;
|
||||||
|
// Returns the fully qualified name of the gRPC method this handler is
|
||||||
|
// implementing. The fully qualified name has the structure
|
||||||
|
// '/<<full service name>>/<<method name>>', where the service name is the
|
||||||
|
// fully qualified proto package name of the service and method name the name
|
||||||
|
// of the method as defined in the service definition of the proto.
|
||||||
|
virtual std::string method_name() const = 0;
|
||||||
virtual void SetExecutionContext(ExecutionContext* execution_context) = 0;
|
virtual void SetExecutionContext(ExecutionContext* execution_context) = 0;
|
||||||
virtual void SetRpc(Rpc* rpc) = 0;
|
virtual void SetRpc(Rpc* rpc) = 0;
|
||||||
virtual void OnRequestInternal(
|
virtual void OnRequestInternal(
|
||||||
|
|
|
@ -39,6 +39,18 @@ void Server::Builder::SetServerAddress(const std::string& server_address) {
|
||||||
options_.server_address = server_address;
|
options_.server_address = server_address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::tuple<std::string, std::string> Server::Builder::ParseMethodFullName(
|
||||||
|
const std::string& method_full_name) {
|
||||||
|
CHECK(method_full_name.at(0) == '/') << "Invalid method name.";
|
||||||
|
std::stringstream stream(method_full_name.substr(1));
|
||||||
|
std::string service_full_name;
|
||||||
|
std::getline(stream, service_full_name, '/');
|
||||||
|
std::string method_name;
|
||||||
|
std::getline(stream, method_name, '/');
|
||||||
|
CHECK(!service_full_name.empty() && !method_name.empty());
|
||||||
|
return std::make_tuple(service_full_name, method_name);
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<Server> Server::Builder::Build() {
|
std::unique_ptr<Server> Server::Builder::Build() {
|
||||||
std::unique_ptr<Server> server(new Server(options_));
|
std::unique_ptr<Server> server(new Server(options_));
|
||||||
for (const auto& service_handlers : rpc_handlers_) {
|
for (const auto& service_handlers : rpc_handlers_) {
|
||||||
|
|
|
@ -55,12 +55,14 @@ class Server {
|
||||||
void SetNumEventThreads(std::size_t num_event_threads);
|
void SetNumEventThreads(std::size_t num_event_threads);
|
||||||
void SetServerAddress(const std::string& server_address);
|
void SetServerAddress(const std::string& server_address);
|
||||||
|
|
||||||
template <typename RpcHandlerType, typename ServiceType>
|
template <typename RpcHandlerType>
|
||||||
void RegisterHandler(const std::string& method_name) {
|
void RegisterHandler() {
|
||||||
std::stringstream fully_qualified_name;
|
std::string method_full_name = GetMethodFullName<RpcHandlerType>();
|
||||||
fully_qualified_name << "/" << ServiceType::service_full_name() << "/"
|
std::string service_full_name;
|
||||||
<< method_name;
|
std::string method_name;
|
||||||
rpc_handlers_[ServiceType::service_full_name()].emplace(
|
std::tie(service_full_name, method_name) =
|
||||||
|
ParseMethodFullName(method_full_name);
|
||||||
|
rpc_handlers_[service_full_name].emplace(
|
||||||
method_name,
|
method_name,
|
||||||
RpcHandlerInfo{
|
RpcHandlerInfo{
|
||||||
RpcHandlerType::RequestType::default_instance().GetDescriptor(),
|
RpcHandlerType::RequestType::default_instance().GetDescriptor(),
|
||||||
|
@ -74,12 +76,21 @@ class Server {
|
||||||
},
|
},
|
||||||
RpcType<typename RpcHandlerType::IncomingType,
|
RpcType<typename RpcHandlerType::IncomingType,
|
||||||
typename RpcHandlerType::OutgoingType>::value,
|
typename RpcHandlerType::OutgoingType>::value,
|
||||||
fully_qualified_name.str()});
|
method_full_name});
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using ServiceInfo = std::map<std::string, RpcHandlerInfo>;
|
using ServiceInfo = std::map<std::string, RpcHandlerInfo>;
|
||||||
|
|
||||||
|
template <typename RpcHandlerType>
|
||||||
|
std::string GetMethodFullName() {
|
||||||
|
auto handler = cartographer::common::make_unique<const RpcHandlerType>();
|
||||||
|
return handler->method_name();
|
||||||
|
}
|
||||||
|
std::tuple<std::string /* service_full_name */,
|
||||||
|
std::string /* method_name */>
|
||||||
|
ParseMethodFullName(const std::string& method_full_name);
|
||||||
|
|
||||||
Options options_;
|
Options options_;
|
||||||
std::map<std::string, ServiceInfo> rpc_handlers_;
|
std::map<std::string, ServiceInfo> rpc_handlers_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "cartographer_grpc/framework/proto/math_service.pb.h"
|
#include "cartographer_grpc/framework/proto/math_service.pb.h"
|
||||||
#include "cartographer_grpc/framework/rpc_handler.h"
|
#include "cartographer_grpc/framework/rpc_handler.h"
|
||||||
#include "glog/logging.h"
|
#include "glog/logging.h"
|
||||||
|
#include "google/protobuf/descriptor.h"
|
||||||
#include "grpc++/grpc++.h"
|
#include "grpc++/grpc++.h"
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
@ -40,6 +41,9 @@ class MathServerContext : public ExecutionContext {
|
||||||
class GetSumHandler
|
class GetSumHandler
|
||||||
: public RpcHandler<Stream<proto::GetSumRequest>, proto::GetSumResponse> {
|
: public RpcHandler<Stream<proto::GetSumRequest>, proto::GetSumResponse> {
|
||||||
public:
|
public:
|
||||||
|
std::string method_name() const override {
|
||||||
|
return "/cartographer_grpc.framework.proto.Math/GetSum";
|
||||||
|
}
|
||||||
void OnRequest(const proto::GetSumRequest& request) override {
|
void OnRequest(const proto::GetSumRequest& request) override {
|
||||||
sum_ += GetContext<MathServerContext>()->additional_increment();
|
sum_ += GetContext<MathServerContext>()->additional_increment();
|
||||||
sum_ += request.input();
|
sum_ += request.input();
|
||||||
|
@ -58,6 +62,9 @@ class GetSumHandler
|
||||||
class GetRunningSumHandler : public RpcHandler<Stream<proto::GetSumRequest>,
|
class GetRunningSumHandler : public RpcHandler<Stream<proto::GetSumRequest>,
|
||||||
Stream<proto::GetSumResponse>> {
|
Stream<proto::GetSumResponse>> {
|
||||||
public:
|
public:
|
||||||
|
std::string method_name() const override {
|
||||||
|
return "/cartographer_grpc.framework.proto.Math/GetRunningSum";
|
||||||
|
}
|
||||||
void OnRequest(const proto::GetSumRequest& request) override {
|
void OnRequest(const proto::GetSumRequest& request) override {
|
||||||
sum_ += request.input();
|
sum_ += request.input();
|
||||||
|
|
||||||
|
@ -78,6 +85,10 @@ class GetRunningSumHandler : public RpcHandler<Stream<proto::GetSumRequest>,
|
||||||
|
|
||||||
class GetSquareHandler
|
class GetSquareHandler
|
||||||
: public RpcHandler<proto::GetSquareRequest, proto::GetSquareResponse> {
|
: public RpcHandler<proto::GetSquareRequest, proto::GetSquareResponse> {
|
||||||
|
public:
|
||||||
|
std::string method_name() const override {
|
||||||
|
return "/cartographer_grpc.framework.proto.Math/GetSquare";
|
||||||
|
}
|
||||||
void OnRequest(const proto::GetSquareRequest& request) override {
|
void OnRequest(const proto::GetSquareRequest& request) override {
|
||||||
auto response =
|
auto response =
|
||||||
cartographer::common::make_unique<proto::GetSquareResponse>();
|
cartographer::common::make_unique<proto::GetSquareResponse>();
|
||||||
|
@ -88,6 +99,10 @@ class GetSquareHandler
|
||||||
|
|
||||||
class GetEchoHandler
|
class GetEchoHandler
|
||||||
: public RpcHandler<proto::GetEchoRequest, proto::GetEchoResponse> {
|
: public RpcHandler<proto::GetEchoRequest, proto::GetEchoResponse> {
|
||||||
|
public:
|
||||||
|
std::string method_name() const override {
|
||||||
|
return "/cartographer_grpc.framework.proto.Math/GetEcho";
|
||||||
|
}
|
||||||
void OnRequest(const proto::GetEchoRequest& request) override {
|
void OnRequest(const proto::GetEchoRequest& request) override {
|
||||||
int value = request.input();
|
int value = request.input();
|
||||||
Writer writer = GetWriter();
|
Writer writer = GetWriter();
|
||||||
|
@ -105,6 +120,9 @@ class GetSequenceHandler
|
||||||
: public RpcHandler<proto::GetSequenceRequest,
|
: public RpcHandler<proto::GetSequenceRequest,
|
||||||
Stream<proto::GetSequenceResponse>> {
|
Stream<proto::GetSequenceResponse>> {
|
||||||
public:
|
public:
|
||||||
|
std::string method_name() const override {
|
||||||
|
return "/cartographer_grpc.framework.proto.Math/GetSequence";
|
||||||
|
}
|
||||||
void OnRequest(const proto::GetSequenceRequest& request) override {
|
void OnRequest(const proto::GetSequenceRequest& request) override {
|
||||||
for (int i = 0; i < request.input(); ++i) {
|
for (int i = 0; i < request.input(); ++i) {
|
||||||
auto response =
|
auto response =
|
||||||
|
@ -129,13 +147,11 @@ class ServerTest : public ::testing::Test {
|
||||||
server_builder.SetServerAddress(kServerAddress);
|
server_builder.SetServerAddress(kServerAddress);
|
||||||
server_builder.SetNumGrpcThreads(kNumThreads);
|
server_builder.SetNumGrpcThreads(kNumThreads);
|
||||||
server_builder.SetNumEventThreads(kNumThreads);
|
server_builder.SetNumEventThreads(kNumThreads);
|
||||||
server_builder.RegisterHandler<GetSumHandler, proto::Math>("GetSum");
|
server_builder.RegisterHandler<GetSumHandler>();
|
||||||
server_builder.RegisterHandler<GetSquareHandler, proto::Math>("GetSquare");
|
server_builder.RegisterHandler<GetSquareHandler>();
|
||||||
server_builder.RegisterHandler<GetRunningSumHandler, proto::Math>(
|
server_builder.RegisterHandler<GetRunningSumHandler>();
|
||||||
"GetRunningSum");
|
server_builder.RegisterHandler<GetEchoHandler>();
|
||||||
server_builder.RegisterHandler<GetEchoHandler, proto::Math>("GetEcho");
|
server_builder.RegisterHandler<GetSequenceHandler>();
|
||||||
server_builder.RegisterHandler<GetSequenceHandler, proto::Math>(
|
|
||||||
"GetSequence");
|
|
||||||
server_ = server_builder.Build();
|
server_ = server_builder.Build();
|
||||||
|
|
||||||
client_channel_ =
|
client_channel_ =
|
||||||
|
|
|
@ -32,6 +32,9 @@ class AddFixedFramePoseDataHandler
|
||||||
framework::Stream<proto::AddFixedFramePoseDataRequest>,
|
framework::Stream<proto::AddFixedFramePoseDataRequest>,
|
||||||
google::protobuf::Empty> {
|
google::protobuf::Empty> {
|
||||||
public:
|
public:
|
||||||
|
std::string method_name() const override {
|
||||||
|
return "/cartographer_grpc.proto.MapBuilderService/AddFixedFramePoseData";
|
||||||
|
}
|
||||||
void OnRequest(const proto::AddFixedFramePoseDataRequest &request) override {
|
void OnRequest(const proto::AddFixedFramePoseDataRequest &request) override {
|
||||||
// The 'BlockingQueue' returned by 'sensor_data_queue()' is already
|
// The 'BlockingQueue' returned by 'sensor_data_queue()' is already
|
||||||
// thread-safe. Therefore it suffices to get an unsynchronized reference to
|
// thread-safe. Therefore it suffices to get an unsynchronized reference to
|
||||||
|
|
|
@ -31,6 +31,9 @@ class AddImuDataHandler
|
||||||
: public framework::RpcHandler<framework::Stream<proto::AddImuDataRequest>,
|
: public framework::RpcHandler<framework::Stream<proto::AddImuDataRequest>,
|
||||||
google::protobuf::Empty> {
|
google::protobuf::Empty> {
|
||||||
public:
|
public:
|
||||||
|
std::string method_name() const override {
|
||||||
|
return "/cartographer_grpc.proto.MapBuilderService/AddImuData";
|
||||||
|
}
|
||||||
void OnRequest(const proto::AddImuDataRequest &request) override {
|
void OnRequest(const proto::AddImuDataRequest &request) override {
|
||||||
// The 'BlockingQueue' returned by 'sensor_data_queue()' is already
|
// The 'BlockingQueue' returned by 'sensor_data_queue()' is already
|
||||||
// thread-safe. Therefore it suffices to get an unsynchronized reference to
|
// thread-safe. Therefore it suffices to get an unsynchronized reference to
|
||||||
|
|
|
@ -31,6 +31,9 @@ class AddLandmarkDataHandler
|
||||||
framework::Stream<proto::AddLandmarkDataRequest>,
|
framework::Stream<proto::AddLandmarkDataRequest>,
|
||||||
google::protobuf::Empty> {
|
google::protobuf::Empty> {
|
||||||
public:
|
public:
|
||||||
|
std::string method_name() const override {
|
||||||
|
return "/cartographer_grpc.proto.MapBuilderService/AddLandmarkData";
|
||||||
|
}
|
||||||
void OnRequest(const proto::AddLandmarkDataRequest &request) override {
|
void OnRequest(const proto::AddLandmarkDataRequest &request) override {
|
||||||
// The 'BlockingQueue' returned by 'sensor_data_queue()' is already
|
// The 'BlockingQueue' returned by 'sensor_data_queue()' is already
|
||||||
// thread-safe. Therefore it suffices to get an unsynchronized reference to
|
// thread-safe. Therefore it suffices to get an unsynchronized reference to
|
||||||
|
|
|
@ -32,6 +32,9 @@ class AddLocalSlamResultDataHandler
|
||||||
framework::Stream<proto::AddLocalSlamResultDataRequest>,
|
framework::Stream<proto::AddLocalSlamResultDataRequest>,
|
||||||
google::protobuf::Empty> {
|
google::protobuf::Empty> {
|
||||||
public:
|
public:
|
||||||
|
std::string method_name() const override {
|
||||||
|
return "/cartographer_grpc.proto.MapBuilderService/AddLocalSlamResultData";
|
||||||
|
}
|
||||||
void OnRequest(const proto::AddLocalSlamResultDataRequest& request) override {
|
void OnRequest(const proto::AddLocalSlamResultDataRequest& request) override {
|
||||||
auto local_slam_result_data =
|
auto local_slam_result_data =
|
||||||
GetContext<MapBuilderServer::MapBuilderContext>()
|
GetContext<MapBuilderServer::MapBuilderContext>()
|
||||||
|
|
|
@ -31,6 +31,9 @@ class AddOdometryDataHandler
|
||||||
framework::Stream<proto::AddOdometryDataRequest>,
|
framework::Stream<proto::AddOdometryDataRequest>,
|
||||||
google::protobuf::Empty> {
|
google::protobuf::Empty> {
|
||||||
public:
|
public:
|
||||||
|
std::string method_name() const override {
|
||||||
|
return "/cartographer_grpc.proto.MapBuilderService/AddOdometryData";
|
||||||
|
}
|
||||||
void OnRequest(const proto::AddOdometryDataRequest &request) override {
|
void OnRequest(const proto::AddOdometryDataRequest &request) override {
|
||||||
// The 'BlockingQueue' returned by 'sensor_data_queue()' is already
|
// The 'BlockingQueue' returned by 'sensor_data_queue()' is already
|
||||||
// thread-safe. Therefore it suffices to get an unsynchronized reference to
|
// thread-safe. Therefore it suffices to get an unsynchronized reference to
|
||||||
|
|
|
@ -31,6 +31,9 @@ class AddRangefinderDataHandler
|
||||||
framework::Stream<proto::AddRangefinderDataRequest>,
|
framework::Stream<proto::AddRangefinderDataRequest>,
|
||||||
google::protobuf::Empty> {
|
google::protobuf::Empty> {
|
||||||
public:
|
public:
|
||||||
|
std::string method_name() const override {
|
||||||
|
return "/cartographer_grpc.proto.MapBuilderService/AddRangefinderData";
|
||||||
|
}
|
||||||
void OnRequest(const proto::AddRangefinderDataRequest &request) override {
|
void OnRequest(const proto::AddRangefinderDataRequest &request) override {
|
||||||
// The 'BlockingQueue' returned by 'sensor_data_queue()' is already
|
// The 'BlockingQueue' returned by 'sensor_data_queue()' is already
|
||||||
// thread-safe. Therefore it suffices to get an unsynchronized reference to
|
// thread-safe. Therefore it suffices to get an unsynchronized reference to
|
||||||
|
|
|
@ -30,6 +30,9 @@ class AddTrajectoryHandler
|
||||||
: public framework::RpcHandler<proto::AddTrajectoryRequest,
|
: public framework::RpcHandler<proto::AddTrajectoryRequest,
|
||||||
proto::AddTrajectoryResponse> {
|
proto::AddTrajectoryResponse> {
|
||||||
public:
|
public:
|
||||||
|
std::string method_name() const override {
|
||||||
|
return "/cartographer_grpc.proto.MapBuilderService/AddTrajectory";
|
||||||
|
}
|
||||||
void OnRequest(const proto::AddTrajectoryRequest& request) override {
|
void OnRequest(const proto::AddTrajectoryRequest& request) override {
|
||||||
auto local_slam_result_callback =
|
auto local_slam_result_callback =
|
||||||
GetUnsynchronizedContext<MapBuilderServer::MapBuilderContext>()
|
GetUnsynchronizedContext<MapBuilderServer::MapBuilderContext>()
|
||||||
|
|
|
@ -30,6 +30,9 @@ class FinishTrajectoryHandler
|
||||||
: public framework::RpcHandler<proto::FinishTrajectoryRequest,
|
: public framework::RpcHandler<proto::FinishTrajectoryRequest,
|
||||||
google::protobuf::Empty> {
|
google::protobuf::Empty> {
|
||||||
public:
|
public:
|
||||||
|
std::string method_name() const override {
|
||||||
|
return "/cartographer_grpc.proto.MapBuilderService/FinishTrajectory";
|
||||||
|
}
|
||||||
void OnRequest(const proto::FinishTrajectoryRequest& request) override {
|
void OnRequest(const proto::FinishTrajectoryRequest& request) override {
|
||||||
GetContext<MapBuilderServer::MapBuilderContext>()
|
GetContext<MapBuilderServer::MapBuilderContext>()
|
||||||
->map_builder()
|
->map_builder()
|
||||||
|
|
|
@ -30,6 +30,9 @@ class GetAllSubmapPosesHandler
|
||||||
: public framework::RpcHandler<google::protobuf::Empty,
|
: public framework::RpcHandler<google::protobuf::Empty,
|
||||||
proto::GetAllSubmapPosesResponse> {
|
proto::GetAllSubmapPosesResponse> {
|
||||||
public:
|
public:
|
||||||
|
std::string method_name() const override {
|
||||||
|
return "/cartographer_grpc.proto.MapBuilderService/GetAllSubmapPoses";
|
||||||
|
}
|
||||||
void OnRequest(const google::protobuf::Empty& request) override {
|
void OnRequest(const google::protobuf::Empty& request) override {
|
||||||
auto submap_poses = GetContext<MapBuilderServer::MapBuilderContext>()
|
auto submap_poses = GetContext<MapBuilderServer::MapBuilderContext>()
|
||||||
->map_builder()
|
->map_builder()
|
||||||
|
|
|
@ -31,6 +31,9 @@ class GetConstraintsHandler
|
||||||
: public framework::RpcHandler<google::protobuf::Empty,
|
: public framework::RpcHandler<google::protobuf::Empty,
|
||||||
proto::GetConstraintsResponse> {
|
proto::GetConstraintsResponse> {
|
||||||
public:
|
public:
|
||||||
|
std::string method_name() const override {
|
||||||
|
return "/cartographer_grpc.proto.MapBuilderService/GetConstraints";
|
||||||
|
}
|
||||||
void OnRequest(const google::protobuf::Empty& request) override {
|
void OnRequest(const google::protobuf::Empty& request) override {
|
||||||
auto constraints = GetContext<MapBuilderServer::MapBuilderContext>()
|
auto constraints = GetContext<MapBuilderServer::MapBuilderContext>()
|
||||||
->map_builder()
|
->map_builder()
|
||||||
|
|
|
@ -24,6 +24,10 @@ class GetLocalToGlobalTransformHandler
|
||||||
: public framework::RpcHandler<proto::GetLocalToGlobalTransformRequest,
|
: public framework::RpcHandler<proto::GetLocalToGlobalTransformRequest,
|
||||||
proto::GetLocalToGlobalTransformResponse> {
|
proto::GetLocalToGlobalTransformResponse> {
|
||||||
public:
|
public:
|
||||||
|
std::string method_name() const override {
|
||||||
|
return "/cartographer_grpc.proto.MapBuilderService/"
|
||||||
|
"GetLocalToGlobalTransform";
|
||||||
|
}
|
||||||
void OnRequest(
|
void OnRequest(
|
||||||
const proto::GetLocalToGlobalTransformRequest& request) override {
|
const proto::GetLocalToGlobalTransformRequest& request) override {
|
||||||
auto response = cartographer::common::make_unique<
|
auto response = cartographer::common::make_unique<
|
||||||
|
|
|
@ -30,6 +30,9 @@ class GetSubmapHandler
|
||||||
: public framework::RpcHandler<proto::GetSubmapRequest,
|
: public framework::RpcHandler<proto::GetSubmapRequest,
|
||||||
proto::GetSubmapResponse> {
|
proto::GetSubmapResponse> {
|
||||||
public:
|
public:
|
||||||
|
std::string method_name() const override {
|
||||||
|
return "/cartographer_grpc.proto.MapBuilderService/GetSubmap";
|
||||||
|
}
|
||||||
void OnRequest(const proto::GetSubmapRequest &request) override {
|
void OnRequest(const proto::GetSubmapRequest &request) override {
|
||||||
auto response =
|
auto response =
|
||||||
cartographer::common::make_unique<proto::GetSubmapResponse>();
|
cartographer::common::make_unique<proto::GetSubmapResponse>();
|
||||||
|
|
|
@ -30,6 +30,9 @@ class GetTrajectoryNodePosesHandler
|
||||||
: public framework::RpcHandler<google::protobuf::Empty,
|
: public framework::RpcHandler<google::protobuf::Empty,
|
||||||
proto::GetTrajectoryNodePosesResponse> {
|
proto::GetTrajectoryNodePosesResponse> {
|
||||||
public:
|
public:
|
||||||
|
std::string method_name() const override {
|
||||||
|
return "/cartographer_grpc.proto.MapBuilderService/GetTrajectoryNodePoses";
|
||||||
|
}
|
||||||
void OnRequest(const google::protobuf::Empty& request) override {
|
void OnRequest(const google::protobuf::Empty& request) override {
|
||||||
auto node_poses = GetContext<MapBuilderServer::MapBuilderContext>()
|
auto node_poses = GetContext<MapBuilderServer::MapBuilderContext>()
|
||||||
->map_builder()
|
->map_builder()
|
||||||
|
|
|
@ -31,6 +31,9 @@ class LoadMapHandler
|
||||||
: public framework::RpcHandler<framework::Stream<proto::LoadMapRequest>,
|
: public framework::RpcHandler<framework::Stream<proto::LoadMapRequest>,
|
||||||
google::protobuf::Empty> {
|
google::protobuf::Empty> {
|
||||||
public:
|
public:
|
||||||
|
std::string method_name() const override {
|
||||||
|
return "/cartographer_grpc.proto.MapBuilderService/LoadMap";
|
||||||
|
}
|
||||||
void OnRequest(const proto::LoadMapRequest& request) override {
|
void OnRequest(const proto::LoadMapRequest& request) override {
|
||||||
switch (request.map_chunk_case()) {
|
switch (request.map_chunk_case()) {
|
||||||
case proto::LoadMapRequest::kPoseGraph:
|
case proto::LoadMapRequest::kPoseGraph:
|
||||||
|
|
|
@ -30,6 +30,9 @@ class ReceiveLocalSlamResultsHandler
|
||||||
proto::ReceiveLocalSlamResultsRequest,
|
proto::ReceiveLocalSlamResultsRequest,
|
||||||
framework::Stream<proto::ReceiveLocalSlamResultsResponse>> {
|
framework::Stream<proto::ReceiveLocalSlamResultsResponse>> {
|
||||||
public:
|
public:
|
||||||
|
std::string method_name() const override {
|
||||||
|
return "/cartographer_grpc.proto.MapBuilderService/ReceiveLocalSlamResults";
|
||||||
|
}
|
||||||
void OnRequest(
|
void OnRequest(
|
||||||
const proto::ReceiveLocalSlamResultsRequest& request) override {
|
const proto::ReceiveLocalSlamResultsRequest& request) override {
|
||||||
auto writer = GetWriter();
|
auto writer = GetWriter();
|
||||||
|
|
|
@ -31,6 +31,9 @@ class RunFinalOptimizationHandler
|
||||||
: public framework::RpcHandler<google::protobuf::Empty,
|
: public framework::RpcHandler<google::protobuf::Empty,
|
||||||
google::protobuf::Empty> {
|
google::protobuf::Empty> {
|
||||||
public:
|
public:
|
||||||
|
std::string method_name() const override {
|
||||||
|
return "/cartographer_grpc.proto.MapBuilderService/RunFinalOptimization";
|
||||||
|
}
|
||||||
void OnRequest(const google::protobuf::Empty& request) override {
|
void OnRequest(const google::protobuf::Empty& request) override {
|
||||||
GetContext<MapBuilderServer::MapBuilderContext>()
|
GetContext<MapBuilderServer::MapBuilderContext>()
|
||||||
->map_builder()
|
->map_builder()
|
|
@ -31,7 +31,7 @@
|
||||||
#include "cartographer_grpc/handlers/get_trajectory_node_poses_handler.h"
|
#include "cartographer_grpc/handlers/get_trajectory_node_poses_handler.h"
|
||||||
#include "cartographer_grpc/handlers/load_map_handler.h"
|
#include "cartographer_grpc/handlers/load_map_handler.h"
|
||||||
#include "cartographer_grpc/handlers/receive_local_slam_results_handler.h"
|
#include "cartographer_grpc/handlers/receive_local_slam_results_handler.h"
|
||||||
#include "cartographer_grpc/handlers/run_final_optimization.h"
|
#include "cartographer_grpc/handlers/run_final_optimization_handler.h"
|
||||||
#include "cartographer_grpc/proto/map_builder_service.grpc.pb.h"
|
#include "cartographer_grpc/proto/map_builder_service.grpc.pb.h"
|
||||||
#include "cartographer_grpc/sensor/serialization.h"
|
#include "cartographer_grpc/sensor/serialization.h"
|
||||||
#include "glog/logging.h"
|
#include "glog/logging.h"
|
||||||
|
@ -216,48 +216,22 @@ MapBuilderServer::MapBuilderServer(
|
||||||
cartographer::common::make_unique<LocalTrajectoryUploader>(
|
cartographer::common::make_unique<LocalTrajectoryUploader>(
|
||||||
map_builder_server_options.uplink_server_address());
|
map_builder_server_options.uplink_server_address());
|
||||||
}
|
}
|
||||||
server_builder.RegisterHandler<handlers::AddTrajectoryHandler,
|
server_builder.RegisterHandler<handlers::AddTrajectoryHandler>();
|
||||||
proto::MapBuilderService>("AddTrajectory");
|
server_builder.RegisterHandler<handlers::AddOdometryDataHandler>();
|
||||||
server_builder.RegisterHandler<handlers::AddOdometryDataHandler,
|
server_builder.RegisterHandler<handlers::AddImuDataHandler>();
|
||||||
proto::MapBuilderService>("AddOdometryData");
|
server_builder.RegisterHandler<handlers::AddRangefinderDataHandler>();
|
||||||
server_builder
|
server_builder.RegisterHandler<handlers::AddFixedFramePoseDataHandler>();
|
||||||
.RegisterHandler<handlers::AddImuDataHandler, proto::MapBuilderService>(
|
server_builder.RegisterHandler<handlers::AddLandmarkDataHandler>();
|
||||||
"AddImuData");
|
server_builder.RegisterHandler<handlers::AddLocalSlamResultDataHandler>();
|
||||||
server_builder.RegisterHandler<handlers::AddRangefinderDataHandler,
|
server_builder.RegisterHandler<handlers::FinishTrajectoryHandler>();
|
||||||
proto::MapBuilderService>(
|
server_builder.RegisterHandler<handlers::ReceiveLocalSlamResultsHandler>();
|
||||||
"AddRangefinderData");
|
server_builder.RegisterHandler<handlers::GetSubmapHandler>();
|
||||||
server_builder.RegisterHandler<handlers::AddFixedFramePoseDataHandler,
|
server_builder.RegisterHandler<handlers::GetTrajectoryNodePosesHandler>();
|
||||||
proto::MapBuilderService>(
|
server_builder.RegisterHandler<handlers::GetAllSubmapPosesHandler>();
|
||||||
"AddFixedFramePoseData");
|
server_builder.RegisterHandler<handlers::GetLocalToGlobalTransformHandler>();
|
||||||
server_builder.RegisterHandler<handlers::AddLandmarkDataHandler,
|
server_builder.RegisterHandler<handlers::GetConstraintsHandler>();
|
||||||
proto::MapBuilderService>("AddLandmarkData");
|
server_builder.RegisterHandler<handlers::LoadMapHandler>();
|
||||||
server_builder.RegisterHandler<handlers::AddLocalSlamResultDataHandler,
|
server_builder.RegisterHandler<handlers::RunFinalOptimizationHandler>();
|
||||||
proto::MapBuilderService>(
|
|
||||||
"AddLocalSlamResultData");
|
|
||||||
server_builder.RegisterHandler<handlers::FinishTrajectoryHandler,
|
|
||||||
proto::MapBuilderService>("FinishTrajectory");
|
|
||||||
server_builder.RegisterHandler<handlers::ReceiveLocalSlamResultsHandler,
|
|
||||||
proto::MapBuilderService>(
|
|
||||||
"ReceiveLocalSlamResults");
|
|
||||||
server_builder
|
|
||||||
.RegisterHandler<handlers::GetSubmapHandler, proto::MapBuilderService>(
|
|
||||||
"GetSubmap");
|
|
||||||
server_builder.RegisterHandler<handlers::GetTrajectoryNodePosesHandler,
|
|
||||||
proto::MapBuilderService>(
|
|
||||||
"GetTrajectoryNodePoses");
|
|
||||||
server_builder.RegisterHandler<handlers::GetAllSubmapPosesHandler,
|
|
||||||
proto::MapBuilderService>("GetAllSubmapPoses");
|
|
||||||
server_builder.RegisterHandler<handlers::GetLocalToGlobalTransformHandler,
|
|
||||||
proto::MapBuilderService>(
|
|
||||||
"GetLocalToGlobalTransform");
|
|
||||||
server_builder.RegisterHandler<handlers::GetConstraintsHandler,
|
|
||||||
proto::MapBuilderService>("GetConstraints");
|
|
||||||
server_builder
|
|
||||||
.RegisterHandler<handlers::LoadMapHandler, proto::MapBuilderService>(
|
|
||||||
"LoadMap");
|
|
||||||
server_builder.RegisterHandler<handlers::RunFinalOptimizationHandler,
|
|
||||||
proto::MapBuilderService>(
|
|
||||||
"RunFinalOptimization");
|
|
||||||
grpc_server_ = server_builder.Build();
|
grpc_server_ = server_builder.Build();
|
||||||
grpc_server_->SetExecutionContext(
|
grpc_server_->SetExecutionContext(
|
||||||
cartographer::common::make_unique<MapBuilderContext>(this));
|
cartographer::common::make_unique<MapBuilderContext>(this));
|
||||||
|
|
Loading…
Reference in New Issue