Amy Zhang | b0f63ab | 2021-01-06 17:19:27 -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 "LnbClient" |
| 18 | |
| 19 | #include <android-base/logging.h> |
| 20 | #include <utils/Log.h> |
| 21 | |
| 22 | #include "LnbClient.h" |
| 23 | |
| 24 | using ::android::hardware::tv::tuner::V1_0::Result; |
| 25 | |
| 26 | namespace android { |
| 27 | |
| 28 | /////////////// LnbClient /////////////////////// |
| 29 | |
| 30 | // TODO: pending aidl interface |
| 31 | LnbClient::LnbClient() { |
| 32 | //mTunerLnb = tunerLnb; |
Amy Zhang | d3d57b4 | 2021-01-07 11:14:43 -0800 | [diff] [blame^] | 33 | mId = -1; |
Amy Zhang | b0f63ab | 2021-01-06 17:19:27 -0800 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | LnbClient::~LnbClient() { |
| 37 | //mTunerLnb = NULL; |
| 38 | mLnb = NULL; |
Amy Zhang | d3d57b4 | 2021-01-07 11:14:43 -0800 | [diff] [blame^] | 39 | mId = -1; |
Amy Zhang | b0f63ab | 2021-01-06 17:19:27 -0800 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | // TODO: remove after migration to Tuner Service is done. |
| 43 | void LnbClient::setHidlLnb(sp<ILnb> lnb) { |
| 44 | mLnb = lnb; |
| 45 | } |
| 46 | |
Amy Zhang | d3d57b4 | 2021-01-07 11:14:43 -0800 | [diff] [blame^] | 47 | Result LnbClient::setCallback(sp<LnbClientCallback> cb) { |
| 48 | // TODO: pending aidl interface |
| 49 | /*if (mTunerFrontend != NULL) { |
| 50 | mAidlCallback = ::ndk::SharedRefBase::make<TunerLnbCallback>(cb); |
| 51 | mTunerLnb->setCallback(mAidlCallback); |
| 52 | return Result::SUCCESS; |
| 53 | }*/ |
| 54 | |
| 55 | mHidlCallback = new HidlLnbCallback(cb); |
| 56 | return mLnb->setCallback(mHidlCallback); |
Amy Zhang | b0f63ab | 2021-01-06 17:19:27 -0800 | [diff] [blame] | 57 | } |
| 58 | |
Amy Zhang | d3d57b4 | 2021-01-07 11:14:43 -0800 | [diff] [blame^] | 59 | Result LnbClient::setVoltage(LnbVoltage voltage) { |
| 60 | // TODO: pending aidl interface |
| 61 | |
| 62 | if (mLnb != NULL) { |
| 63 | return mLnb->setVoltage(voltage); |
| 64 | } |
| 65 | |
| 66 | return Result::INVALID_STATE; |
Amy Zhang | b0f63ab | 2021-01-06 17:19:27 -0800 | [diff] [blame] | 67 | } |
| 68 | |
Amy Zhang | d3d57b4 | 2021-01-07 11:14:43 -0800 | [diff] [blame^] | 69 | Result LnbClient::setTone(LnbTone tone) { |
| 70 | // TODO: pending aidl interface |
| 71 | |
| 72 | if (mLnb != NULL) { |
| 73 | return mLnb->setTone(tone); |
| 74 | } |
| 75 | |
| 76 | return Result::INVALID_STATE; |
Amy Zhang | b0f63ab | 2021-01-06 17:19:27 -0800 | [diff] [blame] | 77 | } |
| 78 | |
Amy Zhang | d3d57b4 | 2021-01-07 11:14:43 -0800 | [diff] [blame^] | 79 | Result LnbClient::setSatellitePosition(LnbPosition position) { |
| 80 | // TODO: pending aidl interface |
| 81 | |
| 82 | if (mLnb != NULL) { |
| 83 | return mLnb->setSatellitePosition(position); |
| 84 | } |
| 85 | |
| 86 | return Result::INVALID_STATE; |
Amy Zhang | b0f63ab | 2021-01-06 17:19:27 -0800 | [diff] [blame] | 87 | } |
| 88 | |
Amy Zhang | d3d57b4 | 2021-01-07 11:14:43 -0800 | [diff] [blame^] | 89 | Result LnbClient::sendDiseqcMessage(vector<uint8_t> diseqcMessage) { |
| 90 | // TODO: pending aidl interface |
| 91 | |
| 92 | if (mLnb != NULL) { |
| 93 | return mLnb->sendDiseqcMessage(diseqcMessage); |
| 94 | } |
| 95 | |
| 96 | return Result::INVALID_STATE; |
Amy Zhang | b0f63ab | 2021-01-06 17:19:27 -0800 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | Result LnbClient::close() { |
Amy Zhang | d3d57b4 | 2021-01-07 11:14:43 -0800 | [diff] [blame^] | 100 | // TODO: pending aidl interface |
| 101 | |
| 102 | if (mLnb != NULL) { |
| 103 | return mLnb->close(); |
| 104 | } |
| 105 | |
| 106 | return Result::INVALID_STATE; |
Amy Zhang | b0f63ab | 2021-01-06 17:19:27 -0800 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | /////////////// ILnbCallback /////////////////////// |
| 110 | |
| 111 | HidlLnbCallback::HidlLnbCallback(sp<LnbClientCallback> lnbClientCallback) |
| 112 | : mLnbClientCallback(lnbClientCallback) {} |
| 113 | |
| 114 | Return<void> HidlLnbCallback::onEvent(const LnbEventType lnbEventType) { |
| 115 | if (mLnbClientCallback != NULL) { |
| 116 | mLnbClientCallback->onEvent(lnbEventType); |
| 117 | } |
| 118 | return Void(); |
| 119 | } |
| 120 | |
| 121 | Return<void> HidlLnbCallback::onDiseqcMessage(const hidl_vec<uint8_t>& diseqcMessage) { |
| 122 | if (mLnbClientCallback != NULL) { |
| 123 | mLnbClientCallback->onDiseqcMessage(diseqcMessage); |
| 124 | } |
| 125 | return Void(); |
| 126 | } |
| 127 | |
| 128 | /////////////// LnbClient Helper Methods /////////////////////// |
| 129 | |
| 130 | } // namespace android |