Tomasz Wasilczyk | 6301e8f | 2021-10-18 16:53:40 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2021 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | #pragma once |
| 17 | |
| 18 | #include <hidl/HidlSupport.h> |
| 19 | |
| 20 | namespace android::hardware::radio::compat { |
| 21 | |
| 22 | /** |
| 23 | * Converts hidl_vec<T> HIDL list to std::vector<T> AIDL list. |
| 24 | * |
| 25 | * To convert values, the template uses toAidl functions for a given type T, assuming it's defined. |
| 26 | * |
| 27 | * \param inp vector to convert |
| 28 | */ |
| 29 | template <typename T> |
| 30 | auto toAidl(const hidl_vec<T>& inp) { |
| 31 | std::vector<decltype(toAidl(T{}))> out(inp.size()); |
| 32 | for (size_t i = 0; i < inp.size(); i++) { |
| 33 | out[i] = toAidl(inp[i]); |
| 34 | } |
| 35 | return out; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Converts std::vector<T> AIDL list to hidl_vec<T> HIDL list. |
| 40 | * |
| 41 | * To convert values, the template uses toHidl functions for a given type T, assuming it's defined. |
| 42 | * |
| 43 | * \param inp vector to convert |
| 44 | */ |
| 45 | template <typename T> |
| 46 | auto toHidl(const std::vector<T>& inp) { |
| 47 | hidl_vec<decltype(toHidl(T{}))> out(inp.size()); |
| 48 | for (size_t i = 0; i < inp.size(); i++) { |
| 49 | out[i] = toHidl(inp[i]); |
| 50 | } |
| 51 | return out; |
| 52 | } |
| 53 | |
| 54 | } // namespace android::hardware::radio::compat |