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

Android IPC 通讯机制源码分析

 2010-05-29 05:27:00 来源:WEB开发网   
核心提示:sp ProcessState::getStrongProxyForHandle(int32_t handle){sp result;AutoMutex _l(mLock);handle_entry* e = lookupHandleLocked(handle);if (e != NULL) {// We need t

sp ProcessState::getStrongProxyForHandle(int32_t handle)

{

sp result;

AutoMutex _l(mLock);

handle_entry* e = lookupHandleLocked(handle);

if (e != NULL) {

// We need to create a new BpBinder if there isn't currently one, OR we

// are unable to acquire a weak reference on this current one. See comment

// in getWeakProxyForHandle() for more info about this.

IBinder* b = e->binder; //第一次调用该函数b为Null

if (b == NULL || !e->refs->attemptIncWeak(this)) {

b = new BpBinder(handle);

e->binder = b;

if (b) e->refs = b->getWeakRefs();

result = b;

} else {

// This little bit of nastyness is to allow us to add a primary

// reference to the remote proxy when this team doesn't have one

// but another team is sending the handle to us.

result.force_set(b);

e->refs->decWeak(this);

}

}

return result;

}

第一次调用的时候b为Null所以会为b生成一BpBinder对象:

BpBinder::BpBinder(int32_t handle)

: mHandle(handle)

, mAlive(1)

, mObitsSent(0)

, mObituaries(NULL)

{

LOGV("Creating BpBinder %p handle %d ", this, mHandle);

extendObjectLifetime(OBJECT_LIFETIME_WEAK);

IPCThreadState::self()->incWeakHandle(handle);

}

void IPCThreadState::incWeakHandle(int32_t handle)

{

LOG_REMOTEREFS("IPCThreadState::incWeakHandle(%d) ", handle);

mOut.writeInt32(BC_INCREFS);

mOut.writeInt32(handle);

}

getContextObject返回了一个BpBinder对象。

interface_cast(

ProcessState::self()->getContextObject(NULL));

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

Tags:Android IPC 通讯

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