blob: acf37a40e7039ea67a93622d89b22b10d767d3da [file] [log] [blame]
Tomasz Wasilczyk48377552017-06-22 10:45:33 -07001/*
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 Wasilczyka02b6ef2017-07-05 11:23:30 -070018#include <Utils.h>
19
Tomasz Wasilczyk48377552017-06-22 10:45:33 -070020namespace android {
21namespace hardware {
22namespace broadcastradio {
23namespace V1_1 {
24namespace implementation {
25
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070026using V1_0::Band;
27
Tomasz Wasilczyk48377552017-06-22 10:45:33 -070028using std::lock_guard;
29using std::move;
30using std::mutex;
31using std::vector;
32
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070033using utils::make_selector;
34
Tomasz Wasilczyk48377552017-06-22 10:45:33 -070035vector<VirtualProgram> gInitialFmPrograms{
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070036 {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 Wasilczyk48377552017-06-22 10:45:33 -070043};
44
45VirtualRadio::VirtualRadio(VirtualRadio&& o) : mPrograms(move(o.mPrograms)) {}
46
47VirtualRadio::VirtualRadio(vector<VirtualProgram> initialList) : mPrograms(initialList) {}
48
49vector<VirtualProgram> VirtualRadio::getProgramList() {
50 lock_guard<mutex> lk(mMut);
51 return mPrograms;
52}
53
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070054bool VirtualRadio::getProgram(const ProgramSelector& selector, VirtualProgram& programOut) {
Tomasz Wasilczyk48377552017-06-22 10:45:33 -070055 lock_guard<mutex> lk(mMut);
56 for (auto&& program : mPrograms) {
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070057 if (utils::tunesTo(selector, program.selector)) {
Tomasz Wasilczyk48377552017-06-22 10:45:33 -070058 programOut = program;
59 return true;
60 }
61 }
62 return false;
63}
64
65VirtualRadio 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