mirror of
https://gitee.com/openharmony/communication_ipc
synced 2024-12-02 13:16:50 +00:00
!1111 【IPC/RPC】【超大函数整改】WaitForCompletion为超大函数
Merge pull request !1111 from frank_bing/master
This commit is contained in:
commit
6f22e92d47
@ -183,6 +183,25 @@ private:
|
||||
void GetSenderInfo(uint64_t &callerTokenID, uint64_t &firstTokenID, pid_t &realPid);
|
||||
|
||||
void PrintErrorMessage(uint64_t writeConsumed);
|
||||
|
||||
void OnTransactionComplete(MessageParcel *reply,
|
||||
int32_t *acquireResult, bool &continueLoop, int32_t &error, uint32_t cmd);
|
||||
|
||||
void OnDeadOrFailedReply(MessageParcel *reply,
|
||||
int32_t *acquireResult, bool &continueLoop, int32_t &error, uint32_t cmd);
|
||||
|
||||
void OnAcquireResult(MessageParcel *reply,
|
||||
int32_t *acquireResult, bool &continueLoop, int32_t &error, uint32_t cmd);
|
||||
|
||||
void OnReply(MessageParcel *reply,
|
||||
int32_t *acquireResult, bool &continueLoop, int32_t &error, uint32_t cmd);
|
||||
|
||||
void OnTranslationComplete(MessageParcel *reply,
|
||||
int32_t *acquireResult, bool &continueLoop, int32_t &error, uint32_t cmd);
|
||||
|
||||
void DealWithCmd(MessageParcel *reply,
|
||||
int32_t *acquireResult, bool &continueLoop, int32_t &error, uint32_t cmd);
|
||||
|
||||
#ifndef CONFIG_IPC_SINGLE
|
||||
bool AddCommAuth(int32_t handle, flat_binder_object *flat);
|
||||
#endif
|
||||
@ -208,6 +227,8 @@ private:
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_MOVE(BinderInvoker);
|
||||
using HandleFunction = void (BinderInvoker::*)(MessageParcel *reply,
|
||||
int32_t *acquireResult, bool &continueLoop, int32_t &error, uint32_t cmd);
|
||||
static constexpr int IPC_DEFAULT_PARCEL_SIZE = 256;
|
||||
static constexpr int IPC_CMD_PROCESS_WARN_TIME = 500;
|
||||
static constexpr int ACCESS_TOKEN_MAX_LEN = 10;
|
||||
@ -221,7 +242,7 @@ private:
|
||||
int lastErrCnt_ = 0;
|
||||
const std::unordered_set<int32_t> GET_HANDLE_CMD_SET = {BC_ACQUIRE, BC_RELEASE,
|
||||
BC_REQUEST_DEATH_NOTIFICATION, BC_REPLY, BC_CLEAR_DEATH_NOTIFICATION, BC_FREE_BUFFER, BC_TRANSACTION};
|
||||
const std::map<int32_t, std::function<void(int32_t cmd, int32_t &error)>> commandMap_ = {
|
||||
const std::map<int32_t, std::function<void(int32_t cmd, int32_t &error)>> receiverCommandMap_ = {
|
||||
{ BR_ERROR, [&](int32_t cmd, int32_t &error) { error = input_.ReadInt32(); } },
|
||||
{ BR_ACQUIRE, [&](int32_t cmd, int32_t &error) { OnAcquireObject(cmd); } },
|
||||
{ BR_INCREFS, [&](int32_t cmd, int32_t &error) { OnAcquireObject(cmd); } },
|
||||
@ -236,6 +257,14 @@ private:
|
||||
{ BR_NOOP, [&](int32_t cmd, int32_t &error) { } },
|
||||
{ BR_CLEAR_DEATH_NOTIFICATION_DONE, [&](int32_t cmd, int32_t &error) { OnRemoveRecipientDone(); } },
|
||||
};
|
||||
const std::map<int32_t, HandleFunction> senderCommandMap_ = {
|
||||
{ BR_TRANSACTION_COMPLETE, &BinderInvoker::OnTransactionComplete },
|
||||
{ BR_DEAD_REPLY, &BinderInvoker::OnDeadOrFailedReply },
|
||||
{ BR_FAILED_REPLY, &BinderInvoker::OnDeadOrFailedReply },
|
||||
{ BR_ACQUIRE_RESULT, &BinderInvoker::OnAcquireResult },
|
||||
{ BR_REPLY, &BinderInvoker::OnReply },
|
||||
{ BR_TRANSLATION_COMPLETE, &BinderInvoker::OnTranslationComplete },
|
||||
};
|
||||
#ifdef CONFIG_ACTV_BINDER
|
||||
bool useActvBinder_ = false;
|
||||
ActvHandlerInfo *actvHandlerInfo_ = nullptr;
|
||||
|
@ -761,8 +761,8 @@ int BinderInvoker::HandleCommandsInner(uint32_t cmd)
|
||||
{
|
||||
int error = ERR_NONE;
|
||||
|
||||
auto it = commandMap_.find(cmd);
|
||||
if (it != commandMap_.end()) {
|
||||
auto it = receiverCommandMap_.find(cmd);
|
||||
if (it != receiverCommandMap_.end()) {
|
||||
it->second(cmd, error);
|
||||
} else {
|
||||
error = IPC_INVOKER_ON_TRANSACT_ERR;
|
||||
@ -899,6 +899,100 @@ bool BinderInvoker::WriteTransaction(int cmd, uint32_t flags, int32_t handle, ui
|
||||
return output_.WriteBuffer(&tr, sizeof(binder_transaction_data));
|
||||
}
|
||||
|
||||
void BinderInvoker::OnTransactionComplete(
|
||||
MessageParcel *reply, int32_t *acquireResult, bool &continueLoop, int32_t &error, uint32_t cmd)
|
||||
{
|
||||
(void)continueLoop;
|
||||
(void)error;
|
||||
(void)cmd;
|
||||
|
||||
if (reply == nullptr && acquireResult == nullptr) {
|
||||
continueLoop = false;
|
||||
}
|
||||
#ifdef CONFIG_ACTV_BINDER
|
||||
/*
|
||||
* Currently, if there are no ready actvs for the actv binder
|
||||
* transaction, the binder transaction would fallback to the
|
||||
* procedure of the native binder in kernel. If going here, it
|
||||
* must be waiting for a reply of the native binder transaction.
|
||||
*/
|
||||
SetUseActvBinder(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
void BinderInvoker::OnDeadOrFailedReply(
|
||||
MessageParcel *reply, int32_t *acquireResult, bool &continueLoop, int32_t &error, uint32_t cmd)
|
||||
{
|
||||
(void)reply;
|
||||
|
||||
error = static_cast<int32_t>(cmd);
|
||||
if (acquireResult != nullptr) {
|
||||
*acquireResult = cmd;
|
||||
}
|
||||
continueLoop = false;
|
||||
}
|
||||
|
||||
void BinderInvoker::OnAcquireResult(
|
||||
MessageParcel *reply, int32_t *acquireResult, bool &continueLoop, int32_t &error, uint32_t cmd)
|
||||
{
|
||||
(void)reply;
|
||||
(void)error;
|
||||
(void)cmd;
|
||||
|
||||
int32_t result = input_.ReadInt32();
|
||||
if (acquireResult != nullptr) {
|
||||
*acquireResult = result ? ERR_NONE : ERR_INVALID_OPERATION;
|
||||
continueLoop = false;
|
||||
}
|
||||
}
|
||||
|
||||
void BinderInvoker::OnReply(
|
||||
MessageParcel *reply, int32_t *acquireResult, bool &continueLoop, int32_t &error, uint32_t cmd)
|
||||
{
|
||||
(void)reply;
|
||||
(void)acquireResult;
|
||||
(void)cmd;
|
||||
|
||||
error = HandleReply(reply);
|
||||
if (error != IPC_INVOKER_INVALID_REPLY_ERR) {
|
||||
continueLoop = false;
|
||||
return;
|
||||
}
|
||||
error = ERR_NONE;
|
||||
}
|
||||
|
||||
void BinderInvoker::OnTranslationComplete(
|
||||
MessageParcel *reply, int32_t *acquireResult, bool &continueLoop, int32_t &error, uint32_t cmd)
|
||||
{
|
||||
(void)reply;
|
||||
(void)acquireResult;
|
||||
(void)error;
|
||||
(void)cmd;
|
||||
|
||||
uint32_t handle = input_.ReadUint32();
|
||||
if (reply != nullptr) {
|
||||
reply->WriteUint32(handle);
|
||||
}
|
||||
continueLoop = false;
|
||||
}
|
||||
|
||||
void BinderInvoker::DealWithCmd(
|
||||
MessageParcel *reply, int32_t *acquireResult, bool &continueLoop, int32_t &error, uint32_t cmd)
|
||||
{
|
||||
auto it = senderCommandMap_.find(cmd);
|
||||
if (it != senderCommandMap_.end()) {
|
||||
HandleFunction itFunc = it->second;
|
||||
if (itFunc != nullptr) {
|
||||
(this->*itFunc)(reply, acquireResult, continueLoop, error, cmd);
|
||||
}
|
||||
} else {
|
||||
error = HandleCommands(cmd);
|
||||
if (error != ERR_NONE) {
|
||||
continueLoop = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int BinderInvoker::WaitForCompletion(MessageParcel *reply, int32_t *acquireResult)
|
||||
{
|
||||
if ((binderConnector_ == nullptr) || (!binderConnector_->IsDriverAlive())) {
|
||||
@ -919,64 +1013,7 @@ int BinderInvoker::WaitForCompletion(MessageParcel *reply, int32_t *acquireResul
|
||||
continue;
|
||||
}
|
||||
cmd = input_.ReadUint32();
|
||||
switch (cmd) {
|
||||
case BR_TRANSACTION_COMPLETE: {
|
||||
if (reply == nullptr && acquireResult == nullptr) {
|
||||
continueLoop = false;
|
||||
}
|
||||
#ifdef CONFIG_ACTV_BINDER
|
||||
/*
|
||||
* Currently, if there are no ready actvs for the actv binder
|
||||
* transaction, the binder transaction would fallback to the
|
||||
* procedure of the native binder in kernel. If going here, it
|
||||
* must be waiting for a reply of the native binder transaction.
|
||||
*/
|
||||
SetUseActvBinder(false);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case BR_DEAD_REPLY: // fall-through
|
||||
case BR_FAILED_REPLY: {
|
||||
error = static_cast<int>(cmd);
|
||||
if (acquireResult != nullptr) {
|
||||
*acquireResult = cmd;
|
||||
}
|
||||
continueLoop = false;
|
||||
break;
|
||||
}
|
||||
case BR_ACQUIRE_RESULT: {
|
||||
int32_t result = input_.ReadInt32();
|
||||
if (acquireResult != nullptr) {
|
||||
*acquireResult = result ? ERR_NONE : ERR_INVALID_OPERATION;
|
||||
continueLoop = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BR_REPLY: {
|
||||
error = HandleReply(reply);
|
||||
if (error != IPC_INVOKER_INVALID_REPLY_ERR) {
|
||||
continueLoop = false;
|
||||
break;
|
||||
}
|
||||
error = ERR_NONE;
|
||||
break;
|
||||
}
|
||||
case BR_TRANSLATION_COMPLETE: {
|
||||
uint32_t handle = input_.ReadUint32();
|
||||
if (reply != nullptr) {
|
||||
reply->WriteUint32(handle);
|
||||
}
|
||||
continueLoop = false;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
error = HandleCommands(cmd);
|
||||
if (error != ERR_NONE) {
|
||||
continueLoop = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
DealWithCmd(reply, acquireResult, continueLoop, error, cmd);
|
||||
}
|
||||
#ifdef CONFIG_ACTV_BINDER
|
||||
SetUseActvBinder(useActvBinder);
|
||||
|
Loading…
Reference in New Issue
Block a user