Skip to content

Commit

Permalink
Merge pull request #16 from ichiro-its/enhancement/load-config-for-se…
Browse files Browse the repository at this point in the history
…rver

[Enhancement] Create Load Config For Server
  • Loading branch information
mbsaloka authored Jun 15, 2024
2 parents dc1d488 + 8f19d4f commit 4d93a48
Show file tree
Hide file tree
Showing 25 changed files with 208 additions and 101 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ message(STATUS "Using gRPC ${gRPC_VERSION}")
add_library(${PROJECT_NAME} SHARED
"src/${PROJECT_NAME}/config/grpc/config.cpp"
"src/${PROJECT_NAME}/config/grpc/call_data_get_color_setting.cpp"
"src/${PROJECT_NAME}/config/grpc/call_data_load_config.cpp"
"src/${PROJECT_NAME}/config/grpc/call_data_save_color_setting.cpp"
"src/${PROJECT_NAME}/config/grpc/call_data_set_color_setting.cpp"
"src/${PROJECT_NAME}/config/utils/config.cpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#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>
#include "ninshiki_cpp/config/grpc/call_data.hpp"

namespace ninshiki_cpp
{
Expand Down
48 changes: 48 additions & 0 deletions include/ninshiki_cpp/config/grpc/call_data_load_config.hpp
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_LOAD_CONFIG_HPP__
#define NINSHIKI_CPP_CONFIG__GRPC__CALL_DATA_LOAD_CONFIG_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 CallDataLoadConfig
: CallData<ninshiki_interfaces::proto::Empty, ninshiki_interfaces::proto::Empty>
{
public:
CallDataLoadConfig(
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_LOAD_CONFIG_HPP__
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#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>
#include "ninshiki_cpp/config/grpc/call_data.hpp"
#include "rclcpp/rclcpp.hpp"

namespace ninshiki_cpp
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
#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>
#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
{
Expand Down
8 changes: 4 additions & 4 deletions include/ninshiki_cpp/config/grpc/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
#ifndef NINSHIKI_CPP__CONFIG__GRPC__CONFIG_HPP_
#define NINSHIKI_CPP__CONFIG__GRPC__CONFIG_HPP_

#include <grpcpp/grpcpp.h>
#include <ninshiki_cpp/detector/color_detector.hpp>
#include <ninshiki_interfaces/ninshiki.grpc.pb.h>
#include <ninshiki_interfaces/ninshiki.pb.h>
#include "grpcpp/grpcpp.h"
#include "ninshiki_cpp/detector/color_detector.hpp"
#include "ninshiki_interfaces/ninshiki.grpc.pb.h"
#include "ninshiki_interfaces/ninshiki.pb.h"

#include <memory>
#include <thread>
Expand Down
23 changes: 11 additions & 12 deletions include/ninshiki_cpp/detector/color_detector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,21 @@
#ifndef NINSHIKI_CPP__DETECTOR__COLOR_DETECTOR_HPP_
#define NINSHIKI_CPP__DETECTOR__COLOR_DETECTOR_HPP_

#include <opencv2/opencv.hpp>
#include <cmath>

#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <map>

#include "keisan/geometry/point_2.hpp"
#include "ninshiki_cpp/detector/detector.hpp"
#include "ninshiki_cpp/utils/color.hpp"
#include "ninshiki_cpp/utils/utils.hpp"
#include "ninshiki_interfaces/msg/point.hpp"
#include "ninshiki_interfaces/msg/contour.hpp"
#include "ninshiki_interfaces/msg/contours.hpp"
#include "ninshiki_cpp/utils/color.hpp"
#include "ninshiki_cpp/utils/utils.hpp"
#include "ninshiki_cpp/detector/detector.hpp"

#include <cmath>
#include <fstream>
#include <map>
#include <opencv2/opencv.hpp>
#include <sstream>
#include <string>
#include <vector>

namespace ninshiki_cpp::detector
{
Expand Down
10 changes: 5 additions & 5 deletions include/ninshiki_cpp/detector/detector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
#ifndef NINSHIKI_CPP__DETECTOR__DETECTOR_HPP_
#define NINSHIKI_CPP__DETECTOR__DETECTOR_HPP_

#include <opencv2/core.hpp>
#include <opencv2/objdetect.hpp>
#include <vector>
#include <string>

#include "ninshiki_cpp/utils/utils.hpp"
#include "ninshiki_interfaces/msg/detected_object.hpp"
#include "ninshiki_interfaces/msg/detected_objects.hpp"

#include <opencv2/core.hpp>
#include <opencv2/objdetect.hpp>
#include <string>
#include <vector>

namespace ninshiki_cpp::detector
{

Expand Down
15 changes: 7 additions & 8 deletions include/ninshiki_cpp/detector/dnn_detector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,18 @@
#ifndef NINSHIKI_CPP__DETECTOR__DNN_DETECTOR_HPP_
#define NINSHIKI_CPP__DETECTOR__DNN_DETECTOR_HPP_

#include <opencv2/dnn.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include "ninshiki_cpp/detector/detector.hpp"
#include "ninshiki_cpp/utils/utils.hpp"
#include "ninshiki_interfaces/msg/detected_object.hpp"
#include "ninshiki_interfaces/msg/detected_objects.hpp"

#include <fstream>
#include <opencv2/dnn.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <string>
#include <vector>

#include "ninshiki_cpp/detector/detector.hpp"
#include "ninshiki_interfaces/msg/detected_object.hpp"
#include "ninshiki_interfaces/msg/detected_objects.hpp"
#include "ninshiki_cpp/utils/utils.hpp"

namespace ninshiki_cpp::detector
{

Expand Down
12 changes: 6 additions & 6 deletions include/ninshiki_cpp/detector/lbp_detector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
#ifndef NINSHIKI_CPP__DETECTOR__LBP_DETECTOR_HPP_
#define NINSHIKI_CPP__DETECTOR__LBP_DETECTOR_HPP_

#include <opencv2/core.hpp>
#include <opencv2/objdetect.hpp>
#include <vector>
#include <string>

#include "ninshiki_cpp/utils/utils.hpp"
#include "ninshiki_cpp/detector/detector.hpp"
#include "ninshiki_cpp/utils/utils.hpp"
#include "ninshiki_interfaces/msg/detected_object.hpp"
#include "ninshiki_interfaces/msg/detected_objects.hpp"

#include <opencv2/core.hpp>
#include <opencv2/objdetect.hpp>
#include <string>
#include <vector>

namespace ninshiki_cpp::detector
{
class LBPDetector : public Detector
Expand Down
17 changes: 8 additions & 9 deletions include/ninshiki_cpp/node/ninshiki_cpp_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,22 @@
#ifndef NINSHIKI_CPP__NODE__NINSHIKI_CPP_NODE_HPP_
#define NINSHIKI_CPP__NODE__NINSHIKI_CPP_NODE_HPP_

#include <opencv2/dnn.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>

#include <memory>
#include <string>

#include "rclcpp/rclcpp.hpp"
#include "sensor_msgs/msg/image.hpp"
#include "ninshiki_cpp/config/grpc/config.hpp"
#include "ninshiki_cpp/detector/color_detector.hpp"
#include "ninshiki_cpp/detector/detector.hpp"
#include "ninshiki_cpp/detector/dnn_detector.hpp"
#include "ninshiki_cpp/detector/lbp_detector.hpp"
#include "ninshiki_interfaces/msg/detected_objects.hpp"
#include "rclcpp/rclcpp.hpp"
#include "sensor_msgs/msg/image.hpp"
#include "shisen_cpp/shisen_cpp.hpp"

#include <memory>
#include <opencv2/dnn.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <string>

namespace ninshiki_cpp::node
{

Expand Down
6 changes: 3 additions & 3 deletions include/ninshiki_cpp/utils/contours.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
#ifndef NINSHIKI_CPP__UTILS__CONTOURS_HPP_
#define NINSHIKI_CPP__UTILS__CONTOURS_HPP_

#include <string>
#include <vector>

#include "opencv2/opencv.hpp"
#include "keisan/keisan.hpp"

#include <string>
#include <vector>

namespace ninshiki_cpp::utils
{

Expand Down
10 changes: 5 additions & 5 deletions src/ninshiki_cpp/config/grpc/call_data_get_color_setting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#include <ninshiki_cpp/config/grpc/call_data_get_color_setting.hpp>
#include <ninshiki_cpp/config/utils/config.hpp>
#include <ninshiki_interfaces/ninshiki.grpc.pb.h>
#include <ninshiki_interfaces/ninshiki.pb.h>
#include <rclcpp/rclcpp.hpp>
#include "ninshiki_cpp/config/grpc/call_data_get_color_setting.hpp"
#include "ninshiki_cpp/config/utils/config.hpp"
#include "ninshiki_interfaces/ninshiki.grpc.pb.h"
#include "ninshiki_interfaces/ninshiki.pb.h"
#include "rclcpp/rclcpp.hpp"

namespace ninshiki_cpp
{
Expand Down
59 changes: 59 additions & 0 deletions src/ninshiki_cpp/config/grpc/call_data_load_config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// 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.

#include "ninshiki_cpp/config/grpc/call_data_load_config.hpp"
#include "ninshiki_cpp/config/utils/config.hpp"
#include "ninshiki_interfaces/ninshiki.grpc.pb.h"
#include "ninshiki_interfaces/ninshiki.pb.h"
#include "rclcpp/rclcpp.hpp"

namespace ninshiki_cpp
{
CallDataLoadConfig::CallDataLoadConfig(
ninshiki_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq,
const std::string & path, std::shared_ptr<ninshiki_cpp::detector::ColorDetector> color_detection)
: CallData(service, cq, path), color_detection_(color_detection)
{
Proceed();
}

void CallDataLoadConfig::AddNextToCompletionQueue()
{
new CallDataLoadConfig(service_, cq_, path_, color_detection_);
}

void CallDataLoadConfig::WaitForRequest()
{
service_->RequestLoadConfig(&ctx_, &request_, &responder_, cq_, cq_, this);
}

void CallDataLoadConfig::HandleRequest()
{
try {
color_detection_->load_configuration(path_);

RCLCPP_INFO(
rclcpp::get_logger("Load config"), "config has been loaded!"
);
} catch (nlohmann::json::exception e) {
RCLCPP_ERROR(rclcpp::get_logger("Load config"), e.what());
}
}
} // namespace ninshiki_cpp
12 changes: 6 additions & 6 deletions src/ninshiki_cpp/config/grpc/call_data_save_color_setting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#include <ninshiki_cpp/config/grpc/call_data_save_color_setting.hpp>
#include <ninshiki_cpp/config/utils/config.hpp>
#include <ninshiki_interfaces/ninshiki.grpc.pb.h>
#include <ninshiki_interfaces/ninshiki.pb.h>
#include <nlohmann/json.hpp>
#include <rclcpp/rclcpp.hpp>
#include "ninshiki_cpp/config/grpc/call_data_save_color_setting.hpp"
#include "ninshiki_cpp/config/utils/config.hpp"
#include "ninshiki_interfaces/ninshiki.grpc.pb.h"
#include "ninshiki_interfaces/ninshiki.pb.h"
#include "nlohmann/json.hpp"
#include "rclcpp/rclcpp.hpp"

namespace ninshiki_cpp
{
Expand Down
10 changes: 5 additions & 5 deletions src/ninshiki_cpp/config/grpc/call_data_set_color_setting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#include <ninshiki_cpp/config/grpc/call_data_set_color_setting.hpp>
#include <ninshiki_cpp/config/utils/config.hpp>
#include <ninshiki_interfaces/ninshiki.grpc.pb.h>
#include <ninshiki_interfaces/ninshiki.pb.h>
#include <rclcpp/rclcpp.hpp>
#include "ninshiki_cpp/config/grpc/call_data_set_color_setting.hpp"
#include "ninshiki_cpp/config/utils/config.hpp"
#include "ninshiki_interfaces/ninshiki.grpc.pb.h"
#include "ninshiki_interfaces/ninshiki.pb.h"
#include "rclcpp/rclcpp.hpp"

namespace ninshiki_cpp
{
Expand Down
Loading

0 comments on commit 4d93a48

Please sign in to comment.