本文主要是介绍Native实现的service怎样加入ServiceManager,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
常见的方法是:xxxx::instantiate();class:xxxx没有定义函数instantiate();肯定是继承过来的
class xxxx : public BinderService<xxxx>, public BnSystemKloService
{
friend class BinderService<xxxx>;
---
}
模板类 BinderService
template<typename SERVICE>
class BinderService
{
public:
static status_t publish(bool allowIsolated = false) {
sp<IServiceManager> sm(defaultServiceManager());
return sm->addService(
String16(SERVICE::getServiceName()),
new SERVICE(), allowIsolated);
}
static void publishAndJoinThreadPool(bool allowIsolated = false) {
publish(allowIsolated);
joinThreadPool();
}
static void instantiate() { publish(); }
}
BinderService<xxxx>:
xxxx::instantiate() -> BinderService<xxxx>::instantiate
-> BinderService<xxxx>::publish
最终调用到ServiceManager的add
这篇关于Native实现的service怎样加入ServiceManager的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!