blob: bf7c607fa0454e1c32c129c12a1de7064cf6c062 [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_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 Wasilczyk8b70ee42017-12-21 11:51:29 -080025#include <optional>
26
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -080027namespace android {
28namespace hardware {
29namespace broadcastradio {
30namespace V2_0 {
31namespace implementation {
32
33struct BroadcastRadio;
34
35struct 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 Wasilczykbceb8852017-12-18 13:59:29 -080043 virtual Return<Result> startProgramListUpdates(const ProgramFilter& filter);
44 virtual Return<void> stopProgramListUpdates();
Tomasz Wasilczyk3dd452a2018-01-12 14:57:45 -080045 virtual Return<void> isConfigFlagSet(ConfigFlag flag, isConfigFlagSet_cb _hidl_cb);
Tomasz Wasilczyk43fe8942017-12-14 11:44:12 -080046 virtual Return<Result> setConfigFlag(ConfigFlag flag, bool value);
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -080047 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 Wasilczyk8b70ee42017-12-21 11:51:29 -080053 std::optional<AmFmBandRange> getAmFmRangeLocked() const;
54
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -080055 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 Wasilczykdb902862018-01-14 17:22:03 -080066 void cancelLocked();
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -080067 void tuneInternalLocked(const ProgramSelector& sel);
68 const VirtualRadio& virtualRadio() const;
Tomasz Wasilczyk8b70ee42017-12-21 11:51:29 -080069 const BroadcastRadio& module() const;
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -080070};
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