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_V2_0_TUNER_H |
| 17 | #define ANDROID_HARDWARE_BROADCASTRADIO_V2_0_TUNER_H |
| 18 | |
| 19 | #include "VirtualRadio.h" |
| 20 | |
| 21 | #include <android/hardware/broadcastradio/2.0/ITunerCallback.h> |
| 22 | #include <android/hardware/broadcastradio/2.0/ITunerSession.h> |
| 23 | #include <broadcastradio-utils/WorkerThread.h> |
| 24 | |
Tomasz Wasilczyk | 8b70ee4 | 2017-12-21 11:51:29 -0800 | [diff] [blame] | 25 | #include <optional> |
| 26 | |
Tomasz Wasilczyk | 06100b3 | 2017-12-04 09:53:32 -0800 | [diff] [blame] | 27 | namespace android { |
| 28 | namespace hardware { |
| 29 | namespace broadcastradio { |
| 30 | namespace V2_0 { |
| 31 | namespace implementation { |
| 32 | |
| 33 | struct BroadcastRadio; |
| 34 | |
| 35 | struct TunerSession : public ITunerSession { |
| 36 | TunerSession(BroadcastRadio& module, const sp<ITunerCallback>& callback); |
| 37 | |
| 38 | // V2_0::ITunerSession methods |
| 39 | virtual Return<Result> tune(const ProgramSelector& program) override; |
| 40 | virtual Return<Result> scan(bool directionUp, bool skipSubChannel) override; |
| 41 | virtual Return<Result> step(bool directionUp) override; |
| 42 | virtual Return<void> cancel() override; |
Tomasz Wasilczyk | bceb885 | 2017-12-18 13:59:29 -0800 | [diff] [blame] | 43 | virtual Return<Result> startProgramListUpdates(const ProgramFilter& filter); |
| 44 | virtual Return<void> stopProgramListUpdates(); |
Tomasz Wasilczyk | 3dd452a | 2018-01-12 14:57:45 -0800 | [diff] [blame] | 45 | virtual Return<void> isConfigFlagSet(ConfigFlag flag, isConfigFlagSet_cb _hidl_cb); |
Tomasz Wasilczyk | 43fe894 | 2017-12-14 11:44:12 -0800 | [diff] [blame] | 46 | virtual Return<Result> setConfigFlag(ConfigFlag flag, bool value); |
Tomasz Wasilczyk | 06100b3 | 2017-12-04 09:53:32 -0800 | [diff] [blame] | 47 | virtual Return<void> setParameters(const hidl_vec<VendorKeyValue>& parameters, |
| 48 | setParameters_cb _hidl_cb) override; |
| 49 | virtual Return<void> getParameters(const hidl_vec<hidl_string>& keys, |
| 50 | getParameters_cb _hidl_cb) override; |
| 51 | virtual Return<void> close() override; |
| 52 | |
Tomasz Wasilczyk | 8b70ee4 | 2017-12-21 11:51:29 -0800 | [diff] [blame] | 53 | std::optional<AmFmBandRange> getAmFmRangeLocked() const; |
| 54 | |
Tomasz Wasilczyk | 06100b3 | 2017-12-04 09:53:32 -0800 | [diff] [blame] | 55 | private: |
| 56 | std::mutex mMut; |
| 57 | WorkerThread mThread; |
| 58 | bool mIsClosed = false; |
| 59 | |
| 60 | const sp<ITunerCallback> mCallback; |
| 61 | |
| 62 | std::reference_wrapper<BroadcastRadio> mModule; |
| 63 | bool mIsTuneCompleted = false; |
| 64 | ProgramSelector mCurrentProgram = {}; |
| 65 | |
Tomasz Wasilczyk | db90286 | 2018-01-14 17:22:03 -0800 | [diff] [blame] | 66 | void cancelLocked(); |
Tomasz Wasilczyk | 06100b3 | 2017-12-04 09:53:32 -0800 | [diff] [blame] | 67 | void tuneInternalLocked(const ProgramSelector& sel); |
| 68 | const VirtualRadio& virtualRadio() const; |
Tomasz Wasilczyk | 8b70ee4 | 2017-12-21 11:51:29 -0800 | [diff] [blame] | 69 | const BroadcastRadio& module() const; |
Tomasz Wasilczyk | 06100b3 | 2017-12-04 09:53:32 -0800 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | } // namespace implementation |
| 73 | } // namespace V2_0 |
| 74 | } // namespace broadcastradio |
| 75 | } // namespace hardware |
| 76 | } // namespace android |
| 77 | |
| 78 | #endif // ANDROID_HARDWARE_BROADCASTRADIO_V2_0_TUNER_H |