1/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_HARDWARE_AUTOMOTIVE_EVS_V1_0_EVSCAMERAENUMERATOR_H
18#define ANDROID_HARDWARE_AUTOMOTIVE_EVS_V1_0_EVSCAMERAENUMERATOR_H
19
20#include <android/hardware/automotive/evs/1.0/IEvsEnumerator.h>
21#include <android/hardware/automotive/evs/1.0/IEvsCamera.h>
22
23#include <list>
24
25
26namespace android {
27namespace hardware {
28namespace automotive {
29namespace evs {
30namespace V1_0 {
31namespace implementation {
32
33
34class EvsV4lCamera;    // from EvsCamera.h
35class EvsGlDisplay;    // from EvsGlDisplay.h
36
37
38class EvsEnumerator : public IEvsEnumerator {
39public:
40    // Methods from ::android::hardware::automotive::evs::V1_0::IEvsEnumerator follow.
41    Return<void> getCameraList(getCameraList_cb _hidl_cb)  override;
42    Return<sp<IEvsCamera>> openCamera(const hidl_string& cameraId) override;
43    Return<void> closeCamera(const ::android::sp<IEvsCamera>& carCamera)  override;
44    Return<sp<IEvsDisplay>> openDisplay()  override;
45    Return<void> closeDisplay(const ::android::sp<IEvsDisplay>& display)  override;
46    Return<DisplayState> getDisplayState()  override;
47
48    // Implementation details
49    EvsEnumerator();
50
51private:
52    struct CameraRecord {
53        CameraDesc          desc;
54        wp<EvsV4lCamera>    activeInstance;
55
56        CameraRecord(const char *cameraId) : desc() { desc.cameraId = cameraId; }
57    };
58
59
60    static bool qualifyCaptureDevice(const char* deviceName);
61    static CameraRecord* findCameraById(const std::string& cameraId);
62
63
64    // NOTE:  All members values are static so that all clients operate on the same state
65    //        That is to say, this is effectively a singleton despite the fact that HIDL
66    //        constructs a new instance for each client.
67    //        Because our server has a single thread in the thread pool, these values are
68    //        never accessed concurrently despite potentially having multiple instance objects
69    //        using them.
70    static std::list<CameraRecord> sCameraList;
71
72    static wp<EvsGlDisplay>          sActiveDisplay; // Weak pointer. Object destructs if client dies.
73};
74
75} // namespace implementation
76} // namespace V1_0
77} // namespace evs
78} // namespace automotive
79} // namespace hardware
80} // namespace android
81
82#endif  // ANDROID_HARDWARE_AUTOMOTIVE_EVS_V1_0_EVSCAMERAENUMERATOR_H
83