blob: 1e2ef4e0a4e900b0f97ea50009393ff36425303f [file] [log] [blame]
Roshan Pius80c3cc62021-08-27 12:55:02 -07001/*
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
20namespace {
21static constexpr char kDefaultChipName[] = "default";
22
23} // namespace
24
25namespace android {
26namespace hardware {
27namespace uwb {
28namespace impl {
29using namespace ::aidl::android::hardware::uwb;
30
31// The default implementation of the HAL assumes 1 chip on the device.
32Uwb::Uwb() : chips_({{kDefaultChipName, ndk::SharedRefBase::make<UwbChip>(kDefaultChipName)}}) {}
33
34Uwb::~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