以下代碼,一直不明白標紅的地方的意義android
const sp<::android::hardware::ICameraService> cs = getCameraService();spa
if (cs != 0) {
TCamConnectService fnConnectService = TCamTraits::fnConnectService;
status = (cs.get()->*fnConnectService)(cl, cameraId, clientPackageName, clientUid,
/*out*/ c->mCamera);
}.net
BpServiceManager(BpBinder(0))的對象對象
http://www.javashuo.com/article/p-zeienxqg-kc.htmlblog
template <typename TCam, typename TCamTraits>
const sp<::android::hardware::ICameraService> CameraBase<TCam, TCamTraits>::getCameraService()
{
Mutex::Autolock _l(gLock);
if (gCameraService.get() == 0) {
char value[PROPERTY_VALUE_MAX];
property_get("config.disable_cameraservice", value, "0");
if (strncmp(value, "0", 2) != 0 && strncasecmp(value, "false", 6) != 0) {
return gCameraService;
}ci
sp<IServiceManager> sm = defaultServiceManager();
sp<IBinder> binder;
do {
binder = sm->getService(String16(kCameraServiceName));
if (binder != 0) {
break;
}
ALOGW("CameraService not published, waiting...");
usleep(kCameraServicePollDelay);
} while(true);
if (gDeathNotifier == NULL) {
gDeathNotifier = new DeathNotifier();
}
binder->linkToDeath(gDeathNotifier);
gCameraService = interface_cast<::android::hardware::ICameraService>(binder);
}
ALOGE_IF(gCameraService == 0, "no CameraService!?");
return gCameraService;
}get
getCameraService最終獲得的是一個BpCameraService(BpBinder(handle))實例,在BpCameraService中實現了對CameraService端的方法封裝。it
其相關代碼:ast
class BpCameraService: public BpInterface<ICameraService>
{
public:
explicit BpCameraService(const sp<IBinder>& impl)
: BpInterface<ICameraService>(impl)
{
}class
。。。
}
回頭再看
const sp<::android::hardware::ICameraService> cs = getCameraService();
cs.get() 其實是class sp 中的get方法
inline T* get() const { return m_ptr; }
能夠理解爲 cs.get返回一個指向ICameraService的對象