From e40d1deefebc81bf49a1c26dcafbaaa81b401b9c Mon Sep 17 00:00:00 2001 From: marfanr Date: Mon, 8 Jan 2024 11:05:25 +0000 Subject: [PATCH] feat: refractor and resolve pull request --- CMakeLists.txt | 2 +- include/akushon/config/grpc/call_data.hpp | 42 ++++++++++++++--- src/akushon/config/grpc/call_data.cpp | 56 ----------------------- 3 files changed, 37 insertions(+), 63 deletions(-) delete mode 100644 src/akushon/config/grpc/call_data.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 38b2620..b816664 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,7 +67,7 @@ ament_target_dependencies(${PROJECT_NAME} tachimawari_interfaces gRPC) - target_link_libraries(${PROJECT_NAME} +target_link_libraries(${PROJECT_NAME} gRPC::grpc++_reflection gRPC::grpc++ ) diff --git a/include/akushon/config/grpc/call_data.hpp b/include/akushon/config/grpc/call_data.hpp index 7b00e79..0ce97ee 100644 --- a/include/akushon/config/grpc/call_data.hpp +++ b/include/akushon/config/grpc/call_data.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2023 Ichiro ITS +// Copyright (c) 2024 Ichiro ITS // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -21,22 +21,23 @@ #ifndef AKUSHON__CONFIG__GRPC__CALL_DATA_HPP_ #define AKUSHON__CONFIG__GRPC__CALL_DATA_HPP_ +#include "akushon/config/grpc/call_data_base.hpp" #include "akushon_interfaces/akushon.grpc.pb.h" #include "akushon_interfaces/akushon.pb.h" #include "grpc/support/log.h" #include "grpcpp/grpcpp.h" -#include "akushon/config/grpc/call_data_base.hpp" namespace akushon { template -class CallData : CallDataBase { +class CallData : CallDataBase +{ public: CallData( akushon_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, - const std::string& path); + const std::string & path); void Proceed() override; - + protected: virtual void AddNextToCompletionQueue() = 0; @@ -46,7 +47,7 @@ class CallData : CallDataBase { akushon_interfaces::proto::Config::AsyncService * service_; - const std::string& path_; + const std::string & path_; grpc::ServerCompletionQueue * cq_; grpc::ServerContext ctx_; @@ -54,6 +55,35 @@ class CallData : CallDataBase { ConfigReply reply_; grpc::ServerAsyncResponseWriter responder_; }; + +template +CallData::CallData( + akushon_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, + const std::string & path) +: status_(CallStatus::CREATE), service_(service), cq_(cq), responder_(&ctx_), path_(path) +{ +} + +template +void CallData::Proceed() +{ + switch (status_) { + case CallStatus::CREATE: + status_ = CallStatus::PROCESS; + WaitForRequest(); + break; + case CallStatus::PROCESS: + AddNextToCompletionQueue(); + HandleRequest(); + status_ = CallStatus::FINISH; + responder_.Finish(reply_, grpc::Status::OK, this); + break; + default: + delete this; + break; + } +} + } // namespace akushon #endif // AKUSHON__CONFIG__GRPC__CALL_DATA_HPP_ diff --git a/src/akushon/config/grpc/call_data.cpp b/src/akushon/config/grpc/call_data.cpp deleted file mode 100644 index 944a761..0000000 --- a/src/akushon/config/grpc/call_data.cpp +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2023 Ichiro ITS -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -#include "akushon/config/grpc/call_data.hpp" - -namespace akushon -{ -template -CallData::CallData( - akushon_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, - const std::string& path) : status_(CallStatus::CREATE), service_(service), cq_(cq), responder_(&ctx_), path_(path) { -} - -template -void CallData::Proceed() -{ - if (status_ == CallStatus::CREATE) { - status_ = CallStatus::PROCESS; - WaitForRequest(); - } else if (status_ == CallStatus::PROCESS) { - AddNextToCompletionQueue(); - HandleRequest(); - status_ = CallStatus::FINISH; - responder_.Finish(reply_, grpc::Status::OK, this); - } else { - GPR_ASSERT(status_ == CallStatus::FINISH); - delete this; - } -} - -template class CallData; -template class CallData; -template class CallData; -template class CallData< - akushon_interfaces::proto::SetTorquesData, akushon_interfaces::proto::Empty>; -template class CallData; -template class CallData< - akushon_interfaces::proto::ConfigRunAction, akushon_interfaces::proto::Empty>; -}