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.
151 lines
4.2 KiB
151 lines
4.2 KiB
/*
|
|
* Copyright (c) Hisilicon Technologies Co., Ltd.. 2012-2019. All rights reserved.
|
|
* Description:
|
|
* Author:
|
|
* Create:
|
|
*/
|
|
|
|
#define LOG_NDEBUG 0
|
|
#define LOG_TAG "TvMW_TVClient"
|
|
|
|
#include "TVClient.h"
|
|
#include <binder/IServiceManager.h>
|
|
#include <binder/IPCThreadState.h>
|
|
#include <binder/MemoryBase.h>
|
|
#include <utils/String8.h>
|
|
#include <vendor/huanglong/hardware/hwtvmw/1.0/IHwtvmw.h>
|
|
#include <vendor/huanglong/hardware/hwtvmw/1.0/IHwtvmwCallback.h>
|
|
#include <vendor/huanglong/hardware/hwtvmw/1.0/types.h>
|
|
#include "hwbinder/Parcel.h"
|
|
|
|
using ::vendor::huanglong::hardware::hwtvmw::V1_0::IHwtvmw;
|
|
using ::vendor::huanglong::hardware::hwtvmw::V1_0::IHwtvmwCallback;
|
|
using ::android::hardware::hidl_string;
|
|
using ::android::hardware::Return;
|
|
using ::android::hardware::Void;
|
|
|
|
using namespace android;
|
|
namespace android {
|
|
class HwTVListener : public ITVClientCallback, public vendor::huanglong::hardware::hwtvmw::V1_0::IHwtvmwCallback {
|
|
public:
|
|
explicit HwTVListener(sp<TVClient> hTvClient) : mTvClient(hTvClient)
|
|
{
|
|
}
|
|
~HwTVListener() override
|
|
{
|
|
}
|
|
void Notify(unsigned int type, const void *data, unsigned int len, const void *prev) override;
|
|
|
|
Return<void> hwNotify(unsigned int type, const hidl_string &reply,
|
|
const hidl_string &request, hwNotify_cb _hidl_cb) override;
|
|
|
|
private:
|
|
sp<TVClient> mTvClient;
|
|
};
|
|
|
|
TVClient::TVClient()
|
|
{
|
|
mHwListener = new HwTVListener(this);
|
|
ALOGI("structure");
|
|
}
|
|
|
|
TVClient::~TVClient()
|
|
{
|
|
ALOGI("destructor");
|
|
}
|
|
|
|
status_t TVClient::connect() const
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
status_t TVClient::invoke(const android::hardware::Parcel &request, android::hardware::Parcel *reply) const
|
|
{
|
|
if (request.dataSize() > 0) {
|
|
hardware::hidl_string inputStr(reinterpret_cast<const char *>(request.data()),
|
|
request.dataSize());
|
|
|
|
String8 retReply;
|
|
auto cb = [&](hidl_string strReply) {
|
|
retReply = String8(strReply.c_str(), strReply.size());
|
|
};
|
|
int cmd = 0; // init value 0.
|
|
if (request.data() != nullptr) {
|
|
cmd = *(reinterpret_cast<const int *>(request.data()));
|
|
}
|
|
ALOGI("=============invoke cmd = 0x%x=======begin=============", cmd);
|
|
|
|
sp<IHwtvmw> hwTvmw = IHwtvmw::getService();
|
|
if (hwTvmw == nullptr) {
|
|
ALOGE("getService failed. please check hwtvmw@1.0-service start or not.");
|
|
return 0;
|
|
}
|
|
|
|
Return<void> ret = hwTvmw->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);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
void TVClient::notify(unsigned int type, const void *data, unsigned int len, const void *prev)
|
|
{
|
|
Mutex::Autolock _l(mNotifyLock);
|
|
|
|
ALOGI("callback application type=0x%X (%d)", type, type);
|
|
if (mCallback.get()) {
|
|
mCallback->Notify(type, data, len, prev);
|
|
}
|
|
ALOGI("back from callback");
|
|
}
|
|
|
|
void TVClient::registCallback(ITVClientCallback *const callback)
|
|
{
|
|
if (!mCallback.get()) {
|
|
mCallback = callback;
|
|
}
|
|
|
|
sp<IHwtvmw> mTvmw = nullptr;
|
|
mTvmw = IHwtvmw::getService();
|
|
if (mTvmw == nullptr) {
|
|
ALOGI("tvmw SetListener error");
|
|
return;
|
|
}
|
|
|
|
mTvmw->hwRegistCallback(mHwListener);
|
|
}
|
|
|
|
/* function for HwTvListener */
|
|
void HwTVListener::Notify(unsigned int type, const void *data, unsigned int len, const void *prev)
|
|
{
|
|
if (mTvClient != nullptr) {
|
|
mTvClient->notify(type, data, len, prev);
|
|
}
|
|
return;
|
|
}
|
|
|
|
Return<void> HwTVListener::hwNotify(unsigned int type, const hidl_string &reply,
|
|
const hidl_string &request, hwNotify_cb _hidl_cb)
|
|
{
|
|
const void *data = reinterpret_cast<const void *>(reply.c_str());
|
|
unsigned int length = reply.size();
|
|
hidl_string replyStr = nullptr;
|
|
(void)request;
|
|
|
|
Notify(type, data, length, nullptr);
|
|
|
|
_hidl_cb(replyStr);
|
|
return hardware::Void();
|
|
}
|
|
}; // namespace android
|