Tomasz Wasilczyk | 06100b3 | 2017-12-04 09:53:32 -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 | 06100b3 | 2017-12-04 09:53:32 -0800 | [diff] [blame] | 16 | #include "VirtualRadio.h" |
| 17 | |
| 18 | #include <broadcastradio-utils-2x/Utils.h> |
Tomasz Wasilczyk | 06100b3 | 2017-12-04 09:53:32 -0800 | [diff] [blame] | 19 | |
| 20 | namespace android { |
| 21 | namespace hardware { |
| 22 | namespace broadcastradio { |
| 23 | namespace V2_0 { |
| 24 | namespace implementation { |
| 25 | |
| 26 | using std::lock_guard; |
| 27 | using std::move; |
| 28 | using std::mutex; |
| 29 | using std::vector; |
| 30 | using utils::make_selector_amfm; |
Allie | f62374d | 2019-02-19 16:21:51 -0800 | [diff] [blame] | 31 | using utils::make_selector_dab; |
Tomasz Wasilczyk | 06100b3 | 2017-12-04 09:53:32 -0800 | [diff] [blame] | 32 | |
| 33 | VirtualRadio gAmFmRadio( |
| 34 | "AM/FM radio mock", |
| 35 | { |
| 36 | {make_selector_amfm(94900), "Wild 94.9", "Drake ft. Rihanna", "Too Good"}, |
| 37 | {make_selector_amfm(96500), "KOIT", "Celine Dion", "All By Myself"}, |
| 38 | {make_selector_amfm(97300), "Alice@97.3", "Drops of Jupiter", "Train"}, |
| 39 | {make_selector_amfm(99700), "99.7 Now!", "The Chainsmokers", "Closer"}, |
| 40 | {make_selector_amfm(101300), "101-3 KISS-FM", "Justin Timberlake", "Rock Your Body"}, |
| 41 | {make_selector_amfm(103700), "iHeart80s @ 103.7", "Michael Jackson", "Billie Jean"}, |
| 42 | {make_selector_amfm(106100), "106 KMEL", "Drake", "Marvins Room"}, |
| 43 | }); |
| 44 | |
Allie | f62374d | 2019-02-19 16:21:51 -0800 | [diff] [blame] | 45 | // clang-format off |
| 46 | VirtualRadio gDabRadio( |
| 47 | "DAB radio mock", |
| 48 | { |
Weilin Xu | 9f4ff57 | 2022-07-25 22:32:19 +0000 | [diff] [blame] | 49 | {make_selector_dab(0xA00001u, 0x0001u), "BBC Radio 1", "Khalid", "Talk"}, |
| 50 | {make_selector_dab(0xB00001u, 0x1001u), "Classic FM", "Jean Sibelius", "Andante Festivo"}, |
| 51 | {make_selector_dab(0xB00002u, 0x1001u), "Absolute Radio", "Coldplay", "Clocks"}, |
Allie | f62374d | 2019-02-19 16:21:51 -0800 | [diff] [blame] | 52 | }); |
| 53 | // clang-format on |
| 54 | |
Tomasz Wasilczyk | 06100b3 | 2017-12-04 09:53:32 -0800 | [diff] [blame] | 55 | VirtualRadio::VirtualRadio(const std::string& name, const vector<VirtualProgram>& initialList) |
| 56 | : mName(name), mPrograms(initialList) {} |
| 57 | |
| 58 | std::string VirtualRadio::getName() const { |
| 59 | return mName; |
| 60 | } |
| 61 | |
| 62 | vector<VirtualProgram> VirtualRadio::getProgramList() const { |
| 63 | lock_guard<mutex> lk(mMut); |
| 64 | return mPrograms; |
| 65 | } |
| 66 | |
| 67 | bool VirtualRadio::getProgram(const ProgramSelector& selector, VirtualProgram& programOut) const { |
| 68 | lock_guard<mutex> lk(mMut); |
| 69 | for (auto&& program : mPrograms) { |
| 70 | if (utils::tunesTo(selector, program.selector)) { |
| 71 | programOut = program; |
| 72 | return true; |
| 73 | } |
| 74 | } |
| 75 | return false; |
| 76 | } |
| 77 | |
| 78 | } // namespace implementation |
| 79 | } // namespace V2_0 |
| 80 | } // namespace broadcastradio |
| 81 | } // namespace hardware |
| 82 | } // namespace android |