blob: f57bc79feb36e7611281326e9c1d043a1ac2f202 [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 {
28namespace V1_1 {
29namespace 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
39IBroadcastRadioFactory* HIDL_FETCH_IBroadcastRadioFactory(const char* name __unused) {
40 return new BroadcastRadioFactory();
Tomasz Wasilczyk213170b2017-02-07 17:38:21 -080041}
42
Tomasz Wasilczyk48377552017-06-22 10:45:33 -070043BroadcastRadioFactory::BroadcastRadioFactory() {
44 for (auto&& classId : gAllClasses) {
45 if (!BroadcastRadio::isSupported(classId)) continue;
46 mRadioModules[classId] = new BroadcastRadio(classId);
47 }
48}
Tomasz Wasilczyk213170b2017-02-07 17:38:21 -080049
Tomasz Wasilczyk48377552017-06-22 10:45:33 -070050Return<void> BroadcastRadioFactory::connectModule(Class classId, connectModule_cb _hidl_cb) {
Tomasz Wasilczykc9ba6462017-07-07 13:28:00 -070051 ALOGV("%s(%s)", __func__, toString(classId).c_str());
Tomasz Wasilczyk48377552017-06-22 10:45:33 -070052
53 auto moduleIt = mRadioModules.find(classId);
54 if (moduleIt == mRadioModules.end()) {
55 _hidl_cb(Result::INVALID_ARGUMENTS, nullptr);
56 } else {
57 _hidl_cb(Result::OK, moduleIt->second);
58 }
59
60 return Void();
Tomasz Wasilczyk213170b2017-02-07 17:38:21 -080061}
62
63} // namespace implementation
64} // namespace V1_1
65} // namespace broadcastradio
66} // namespace hardware
67} // namespace android