TextOutput::Bundle _b(alog);
alog << \ << handle << \
if (reply) alog << indent << *reply << dedent << endl; else alog << \ } } else {
err = waitForResponse(NULL, NULL); }
return err; }
status_t IPCThreadState::waitForResponse(Parcel *reply, status_t *acquireResult) {
int32_t cmd; int32_t err;
while (1) {
if ((err=talkWithDriver()) < NO_ERROR) break; err = mIn.errorCheck(); if (err < NO_ERROR) break; if (mIn.dataAvail() == 0) continue;
cmd = mIn.readInt32();
IF_LOG_COMMANDS() {
alog << \ << getReturnString(cmd) << endl; }
switch (cmd) {
case BR_TRANSACTION_COMPLETE: if (!reply && !acquireResult) goto finish; break;
case BR_DEAD_REPLY: err = DEAD_OBJECT; goto finish;
case BR_FAILED_REPLY: err = FAILED_TRANSACTION; goto finish;
case BR_ACQUIRE_RESULT: {
LOG_ASSERT(acquireResult != NULL, \ const int32_t result = mIn.readInt32(); if (!acquireResult) continue;
*acquireResult = result ? NO_ERROR : INVALID_OPERATION; }
goto finish;
case BR_REPLY:
{
binder_transaction_data tr; err = mIn.read(&tr, sizeof(tr));
LOG_ASSERT(err == NO_ERROR, \brREPLY\
if (err != NO_ERROR) goto finish;
if (reply) {
if ((tr.flags & TF_STATUS_CODE) == 0) { reply->ipcSetDataReference( reinterpret_cast(tr.data.ptr.buffer), tr.data_size,
reinterpret_cast(tr.data.ptr.offsets), tr.offsets_size/sizeof(size_t), freeBuffer, this); } else {
err = *static_cast(tr.data.ptr.buffer); freeBuffer(NULL,
reinterpret_cast(tr.data.ptr.buffer), tr.data_size,
reinterpret_cast(tr.data.ptr.offsets), tr.offsets_size/sizeof(size_t), this); } } else {
freeBuffer(NULL,
reinterpret_cast(tr.data.ptr.buffer), tr.data_size,
reinterpret_cast(tr.data.ptr.offsets), tr.offsets_size/sizeof(size_t), this); continue; } }
goto finish;
default:
err = executeCommand(cmd); if (err != NO_ERROR) goto finish; break; } } finish:
if (err != NO_ERROR) {
if (acquireResult) *acquireResult = err; if (reply) reply->setError(err); mLastError = err; }
return err; }
这里transact把请求经内核模块发送了给服务端,服务端处理完请求之后,沿原路返回结果给调用者。这里也可以看出请求是同步操作,它会等待直到结果返回为止。
在BpBinder之上进行简单包装,我们可以得到与服务对象相同的接口,调用者无需要关心调用的对象是远程的还是本地的。拿ServiceManager来说: (frameworks/base/libs/utils/IServiceManager.cpp)
相关推荐: