You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
3.8 KiB

/*
* 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 <binder/IServiceManager.h>
#include <binder/IPCThreadState.h>
#include <binder/MemoryBase.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <utils/String8.h>
#include <vendor/huanglong/hardware/hwdisplay/2.0/types.h>
#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<char *>(const_cast<uint8_t *>(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<int *>(const_cast<uint8_t *>(request.data())));
}
ALOGI("=============invoke cmd = 0x%x=======begin=============", cmd);
sp<IHwdisplay> hwDisplay = IHwdisplay::getService();
if (hwDisplay == nullptr) {
ALOGE("getService failed. please check hwdisplay@2.0-service start or not.");
return 0;
}
Return<void> 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<IHwdisplay> 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<IHwdisplay> 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<void> HwTVListener::OnDispmngCallback(unsigned int type, const hidl_string &reply)
{
void *data = reinterpret_cast<void *>(const_cast<char *>(reply.c_str()));
unsigned int length = reply.size();
Notify(type, data, length);
return hardware::Void();
}
}; // namespace android