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