1/*
2 * Copyright (C) 2017 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#define LOG_TAG "BroadcastRadioDefault.factory"
17#define LOG_NDEBUG 0
18
19#include "BroadcastRadioFactory.h"
20
21#include "BroadcastRadio.h"
22
23#include <log/log.h>
24
25namespace android {
26namespace hardware {
27namespace broadcastradio {
28namespace V1_1 {
29namespace implementation {
30
31using V1_0::Class;
32
33using std::vector;
34
35static const vector<Class> gAllClasses = {
36    Class::AM_FM, Class::SAT, Class::DT,
37};
38
39BroadcastRadioFactory::BroadcastRadioFactory() {
40    for (auto&& classId : gAllClasses) {
41        if (!BroadcastRadio::isSupported(classId)) continue;
42        mRadioModules[classId] = new BroadcastRadio(classId);
43    }
44}
45
46Return<void> BroadcastRadioFactory::connectModule(Class classId, connectModule_cb _hidl_cb) {
47    ALOGV("%s(%s)", __func__, toString(classId).c_str());
48
49    auto moduleIt = mRadioModules.find(classId);
50    if (moduleIt == mRadioModules.end()) {
51        _hidl_cb(Result::INVALID_ARGUMENTS, nullptr);
52    } else {
53        _hidl_cb(Result::OK, moduleIt->second);
54    }
55
56    return Void();
57}
58
59}  // namespace implementation
60}  // namespace V1_1
61}  // namespace broadcastradio
62}  // namespace hardware
63}  // namespace android
64