Roshan Pius | 80c3cc6 | 2021-08-27 12:55:02 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 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 | #include <android-base/logging.h> |
| 17 | |
| 18 | #include "uwb.h" |
| 19 | |
| 20 | namespace { |
| 21 | static constexpr char kDefaultChipName[] = "default"; |
| 22 | |
| 23 | } // namespace |
| 24 | |
| 25 | namespace android { |
| 26 | namespace hardware { |
| 27 | namespace uwb { |
| 28 | namespace impl { |
| 29 | using namespace ::aidl::android::hardware::uwb; |
| 30 | |
| 31 | // The default implementation of the HAL assumes 1 chip on the device. |
| 32 | Uwb::Uwb() : chips_({{kDefaultChipName, ndk::SharedRefBase::make<UwbChip>(kDefaultChipName)}}) {} |
| 33 | |
| 34 | Uwb::~Uwb() {} |
| 35 | |
| 36 | ::ndk::ScopedAStatus Uwb::getChips(std::vector<std::string>* names) { |
| 37 | for (const auto& chip : chips_) { |
| 38 | names->push_back(chip.first); |
| 39 | } |
| 40 | return ndk::ScopedAStatus::ok(); |
| 41 | } |
| 42 | |
| 43 | ::ndk::ScopedAStatus Uwb::getChip(const std::string& name, std::shared_ptr<IUwbChip>* chip) { |
| 44 | const auto chip_found = chips_.find(name); |
| 45 | if (chip_found == chips_.end()) { |
| 46 | LOG(ERROR) << "Unknown chip name" << name; |
| 47 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 48 | } |
| 49 | *chip = chip_found->second; |
| 50 | return ndk::ScopedAStatus::ok(); |
| 51 | } |
| 52 | } // namespace impl |
| 53 | } // namespace uwb |
| 54 | } // namespace hardware |
| 55 | } // namespace android |