Debian Codegraph @

media/jni/tuner/LnbClient.cpp

raw symbols SCIP
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 namespace android {
25
26 /////////////// LnbClient ///////////////////////
27 LnbClient::LnbClient(shared_ptr<ITunerLnb> tunerLnb) {
28 mTunerLnb = tunerLnb;
29 }
30
31 LnbClient::~LnbClient() {
32 mTunerLnb = nullptr;
33 }
34
35 Result LnbClient::setCallback(sp<LnbClientCallback> cb) {
36 if (mTunerLnb != nullptr) {
37 shared_ptr<TunerLnbCallback> aidlCallback =
38 ::ndk::SharedRefBase::make<TunerLnbCallback>(cb);
39 Status s = mTunerLnb->setCallback(aidlCallback);
40 return ClientHelper::getServiceSpecificErrorCode(s);
41 }
42
43 return Result::INVALID_STATE;
44 }
45
46 Result LnbClient::setVoltage(LnbVoltage voltage) {
47 if (mTunerLnb != nullptr) {
48 Status s = mTunerLnb->setVoltage(voltage);
49 return ClientHelper::getServiceSpecificErrorCode(s);
50 }
51
52 return Result::INVALID_STATE;
53 }
54
55 Result LnbClient::setTone(LnbTone tone) {
56 if (mTunerLnb != nullptr) {
57 Status s = mTunerLnb->setTone(tone);
58 return ClientHelper::getServiceSpecificErrorCode(s);
59 }
60
61 return Result::INVALID_STATE;
62 }
63
64 Result LnbClient::setSatellitePosition(LnbPosition position) {
65 if (mTunerLnb != nullptr) {
66 Status s = mTunerLnb->setSatellitePosition(position);
67 return ClientHelper::getServiceSpecificErrorCode(s);
68 }
69
70 return Result::INVALID_STATE;
71 }
72
73 Result LnbClient::sendDiseqcMessage(vector<uint8_t> diseqcMessage) {
74 if (mTunerLnb != nullptr) {
75 Status s = mTunerLnb->sendDiseqcMessage(diseqcMessage);
76 return ClientHelper::getServiceSpecificErrorCode(s);
77 }
78
79 return Result::INVALID_STATE;
80 }
81
82 Result LnbClient::close() {
83 if (mTunerLnb != nullptr) {
84 Status s = mTunerLnb->close();
85 mTunerLnb = nullptr;
86 return ClientHelper::getServiceSpecificErrorCode(s);
87 }
88
89 return Result::INVALID_STATE;
90 }
91
92 /////////////// TunerLnbCallback ///////////////////////
93 TunerLnbCallback::TunerLnbCallback(sp<LnbClientCallback> lnbClientCallback)
94 : mLnbClientCallback(lnbClientCallback) {}
95
96 Status TunerLnbCallback::onEvent(LnbEventType lnbEventType) {
97 if (mLnbClientCallback != nullptr) {
98 mLnbClientCallback->onEvent(lnbEventType);
99 return Status::ok();
100 }
101 return Status::fromServiceSpecificError(static_cast<int32_t>(Result::INVALID_STATE));
102 }
103
104 Status TunerLnbCallback::onDiseqcMessage(const vector<uint8_t>& diseqcMessage) {
105 if (mLnbClientCallback != nullptr) {
106 mLnbClientCallback->onDiseqcMessage(diseqcMessage);
107 return Status::ok();
108 }
109 return Status::fromServiceSpecificError(static_cast<int32_t>(Result::INVALID_STATE));
110 }
111 } // namespace android