blob: 49237d5bdddac6f6e5a8d5515e2c0a2800f31f5e [file] [log] [blame]
Donghyun Cho8bdb7f92016-10-13 22:29:54 +09001/*
2 * Copyright (C) 2016 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#ifndef HIDL_GENERATED_android_hardware_tv_cec_V1_0_HdmiCec_H_
18#define HIDL_GENERATED_android_hardware_tv_cec_V1_0_HdmiCec_H_
19
20#include <algorithm>
21
22#include <android/hardware/tv/cec/1.0/IHdmiCec.h>
23#include <hidl/Status.h>
24#include <hardware/hardware.h>
25#include <hardware/hdmi_cec.h>
26
27#include <hidl/MQDescriptor.h>
28namespace android {
29namespace hardware {
30namespace tv {
31namespace cec {
32namespace V1_0 {
33namespace implementation {
34
35using ::android::hardware::tv::cec::V1_0::CecLogicalAddress;
36using ::android::hardware::tv::cec::V1_0::CecMessage;
Donghyun Choc22bed32016-11-04 05:38:40 +090037using ::android::hardware::tv::cec::V1_0::MaxLength;
Donghyun Cho8bdb7f92016-10-13 22:29:54 +090038using ::android::hardware::tv::cec::V1_0::HdmiPortInfo;
39using ::android::hardware::tv::cec::V1_0::IHdmiCec;
40using ::android::hardware::tv::cec::V1_0::IHdmiCecCallback;
41using ::android::hardware::tv::cec::V1_0::OptionKey;
42using ::android::hardware::tv::cec::V1_0::Result;
43using ::android::hardware::tv::cec::V1_0::SendMessageResult;
44using ::android::hardware::Return;
45using ::android::hardware::Void;
46using ::android::hardware::hidl_vec;
47using ::android::hardware::hidl_string;
48using ::android::sp;
49
50struct HdmiCec : public IHdmiCec {
51 HdmiCec(hdmi_cec_device_t* device);
52 // Methods from ::android::hardware::tv::cec::V1_0::IHdmiCec follow.
53 Return<Result> addLogicalAddress(CecLogicalAddress addr) override;
54 Return<void> clearLogicalAddress() override;
55 Return<void> getPhysicalAddress(getPhysicalAddress_cb _hidl_cb) override;
56 Return<SendMessageResult> sendMessage(const CecMessage& message) override;
57 Return<void> setCallback(const sp<IHdmiCecCallback>& callback) override;
58 Return<int32_t> getCecVersion() override;
59 Return<uint32_t> getVendorId() override;
60 Return<void> getPortInfo(getPortInfo_cb _hidl_cb) override;
61 Return<void> setOption(OptionKey key, bool value) override;
62 Return<void> setLanguage(const hidl_string& language) override;
63 Return<void> enableAudioReturnChannel(int32_t portId, bool enable) override;
64 Return<bool> isConnected(int32_t portId) override;
65
66 static void eventCallback(const hdmi_event_t* event, void* arg) {
67 if (mCallback != nullptr && event != nullptr) {
68 if (event->type == HDMI_EVENT_CEC_MESSAGE) {
Donghyun Choc22bed32016-11-04 05:38:40 +090069 size_t length = std::min(event->cec.length,
70 static_cast<size_t>(MaxLength::MESSAGE_BODY));
Donghyun Cho8bdb7f92016-10-13 22:29:54 +090071 CecMessage cecMessage {
72 .initiator = static_cast<CecLogicalAddress>(event->cec.initiator),
73 .destination = static_cast<CecLogicalAddress>(event->cec.destination),
74 };
75 cecMessage.body.resize(length);
76 for (size_t i = 0; i < length; ++i) {
77 cecMessage.body[i] = static_cast<uint8_t>(event->cec.body[i]);
78 }
79 mCallback->onCecMessage(cecMessage);
80 } else if (event->type == HDMI_EVENT_HOT_PLUG) {
81 HotplugEvent hotplugEvent {
82 .connected = event->hotplug.connected > 0,
83 .portId = static_cast<uint32_t>(event->hotplug.port_id)
84 };
85 mCallback->onHotplugEvent(hotplugEvent);
86 }
87 }
88 }
89
90private:
91 static sp<IHdmiCecCallback> mCallback;
92 const hdmi_cec_device_t* mDevice;
93};
94
95extern "C" IHdmiCec* HIDL_FETCH_IHdmiCec(const char* name);
96
97} // namespace implementation
98} // namespace V1_0
99} // namespace cec
100} // namespace tv
101} // namespace hardware
102} // namespace android
103
104#endif // HIDL_GENERATED_android_hardware_tv_cec_V1_0_HdmiCec_H_