| // Copyright 2024 Google LLC |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| #include "libhoth_usb.hpp" |
| |
| #include <stdexcept> |
| #include <type_traits> |
| |
| // NOLINTNEXTLINE(cert-dcl58-cpp) |
| namespace google |
| { |
| namespace hoth |
| { |
| namespace |
| { |
| template <typename T> |
| int convertStatus(T status) |
| { |
| if constexpr (std::is_same_v<std::decay_t<T>, int>) |
| { |
| return status; |
| } |
| else |
| { |
| return static_cast<int>( |
| static_cast<int32_t>(LIBHOTH_ERR_GET_CODE(status))); |
| } |
| } |
| } // namespace |
| |
| int LibHothUsbImpl::open(const option* opt, device** dev) |
| { |
| return convertStatus(::libhoth_usb_open(opt, dev)); |
| } |
| |
| int LibHothUsbImpl::send(device* dev, const void* request, size_t size) |
| { |
| return convertStatus(::libhoth_send_request(dev, request, size)); |
| } |
| |
| int LibHothUsbImpl::recv(device* dev, void* response, size_t response_size, |
| size_t* actual_size, int timeout_ms) |
| { |
| return convertStatus(::libhoth_usb_receive_response( |
| dev, response, response_size, actual_size, timeout_ms)); |
| } |
| |
| int LibHothUsbImpl::close(device* dev) |
| { |
| return convertStatus(::libhoth_usb_close(dev)); |
| } |
| |
| int LibHothUsbImpl::claim(device* dev) |
| { |
| return convertStatus(dev->claim(dev)); |
| } |
| |
| int LibHothUsbImpl::release(device* dev) |
| { |
| return convertStatus(dev->release(dev)); |
| } |
| |
| LibHothUsbImpl libhoth_usb; |
| } // namespace hoth |
| |
| } // namespace google |