-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from ichiro-its/feature/fix-grpc
[Sprint 22/23 / PD-405] [Feature] Add implementation GRPC
- Loading branch information
Showing
18 changed files
with
778 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// 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 | ||
// 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. | ||
|
||
#ifndef __NINSHIKI_CPP__CONFIG__GRPC__CALL_DATA_HPP__ | ||
#define __NINSHIKI_CPP__CONFIG__GRPC__CALL_DATA_HPP__ | ||
|
||
#include "ninshiki_cpp/config/grpc/call_data_base.hpp" | ||
#include "ninshiki_interfaces/ninshiki.grpc.pb.h" | ||
#include "ninshiki_interfaces/ninshiki.pb.h" | ||
#include "grpc/support/log.h" | ||
#include "grpcpp/grpcpp.h" | ||
|
||
namespace ninshiki_cpp | ||
{ | ||
template <class ConfigRequest, class ConfigReply> | ||
class CallData : public CallDataBase | ||
{ | ||
public: | ||
CallData( | ||
ninshiki_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, | ||
const std::string & path); | ||
|
||
void Proceed(); | ||
|
||
protected: | ||
virtual void AddNextToCompletionQueue() = 0; | ||
|
||
enum CallStatus { CREATE, PROCESS, FINISH }; | ||
|
||
CallStatus status_; // The current serving state. | ||
|
||
ninshiki_interfaces::proto::Config::AsyncService * service_; | ||
|
||
const std::string path_; | ||
|
||
grpc::ServerCompletionQueue * cq_; | ||
grpc::ServerContext ctx_; | ||
ConfigRequest request_; | ||
ConfigReply reply_; | ||
grpc::ServerAsyncResponseWriter<ConfigReply> responder_; | ||
}; | ||
|
||
template <class ConfigRequest, class ConfigReply> | ||
CallData<ConfigRequest, ConfigReply>::CallData( | ||
ninshiki_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, | ||
const std::string & path) | ||
: status_(CREATE), service_(service), cq_(cq), responder_(&ctx_), path_(path) | ||
{ | ||
} | ||
|
||
template <class ConfigRequest, class ConfigReply> | ||
void CallData<ConfigRequest, ConfigReply>::Proceed() | ||
{ | ||
if (status_ == CREATE) { | ||
status_ = PROCESS; | ||
WaitForRequest(); | ||
} else if (status_ == PROCESS) { | ||
AddNextToCompletionQueue(); | ||
HandleRequest(); | ||
status_ = FINISH; | ||
responder_.Finish(reply_, grpc::Status::OK, this); | ||
} else { | ||
GPR_ASSERT(status_ == FINISH); | ||
delete this; | ||
} | ||
} | ||
|
||
} // namespace ninshiki_cpp | ||
|
||
#endif // __NINSHIKI_CPP__CONFIG__GRPC__CALL_DATA_HPP__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// 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 | ||
// 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. | ||
|
||
#ifndef NINSHIKI_CPP__CONFIG__GRPC__CALL_DATA_BASE_HPP_ | ||
#define NINSHIKI_CPP__CONFIG__GRPC__CALL_DATA_BASE_HPP_ | ||
|
||
namespace ninshiki_cpp | ||
{ | ||
class CallDataBase | ||
{ | ||
public: | ||
virtual void Proceed() = 0; | ||
|
||
protected: | ||
virtual void WaitForRequest() = 0; | ||
virtual void HandleRequest() = 0; | ||
}; | ||
} // namespace ninshiki_cpp | ||
|
||
#endif // NINSHIKI_CPP__CONFIG__GRPC__CALL_DATA_BASE_HPP_ |
43 changes: 43 additions & 0 deletions
43
include/ninshiki_cpp/config/grpc/call_data_get_color_setting.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// 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 | ||
// 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. | ||
|
||
#ifndef NINSHIKI_CPP__CONFIG__GRPC__CALL_DATA_GET_COLOR_SETTING_HPP__ | ||
#define NINSHIKI_CPP__CONFIG__GRPC__CALL_DATA_GET_COLOR_SETTING_HPP__ | ||
|
||
#include <ninshiki_cpp/config/grpc/call_data.hpp> | ||
|
||
namespace ninshiki_cpp | ||
{ | ||
class CallDataGetColorSetting | ||
: CallData<ninshiki_interfaces::proto::Empty, ninshiki_interfaces::proto::ConfigColor> | ||
{ | ||
public: | ||
CallDataGetColorSetting( | ||
ninshiki_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, | ||
const std::string & path); | ||
|
||
protected: | ||
void AddNextToCompletionQueue() override; | ||
void WaitForRequest() override; | ||
void HandleRequest() override; | ||
}; | ||
} // namespace ninshiki_cpp | ||
|
||
#endif // NINSHIKI_CPP__CONFIG__GRPC__CALL_DATA_GET_COLOR_SETTING_HPP__ |
45 changes: 45 additions & 0 deletions
45
include/ninshiki_cpp/config/grpc/call_data_save_color_setting.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// 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 | ||
// 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. | ||
|
||
#ifndef NINSHIKI_CPP__CONFIG__GRPC__CALL_DATA_SAVE_COLOR_SETTING_HPP__ | ||
#define NINSHIKI_CPP__CONFIG__GRPC__CALL_DATA_SAVE_COLOR_SETTING_HPP__ | ||
|
||
#include <ninshiki_cpp/config/grpc/call_data.hpp> | ||
#include <rclcpp/rclcpp.hpp> | ||
|
||
namespace ninshiki_cpp | ||
{ | ||
class CallDataSaveColorSetting | ||
: CallData<ninshiki_interfaces::proto::ConfigColor, ninshiki_interfaces::proto::Empty> | ||
{ | ||
public: | ||
CallDataSaveColorSetting( | ||
ninshiki_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, | ||
const std::string & path); | ||
|
||
protected: | ||
void AddNextToCompletionQueue() override; | ||
void WaitForRequest() override; | ||
void HandleRequest() override; | ||
}; | ||
|
||
} // namespace ninshiki_cpp | ||
|
||
#endif // NINSHIKI_CPP__CONFIG__GRPC__CALL_DATA_SAVE_COLOR_SETTING_HPP__ |
48 changes: 48 additions & 0 deletions
48
include/ninshiki_cpp/config/grpc/call_data_set_color_setting.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// 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 | ||
// 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. | ||
|
||
#ifndef NINSHIKI_CPP_CONFIG__GRPC__CALL_DATA_SET_COLOR_SETTING_HPP__ | ||
#define NINSHIKI_CPP_CONFIG__GRPC__CALL_DATA_SET_COLOR_SETTING_HPP__ | ||
|
||
#include <rclcpp/rclcpp.hpp> | ||
#include <ninshiki_cpp/config/grpc/call_data.hpp> | ||
#include <ninshiki_cpp/detector/color_detector.hpp> | ||
#include <ninshiki_cpp/utils/color.hpp> | ||
|
||
namespace ninshiki_cpp | ||
{ | ||
class CallDataSetColorSetting | ||
: CallData<ninshiki_interfaces::proto::ColorSetting, ninshiki_interfaces::proto::Empty> | ||
{ | ||
public: | ||
CallDataSetColorSetting( | ||
ninshiki_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, | ||
const std::string & path, std::shared_ptr<ninshiki_cpp::detector::ColorDetector> color_detection); | ||
using ColorDetector = ninshiki_cpp::detector::ColorDetector; | ||
|
||
protected: | ||
void AddNextToCompletionQueue() override; | ||
void WaitForRequest() override; | ||
void HandleRequest() override; | ||
std::shared_ptr<ColorDetector> color_detection_; | ||
}; | ||
} // namespace ninshiki_cpp | ||
|
||
#endif // NINSHIKI_CPP__CONFIG__GRPC__CALL_DATA_SET_COLOR_SETTING_HPP__ |
Oops, something went wrong.