blob: e9ac8642dc4bbf2bf6e78a75545e6ea5ae6033e5 [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 */
16#ifndef ANDROID_HARDWARE_BROADCASTRADIO_COMMON_UTILS_2X_H
17#define ANDROID_HARDWARE_BROADCASTRADIO_COMMON_UTILS_2X_H
18
19#include <android/hardware/broadcastradio/2.0/types.h>
20#include <chrono>
21#include <queue>
22#include <thread>
23
24namespace android {
25namespace hardware {
26namespace broadcastradio {
27namespace utils {
28
29V2_0::IdentifierType getType(const V2_0::ProgramIdentifier& id);
30
31/**
32 * Checks, if {@code pointer} tunes to {@channel}.
33 *
34 * For example, having a channel {AMFM_FREQUENCY = 103.3}:
35 * - selector {AMFM_FREQUENCY = 103.3, HD_SUBCHANNEL = 0} can tune to this channel;
36 * - selector {AMFM_FREQUENCY = 103.3, HD_SUBCHANNEL = 1} can't.
37 *
38 * @param pointer selector we're trying to match against channel.
39 * @param channel existing channel.
40 */
41bool tunesTo(const V2_0::ProgramSelector& pointer, const V2_0::ProgramSelector& channel);
42
43bool hasId(const V2_0::ProgramSelector& sel, const V2_0::IdentifierType type);
44
45/**
46 * Returns ID (either primary or secondary) for a given program selector.
47 *
48 * If the selector does not contain given type, returns 0 and emits a warning.
49 */
50uint64_t getId(const V2_0::ProgramSelector& sel, const V2_0::IdentifierType type);
51
52/**
53 * Returns ID (either primary or secondary) for a given program selector.
54 *
55 * If the selector does not contain given type, returns default value.
56 */
57uint64_t getId(const V2_0::ProgramSelector& sel, const V2_0::IdentifierType type, uint64_t defval);
58
59/**
60 * Checks, if a given selector is supported by the radio module.
61 *
62 * @param prop Module description.
63 * @param sel The selector to check.
64 * @return True, if the selector is supported, false otherwise.
65 */
66bool isSupported(const V2_0::Properties& prop, const V2_0::ProgramSelector& sel);
67
68bool isValid(const V2_0::ProgramSelector& sel);
69
70V2_0::ProgramIdentifier make_identifier(V2_0::IdentifierType type, uint64_t value);
71V2_0::ProgramSelector make_selector_amfm(uint32_t frequency);
72V2_0::Metadata make_metadata(V2_0::MetadataKey key, int64_t value);
73V2_0::Metadata make_metadata(V2_0::MetadataKey key, std::string value);
74
75} // namespace utils
76} // namespace broadcastradio
77} // namespace hardware
78} // namespace android
79
80#endif // ANDROID_HARDWARE_BROADCASTRADIO_COMMON_UTILS_2X_H