blob: 0b65979b76de97f1bafc9445b5553526b113463d [file] [log] [blame]
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -08001/*
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 Wasilczyk06100b32017-12-04 09:53:32 -080016#include "VirtualRadio.h"
17
18#include <broadcastradio-utils-2x/Utils.h>
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -080019
20namespace android {
21namespace hardware {
22namespace broadcastradio {
23namespace V2_0 {
24namespace implementation {
25
26using std::lock_guard;
27using std::move;
28using std::mutex;
29using std::vector;
30using utils::make_selector_amfm;
31
32VirtualRadio gAmFmRadio(
33 "AM/FM radio mock",
34 {
35 {make_selector_amfm(94900), "Wild 94.9", "Drake ft. Rihanna", "Too Good"},
36 {make_selector_amfm(96500), "KOIT", "Celine Dion", "All By Myself"},
37 {make_selector_amfm(97300), "Alice@97.3", "Drops of Jupiter", "Train"},
38 {make_selector_amfm(99700), "99.7 Now!", "The Chainsmokers", "Closer"},
39 {make_selector_amfm(101300), "101-3 KISS-FM", "Justin Timberlake", "Rock Your Body"},
40 {make_selector_amfm(103700), "iHeart80s @ 103.7", "Michael Jackson", "Billie Jean"},
41 {make_selector_amfm(106100), "106 KMEL", "Drake", "Marvins Room"},
42 });
43
44VirtualRadio::VirtualRadio(const std::string& name, const vector<VirtualProgram>& initialList)
45 : mName(name), mPrograms(initialList) {}
46
47std::string VirtualRadio::getName() const {
48 return mName;
49}
50
51vector<VirtualProgram> VirtualRadio::getProgramList() const {
52 lock_guard<mutex> lk(mMut);
53 return mPrograms;
54}
55
56bool VirtualRadio::getProgram(const ProgramSelector& selector, VirtualProgram& programOut) const {
57 lock_guard<mutex> lk(mMut);
58 for (auto&& program : mPrograms) {
59 if (utils::tunesTo(selector, program.selector)) {
60 programOut = program;
61 return true;
62 }
63 }
64 return false;
65}
66
67} // namespace implementation
68} // namespace V2_0
69} // namespace broadcastradio
70} // namespace hardware
71} // namespace android