/* * Copyright (c) Hisilicon Technologies Co., Ltd.. 2019-2022. All rights reserved. * Description: Support hwdisplay hal adaptation interface * Author: Hisilicon * Created: 2022-12-28 */ #define LOG_NDEBUG 0 #define LOG_TAG "Display_TVClient" #include "DispClient.h" #include #include #include #include #include #include #include #include #include #include "hwbinder/Parcel.h" using ::vendor::huanglong::hardware::hwdisplay::V2_0::IHwdisplay; namespace android { DispClient::DispClient() { ALOGI("structure"); mHwListener = new HwTVListener(this); } DispClient::~DispClient() { ALOGI("destructor"); } status_t DispClient::Invoke(const android::hardware::Parcel &request, android::hardware::Parcel *reply) const { ALOGI("===========DispClient::invoke begin========="); if (request.dataSize() > 0) { hardware::hidl_string inputStr(reinterpret_cast(const_cast(request.data())), request.dataSize()); String8 retReply; auto cb = [&retReply](hidl_string strReply) { retReply = String8(strReply.c_str(), strReply.size()); }; int cmd = 0; // init value 0. if (request.data() != nullptr) { cmd = *(reinterpret_cast(const_cast(request.data()))); } ALOGI("=============invoke cmd = 0x%x=======begin=============", cmd); sp hwDisplay = IHwdisplay::getService(); if (hwDisplay == nullptr) { ALOGE("getService failed. please check hwdisplay@2.0-service start or not."); return 0; } Return ret = hwDisplay->hwInvoke(inputStr, cb); if (!ret.isOk() && ret.isDeadObject()) { ALOGE("Error, hwInvoke failed, service is a DEAD_OBJECT."); } ALOGI("=============invoke cmd = 0x%x=======end===============", cmd); if (reply == nullptr) { ALOGE("input null param."); return 0; } reply->setDataSize(retReply.size()); reply->setDataPosition(0); reply->write(retReply.c_str(), retReply.size()); reply->setDataPosition(0); } ALOGI("===========DispClient::invoke end========="); return 0; } void DispClient::Notify(unsigned int type, const void *data, unsigned int len) { Mutex::Autolock lock(mNotifyLock); if (mCallback.get()) { mCallback->Notify(type, data, len); } } void DispClient::RegisterCallback(unsigned int eventId, IDispClientCallback *callback) { if (!mCallback.get()) { mCallback = callback; } sp hwDisplay = IHwdisplay::getService(); if (hwDisplay == nullptr) { ALOGI("hwDisplay registerCallback error"); return; } hwDisplay->RegisterCallback(eventId, mHwListener); } void DispClient::UnRegisterCallback(unsigned int eventId, const IDispClientCallback *callback) { if (mCallback.get() == callback) { mCallback = nullptr; } sp hwDisplay = IHwdisplay::getService(); if (hwDisplay == nullptr) { ALOGI("hwDisplay unRegisterCallback error"); return; } hwDisplay->UnRegisterCallback(eventId, mHwListener); } /* function for HwTvListener */ void HwTVListener::Notify(unsigned int type, const void *data, unsigned int len) { if (mTvClient != nullptr) { mTvClient->Notify(type, data, len); } return; } Return HwTVListener::OnDispmngCallback(unsigned int type, const hidl_string &reply) { void *data = reinterpret_cast(const_cast(reply.c_str())); unsigned int length = reply.size(); Notify(type, data, length); return hardware::Void(); } }; // namespace android