常见的方法是: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
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