Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 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 | |
Changyeon Jo | c6fa0ab | 2019-10-12 05:25:44 -0700 | [diff] [blame] | 20 | #include <android/hardware/automotive/evs/1.1/IEvsEnumerator.h> |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 21 | #include <android/hardware/automotive/evs/1.1/IEvsCamera.h> |
Changyeon Jo | 043a7a0 | 2020-01-02 17:55:55 -0800 | [diff] [blame] | 22 | #include <android/hardware/automotive/evs/1.1/IEvsDisplay.h> |
| 23 | #include <android/frameworks/automotive/display/1.0/IAutomotiveDisplayProxyService.h> |
Tanmay Patil | b97cceb | 2020-02-07 16:48:39 -0800 | [diff] [blame] | 24 | #include <android/hardware/automotive/evs/1.1/IEvsUltrasonicsArray.h> |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 25 | |
| 26 | #include <list> |
| 27 | |
Changyeon Jo | c6fa0ab | 2019-10-12 05:25:44 -0700 | [diff] [blame] | 28 | #include "ConfigManager.h" |
| 29 | |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 30 | using ::android::hardware::automotive::evs::V1_0::EvsResult; |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 31 | using ::android::hardware::automotive::evs::V1_0::DisplayState; |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 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; |
Changyeon Jo | c6fa0ab | 2019-10-12 05:25:44 -0700 | [diff] [blame] | 35 | using CameraDesc_1_1 = ::android::hardware::automotive::evs::V1_1::CameraDesc; |
Changyeon Jo | 043a7a0 | 2020-01-02 17:55:55 -0800 | [diff] [blame] | 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; |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 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 |
Tanmay Patil | b97cceb | 2020-02-07 16:48:39 -0800 | [diff] [blame] | 50 | class EvsUltrasonicsArray; // from EvsUltrasonicsArray.h |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 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; |
Changyeon Jo | 043a7a0 | 2020-01-02 17:55:55 -0800 | [diff] [blame] | 59 | Return<sp<IEvsDisplay_1_0>> openDisplay() override; |
| 60 | Return<void> closeDisplay(const ::android::sp<IEvsDisplay_1_0>& display) override; |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 61 | Return<DisplayState> getDisplayState() override; |
| 62 | |
Changyeon Jo | c6fa0ab | 2019-10-12 05:25:44 -0700 | [diff] [blame] | 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; |
Changyeon Jo | 8bcb492 | 2020-01-15 19:34:50 -0800 | [diff] [blame] | 67 | Return<bool> isHardware() override { return true; } |
Changyeon Jo | 043a7a0 | 2020-01-02 17:55:55 -0800 | [diff] [blame] | 68 | Return<void> getDisplayIdList(getDisplayIdList_cb _list_cb) override; |
| 69 | Return<sp<IEvsDisplay_1_1>> openDisplay_1_1(uint8_t port) override; |
Tanmay Patil | 496b86c | 2020-01-07 17:50:23 -0800 | [diff] [blame] | 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; |
Changyeon Jo | c6fa0ab | 2019-10-12 05:25:44 -0700 | [diff] [blame] | 75 | |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 76 | // Implementation details |
Changyeon Jo | 043a7a0 | 2020-01-02 17:55:55 -0800 | [diff] [blame] | 77 | EvsEnumerator(sp<IAutomotiveDisplayProxyService> windowService = nullptr); |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 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 { |
Changyeon Jo | c6fa0ab | 2019-10-12 05:25:44 -0700 | [diff] [blame] | 84 | CameraDesc_1_1 desc; |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 85 | wp<EvsCamera> activeInstance; |
| 86 | |
Changyeon Jo | c6fa0ab | 2019-10-12 05:25:44 -0700 | [diff] [blame] | 87 | CameraRecord(const char *cameraId) : desc() { desc.v1.cameraId = cameraId; } |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 88 | }; |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 89 | |
Tanmay Patil | b97cceb | 2020-02-07 16:48:39 -0800 | [diff] [blame] | 90 | struct UltrasonicsArrayRecord { |
| 91 | UltrasonicsArrayDesc desc; |
| 92 | wp<EvsUltrasonicsArray> activeInstance; |
| 93 | |
| 94 | UltrasonicsArrayRecord(const UltrasonicsArrayDesc& arrayDesc) : desc(arrayDesc) {}; |
| 95 | }; |
| 96 | |
Changyeon Jo | c6fa0ab | 2019-10-12 05:25:44 -0700 | [diff] [blame] | 97 | static CameraRecord* findCameraById(const std::string& cameraId); |
| 98 | |
| 99 | static std::list<CameraRecord> sCameraList; |
| 100 | |
Tanmay Patil | b97cceb | 2020-02-07 16:48:39 -0800 | [diff] [blame] | 101 | static UltrasonicsArrayRecord* findUltrasonicsArrayById(const std::string& ultrasonicsArrayId); |
| 102 | |
| 103 | static std::list<UltrasonicsArrayRecord> sUltrasonicsArrayRecordList; |
| 104 | |
Changyeon Jo | c6fa0ab | 2019-10-12 05:25:44 -0700 | [diff] [blame] | 105 | // Weak pointer. Object destructs if client dies. |
| 106 | static wp<EvsDisplay> sActiveDisplay; |
| 107 | |
| 108 | static unique_ptr<ConfigManager> sConfigManager; |
Changyeon Jo | 043a7a0 | 2020-01-02 17:55:55 -0800 | [diff] [blame] | 109 | |
| 110 | static sp<IAutomotiveDisplayProxyService> sDisplayProxyService; |
| 111 | static std::unordered_map<uint8_t, |
| 112 | uint64_t> sDisplayPortList; |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 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 |