binder详解(二)_defaultServiceManager
来源:互联网 发布:怎样去开淘宝店 编辑:程序博客网 时间:2024/05/16 00:25
IServiceManager.cpp::defaultServiceManager()
->
sp<IBinder> ProcessState::getContextObject(const sp<IBinder>& caller)
->
sp<IBinder> ProcessState::getStrongProxyForHandle(int32_t handle)// handle为0
sp<IBinder> result;
b = new BpBinder(handle);
result = b;
return result;
->
gDefaultServiceManager = interface_cast<IServiceManager>(
ProcessState::self()->getContextObject(NULL));
template<typename INTERFACE>
inline sp<INTERFACE> interface_cast(const sp<IBinder>& obj)
{
return INTERFACE::asInterface(obj); // IServiceManager::asInterface(obj);
}
IServiceManager类的继承关系:
class IServiceManager : public IInterface
class IInterface : public virtual RefBase
class RefBase
asInterface方法的声明:
IServiceManager.h
class IServiceManager : public IInterface
{
public:
DECLARE_META_INTERFACE(ServiceManager);
#define DECLARE_META_INTERFACE(INTERFACE) /
static const String16 descriptor; /
static sp<I##INTERFACE> asInterface(const sp<IBinder>& obj); /
virtual const String16& getInterfaceDescriptor() const; /
I##INTERFACE(); /
virtual ~I##INTERFACE();
定义:
IServiceManager.cpp
IMPLEMENT_META_INTERFACE(ServiceManager, "android.os.IServiceManager");
#define IMPLEMENT_META_INTERFACE(INTERFACE, NAME) /
const String16 I##INTERFACE::descriptor(NAME); /
const String16& I##INTERFACE::getInterfaceDescriptor() const { /
return I##INTERFACE::descriptor; /
} /
sp<I##INTERFACE> I##INTERFACE::asInterface(const sp<IBinder>& obj) /
{ /
sp<I##INTERFACE> intr; /
if (obj != NULL) { /
intr = static_cast<I##INTERFACE*>( /
obj->queryLocalInterface( /
I##INTERFACE::descriptor).get()); /
if (intr == NULL) { /
intr = new Bp##INTERFACE(obj); / // intr = new BpServiceManager(obj);
} /
} /
return intr; /
} /
I##INTERFACE::I##INTERFACE() { } /
I##INTERFACE::~I##INTERFACE() { } /
而BpServiceManager的继承关系:
class BpServiceManager : public BpInterface<IServiceManager>
class BpInterface : public INTERFACE, public BpRefBase
class BpRefBase : public virtual RefBase
因此,对于sp<IServiceManager> gDefaultServiceManager; ,BpServiceManager是IServiceManager的子类,所以可以作为gDefaultServiceManager的构造函数的参数。
- binder详解(二)_defaultServiceManager
- android binder 讲解(二)
- Android Binder设计(二)
- binder学习笔记(二)
- Android中的Binder(二)
- Binder实用指南(二)
- binder详解(三)_addService
- binder详解(四)_getService
- android Binder详解 (1)
- android Binder详解 (2)
- android Binder详解(3)
- android Binder详解(4)
- Binder通信二(MediaService理解Binder机制)
- Binder详解
- Binder详解
- Binder详解
- Binder详解
- Binder详解
- [OPENGL]纹理,材质,光照
- 完成端口模型
- install ns2
- 计算机的点点滴滴
- window.showModalDialog 与window.open传递参数的不同?
- binder详解(二)_defaultServiceManager
- js调用父框架函数与弹窗调用父页面函数的方法
- XML序列化与反序列化
- 小满的C++学习心得(2) 说说类构造函数和动态内存管理
- Xml.Serialization.XmlElement
- 构建易于维护的分布式程序
- 在Gnome下让GVIM自动最大化
- 建立一个当前date 命名的文件夹,copy文件到此文件夹中,并记录log
- 配置android sd卡