blob: e6b101780859c3c88d2f11f09b5ffa9ac3092a72 [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;
Allief62374d2019-02-19 16:21:51 -080031using utils::make_selector_dab;
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -080032
33VirtualRadio 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@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
Allief62374d2019-02-19 16:21:51 -080045// clang-format off
46VirtualRadio gDabRadio(
47 "DAB radio mock",
48 {
Weilin Xu9f4ff572022-07-25 22:32:19 +000049 {make_selector_dab(0xA00001u, 0x0001u), "BBC Radio 1", "Khalid", "Talk"},
50 {make_selector_dab(0xB00001u, 0x1001u), "Classic FM", "Jean Sibelius", "Andante Festivo"},
51 {make_selector_dab(0xB00002u, 0x1001u), "Absolute Radio", "Coldplay", "Clocks"},
Allief62374d2019-02-19 16:21:51 -080052 });
53// clang-format on
54
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -080055VirtualRadio::VirtualRadio(const std::string& name, const vector<VirtualProgram>& initialList)
56 : mName(name), mPrograms(initialList) {}
57
58std::string VirtualRadio::getName() const {
59 return mName;
60}
61
62vector<VirtualProgram> VirtualRadio::getProgramList() const {
63 lock_guard<mutex> lk(mMut);
64 return mPrograms;
65}
66
67bool 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