1 /*
2  * Copyright (C) 2019 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_1_EVSCAMERAENUMERATOR_H
18 #define ANDROID_HARDWARE_AUTOMOTIVE_EVS_V1_1_EVSCAMERAENUMERATOR_H
19 
20 #include "ConfigManager.h"
21 
22 #include <android/frameworks/automotive/display/1.0/IAutomotiveDisplayProxyService.h>
23 #include <android/hardware/automotive/evs/1.1/IEvsCamera.h>
24 #include <android/hardware/automotive/evs/1.1/IEvsDisplay.h>
25 #include <android/hardware/automotive/evs/1.1/IEvsEnumerator.h>
26 #include <android/hardware/automotive/evs/1.1/IEvsUltrasonicsArray.h>
27 
28 #include <list>
29 
30 namespace android::hardware::automotive::evs::V1_1::implementation {
31 
32 namespace evs_v1_0 = ::android::hardware::automotive::evs::V1_0;
33 
34 class EvsCamera;            // from EvsCamera.h
35 class EvsDisplay;           // from EvsDisplay.h
36 class EvsUltrasonicsArray;  // from EvsUltrasonicsArray.h
37 
38 class EvsEnumerator : public IEvsEnumerator {
39   public:
40     // Methods from ::android::hardware::automotive::evs::V1_0::IEvsEnumerator follow.
41     Return<void> getCameraList(getCameraList_cb _hidl_cb) override;
42     Return<sp<evs_v1_0::IEvsCamera>> openCamera(const hidl_string& cameraId) override;
43     Return<void> closeCamera(const ::android::sp<evs_v1_0::IEvsCamera>& carCamera) override;
44     Return<sp<evs_v1_0::IEvsDisplay>> openDisplay() override;
45     Return<void> closeDisplay(const ::android::sp<evs_v1_0::IEvsDisplay>& display) override;
46     Return<V1_0::DisplayState> getDisplayState() override;
47 
48     // Methods from ::android::hardware::automotive::evs::V1_1::IEvsEnumerator follow.
49     Return<void> getCameraList_1_1(getCameraList_1_1_cb _hidl_cb) override;
50     Return<sp<IEvsCamera>> openCamera_1_1(const hidl_string& cameraId,
51                                           const Stream& streamCfg) override;
isHardware()52     Return<bool> isHardware() override { return true; }
53     Return<void> getDisplayIdList(getDisplayIdList_cb _list_cb) override;
54     Return<sp<IEvsDisplay>> openDisplay_1_1(uint8_t port) override;
55     Return<void> getUltrasonicsArrayList(getUltrasonicsArrayList_cb _hidl_cb) override;
56     Return<sp<IEvsUltrasonicsArray>> openUltrasonicsArray(
57             const hidl_string& ultrasonicsArrayId) override;
58     Return<void> closeUltrasonicsArray(
59             const ::android::sp<IEvsUltrasonicsArray>& evsUltrasonicsArray) override;
60 
61     // Implementation details
62     EvsEnumerator(sp<frameworks::automotive::display::V1_0::IAutomotiveDisplayProxyService>&
63                           windowService);
64 
65   private:
66     // NOTE:  All members values are static so that all clients operate on the same state
67     //        That is to say, this is effectively a singleton despite the fact that HIDL
68     //        constructs a new instance for each client.
69     struct CameraRecord {
70         CameraDesc desc;
71         wp<EvsCamera> activeInstance;
72 
CameraRecordCameraRecord73         CameraRecord(const char* cameraId) : desc() { desc.v1.cameraId = cameraId; }
74     };
75 
76     struct UltrasonicsArrayRecord {
77         UltrasonicsArrayDesc desc;
78         wp<EvsUltrasonicsArray> activeInstance;
79 
UltrasonicsArrayRecordUltrasonicsArrayRecord80         UltrasonicsArrayRecord(const UltrasonicsArrayDesc& arrayDesc) : desc(arrayDesc){};
81     };
82 
83     static CameraRecord* findCameraById(const std::string& cameraId);
84     static std::list<CameraRecord> sCameraList;
85     static UltrasonicsArrayRecord* findUltrasonicsArrayById(const std::string& ultrasonicsArrayId);
86     static std::list<UltrasonicsArrayRecord> sUltrasonicsArrayRecordList;
87 
88     static wp<EvsDisplay> sActiveDisplay;  // Weak pointer. Object destructs if client dies.
89     static uint64_t sInternalDisplayId;
90     static sp<frameworks::automotive::display::V1_0::IAutomotiveDisplayProxyService>
91             sDisplayProxyService;
92     static std::unordered_map<uint8_t, uint64_t> sDisplayPortList;
93     static std::unique_ptr<ConfigManager> sConfigManager;
94 };
95 
96 }  // namespace android::hardware::automotive::evs::V1_1::implementation
97 
98 #endif  // ANDROID_HARDWARE_AUTOMOTIVE_EVS_V1_1_EVSCAMERAENUMERATOR_H
99