Tomasz Wasilczyk | 06100b3 | 2017-12-04 09:53:32 -0800 | [diff] [blame] | 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 | #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 | |
| 24 | namespace android { |
| 25 | namespace hardware { |
| 26 | namespace broadcastradio { |
| 27 | namespace utils { |
| 28 | |
| 29 | V2_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 | */ |
| 41 | bool tunesTo(const V2_0::ProgramSelector& pointer, const V2_0::ProgramSelector& channel); |
| 42 | |
| 43 | bool 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 | */ |
| 50 | uint64_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 | */ |
| 57 | uint64_t getId(const V2_0::ProgramSelector& sel, const V2_0::IdentifierType type, uint64_t defval); |
| 58 | |
| 59 | /** |
Tomasz Wasilczyk | 31e8632 | 2017-12-05 09:36:11 -0800 | [diff] [blame] | 60 | * Returns all IDs of a given type. |
| 61 | */ |
| 62 | std::vector<uint64_t> getAllIds(const V2_0::ProgramSelector& sel, const V2_0::IdentifierType type); |
| 63 | |
| 64 | /** |
Tomasz Wasilczyk | 06100b3 | 2017-12-04 09:53:32 -0800 | [diff] [blame] | 65 | * Checks, if a given selector is supported by the radio module. |
| 66 | * |
| 67 | * @param prop Module description. |
| 68 | * @param sel The selector to check. |
| 69 | * @return True, if the selector is supported, false otherwise. |
| 70 | */ |
| 71 | bool isSupported(const V2_0::Properties& prop, const V2_0::ProgramSelector& sel); |
| 72 | |
| 73 | bool isValid(const V2_0::ProgramSelector& sel); |
| 74 | |
| 75 | V2_0::ProgramIdentifier make_identifier(V2_0::IdentifierType type, uint64_t value); |
| 76 | V2_0::ProgramSelector make_selector_amfm(uint32_t frequency); |
| 77 | V2_0::Metadata make_metadata(V2_0::MetadataKey key, int64_t value); |
| 78 | V2_0::Metadata make_metadata(V2_0::MetadataKey key, std::string value); |
| 79 | |
| 80 | } // namespace utils |
| 81 | } // namespace broadcastradio |
| 82 | } // namespace hardware |
| 83 | } // namespace android |
| 84 | |
| 85 | #endif // ANDROID_HARDWARE_BROADCASTRADIO_COMMON_UTILS_2X_H |