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 #include "VirtualRadio.h" 17 18 #include <broadcastradio-utils-2x/Utils.h> 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; 31 using utils::make_selector_dab; 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 (at) 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 45 // clang-format off 46 VirtualRadio gDabRadio( 47 "DAB radio mock", 48 { 49 {make_selector_dab(12345, 225648), "BBC Radio 1", "Khalid", "Talk"}, // 12B 50 {make_selector_dab(22345, 222064), "Classic FM", "Jean Sibelius", "Andante Festivo"}, // 11D 51 {make_selector_dab(32345, 222064), "Absolute Radio", "Coldplay", "Clocks"}, // 11D 52 }); 53 // clang-format on 54 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 83