cs.get()->*fnConnectService 表达的意义

以下代码,一直不明白标红的地方的意义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的对象

相关文章
相关标签/搜索