Amy Zhang | a046eee | 2021-01-12 14:44:58 -0800 | [diff] [blame] | 1 | /** |
| 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 | |
Hongguang | eae6839 | 2021-07-27 20:56:23 -0700 | [diff] [blame^] | 21 | #include <aidl/android/hardware/tv/tuner/ILnbCallback.h> |
| 22 | #include <aidl/android/hardware/tv/tuner/Result.h> |
Amy Zhang | a046eee | 2021-01-12 14:44:58 -0800 | [diff] [blame] | 23 | |
Hongguang | eae6839 | 2021-07-27 20:56:23 -0700 | [diff] [blame^] | 24 | using ::aidl::android::hardware::tv::tuner::ILnbCallback; |
| 25 | using ::aidl::android::hardware::tv::tuner::Result; |
| 26 | |
| 27 | namespace aidl { |
Amy Zhang | a046eee | 2021-01-12 14:44:58 -0800 | [diff] [blame] | 28 | namespace android { |
Hongguang | eae6839 | 2021-07-27 20:56:23 -0700 | [diff] [blame^] | 29 | namespace media { |
| 30 | namespace tv { |
| 31 | namespace tuner { |
Amy Zhang | a046eee | 2021-01-12 14:44:58 -0800 | [diff] [blame] | 32 | |
Hongguang | eae6839 | 2021-07-27 20:56:23 -0700 | [diff] [blame^] | 33 | TunerLnb::TunerLnb(shared_ptr<ILnb> lnb, int id) { |
Amy Zhang | a046eee | 2021-01-12 14:44:58 -0800 | [diff] [blame] | 34 | mLnb = lnb; |
| 35 | mId = id; |
| 36 | } |
| 37 | |
| 38 | TunerLnb::~TunerLnb() { |
Hongguang | eae6839 | 2021-07-27 20:56:23 -0700 | [diff] [blame^] | 39 | mLnb = nullptr; |
Amy Zhang | a046eee | 2021-01-12 14:44:58 -0800 | [diff] [blame] | 40 | mId = -1; |
| 41 | } |
| 42 | |
Hongguang | eae6839 | 2021-07-27 20:56:23 -0700 | [diff] [blame^] | 43 | ::ndk::ScopedAStatus TunerLnb::setCallback( |
| 44 | const shared_ptr<ITunerLnbCallback>& in_tunerLnbCallback) { |
| 45 | if (mLnb == nullptr) { |
Amy Zhang | a046eee | 2021-01-12 14:44:58 -0800 | [diff] [blame] | 46 | ALOGE("ILnb is not initialized"); |
Hongguang | eae6839 | 2021-07-27 20:56:23 -0700 | [diff] [blame^] | 47 | return ::ndk::ScopedAStatus::fromServiceSpecificError( |
| 48 | static_cast<int32_t>(Result::UNAVAILABLE)); |
Amy Zhang | a046eee | 2021-01-12 14:44:58 -0800 | [diff] [blame] | 49 | } |
| 50 | |
Hongguang | eae6839 | 2021-07-27 20:56:23 -0700 | [diff] [blame^] | 51 | if (in_tunerLnbCallback == nullptr) { |
| 52 | return ::ndk::ScopedAStatus::fromServiceSpecificError( |
| 53 | static_cast<int32_t>(Result::INVALID_ARGUMENT)); |
Amy Zhang | a046eee | 2021-01-12 14:44:58 -0800 | [diff] [blame] | 54 | } |
| 55 | |
Hongguang | eae6839 | 2021-07-27 20:56:23 -0700 | [diff] [blame^] | 56 | shared_ptr<ILnbCallback> lnbCallback = |
| 57 | ::ndk::SharedRefBase::make<LnbCallback>(in_tunerLnbCallback); |
| 58 | return mLnb->setCallback(lnbCallback); |
Amy Zhang | a046eee | 2021-01-12 14:44:58 -0800 | [diff] [blame] | 59 | } |
| 60 | |
Hongguang | eae6839 | 2021-07-27 20:56:23 -0700 | [diff] [blame^] | 61 | ::ndk::ScopedAStatus TunerLnb::setVoltage(LnbVoltage in_voltage) { |
| 62 | if (mLnb == nullptr) { |
Amy Zhang | 077cc1f | 2021-01-14 18:54:07 -0800 | [diff] [blame] | 63 | ALOGE("ILnb is not initialized"); |
Hongguang | eae6839 | 2021-07-27 20:56:23 -0700 | [diff] [blame^] | 64 | return ::ndk::ScopedAStatus::fromServiceSpecificError( |
| 65 | static_cast<int32_t>(Result::UNAVAILABLE)); |
Amy Zhang | 077cc1f | 2021-01-14 18:54:07 -0800 | [diff] [blame] | 66 | } |
| 67 | |
Hongguang | eae6839 | 2021-07-27 20:56:23 -0700 | [diff] [blame^] | 68 | return mLnb->setVoltage(in_voltage); |
Amy Zhang | a046eee | 2021-01-12 14:44:58 -0800 | [diff] [blame] | 69 | } |
| 70 | |
Hongguang | eae6839 | 2021-07-27 20:56:23 -0700 | [diff] [blame^] | 71 | ::ndk::ScopedAStatus TunerLnb::setTone(LnbTone in_tone) { |
| 72 | if (mLnb == nullptr) { |
Amy Zhang | 077cc1f | 2021-01-14 18:54:07 -0800 | [diff] [blame] | 73 | ALOGE("ILnb is not initialized"); |
Hongguang | eae6839 | 2021-07-27 20:56:23 -0700 | [diff] [blame^] | 74 | return ::ndk::ScopedAStatus::fromServiceSpecificError( |
| 75 | static_cast<int32_t>(Result::UNAVAILABLE)); |
Amy Zhang | 077cc1f | 2021-01-14 18:54:07 -0800 | [diff] [blame] | 76 | } |
| 77 | |
Hongguang | eae6839 | 2021-07-27 20:56:23 -0700 | [diff] [blame^] | 78 | return mLnb->setTone(in_tone); |
Amy Zhang | a046eee | 2021-01-12 14:44:58 -0800 | [diff] [blame] | 79 | } |
| 80 | |
Hongguang | eae6839 | 2021-07-27 20:56:23 -0700 | [diff] [blame^] | 81 | ::ndk::ScopedAStatus TunerLnb::setSatellitePosition(LnbPosition in_position) { |
| 82 | if (mLnb == nullptr) { |
Amy Zhang | 077cc1f | 2021-01-14 18:54:07 -0800 | [diff] [blame] | 83 | ALOGE("ILnb is not initialized"); |
Hongguang | eae6839 | 2021-07-27 20:56:23 -0700 | [diff] [blame^] | 84 | return ::ndk::ScopedAStatus::fromServiceSpecificError( |
| 85 | static_cast<int32_t>(Result::UNAVAILABLE)); |
Amy Zhang | 077cc1f | 2021-01-14 18:54:07 -0800 | [diff] [blame] | 86 | } |
| 87 | |
Hongguang | eae6839 | 2021-07-27 20:56:23 -0700 | [diff] [blame^] | 88 | return mLnb->setSatellitePosition(in_position); |
Amy Zhang | a046eee | 2021-01-12 14:44:58 -0800 | [diff] [blame] | 89 | } |
| 90 | |
Hongguang | eae6839 | 2021-07-27 20:56:23 -0700 | [diff] [blame^] | 91 | ::ndk::ScopedAStatus TunerLnb::sendDiseqcMessage(const vector<uint8_t>& in_diseqcMessage) { |
| 92 | if (mLnb == nullptr) { |
Amy Zhang | 077cc1f | 2021-01-14 18:54:07 -0800 | [diff] [blame] | 93 | ALOGE("ILnb is not initialized"); |
Hongguang | eae6839 | 2021-07-27 20:56:23 -0700 | [diff] [blame^] | 94 | return ::ndk::ScopedAStatus::fromServiceSpecificError( |
| 95 | static_cast<int32_t>(Result::UNAVAILABLE)); |
Amy Zhang | 077cc1f | 2021-01-14 18:54:07 -0800 | [diff] [blame] | 96 | } |
| 97 | |
Hongguang | eae6839 | 2021-07-27 20:56:23 -0700 | [diff] [blame^] | 98 | return mLnb->sendDiseqcMessage(in_diseqcMessage); |
Amy Zhang | a046eee | 2021-01-12 14:44:58 -0800 | [diff] [blame] | 99 | } |
| 100 | |
Hongguang | eae6839 | 2021-07-27 20:56:23 -0700 | [diff] [blame^] | 101 | ::ndk::ScopedAStatus TunerLnb::close() { |
| 102 | if (mLnb == nullptr) { |
Amy Zhang | 077cc1f | 2021-01-14 18:54:07 -0800 | [diff] [blame] | 103 | ALOGE("ILnb is not initialized"); |
Hongguang | eae6839 | 2021-07-27 20:56:23 -0700 | [diff] [blame^] | 104 | return ::ndk::ScopedAStatus::fromServiceSpecificError( |
| 105 | static_cast<int32_t>(Result::UNAVAILABLE)); |
Amy Zhang | 077cc1f | 2021-01-14 18:54:07 -0800 | [diff] [blame] | 106 | } |
| 107 | |
Hongguang | eae6839 | 2021-07-27 20:56:23 -0700 | [diff] [blame^] | 108 | auto res = mLnb->close(); |
| 109 | mLnb = nullptr; |
Amy Zhang | 14a60e8 | 2021-02-11 15:22:52 -0800 | [diff] [blame] | 110 | |
Hongguang | eae6839 | 2021-07-27 20:56:23 -0700 | [diff] [blame^] | 111 | return res; |
Amy Zhang | a046eee | 2021-01-12 14:44:58 -0800 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | /////////////// ILnbCallback /////////////////////// |
Hongguang | eae6839 | 2021-07-27 20:56:23 -0700 | [diff] [blame^] | 115 | ::ndk::ScopedAStatus TunerLnb::LnbCallback::onEvent(const LnbEventType lnbEventType) { |
| 116 | if (mTunerLnbCallback != nullptr) { |
| 117 | mTunerLnbCallback->onEvent(lnbEventType); |
Amy Zhang | a046eee | 2021-01-12 14:44:58 -0800 | [diff] [blame] | 118 | } |
Hongguang | eae6839 | 2021-07-27 20:56:23 -0700 | [diff] [blame^] | 119 | return ndk::ScopedAStatus::ok(); |
Amy Zhang | a046eee | 2021-01-12 14:44:58 -0800 | [diff] [blame] | 120 | } |
| 121 | |
Hongguang | eae6839 | 2021-07-27 20:56:23 -0700 | [diff] [blame^] | 122 | ::ndk::ScopedAStatus TunerLnb::LnbCallback::onDiseqcMessage(const vector<uint8_t>& diseqcMessage) { |
| 123 | if (mTunerLnbCallback != nullptr) { |
| 124 | mTunerLnbCallback->onDiseqcMessage(diseqcMessage); |
Amy Zhang | a046eee | 2021-01-12 14:44:58 -0800 | [diff] [blame] | 125 | } |
Hongguang | eae6839 | 2021-07-27 20:56:23 -0700 | [diff] [blame^] | 126 | return ndk::ScopedAStatus::ok(); |
Amy Zhang | a046eee | 2021-01-12 14:44:58 -0800 | [diff] [blame] | 127 | } |
Hongguang | eae6839 | 2021-07-27 20:56:23 -0700 | [diff] [blame^] | 128 | |
| 129 | } // namespace tuner |
| 130 | } // namespace tv |
| 131 | } // namespace media |
Amy Zhang | a046eee | 2021-01-12 14:44:58 -0800 | [diff] [blame] | 132 | } // namespace android |
Hongguang | eae6839 | 2021-07-27 20:56:23 -0700 | [diff] [blame^] | 133 | } // namespace aidl |