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