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

Android IPC 通讯机制源码分析

 2010-05-29 05:27:00 来源:WEB开发网   
核心提示:{.................................binder_write(bs, readbuf, sizeof(unsigned));for (;;) {bwr.read_size = sizeof(readbuf);bwr.read_consumed = 0;bwr.read_buffer =

{

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

binder_write(bs, readbuf, sizeof(unsigned));

for (;;) {

bwr.read_size = sizeof(readbuf);

bwr.read_consumed = 0;

bwr.read_buffer = (unsigned) readbuf;

res = ioctl(bs->fd, BINDER_WRITE_READ, &bwr); //如果没有要处理的请求进程将挂起

if (res < 0) {

LOGE("binder_loop: ioctl failed (%s) ", strerror(errno));

break;

}

res = binder_parse(bs, 0, readbuf, bwr.read_consumed, func);//这里func就是

................................... //svcmgr_handler

}

}

接收到数据处理的请求,这里进行解析并调用前面注册的回调函数查找caller请求的service

int binder_parse(struct binder_state *bs, struct binder_io *bio,

uint32_t *ptr, uint32_t size, binder_handler func)

{

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

switch(cmd) {

......

case BR_TRANSACTION: {

struct binder_txn *txn = (void *) ptr;

if ((end - ptr) * sizeof(uint32_t) < sizeof(struct binder_txn)) {

LOGE("parse: txn too small! ");

return -1;

}

binder_dump_txn(txn);

if (func) {

unsigned rdata[256/4];

struct binder_io msg;

struct binder_io reply;

int res;

bio_init(&reply, rdata, sizeof(rdata), 4);

bio_init_from_txn(&msg, txn);

res = func(bs, txn, &msg, &reply); //找到caller请求的service

binder_send_reply(bs, &reply, txn->data, res);//将找到的service返回给caller

}

ptr += sizeof(*txn) / sizeof(uint32_t);

break;

........

}

}

void binder_send_reply(struct binder_state *bs,

struct binder_io *reply,

void *buffer_to_free,

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

Tags:Android IPC 通讯

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