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