Android开发之ProcessState和IPCThreadState类分析

         在Android中ProcessState是客户端和服务端公共的部分,作为Binder通信的基础,ProcessState是一个singleton类,每个
进程只有一个对象,这个对象负责打开Binder驱动,建立线程池,让其进程里面的所有线程都能通过Binder通信。
与之相关的是IPCThreadState,每个线程都有一个IPCThreadState实例登记在Linux线程的上下文附属数据中,主要负责
Binder的读取,写入和请求处理框架。IPCThreadState在构造的时候获取进程的ProcessState并记录在自己的成员变量
mProcess中,通过mProcess可以获得Binder的句柄。

frameworks/base/include/binder/ProcessState.h
class ProcessState : public virtual RefBase
{
public:
	static sp<ProcessState> self();	// 单例模式,获取实例
	
	void setContextObject(const sp<IBinder>& object);
	sp<IBinder> getContextObject(const sp<IBinder>& caller);
	
	void setContextObject(const sp<IBinder>& object, const String16& name);
	sp<IBinder> getContextObject(const String16& name, const sp<IBinder>& caller);
	
	void startThreadePool();
	
	typdef bool (*context_check_func)(const String16& name, const sp<IBinder>& caller, void* userData);
	
	bool isContextManager(void) const;
	bool becomeContextManager(context_check_func checkFunc, void* userData);
	
	sp<IBinder> getStrongProxyForHandle(int32_t handle);
	wp<IBinder> getWeakProxyForHandle(int32_t handle);
	void espungeHandle(int32_t handle, IBinder* binder);
	
	void spawnPooledThread(boot isMain);
private:
	friend class IPCThreadState;
		ProcessState();
		~ProcessState;
		ProcessState(const ProcessState& o);
	ProcessState& operator=(const ProcessState& o);
	
	struct hdndle_entry {
		IBinder* binder;
		RefBase::weakref_type* refs;
	};
	
	handle_entry* lookupHandleLocked(int32_t handle);
	
	int mDriverFD;		// 打开的binder驱动文件描述符
	void* mVMStart;
	
	Vector<handle_entry> mHandleToObject;
	
	bool mManagerContexts;
	context_check_func mBinderContextCheckFunc;
	v
  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值