|
| 1 | +// Copyright (c) 2024 ICHIRO ITS |
| 2 | +// |
| 3 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 4 | +// of this software and associated documentation files (the "Software"), to deal |
| 5 | +// in the Software without restriction, including without limitation the rights |
| 6 | +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 7 | +// copies of the Software, and to permit persons to whom the Software is |
| 8 | +// furnished to do so, subject to the following conditions: |
| 9 | +// |
| 10 | +// The above copyright notice and this permission notice shall be included in |
| 11 | +// all copies or substantial portions of the Software. |
| 12 | +// |
| 13 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 16 | +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 18 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 19 | +// THE SOFTWARE. |
| 20 | + |
| 21 | +#include <rclcpp/rclcpp.hpp> |
| 22 | +#include <shisen_cpp/config/grpc/call_data_record_image.hpp> |
| 23 | +#include <shisen_interfaces/shisen.grpc.pb.h> |
| 24 | +#include <shisen_interfaces/shisen.pb.h> |
| 25 | + |
| 26 | +namespace shisen_cpp |
| 27 | +{ |
| 28 | +CallDataRecordImage::CallDataRecordImage( |
| 29 | + shisen_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, |
| 30 | + const std::string & path, const std::shared_ptr<camera::CameraNode>& camera_node) |
| 31 | +: CallData(service, cq, path), camera_node_(camera_node) |
| 32 | +{ |
| 33 | + Proceed(); |
| 34 | +} |
| 35 | + |
| 36 | +void CallDataRecordImage::AddNextToCompletionQueue() |
| 37 | +{ |
| 38 | + new CallDataRecordImage(service_, cq_, path_, camera_node_); |
| 39 | +} |
| 40 | + |
| 41 | +void CallDataRecordImage::WaitForRequest() |
| 42 | +{ |
| 43 | + service_->RequestRecordImage(&ctx_, &request_, &responder_, cq_, cq_, this); |
| 44 | +} |
| 45 | + |
| 46 | +void CallDataRecordImage::HandleRequest() |
| 47 | +{ |
| 48 | + try { |
| 49 | + camera_node_->save_image(camera_node_->get_mat()); |
| 50 | + } catch(const std::exception& e) { |
| 51 | + RCLCPP_ERROR(rclcpp::get_logger("Record Image"), e.what()); |
| 52 | + } |
| 53 | +} |
| 54 | +} // namespace shisen_cpp |
0 commit comments