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