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.

80 lines
1.9 KiB

/*
* Copyright (c) Hisilicon Technologies Co., Ltd.. 2012-2019. All rights reserved.
* Description:
* Author:
* Create:
*/
#define LOG_NDEBUG 0
#define LOG_TAG "TvMW_ITVClient"
#include <utils/RefBase.h>
#include <binder/IInterface.h>
#include <binder/Parcel.h>
#include "ITVClient.h"
namespace android {
enum {
NOTIFY = IBinder::FIRST_CALL_TRANSACTION,
};
class BpTVClient : public BpInterface<ITVClient> {
public:
explicit BpTVClient(const sp<IBinder> &impl) : BpInterface<ITVClient>(impl)
{}
~BpTVClient() override {}
void notify(unsigned int type, const void *data, unsigned int len, const void *prev) override
{
TD_UNUSED(prev);
Parcel request, reply;
request.writeInterfaceToken(ITVClient::getInterfaceDescriptor());
request.writeInt32(type);
if (data != nullptr && len > 0) {
request.write(data, len);
}
remote()->transact(NOTIFY, request, &reply, IBinder::FLAG_ONEWAY);
}
};
IMPLEMENT_META_INTERFACE(TVClient, "android.ITVClient");
// ----------------------------------------------------------------------
Mutex BnTVClient::mNotifyLock;
status_t BnTVClient::onTransact(uint32_t code, const Parcel &request, Parcel *reply, uint32_t flags)
{
Mutex::Autolock _l(mNotifyLock);
switch (code) {
case NOTIFY: {
CHECK_INTERFACE(ITVClient, request, reply);
int type = request.readInt32();
int len = static_cast<int>(request.dataAvail());
if (len <= 0) {
return -1;
}
char *data = new char[len];
request.read(data, len);
notify(type, data, len, nullptr);
if (data != nullptr) {
delete[] data;
data = nullptr;
}
return NO_ERROR;
}
default:
return BBinder::onTransact(code, request, reply, flags);
}
}
BnTVClient::~BnTVClient()
{
}
}; // namespace android