Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 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 | */ |
Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 16 | #define LOG_TAG "BroadcastRadioDefault.factory" |
| 17 | #define LOG_NDEBUG 0 |
| 18 | |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 19 | #include "BroadcastRadioFactory.h" |
Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 20 | |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 21 | #include "BroadcastRadio.h" |
| 22 | |
Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 23 | #include <log/log.h> |
| 24 | |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 25 | namespace android { |
| 26 | namespace hardware { |
| 27 | namespace broadcastradio { |
| 28 | namespace V1_1 { |
| 29 | namespace implementation { |
| 30 | |
Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 31 | using V1_0::Class; |
| 32 | |
| 33 | using std::vector; |
| 34 | |
| 35 | static const vector<Class> gAllClasses = { |
| 36 | Class::AM_FM, Class::SAT, Class::DT, |
| 37 | }; |
| 38 | |
| 39 | IBroadcastRadioFactory* HIDL_FETCH_IBroadcastRadioFactory(const char* name __unused) { |
| 40 | return new BroadcastRadioFactory(); |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 41 | } |
| 42 | |
Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 43 | BroadcastRadioFactory::BroadcastRadioFactory() { |
| 44 | for (auto&& classId : gAllClasses) { |
| 45 | if (!BroadcastRadio::isSupported(classId)) continue; |
| 46 | mRadioModules[classId] = new BroadcastRadio(classId); |
| 47 | } |
| 48 | } |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 49 | |
Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 50 | Return<void> BroadcastRadioFactory::connectModule(Class classId, connectModule_cb _hidl_cb) { |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame^] | 51 | ALOGV("%s(%s)", __func__, toString(classId).c_str()); |
Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 52 | |
| 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 Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | } // namespace implementation |
| 64 | } // namespace V1_1 |
| 65 | } // namespace broadcastradio |
| 66 | } // namespace hardware |
| 67 | } // namespace android |