-
Notifications
You must be signed in to change notification settings - Fork 1
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 #25 from ichiro-its/feature/using-grpc
[Sprint 22/23 / PD-405] [Feature] Add implementation GRPC
- Loading branch information
Showing
30 changed files
with
921 additions
and
50 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
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
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,93 @@ | ||
// 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 __SHISEN_CPP__CONFIG__GRPC__CALL_DATA_HPP__ | ||
#define __SHISEN_CPP__CONFIG__GRPC__CALL_DATA_HPP__ | ||
|
||
#include <shisen_cpp/config/grpc/call_data_base.hpp> | ||
#include <shisen_interfaces/shisen.grpc.pb.h> | ||
#include <shisen_interfaces/shisen.pb.h> | ||
|
||
enum class CallStatus | ||
{ | ||
CREATE, | ||
PROCESS, | ||
FINISH, | ||
}; | ||
|
||
namespace shisen_cpp | ||
{ | ||
template <class ConfigRequest, class ConfigReply> | ||
class CallData : public CallDataBase | ||
{ | ||
public: | ||
CallData( | ||
shisen_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, | ||
const std::string & path); | ||
|
||
void Proceed() override; | ||
|
||
protected: | ||
virtual void AddNextToCompletionQueue() = 0; | ||
|
||
CallStatus status_; // The current serving state. | ||
|
||
shisen_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( | ||
shisen_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, | ||
const std::string & path) | ||
: status_(CallStatus::CREATE), service_(service), cq_(cq), responder_(&ctx_), path_(path) | ||
{ | ||
} | ||
|
||
template <class ConfigRequest, class ConfigReply> | ||
void CallData<ConfigRequest, ConfigReply>::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; | ||
case CallStatus::FINISH: | ||
delete this; | ||
break; | ||
} | ||
} | ||
|
||
} // namespace shisen_cpp | ||
|
||
#endif // __SHISEN_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 SHISEN_CPP__CONFIG__GRPC__CALL_DATA_BASE_HPP_ | ||
#define SHISEN_CPP__CONFIG__GRPC__CALL_DATA_BASE_HPP_ | ||
|
||
namespace shisen_cpp | ||
{ | ||
class CallDataBase | ||
{ | ||
public: | ||
virtual void Proceed() = 0; | ||
|
||
protected: | ||
virtual void WaitForRequest() = 0; | ||
virtual void HandleRequest() = 0; | ||
}; | ||
} // namespace shisen_cpp | ||
|
||
#endif // SHISEN_CPP__CONFIG__GRPC__CALL_DATA_BASE_HPP_ |
43 changes: 43 additions & 0 deletions
43
include/shisen_cpp/config/grpc/call_data_get_capture_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 SHISEN_CPP__CONFIG__GRPC__CALL_DATA_GET_CAPTURE_SETTING_HPP__ | ||
#define SHISEN_CPP__CONFIG__GRPC__CALL_DATA_GET_CAPTURE_SETTING_HPP__ | ||
|
||
#include <shisen_cpp/config/grpc/call_data.hpp> | ||
|
||
namespace shisen_cpp | ||
{ | ||
class CallDataGetCaptureSetting | ||
: CallData<shisen_interfaces::proto::Empty, shisen_interfaces::proto::ConfigCapture> | ||
{ | ||
public: | ||
CallDataGetCaptureSetting( | ||
shisen_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, | ||
const std::string & path); | ||
|
||
protected: | ||
void AddNextToCompletionQueue() override; | ||
void WaitForRequest() override; | ||
void HandleRequest() override; | ||
}; | ||
} // namespace shisen_cpp | ||
|
||
#endif // SHISEN_CPP__CONFIG__GRPC__CALL_DATA_GET_CAPTURE_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 SHISEN_CPP__CONFIG__GRPC__CALL_DATA_GET_IMAGE_HPP__ | ||
#define SHISEN_CPP__CONFIG__GRPC__CALL_DATA_GET_IMAGE_HPP__ | ||
|
||
#include <shisen_cpp/camera/node/camera_node.hpp> | ||
#include <shisen_cpp/config/grpc/call_data.hpp> | ||
|
||
namespace shisen_cpp | ||
{ | ||
class CallDataGetImage | ||
: CallData<shisen_interfaces::proto::Empty, shisen_interfaces::proto::Image> | ||
{ | ||
public: | ||
CallDataGetImage( | ||
shisen_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, | ||
const std::string & path, const std::shared_ptr<camera::CameraNode>& camera_node); | ||
|
||
protected: | ||
void AddNextToCompletionQueue() override; | ||
void WaitForRequest() override; | ||
void HandleRequest() override; | ||
std::shared_ptr<camera::CameraNode> camera_node_; | ||
}; | ||
} // namespace shisen_cpp | ||
|
||
#endif // SHISEN_CPP__CONFIG__GRPC__CALL_DATA_GET_IMAGE_HPP__ |
Oops, something went wrong.