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

Android IPC 通讯机制源码分析

 2010-05-29 05:27:00 来源:WEB开发网   
核心提示:if (IN < sizeof(int32_t)) continue;cmd = mIn.readInt32();IF_LOG_COMMANDS() {alog << "Processing top-level Command: "<< getReturnString(

if (IN < sizeof(int32_t)) continue;

cmd = mIn.readInt32();

IF_LOG_COMMANDS() {

alog << "Processing top-level Command: "

<< getReturnString(cmd) << endl;

}

result = executeCommand(cmd); //service 执行binder kernel请求的命令

}

// Let this thread exit the thread pool if it is no longer

// needed and it is not the main process thread.

if(result == TIMED_OUT && !isMain) {

break;

}

} while (result != -ECONNREFUSED && result != -EBADF);

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

}

status_t IPCThreadState::executeCommand(int32_t cmd)

{

BBinder* obj;

RefBase::weakref_type* refs;

status_t result = NO_ERROR;

switch (cmd) {

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

case BR_TRANSACTION:

{

binder_transaction_data tr;

result = mIn.read(&tr, sizeof(tr));

LOG_ASSERT(result == NO_ERROR,

"Not enough command data for brTRANSACTION");

if (result != NO_ERROR) break;

Parcel buffer;

buffer.ipcSetDataReference(

reinterpret_cast(tr.data.ptr.buffer),

tr.data_size,

reinterpret_cast(tr.data.ptr.offsets),

tr.offsets_size/sizeof(size_t), freeBuffer, this);

const pid_t origPid = mCallingPid;

const uid_t origUid = mCallingUid;

mCallingPid = tr.sender_pid;

mCallingUid = tr.sender_euid;

//LOGI(">>>> TRANSACT from pid %d uid %d ", mCallingPid, mCallingUid);

Parcel reply;

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

if (tr.target.ptr) {

sp b((BBinder*)tr.cookie); //service中Binder对象即CameraService

const status_t error = b->transact(tr.code, buffer, &reply,

上一页  9 10 11 12 13 14 15 16 17 18  下一页

Tags:Android IPC 通讯

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