blob: aecc96745dc9989ddb6de3321fb5447e238a52a7 [file] [log] [blame]
Tomasz Wasilczyk213170b2017-02-07 17:38:21 -08001/*
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 */
Tomasz Wasilczyk48377552017-06-22 10:45:33 -070016#define LOG_TAG "BroadcastRadioDefault.factory"
17#define LOG_NDEBUG 0
18
Tomasz Wasilczyk213170b2017-02-07 17:38:21 -080019#include "BroadcastRadioFactory.h"
Tomasz Wasilczyk48377552017-06-22 10:45:33 -070020
Tomasz Wasilczyk213170b2017-02-07 17:38:21 -080021#include "BroadcastRadio.h"
22
Tomasz Wasilczyk48377552017-06-22 10:45:33 -070023#include <log/log.h>
24
Tomasz Wasilczyk213170b2017-02-07 17:38:21 -080025namespace android {
26namespace hardware {
27namespace broadcastradio {
Tomasz Wasilczyk8c34c812018-02-08 13:42:31 -080028namespace V1_1 {
Tomasz Wasilczyk213170b2017-02-07 17:38:21 -080029namespace implementation {
30
Tomasz Wasilczyk48377552017-06-22 10:45:33 -070031using V1_0::Class;
32
33using std::vector;
34
35static const vector<Class> gAllClasses = {
36 Class::AM_FM, Class::SAT, Class::DT,
37};
38
Tomasz Wasilczyk48377552017-06-22 10:45:33 -070039BroadcastRadioFactory::BroadcastRadioFactory() {
40 for (auto&& classId : gAllClasses) {
41 if (!BroadcastRadio::isSupported(classId)) continue;
42 mRadioModules[classId] = new BroadcastRadio(classId);
43 }
44}
Tomasz Wasilczyk213170b2017-02-07 17:38:21 -080045
Tomasz Wasilczyk48377552017-06-22 10:45:33 -070046Return<void> BroadcastRadioFactory::connectModule(Class classId, connectModule_cb _hidl_cb) {
Tomasz Wasilczykc9ba6462017-07-07 13:28:00 -070047 ALOGV("%s(%s)", __func__, toString(classId).c_str());
Tomasz Wasilczyk48377552017-06-22 10:45:33 -070048
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();
Tomasz Wasilczyk213170b2017-02-07 17:38:21 -080057}
58
59} // namespace implementation
Tomasz Wasilczyk8c34c812018-02-08 13:42:31 -080060} // namespace V1_1
Tomasz Wasilczyk213170b2017-02-07 17:38:21 -080061} // namespace broadcastradio
62} // namespace hardware
63} // namespace android