WEB开发网
开发学院手机开发Android 开发 Android IPC 通讯机制源码分析 阅读

Android IPC 通讯机制源码分析

 2010-05-29 05:27:00 来源:WEB开发网   
核心提示:{unsigned n;for (n = 0; n < 5; n++){sp svc = checkService(name);if (svc != NULL) return svc;LOGI("Waiting for sevice %s...", String8(name).string()

{

unsigned n;

for (n = 0; n < 5; n++){

sp svc = checkService(name);

if (svc != NULL) return svc;

LOGI("Waiting for sevice %s... ", String8(name).string());

sleep(1);

}

return NULL;

}

virtual sp checkService( const String16& name) const

{

Parcel data, reply;

data.writeInterfaceToken(IServiceManager::getInterfaceDescriptor());

data.writeString16(name);

remote()->transact(CHECK_SERVICE_TRANSACTION, data, &reply);

return reply.readStrongBinder();

}

这里的remote就是我们前面得到BpBinder对象。所以checkService将调用BpBinder中的transact函数:

status_t BpBinder::transact(

uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)

{

// Once a binder has died, it will never come back to life.

if (mAlive) {

status_t status = IPCThreadState::self()->transact(

mHandle, code, data, reply, flags);

if (status == DEAD_OBJECT) mAlive = 0;

return status;

}

return DEAD_OBJECT;

}

mHandle为0,BpBinder继续往下调用IPCThreadState:transact函数将数据发给与mHandle相关联的Service Manager Process。

status_t IPCThreadState::transact(int32_t handle,

uint32_t code, const Parcel& data,

Parcel* reply, uint32_t flags)

{

............................................................

if (err == NO_ERROR) {

LOG_ONEWAY(">>>> SEND from pid %d uid %d %s", getpid(), getuid(),

(flags & TF_ONE_WAY) == 0 ? "READ REPLY" : "ONE WAY");

err = writeTransactionData(BC_TRANSACTION, flags, handle, code, data, NULL);

}

if (err != NO_ERROR) {

上一页  1 2 3 4 5 6 7 8 9 10 11  下一页

Tags:Android IPC 通讯

编辑录入:coldstar [复制链接] [打 印]
赞助商链接