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 | |
| 21 | using ::android::hardware::tv::tuner::V1_0::Result; |
| 22 | |
| 23 | namespace android { |
| 24 | |
| 25 | TunerLnb::TunerLnb(sp<ILnb> lnb, int id) { |
| 26 | mLnb = lnb; |
| 27 | mId = id; |
| 28 | } |
| 29 | |
| 30 | TunerLnb::~TunerLnb() { |
| 31 | mLnb = NULL; |
| 32 | mId = -1; |
| 33 | } |
| 34 | |
| 35 | Status TunerLnb::setCallback( |
| 36 | const shared_ptr<ITunerLnbCallback>& tunerLnbCallback) { |
| 37 | if (mLnb == NULL) { |
| 38 | ALOGE("ILnb is not initialized"); |
| 39 | return Status::fromServiceSpecificError(static_cast<int32_t>(Result::UNAVAILABLE)); |
| 40 | } |
| 41 | |
| 42 | if (tunerLnbCallback == NULL) { |
| 43 | return Status::fromServiceSpecificError(static_cast<int32_t>(Result::INVALID_ARGUMENT)); |
| 44 | } |
| 45 | |
| 46 | sp<ILnbCallback> lnbCallback = new LnbCallback(tunerLnbCallback); |
| 47 | Result status = mLnb->setCallback(lnbCallback); |
| 48 | if (status == Result::SUCCESS) { |
| 49 | return Status::ok(); |
| 50 | } |
| 51 | |
| 52 | return Status::fromServiceSpecificError(static_cast<int32_t>(status)); |
| 53 | } |
| 54 | |
| 55 | Status TunerLnb::setVoltage(int /*voltage*/) { |
| 56 | return Status::ok(); |
| 57 | } |
| 58 | |
| 59 | Status TunerLnb::setTone(int /*voltage*/) { |
| 60 | return Status::ok(); |
| 61 | } |
| 62 | |
| 63 | Status TunerLnb::setSatellitePosition(int /*position*/) { |
| 64 | return Status::ok(); |
| 65 | } |
| 66 | |
| 67 | Status TunerLnb::sendDiseqcMessage(const vector<uint8_t>& /*diseqcMessage*/) { |
| 68 | return Status::ok(); |
| 69 | } |
| 70 | |
| 71 | Status TunerLnb::close() { |
| 72 | return Status::ok(); |
| 73 | } |
| 74 | |
| 75 | /////////////// ILnbCallback /////////////////////// |
| 76 | |
| 77 | Return<void> TunerLnb::LnbCallback::onEvent(const LnbEventType lnbEventType) { |
| 78 | if (mTunerLnbCallback != NULL) { |
| 79 | mTunerLnbCallback->onEvent((int)lnbEventType); |
| 80 | } |
| 81 | return Void(); |
| 82 | } |
| 83 | |
| 84 | Return<void> TunerLnb::LnbCallback::onDiseqcMessage(const hidl_vec<uint8_t>& diseqcMessage) { |
| 85 | if (mTunerLnbCallback != NULL && diseqcMessage != NULL) { |
| 86 | vector<uint8_t> msg(begin(diseqcMessage), end(diseqcMessage)); |
| 87 | mTunerLnbCallback->onDiseqcMessage(msg); |
| 88 | } |
| 89 | return Void(); |
| 90 | } |
| 91 | } // namespace android |