/* * 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 #include #include #include #include #include #include #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 hTvClient) : mTvClient(hTvClient) { } ~HwTVListener() override { } void Notify(unsigned int type, const void *data, unsigned int len, const void *prev) override; Return hwNotify(unsigned int type, const hidl_string &reply, const hidl_string &request, hwNotify_cb _hidl_cb) override; private: sp 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(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(request.data())); } ALOGI("=============invoke cmd = 0x%x=======begin=============", cmd); sp hwTvmw = IHwtvmw::getService(); if (hwTvmw == nullptr) { ALOGE("getService failed. please check hwtvmw@1.0-service start or not."); return 0; } Return 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 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 HwTVListener::hwNotify(unsigned int type, const hidl_string &reply, const hidl_string &request, hwNotify_cb _hidl_cb) { const void *data = reinterpret_cast(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