Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [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 | */ |
| 16 | #include "VirtualRadio.h" |
| 17 | |
Tomasz Wasilczyk | a02b6ef | 2017-07-05 11:23:30 -0700 | [diff] [blame] | 18 | #include <Utils.h> |
| 19 | |
Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 20 | namespace android { |
| 21 | namespace hardware { |
| 22 | namespace broadcastradio { |
| 23 | namespace V1_1 { |
| 24 | namespace implementation { |
| 25 | |
Tomasz Wasilczyk | a02b6ef | 2017-07-05 11:23:30 -0700 | [diff] [blame] | 26 | using V1_0::Band; |
| 27 | |
Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 28 | using std::lock_guard; |
| 29 | using std::move; |
| 30 | using std::mutex; |
| 31 | using std::vector; |
| 32 | |
Tomasz Wasilczyk | a02b6ef | 2017-07-05 11:23:30 -0700 | [diff] [blame] | 33 | using utils::make_selector; |
| 34 | |
Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 35 | vector<VirtualProgram> gInitialFmPrograms{ |
Tomasz Wasilczyk | a02b6ef | 2017-07-05 11:23:30 -0700 | [diff] [blame] | 36 | {make_selector(Band::FM, 94900), "Wild 94.9", "Drake ft. Rihanna", "Too Good"}, |
| 37 | {make_selector(Band::FM, 96500), "KOIT", "Celine Dion", "All By Myself"}, |
| 38 | {make_selector(Band::FM, 97300), "Alice@97.3", "Drops of Jupiter", "Train"}, |
| 39 | {make_selector(Band::FM, 99700), "99.7 Now!", "The Chainsmokers", "Closer"}, |
| 40 | {make_selector(Band::FM, 101300), "101-3 KISS-FM", "Justin Timberlake", "Rock Your Body"}, |
| 41 | {make_selector(Band::FM, 103700), "iHeart80s @ 103.7", "Michael Jackson", "Billie Jean"}, |
| 42 | {make_selector(Band::FM, 106100), "106 KMEL", "Drake", "Marvins Room"}, |
Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | VirtualRadio::VirtualRadio(VirtualRadio&& o) : mPrograms(move(o.mPrograms)) {} |
| 46 | |
| 47 | VirtualRadio::VirtualRadio(vector<VirtualProgram> initialList) : mPrograms(initialList) {} |
| 48 | |
| 49 | vector<VirtualProgram> VirtualRadio::getProgramList() { |
| 50 | lock_guard<mutex> lk(mMut); |
| 51 | return mPrograms; |
| 52 | } |
| 53 | |
Tomasz Wasilczyk | a02b6ef | 2017-07-05 11:23:30 -0700 | [diff] [blame] | 54 | bool VirtualRadio::getProgram(const ProgramSelector& selector, VirtualProgram& programOut) { |
Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 55 | lock_guard<mutex> lk(mMut); |
| 56 | for (auto&& program : mPrograms) { |
Tomasz Wasilczyk | a02b6ef | 2017-07-05 11:23:30 -0700 | [diff] [blame] | 57 | if (utils::tunesTo(selector, program.selector)) { |
Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 58 | programOut = program; |
| 59 | return true; |
| 60 | } |
| 61 | } |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | VirtualRadio make_fm_radio() { |
| 66 | return VirtualRadio(gInitialFmPrograms); |
| 67 | } |
| 68 | |
| 69 | } // namespace implementation |
| 70 | } // namespace V1_1 |
| 71 | } // namespace broadcastradio |
| 72 | } // namespace hardware |
| 73 | } // namespace android |