From fcac7f426fdf94f8637241e0aeffeb25a9f690f5 Mon Sep 17 00:00:00 2001 From: arefsa78 Date: Tue, 23 Apr 2024 00:04:50 -0230 Subject: [PATCH 1/2] add bye command --- grpc/protos/service.proto | 1 + src/coach/sample_coach.cpp | 7 ++ src/coach/sample_coach.h | 2 + src/grpc/grpc_agent.cpp | 15 ++++ src/grpc/grpc_agent.h | 1 + src/grpc/service.grpc.pb.cc | 42 +++++++++ src/grpc/service.grpc.pb.h | 165 ++++++++++++++++++++++++++++++++++- src/grpc/service.pb.cc | 7 +- src/player/sample_player.cpp | 9 ++ src/player/sample_player.h | 3 + 10 files changed, 245 insertions(+), 7 deletions(-) diff --git a/grpc/protos/service.proto b/grpc/protos/service.proto index 6f7fdeb0..caea7d9e 100644 --- a/grpc/protos/service.proto +++ b/grpc/protos/service.proto @@ -1204,4 +1204,5 @@ service Game { rpc SendPlayerParams(PlayerParam) returns (Empty) {} rpc SendPlayerType(PlayerType) returns (Empty) {} //should be PlayerTypes rpc GetInitMessage(Empty) returns (InitMessageFromServer) {} + rpc SendByeCommand(Empty) returns (Empty) {} } \ No newline at end of file diff --git a/src/coach/sample_coach.cpp b/src/coach/sample_coach.cpp index ef4b31da..4a97367e 100644 --- a/src/coach/sample_coach.cpp +++ b/src/coach/sample_coach.cpp @@ -236,6 +236,13 @@ SampleCoach::actionImpl() sayPlayerTypes(); } +void +SampleCoach::handleExit() +{ + M_grpc_agent.sendByeCommand(); + CoachAgent::handleExit(); +} + /*-------------------------------------------------------------------*/ /*! diff --git a/src/coach/sample_coach.h b/src/coach/sample_coach.h index c04a36e0..1bb25940 100644 --- a/src/coach/sample_coach.h +++ b/src/coach/sample_coach.h @@ -81,6 +81,8 @@ class SampleCoach //! main decision making virtual void actionImpl(); + void + handleExit() override; virtual diff --git a/src/grpc/grpc_agent.cpp b/src/grpc/grpc_agent.cpp index 2a6f9a48..d6ed8e07 100644 --- a/src/grpc/grpc_agent.cpp +++ b/src/grpc/grpc_agent.cpp @@ -434,6 +434,21 @@ bool GrpcAgent::getInitMessage() const } } +void GrpcAgent::sendByeCommand() const +{ + ClientContext context; + protos::Empty empty1; + protos::Empty empty2; + Status status = stub_->SendByeCommand(&context, empty1, &empty2); + if (!status.ok()) + { + std::cout << "SendByeCommand rpc failed." << std::endl + << status.error_code() << ": " << status.error_message() + << std::endl; + } + +} + bool GrpcAgent::connectToGrpcServer() { channel = grpc::CreateChannel(this->target, grpc::InsecureChannelCredentials()); diff --git a/src/grpc/grpc_agent.h b/src/grpc/grpc_agent.h index ba88803d..a8b86dc6 100644 --- a/src/grpc/grpc_agent.h +++ b/src/grpc/grpc_agent.h @@ -39,6 +39,7 @@ class GrpcAgent { void sendPlayerType() const; void sendInitMessage(bool offline_logging) const; bool getInitMessage() const; + void sendByeCommand() const; bool connectToGrpcServer(); static rcsc::ViewWidth convertViewWidth(protos::ViewWidth view_width); diff --git a/src/grpc/service.grpc.pb.cc b/src/grpc/service.grpc.pb.cc index 4d8df83b..d6c45da4 100644 --- a/src/grpc/service.grpc.pb.cc +++ b/src/grpc/service.grpc.pb.cc @@ -30,6 +30,7 @@ static const char* Game_method_names[] = { "/protos.Game/SendPlayerParams", "/protos.Game/SendPlayerType", "/protos.Game/GetInitMessage", + "/protos.Game/SendByeCommand", }; std::unique_ptr< Game::Stub> Game::NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options) { @@ -47,6 +48,7 @@ Game::Stub::Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, cons , rpcmethod_SendPlayerParams_(Game_method_names[5], options.suffix_for_stats(),::grpc::internal::RpcMethod::NORMAL_RPC, channel) , rpcmethod_SendPlayerType_(Game_method_names[6], options.suffix_for_stats(),::grpc::internal::RpcMethod::NORMAL_RPC, channel) , rpcmethod_GetInitMessage_(Game_method_names[7], options.suffix_for_stats(),::grpc::internal::RpcMethod::NORMAL_RPC, channel) + , rpcmethod_SendByeCommand_(Game_method_names[8], options.suffix_for_stats(),::grpc::internal::RpcMethod::NORMAL_RPC, channel) {} ::grpc::Status Game::Stub::GetPlayerActions(::grpc::ClientContext* context, const ::protos::State& request, ::protos::PlayerActions* response) { @@ -233,6 +235,29 @@ ::grpc::ClientAsyncResponseReader< ::protos::InitMessageFromServer>* Game::Stub: return result; } +::grpc::Status Game::Stub::SendByeCommand(::grpc::ClientContext* context, const ::protos::Empty& request, ::protos::Empty* response) { + return ::grpc::internal::BlockingUnaryCall< ::protos::Empty, ::protos::Empty, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), rpcmethod_SendByeCommand_, context, request, response); +} + +void Game::Stub::async::SendByeCommand(::grpc::ClientContext* context, const ::protos::Empty* request, ::protos::Empty* response, std::function f) { + ::grpc::internal::CallbackUnaryCall< ::protos::Empty, ::protos::Empty, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_SendByeCommand_, context, request, response, std::move(f)); +} + +void Game::Stub::async::SendByeCommand(::grpc::ClientContext* context, const ::protos::Empty* request, ::protos::Empty* response, ::grpc::ClientUnaryReactor* reactor) { + ::grpc::internal::ClientCallbackUnaryFactory::Create< ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_SendByeCommand_, context, request, response, reactor); +} + +::grpc::ClientAsyncResponseReader< ::protos::Empty>* Game::Stub::PrepareAsyncSendByeCommandRaw(::grpc::ClientContext* context, const ::protos::Empty& request, ::grpc::CompletionQueue* cq) { + return ::grpc::internal::ClientAsyncResponseReaderHelper::Create< ::protos::Empty, ::protos::Empty, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), cq, rpcmethod_SendByeCommand_, context, request); +} + +::grpc::ClientAsyncResponseReader< ::protos::Empty>* Game::Stub::AsyncSendByeCommandRaw(::grpc::ClientContext* context, const ::protos::Empty& request, ::grpc::CompletionQueue* cq) { + auto* result = + this->PrepareAsyncSendByeCommandRaw(context, request, cq); + result->StartCall(); + return result; +} + Game::Service::Service() { AddMethod(new ::grpc::internal::RpcServiceMethod( Game_method_names[0], @@ -314,6 +339,16 @@ Game::Service::Service() { ::protos::InitMessageFromServer* resp) { return service->GetInitMessage(ctx, req, resp); }, this))); + AddMethod(new ::grpc::internal::RpcServiceMethod( + Game_method_names[8], + ::grpc::internal::RpcMethod::NORMAL_RPC, + new ::grpc::internal::RpcMethodHandler< Game::Service, ::protos::Empty, ::protos::Empty, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>( + [](Game::Service* service, + ::grpc::ServerContext* ctx, + const ::protos::Empty* req, + ::protos::Empty* resp) { + return service->SendByeCommand(ctx, req, resp); + }, this))); } Game::Service::~Service() { @@ -375,6 +410,13 @@ ::grpc::Status Game::Service::GetInitMessage(::grpc::ServerContext* context, con return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); } +::grpc::Status Game::Service::SendByeCommand(::grpc::ServerContext* context, const ::protos::Empty* request, ::protos::Empty* response) { + (void) context; + (void) request; + (void) response; + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); +} + } // namespace protos diff --git a/src/grpc/service.grpc.pb.h b/src/grpc/service.grpc.pb.h index 9c827a15..c2b0b3ad 100644 --- a/src/grpc/service.grpc.pb.h +++ b/src/grpc/service.grpc.pb.h @@ -91,6 +91,13 @@ class Game final { std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::protos::InitMessageFromServer>> PrepareAsyncGetInitMessage(::grpc::ClientContext* context, const ::protos::Empty& request, ::grpc::CompletionQueue* cq) { return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::protos::InitMessageFromServer>>(PrepareAsyncGetInitMessageRaw(context, request, cq)); } + virtual ::grpc::Status SendByeCommand(::grpc::ClientContext* context, const ::protos::Empty& request, ::protos::Empty* response) = 0; + std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::protos::Empty>> AsyncSendByeCommand(::grpc::ClientContext* context, const ::protos::Empty& request, ::grpc::CompletionQueue* cq) { + return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::protos::Empty>>(AsyncSendByeCommandRaw(context, request, cq)); + } + std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::protos::Empty>> PrepareAsyncSendByeCommand(::grpc::ClientContext* context, const ::protos::Empty& request, ::grpc::CompletionQueue* cq) { + return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::protos::Empty>>(PrepareAsyncSendByeCommandRaw(context, request, cq)); + } class async_interface { public: virtual ~async_interface() {} @@ -110,6 +117,8 @@ class Game final { virtual void SendPlayerType(::grpc::ClientContext* context, const ::protos::PlayerType* request, ::protos::Empty* response, ::grpc::ClientUnaryReactor* reactor) = 0; virtual void GetInitMessage(::grpc::ClientContext* context, const ::protos::Empty* request, ::protos::InitMessageFromServer* response, std::function) = 0; virtual void GetInitMessage(::grpc::ClientContext* context, const ::protos::Empty* request, ::protos::InitMessageFromServer* response, ::grpc::ClientUnaryReactor* reactor) = 0; + virtual void SendByeCommand(::grpc::ClientContext* context, const ::protos::Empty* request, ::protos::Empty* response, std::function) = 0; + virtual void SendByeCommand(::grpc::ClientContext* context, const ::protos::Empty* request, ::protos::Empty* response, ::grpc::ClientUnaryReactor* reactor) = 0; }; typedef class async_interface experimental_async_interface; virtual class async_interface* async() { return nullptr; } @@ -131,6 +140,8 @@ class Game final { virtual ::grpc::ClientAsyncResponseReaderInterface< ::protos::Empty>* PrepareAsyncSendPlayerTypeRaw(::grpc::ClientContext* context, const ::protos::PlayerType& request, ::grpc::CompletionQueue* cq) = 0; virtual ::grpc::ClientAsyncResponseReaderInterface< ::protos::InitMessageFromServer>* AsyncGetInitMessageRaw(::grpc::ClientContext* context, const ::protos::Empty& request, ::grpc::CompletionQueue* cq) = 0; virtual ::grpc::ClientAsyncResponseReaderInterface< ::protos::InitMessageFromServer>* PrepareAsyncGetInitMessageRaw(::grpc::ClientContext* context, const ::protos::Empty& request, ::grpc::CompletionQueue* cq) = 0; + virtual ::grpc::ClientAsyncResponseReaderInterface< ::protos::Empty>* AsyncSendByeCommandRaw(::grpc::ClientContext* context, const ::protos::Empty& request, ::grpc::CompletionQueue* cq) = 0; + virtual ::grpc::ClientAsyncResponseReaderInterface< ::protos::Empty>* PrepareAsyncSendByeCommandRaw(::grpc::ClientContext* context, const ::protos::Empty& request, ::grpc::CompletionQueue* cq) = 0; }; class Stub final : public StubInterface { public: @@ -191,6 +202,13 @@ class Game final { std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::protos::InitMessageFromServer>> PrepareAsyncGetInitMessage(::grpc::ClientContext* context, const ::protos::Empty& request, ::grpc::CompletionQueue* cq) { return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::protos::InitMessageFromServer>>(PrepareAsyncGetInitMessageRaw(context, request, cq)); } + ::grpc::Status SendByeCommand(::grpc::ClientContext* context, const ::protos::Empty& request, ::protos::Empty* response) override; + std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::protos::Empty>> AsyncSendByeCommand(::grpc::ClientContext* context, const ::protos::Empty& request, ::grpc::CompletionQueue* cq) { + return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::protos::Empty>>(AsyncSendByeCommandRaw(context, request, cq)); + } + std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::protos::Empty>> PrepareAsyncSendByeCommand(::grpc::ClientContext* context, const ::protos::Empty& request, ::grpc::CompletionQueue* cq) { + return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::protos::Empty>>(PrepareAsyncSendByeCommandRaw(context, request, cq)); + } class async final : public StubInterface::async_interface { public: @@ -210,6 +228,8 @@ class Game final { void SendPlayerType(::grpc::ClientContext* context, const ::protos::PlayerType* request, ::protos::Empty* response, ::grpc::ClientUnaryReactor* reactor) override; void GetInitMessage(::grpc::ClientContext* context, const ::protos::Empty* request, ::protos::InitMessageFromServer* response, std::function) override; void GetInitMessage(::grpc::ClientContext* context, const ::protos::Empty* request, ::protos::InitMessageFromServer* response, ::grpc::ClientUnaryReactor* reactor) override; + void SendByeCommand(::grpc::ClientContext* context, const ::protos::Empty* request, ::protos::Empty* response, std::function) override; + void SendByeCommand(::grpc::ClientContext* context, const ::protos::Empty* request, ::protos::Empty* response, ::grpc::ClientUnaryReactor* reactor) override; private: friend class Stub; explicit async(Stub* stub): stub_(stub) { } @@ -237,6 +257,8 @@ class Game final { ::grpc::ClientAsyncResponseReader< ::protos::Empty>* PrepareAsyncSendPlayerTypeRaw(::grpc::ClientContext* context, const ::protos::PlayerType& request, ::grpc::CompletionQueue* cq) override; ::grpc::ClientAsyncResponseReader< ::protos::InitMessageFromServer>* AsyncGetInitMessageRaw(::grpc::ClientContext* context, const ::protos::Empty& request, ::grpc::CompletionQueue* cq) override; ::grpc::ClientAsyncResponseReader< ::protos::InitMessageFromServer>* PrepareAsyncGetInitMessageRaw(::grpc::ClientContext* context, const ::protos::Empty& request, ::grpc::CompletionQueue* cq) override; + ::grpc::ClientAsyncResponseReader< ::protos::Empty>* AsyncSendByeCommandRaw(::grpc::ClientContext* context, const ::protos::Empty& request, ::grpc::CompletionQueue* cq) override; + ::grpc::ClientAsyncResponseReader< ::protos::Empty>* PrepareAsyncSendByeCommandRaw(::grpc::ClientContext* context, const ::protos::Empty& request, ::grpc::CompletionQueue* cq) override; const ::grpc::internal::RpcMethod rpcmethod_GetPlayerActions_; const ::grpc::internal::RpcMethod rpcmethod_GetCoachActions_; const ::grpc::internal::RpcMethod rpcmethod_GetTrainerActions_; @@ -245,6 +267,7 @@ class Game final { const ::grpc::internal::RpcMethod rpcmethod_SendPlayerParams_; const ::grpc::internal::RpcMethod rpcmethod_SendPlayerType_; const ::grpc::internal::RpcMethod rpcmethod_GetInitMessage_; + const ::grpc::internal::RpcMethod rpcmethod_SendByeCommand_; }; static std::unique_ptr NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options = ::grpc::StubOptions()); @@ -260,6 +283,7 @@ class Game final { virtual ::grpc::Status SendPlayerParams(::grpc::ServerContext* context, const ::protos::PlayerParam* request, ::protos::Empty* response); virtual ::grpc::Status SendPlayerType(::grpc::ServerContext* context, const ::protos::PlayerType* request, ::protos::Empty* response); virtual ::grpc::Status GetInitMessage(::grpc::ServerContext* context, const ::protos::Empty* request, ::protos::InitMessageFromServer* response); + virtual ::grpc::Status SendByeCommand(::grpc::ServerContext* context, const ::protos::Empty* request, ::protos::Empty* response); }; template class WithAsyncMethod_GetPlayerActions : public BaseClass { @@ -421,7 +445,27 @@ class Game final { ::grpc::Service::RequestAsyncUnary(7, context, request, response, new_call_cq, notification_cq, tag); } }; - typedef WithAsyncMethod_GetPlayerActions > > > > > > > AsyncService; + template + class WithAsyncMethod_SendByeCommand : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} + public: + WithAsyncMethod_SendByeCommand() { + ::grpc::Service::MarkMethodAsync(8); + } + ~WithAsyncMethod_SendByeCommand() override { + BaseClassMustBeDerivedFromService(this); + } + // disable synchronous version of this method + ::grpc::Status SendByeCommand(::grpc::ServerContext* /*context*/, const ::protos::Empty* /*request*/, ::protos::Empty* /*response*/) override { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + void RequestSendByeCommand(::grpc::ServerContext* context, ::protos::Empty* request, ::grpc::ServerAsyncResponseWriter< ::protos::Empty>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { + ::grpc::Service::RequestAsyncUnary(8, context, request, response, new_call_cq, notification_cq, tag); + } + }; + typedef WithAsyncMethod_GetPlayerActions > > > > > > > > AsyncService; template class WithCallbackMethod_GetPlayerActions : public BaseClass { private: @@ -638,7 +682,34 @@ class Game final { virtual ::grpc::ServerUnaryReactor* GetInitMessage( ::grpc::CallbackServerContext* /*context*/, const ::protos::Empty* /*request*/, ::protos::InitMessageFromServer* /*response*/) { return nullptr; } }; - typedef WithCallbackMethod_GetPlayerActions > > > > > > > CallbackService; + template + class WithCallbackMethod_SendByeCommand : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} + public: + WithCallbackMethod_SendByeCommand() { + ::grpc::Service::MarkMethodCallback(8, + new ::grpc::internal::CallbackUnaryHandler< ::protos::Empty, ::protos::Empty>( + [this]( + ::grpc::CallbackServerContext* context, const ::protos::Empty* request, ::protos::Empty* response) { return this->SendByeCommand(context, request, response); }));} + void SetMessageAllocatorFor_SendByeCommand( + ::grpc::MessageAllocator< ::protos::Empty, ::protos::Empty>* allocator) { + ::grpc::internal::MethodHandler* const handler = ::grpc::Service::GetHandler(8); + static_cast<::grpc::internal::CallbackUnaryHandler< ::protos::Empty, ::protos::Empty>*>(handler) + ->SetMessageAllocator(allocator); + } + ~WithCallbackMethod_SendByeCommand() override { + BaseClassMustBeDerivedFromService(this); + } + // disable synchronous version of this method + ::grpc::Status SendByeCommand(::grpc::ServerContext* /*context*/, const ::protos::Empty* /*request*/, ::protos::Empty* /*response*/) override { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + virtual ::grpc::ServerUnaryReactor* SendByeCommand( + ::grpc::CallbackServerContext* /*context*/, const ::protos::Empty* /*request*/, ::protos::Empty* /*response*/) { return nullptr; } + }; + typedef WithCallbackMethod_GetPlayerActions > > > > > > > > CallbackService; typedef CallbackService ExperimentalCallbackService; template class WithGenericMethod_GetPlayerActions : public BaseClass { @@ -777,6 +848,23 @@ class Game final { } }; template + class WithGenericMethod_SendByeCommand : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} + public: + WithGenericMethod_SendByeCommand() { + ::grpc::Service::MarkMethodGeneric(8); + } + ~WithGenericMethod_SendByeCommand() override { + BaseClassMustBeDerivedFromService(this); + } + // disable synchronous version of this method + ::grpc::Status SendByeCommand(::grpc::ServerContext* /*context*/, const ::protos::Empty* /*request*/, ::protos::Empty* /*response*/) override { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + }; + template class WithRawMethod_GetPlayerActions : public BaseClass { private: void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} @@ -937,6 +1025,26 @@ class Game final { } }; template + class WithRawMethod_SendByeCommand : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} + public: + WithRawMethod_SendByeCommand() { + ::grpc::Service::MarkMethodRaw(8); + } + ~WithRawMethod_SendByeCommand() override { + BaseClassMustBeDerivedFromService(this); + } + // disable synchronous version of this method + ::grpc::Status SendByeCommand(::grpc::ServerContext* /*context*/, const ::protos::Empty* /*request*/, ::protos::Empty* /*response*/) override { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + void RequestSendByeCommand(::grpc::ServerContext* context, ::grpc::ByteBuffer* request, ::grpc::ServerAsyncResponseWriter< ::grpc::ByteBuffer>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { + ::grpc::Service::RequestAsyncUnary(8, context, request, response, new_call_cq, notification_cq, tag); + } + }; + template class WithRawCallbackMethod_GetPlayerActions : public BaseClass { private: void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} @@ -1113,6 +1221,28 @@ class Game final { ::grpc::CallbackServerContext* /*context*/, const ::grpc::ByteBuffer* /*request*/, ::grpc::ByteBuffer* /*response*/) { return nullptr; } }; template + class WithRawCallbackMethod_SendByeCommand : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} + public: + WithRawCallbackMethod_SendByeCommand() { + ::grpc::Service::MarkMethodRawCallback(8, + new ::grpc::internal::CallbackUnaryHandler< ::grpc::ByteBuffer, ::grpc::ByteBuffer>( + [this]( + ::grpc::CallbackServerContext* context, const ::grpc::ByteBuffer* request, ::grpc::ByteBuffer* response) { return this->SendByeCommand(context, request, response); })); + } + ~WithRawCallbackMethod_SendByeCommand() override { + BaseClassMustBeDerivedFromService(this); + } + // disable synchronous version of this method + ::grpc::Status SendByeCommand(::grpc::ServerContext* /*context*/, const ::protos::Empty* /*request*/, ::protos::Empty* /*response*/) override { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + virtual ::grpc::ServerUnaryReactor* SendByeCommand( + ::grpc::CallbackServerContext* /*context*/, const ::grpc::ByteBuffer* /*request*/, ::grpc::ByteBuffer* /*response*/) { return nullptr; } + }; + template class WithStreamedUnaryMethod_GetPlayerActions : public BaseClass { private: void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} @@ -1328,9 +1458,36 @@ class Game final { // replace default version of method with streamed unary virtual ::grpc::Status StreamedGetInitMessage(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer< ::protos::Empty,::protos::InitMessageFromServer>* server_unary_streamer) = 0; }; - typedef WithStreamedUnaryMethod_GetPlayerActions > > > > > > > StreamedUnaryService; + template + class WithStreamedUnaryMethod_SendByeCommand : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} + public: + WithStreamedUnaryMethod_SendByeCommand() { + ::grpc::Service::MarkMethodStreamed(8, + new ::grpc::internal::StreamedUnaryHandler< + ::protos::Empty, ::protos::Empty>( + [this](::grpc::ServerContext* context, + ::grpc::ServerUnaryStreamer< + ::protos::Empty, ::protos::Empty>* streamer) { + return this->StreamedSendByeCommand(context, + streamer); + })); + } + ~WithStreamedUnaryMethod_SendByeCommand() override { + BaseClassMustBeDerivedFromService(this); + } + // disable regular version of this method + ::grpc::Status SendByeCommand(::grpc::ServerContext* /*context*/, const ::protos::Empty* /*request*/, ::protos::Empty* /*response*/) override { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + // replace default version of method with streamed unary + virtual ::grpc::Status StreamedSendByeCommand(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer< ::protos::Empty,::protos::Empty>* server_unary_streamer) = 0; + }; + typedef WithStreamedUnaryMethod_GetPlayerActions > > > > > > > > StreamedUnaryService; typedef Service SplitStreamedService; - typedef WithStreamedUnaryMethod_GetPlayerActions > > > > > > > StreamedService; + typedef WithStreamedUnaryMethod_GetPlayerActions > > > > > > > > StreamedService; }; } // namespace protos diff --git a/src/grpc/service.pb.cc b/src/grpc/service.pb.cc index e326e795..75f2f852 100644 --- a/src/grpc/service.pb.cc +++ b/src/grpc/service.pb.cc @@ -5955,7 +5955,7 @@ const char descriptor_table_protodef_service_2eproto[] PROTOBUF_SECTION_VARIABLE "eld_\020\034\022\020\n\014PenaltyFoul_\020\035\022\020\n\014GoalieCatch_" "\020\036\022\016\n\nExtendHalf\020\037\022\014\n\010MODE_MAX\020 *2\n\tAgen" "tType\022\013\n\007PlayerT\020\000\022\n\n\006CoachT\020\001\022\014\n\010Traine" - "rT\020\0022\340\003\n\004Game\022:\n\020GetPlayerActions\022\r.prot" + "rT\020\0022\222\004\n\004Game\022:\n\020GetPlayerActions\022\r.prot" "os.State\032\025.protos.PlayerActions\"\000\0228\n\017Get" "CoachActions\022\r.protos.State\032\024.protos.Coa" "chActions\"\000\022<\n\021GetTrainerActions\022\r.proto" @@ -5967,13 +5967,14 @@ const char descriptor_table_protodef_service_2eproto[] PROTOBUF_SECTION_VARIABLE "mpty\"\000\0225\n\016SendPlayerType\022\022.protos.Player" "Type\032\r.protos.Empty\"\000\022@\n\016GetInitMessage\022" "\r.protos.Empty\032\035.protos.InitMessageFromS" - "erver\"\000b\006proto3" + "erver\"\000\0220\n\016SendByeCommand\022\r.protos.Empty" + "\032\r.protos.Empty\"\000b\006proto3" }; static ::absl::once_flag descriptor_table_service_2eproto_once; const ::_pbi::DescriptorTable descriptor_table_service_2eproto = { false, false, - 26455, + 26505, descriptor_table_protodef_service_2eproto, "service.proto", &descriptor_table_service_2eproto_once, diff --git a/src/player/sample_player.cpp b/src/player/sample_player.cpp index cf691035..5668340e 100644 --- a/src/player/sample_player.cpp +++ b/src/player/sample_player.cpp @@ -338,6 +338,15 @@ SamplePlayer::actionImpl() Bhv_SetPlay().execute( this ); } +void +SamplePlayer::handleExit() +{ + std::cout << "BYE BYE BYE BYE BYE" << std::endl; + M_grpc_agent.sendByeCommand(); + // call super class method + PlayerAgent::handleExit(); +} + /*-------------------------------------------------------------------*/ /*! diff --git a/src/player/sample_player.h b/src/player/sample_player.h index d0d9e500..b0e58899 100644 --- a/src/player/sample_player.h +++ b/src/player/sample_player.h @@ -74,6 +74,9 @@ class SamplePlayer virtual void actionImpl(); + void + handleExit() override; + //! communication decision virtual void communicationImpl(); From 21117a54af0471001c04a9b5080049d464e18dd6 Mon Sep 17 00:00:00 2001 From: arefsa78 Date: Tue, 23 Apr 2024 00:21:17 -0230 Subject: [PATCH 2/2] add trainer handle exit --- src/trainer/sample_trainer.cpp | 7 +++++++ src/trainer/sample_trainer.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/src/trainer/sample_trainer.cpp b/src/trainer/sample_trainer.cpp index 6874faee..9a04d8d7 100644 --- a/src/trainer/sample_trainer.cpp +++ b/src/trainer/sample_trainer.cpp @@ -145,6 +145,13 @@ SampleTrainer::actionImpl() doKeepaway(); } +void +SampleTrainer::handleExit() +{ + M_grpc_agent.sendByeCommand(); + TrainerAgent::handleExit(); +} + /*-------------------------------------------------------------------*/ /*! diff --git a/src/trainer/sample_trainer.h b/src/trainer/sample_trainer.h index e528a91e..9154ec4c 100644 --- a/src/trainer/sample_trainer.h +++ b/src/trainer/sample_trainer.h @@ -58,6 +58,8 @@ class SampleTrainer */ virtual bool initImpl( rcsc::CmdLineParser & cmd_parser ); + void + handleExit() override; //! main decision virtual