xref: /aosp_15_r20/frameworks/av/services/tuner/TunerLnb.cpp (revision ec779b8e0859a360c3d303172224686826e6e0e1)
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 #include <aidl/android/hardware/tv/tuner/ILnbCallback.h>
22 #include <aidl/android/hardware/tv/tuner/Result.h>
23 
24 using ::aidl::android::hardware::tv::tuner::ILnbCallback;
25 using ::aidl::android::hardware::tv::tuner::Result;
26 
27 namespace aidl {
28 namespace android {
29 namespace media {
30 namespace tv {
31 namespace tuner {
32 
TunerLnb(shared_ptr<ILnb> lnb,int id)33 TunerLnb::TunerLnb(shared_ptr<ILnb> lnb, int id) {
34     mLnb = lnb;
35     mId = id;
36 }
37 
~TunerLnb()38 TunerLnb::~TunerLnb() {
39     if (!isClosed) {
40         close();
41     }
42     mLnb = nullptr;
43     mId = -1;
44 }
45 
setCallback(const shared_ptr<ITunerLnbCallback> & in_tunerLnbCallback)46 ::ndk::ScopedAStatus TunerLnb::setCallback(
47         const shared_ptr<ITunerLnbCallback>& in_tunerLnbCallback) {
48     if (in_tunerLnbCallback == nullptr) {
49         return ::ndk::ScopedAStatus::fromServiceSpecificError(
50                 static_cast<int32_t>(Result::INVALID_ARGUMENT));
51     }
52 
53     shared_ptr<ILnbCallback> lnbCallback =
54             ::ndk::SharedRefBase::make<LnbCallback>(in_tunerLnbCallback);
55     return mLnb->setCallback(lnbCallback);
56 }
57 
setVoltage(LnbVoltage in_voltage)58 ::ndk::ScopedAStatus TunerLnb::setVoltage(LnbVoltage in_voltage) {
59     return mLnb->setVoltage(in_voltage);
60 }
61 
setTone(LnbTone in_tone)62 ::ndk::ScopedAStatus TunerLnb::setTone(LnbTone in_tone) {
63     return mLnb->setTone(in_tone);
64 }
65 
setSatellitePosition(LnbPosition in_position)66 ::ndk::ScopedAStatus TunerLnb::setSatellitePosition(LnbPosition in_position) {
67     return mLnb->setSatellitePosition(in_position);
68 }
69 
sendDiseqcMessage(const vector<uint8_t> & in_diseqcMessage)70 ::ndk::ScopedAStatus TunerLnb::sendDiseqcMessage(const vector<uint8_t>& in_diseqcMessage) {
71     return mLnb->sendDiseqcMessage(in_diseqcMessage);
72 }
73 
close()74 ::ndk::ScopedAStatus TunerLnb::close() {
75     isClosed = true;
76     return mLnb->close();
77 }
78 
79 /////////////// ILnbCallback ///////////////////////
onEvent(const LnbEventType lnbEventType)80 ::ndk::ScopedAStatus TunerLnb::LnbCallback::onEvent(const LnbEventType lnbEventType) {
81     if (mTunerLnbCallback != nullptr) {
82         mTunerLnbCallback->onEvent(lnbEventType);
83     }
84     return ndk::ScopedAStatus::ok();
85 }
86 
onDiseqcMessage(const vector<uint8_t> & diseqcMessage)87 ::ndk::ScopedAStatus TunerLnb::LnbCallback::onDiseqcMessage(const vector<uint8_t>& diseqcMessage) {
88     if (mTunerLnbCallback != nullptr) {
89         mTunerLnbCallback->onDiseqcMessage(diseqcMessage);
90     }
91     return ndk::ScopedAStatus::ok();
92 }
93 
94 }  // namespace tuner
95 }  // namespace tv
96 }  // namespace media
97 }  // namespace android
98 }  // namespace aidl
99