• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     mLnb = nullptr;
40     mId = -1;
41 }
42 
setCallback(const shared_ptr<ITunerLnbCallback> & in_tunerLnbCallback)43 ::ndk::ScopedAStatus TunerLnb::setCallback(
44         const shared_ptr<ITunerLnbCallback>& in_tunerLnbCallback) {
45     if (mLnb == nullptr) {
46         ALOGE("ILnb is not initialized");
47         return ::ndk::ScopedAStatus::fromServiceSpecificError(
48                 static_cast<int32_t>(Result::UNAVAILABLE));
49     }
50 
51     if (in_tunerLnbCallback == nullptr) {
52         return ::ndk::ScopedAStatus::fromServiceSpecificError(
53                 static_cast<int32_t>(Result::INVALID_ARGUMENT));
54     }
55 
56     shared_ptr<ILnbCallback> lnbCallback =
57             ::ndk::SharedRefBase::make<LnbCallback>(in_tunerLnbCallback);
58     return mLnb->setCallback(lnbCallback);
59 }
60 
setVoltage(LnbVoltage in_voltage)61 ::ndk::ScopedAStatus TunerLnb::setVoltage(LnbVoltage in_voltage) {
62     if (mLnb == nullptr) {
63         ALOGE("ILnb is not initialized");
64         return ::ndk::ScopedAStatus::fromServiceSpecificError(
65                 static_cast<int32_t>(Result::UNAVAILABLE));
66     }
67 
68     return mLnb->setVoltage(in_voltage);
69 }
70 
setTone(LnbTone in_tone)71 ::ndk::ScopedAStatus TunerLnb::setTone(LnbTone in_tone) {
72     if (mLnb == nullptr) {
73         ALOGE("ILnb is not initialized");
74         return ::ndk::ScopedAStatus::fromServiceSpecificError(
75                 static_cast<int32_t>(Result::UNAVAILABLE));
76     }
77 
78     return mLnb->setTone(in_tone);
79 }
80 
setSatellitePosition(LnbPosition in_position)81 ::ndk::ScopedAStatus TunerLnb::setSatellitePosition(LnbPosition in_position) {
82     if (mLnb == nullptr) {
83         ALOGE("ILnb is not initialized");
84         return ::ndk::ScopedAStatus::fromServiceSpecificError(
85                 static_cast<int32_t>(Result::UNAVAILABLE));
86     }
87 
88     return mLnb->setSatellitePosition(in_position);
89 }
90 
sendDiseqcMessage(const vector<uint8_t> & in_diseqcMessage)91 ::ndk::ScopedAStatus TunerLnb::sendDiseqcMessage(const vector<uint8_t>& in_diseqcMessage) {
92     if (mLnb == nullptr) {
93         ALOGE("ILnb is not initialized");
94         return ::ndk::ScopedAStatus::fromServiceSpecificError(
95                 static_cast<int32_t>(Result::UNAVAILABLE));
96     }
97 
98     return mLnb->sendDiseqcMessage(in_diseqcMessage);
99 }
100 
close()101 ::ndk::ScopedAStatus TunerLnb::close() {
102     if (mLnb == nullptr) {
103         ALOGE("ILnb is not initialized");
104         return ::ndk::ScopedAStatus::fromServiceSpecificError(
105                 static_cast<int32_t>(Result::UNAVAILABLE));
106     }
107 
108     auto res = mLnb->close();
109     mLnb = nullptr;
110 
111     return res;
112 }
113 
114 /////////////// ILnbCallback ///////////////////////
onEvent(const LnbEventType lnbEventType)115 ::ndk::ScopedAStatus TunerLnb::LnbCallback::onEvent(const LnbEventType lnbEventType) {
116     if (mTunerLnbCallback != nullptr) {
117         mTunerLnbCallback->onEvent(lnbEventType);
118     }
119     return ndk::ScopedAStatus::ok();
120 }
121 
onDiseqcMessage(const vector<uint8_t> & diseqcMessage)122 ::ndk::ScopedAStatus TunerLnb::LnbCallback::onDiseqcMessage(const vector<uint8_t>& diseqcMessage) {
123     if (mTunerLnbCallback != nullptr) {
124         mTunerLnbCallback->onDiseqcMessage(diseqcMessage);
125     }
126     return ndk::ScopedAStatus::ok();
127 }
128 
129 }  // namespace tuner
130 }  // namespace tv
131 }  // namespace media
132 }  // namespace android
133 }  // namespace aidl
134