blob: 1e143c349d03fc6952bd3178a2c57b69c69bf22d [file] [log] [blame]
Amy Zhanga046eee2021-01-12 14:44:58 -08001/**
2 * Copyright 2021, 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
17#define LOG_TAG "TunerLnb"
18
19#include "TunerLnb.h"
20
Hongguangeae68392021-07-27 20:56:23 -070021#include <aidl/android/hardware/tv/tuner/ILnbCallback.h>
22#include <aidl/android/hardware/tv/tuner/Result.h>
Amy Zhanga046eee2021-01-12 14:44:58 -080023
Hongguangeae68392021-07-27 20:56:23 -070024using ::aidl::android::hardware::tv::tuner::ILnbCallback;
25using ::aidl::android::hardware::tv::tuner::Result;
26
27namespace aidl {
Amy Zhanga046eee2021-01-12 14:44:58 -080028namespace android {
Hongguangeae68392021-07-27 20:56:23 -070029namespace media {
30namespace tv {
31namespace tuner {
Amy Zhanga046eee2021-01-12 14:44:58 -080032
Hongguangeae68392021-07-27 20:56:23 -070033TunerLnb::TunerLnb(shared_ptr<ILnb> lnb, int id) {
Amy Zhanga046eee2021-01-12 14:44:58 -080034 mLnb = lnb;
35 mId = id;
36}
37
38TunerLnb::~TunerLnb() {
Hongguangeae68392021-07-27 20:56:23 -070039 mLnb = nullptr;
Amy Zhanga046eee2021-01-12 14:44:58 -080040 mId = -1;
41}
42
Hongguangeae68392021-07-27 20:56:23 -070043::ndk::ScopedAStatus TunerLnb::setCallback(
44 const shared_ptr<ITunerLnbCallback>& in_tunerLnbCallback) {
45 if (mLnb == nullptr) {
Amy Zhanga046eee2021-01-12 14:44:58 -080046 ALOGE("ILnb is not initialized");
Hongguangeae68392021-07-27 20:56:23 -070047 return ::ndk::ScopedAStatus::fromServiceSpecificError(
48 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhanga046eee2021-01-12 14:44:58 -080049 }
50
Hongguangeae68392021-07-27 20:56:23 -070051 if (in_tunerLnbCallback == nullptr) {
52 return ::ndk::ScopedAStatus::fromServiceSpecificError(
53 static_cast<int32_t>(Result::INVALID_ARGUMENT));
Amy Zhanga046eee2021-01-12 14:44:58 -080054 }
55
Hongguangeae68392021-07-27 20:56:23 -070056 shared_ptr<ILnbCallback> lnbCallback =
57 ::ndk::SharedRefBase::make<LnbCallback>(in_tunerLnbCallback);
58 return mLnb->setCallback(lnbCallback);
Amy Zhanga046eee2021-01-12 14:44:58 -080059}
60
Hongguangeae68392021-07-27 20:56:23 -070061::ndk::ScopedAStatus TunerLnb::setVoltage(LnbVoltage in_voltage) {
62 if (mLnb == nullptr) {
Amy Zhang077cc1f2021-01-14 18:54:07 -080063 ALOGE("ILnb is not initialized");
Hongguangeae68392021-07-27 20:56:23 -070064 return ::ndk::ScopedAStatus::fromServiceSpecificError(
65 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhang077cc1f2021-01-14 18:54:07 -080066 }
67
Hongguangeae68392021-07-27 20:56:23 -070068 return mLnb->setVoltage(in_voltage);
Amy Zhanga046eee2021-01-12 14:44:58 -080069}
70
Hongguangeae68392021-07-27 20:56:23 -070071::ndk::ScopedAStatus TunerLnb::setTone(LnbTone in_tone) {
72 if (mLnb == nullptr) {
Amy Zhang077cc1f2021-01-14 18:54:07 -080073 ALOGE("ILnb is not initialized");
Hongguangeae68392021-07-27 20:56:23 -070074 return ::ndk::ScopedAStatus::fromServiceSpecificError(
75 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhang077cc1f2021-01-14 18:54:07 -080076 }
77
Hongguangeae68392021-07-27 20:56:23 -070078 return mLnb->setTone(in_tone);
Amy Zhanga046eee2021-01-12 14:44:58 -080079}
80
Hongguangeae68392021-07-27 20:56:23 -070081::ndk::ScopedAStatus TunerLnb::setSatellitePosition(LnbPosition in_position) {
82 if (mLnb == nullptr) {
Amy Zhang077cc1f2021-01-14 18:54:07 -080083 ALOGE("ILnb is not initialized");
Hongguangeae68392021-07-27 20:56:23 -070084 return ::ndk::ScopedAStatus::fromServiceSpecificError(
85 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhang077cc1f2021-01-14 18:54:07 -080086 }
87
Hongguangeae68392021-07-27 20:56:23 -070088 return mLnb->setSatellitePosition(in_position);
Amy Zhanga046eee2021-01-12 14:44:58 -080089}
90
Hongguangeae68392021-07-27 20:56:23 -070091::ndk::ScopedAStatus TunerLnb::sendDiseqcMessage(const vector<uint8_t>& in_diseqcMessage) {
92 if (mLnb == nullptr) {
Amy Zhang077cc1f2021-01-14 18:54:07 -080093 ALOGE("ILnb is not initialized");
Hongguangeae68392021-07-27 20:56:23 -070094 return ::ndk::ScopedAStatus::fromServiceSpecificError(
95 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhang077cc1f2021-01-14 18:54:07 -080096 }
97
Hongguangeae68392021-07-27 20:56:23 -070098 return mLnb->sendDiseqcMessage(in_diseqcMessage);
Amy Zhanga046eee2021-01-12 14:44:58 -080099}
100
Hongguangeae68392021-07-27 20:56:23 -0700101::ndk::ScopedAStatus TunerLnb::close() {
102 if (mLnb == nullptr) {
Amy Zhang077cc1f2021-01-14 18:54:07 -0800103 ALOGE("ILnb is not initialized");
Hongguangeae68392021-07-27 20:56:23 -0700104 return ::ndk::ScopedAStatus::fromServiceSpecificError(
105 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhang077cc1f2021-01-14 18:54:07 -0800106 }
107
Hongguangeae68392021-07-27 20:56:23 -0700108 auto res = mLnb->close();
109 mLnb = nullptr;
Amy Zhang14a60e82021-02-11 15:22:52 -0800110
Hongguangeae68392021-07-27 20:56:23 -0700111 return res;
Amy Zhanga046eee2021-01-12 14:44:58 -0800112}
113
114/////////////// ILnbCallback ///////////////////////
Hongguangeae68392021-07-27 20:56:23 -0700115::ndk::ScopedAStatus TunerLnb::LnbCallback::onEvent(const LnbEventType lnbEventType) {
116 if (mTunerLnbCallback != nullptr) {
117 mTunerLnbCallback->onEvent(lnbEventType);
Amy Zhanga046eee2021-01-12 14:44:58 -0800118 }
Hongguangeae68392021-07-27 20:56:23 -0700119 return ndk::ScopedAStatus::ok();
Amy Zhanga046eee2021-01-12 14:44:58 -0800120}
121
Hongguangeae68392021-07-27 20:56:23 -0700122::ndk::ScopedAStatus TunerLnb::LnbCallback::onDiseqcMessage(const vector<uint8_t>& diseqcMessage) {
123 if (mTunerLnbCallback != nullptr) {
124 mTunerLnbCallback->onDiseqcMessage(diseqcMessage);
Amy Zhanga046eee2021-01-12 14:44:58 -0800125 }
Hongguangeae68392021-07-27 20:56:23 -0700126 return ndk::ScopedAStatus::ok();
Amy Zhanga046eee2021-01-12 14:44:58 -0800127}
Hongguangeae68392021-07-27 20:56:23 -0700128
129} // namespace tuner
130} // namespace tv
131} // namespace media
Amy Zhanga046eee2021-01-12 14:44:58 -0800132} // namespace android
Hongguangeae68392021-07-27 20:56:23 -0700133} // namespace aidl