2024年6月9日发(作者:)
CameraService服务启动流程
启动rc脚本文件
//
service cameraserver /system/bin/cameraserver
1
2
进程入口:
//frameworksavcameracameraservermain_cameraserver.
cpp
int main(int argc __unused, char** argv __unused)
{
signal(SIGPIPE, SIG_IGN);
//之前讲过,会打开/dev/hwbinder,通知kernel,当前进程最
大允许的binder线程池为maxThreads
// Set 3 threads for HIDL calls
hardware::configureRpcThreadpool(3, /*willjoin*/ false);
//创建ProcessState单例对象
sp
//获取IServiceManager服务代理对象BpServiceManager
//代码在
/frameworks/native/libs/binder/
sp
ALOGI("ServiceManager: %p", ());
//1、创建CameraService
//2、触发CameraService::onFirstRef()
//3、将CameraService注册给IServiceManager
CameraService::instantiate();
//创建一个子线程并加入binder线程池
ProcessState::self()->startThreadPool();
//将主线程加入binder线程池
IPCThreadState::self()->joinThreadPool();
}
下边对CameraService::instantiate()方法进行详细介绍下.
首先给出CameraService的类图,如下:
CameraService::instantiate()调用的是其父类BinderService的
方法
// /frameworks/native/include/binder/BinderService.h
static void instantiate() { publish(); }
1
2
接着调用了publish()方法
// /frameworks/native/include/binder/BinderService.h
static status_t publish(bool allowIsolated = false) {
//获取IServiceManager服务代理对象BpServiceManager
sp
//注册服务SERVICE为CameraService
return sm->addService(
String16(SERVICE::getServiceName()),
new SERVICE(), allowIsolated);
}
在注册服务时,首先调用CameraService::getServiceName()获
取CameraService的服务名称–"",然后新建
CameraService对象。
下边介绍下BpServiceManager的addService方法。
//
virtual status_t addService(const String16& name, const
sp
bool allowIsolated)
{


发布评论