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 | 47b45af | 2019-10-11 10:17:33 -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> |
| 22 | |
| 23 | #include <list> |
| 24 | |
Changyeon Jo | 47b45af | 2019-10-11 10:17:33 -0700 | [diff] [blame^] | 25 | #include "ConfigManager.h" |
| 26 | |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 27 | using ::android::hardware::automotive::evs::V1_0::EvsResult; |
| 28 | using ::android::hardware::automotive::evs::V1_0::IEvsDisplay; |
| 29 | using ::android::hardware::automotive::evs::V1_0::DisplayState; |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 30 | using IEvsCamera_1_0 = ::android::hardware::automotive::evs::V1_0::IEvsCamera; |
| 31 | using IEvsCamera_1_1 = ::android::hardware::automotive::evs::V1_1::IEvsCamera; |
| 32 | using CameraDesc_1_0 = ::android::hardware::automotive::evs::V1_0::CameraDesc; |
Changyeon Jo | 47b45af | 2019-10-11 10:17:33 -0700 | [diff] [blame^] | 33 | using CameraDesc_1_1 = ::android::hardware::automotive::evs::V1_1::CameraDesc; |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 34 | |
| 35 | |
| 36 | namespace android { |
| 37 | namespace hardware { |
| 38 | namespace automotive { |
| 39 | namespace evs { |
| 40 | namespace V1_1 { |
| 41 | namespace implementation { |
| 42 | |
| 43 | |
| 44 | class EvsCamera; // from EvsCamera.h |
| 45 | class EvsDisplay; // from EvsDisplay.h |
| 46 | |
| 47 | |
| 48 | class EvsEnumerator : public IEvsEnumerator { |
| 49 | public: |
| 50 | // Methods from ::android::hardware::automotive::evs::V1_0::IEvsEnumerator follow. |
| 51 | Return<void> getCameraList(getCameraList_cb _hidl_cb) override; |
| 52 | Return<sp<IEvsCamera_1_0>> openCamera(const hidl_string& cameraId) override; |
| 53 | Return<void> closeCamera(const ::android::sp<IEvsCamera_1_0>& carCamera) override; |
| 54 | Return<sp<IEvsDisplay>> openDisplay() override; |
| 55 | Return<void> closeDisplay(const ::android::sp<IEvsDisplay>& display) override; |
| 56 | Return<DisplayState> getDisplayState() override; |
| 57 | |
Changyeon Jo | 47b45af | 2019-10-11 10:17:33 -0700 | [diff] [blame^] | 58 | // Methods from ::android::hardware::automotive::evs::V1_1::IEvsEnumerator follow. |
| 59 | Return<void> getCameraList_1_1(getCameraList_1_1_cb _hidl_cb) override; |
| 60 | Return<sp<IEvsCamera_1_1>> openCamera_1_1(const hidl_string& cameraId, |
| 61 | const Stream& streamCfg) override; |
| 62 | |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 63 | // Implementation details |
| 64 | EvsEnumerator(); |
| 65 | |
| 66 | private: |
| 67 | // NOTE: All members values are static so that all clients operate on the same state |
| 68 | // That is to say, this is effectively a singleton despite the fact that HIDL |
| 69 | // constructs a new instance for each client. |
| 70 | struct CameraRecord { |
Changyeon Jo | 47b45af | 2019-10-11 10:17:33 -0700 | [diff] [blame^] | 71 | CameraDesc_1_1 desc; |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 72 | wp<EvsCamera> activeInstance; |
| 73 | |
Changyeon Jo | 47b45af | 2019-10-11 10:17:33 -0700 | [diff] [blame^] | 74 | CameraRecord(const char *cameraId) : desc() { desc.v1.cameraId = cameraId; } |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 75 | }; |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 76 | |
Changyeon Jo | 47b45af | 2019-10-11 10:17:33 -0700 | [diff] [blame^] | 77 | static CameraRecord* findCameraById(const std::string& cameraId); |
| 78 | |
| 79 | static std::list<CameraRecord> sCameraList; |
| 80 | |
| 81 | // Weak pointer. Object destructs if client dies. |
| 82 | static wp<EvsDisplay> sActiveDisplay; |
| 83 | |
| 84 | static unique_ptr<ConfigManager> sConfigManager; |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | } // namespace implementation |
| 88 | } // namespace V1_1 |
| 89 | } // namespace evs |
| 90 | } // namespace automotive |
| 91 | } // namespace hardware |
| 92 | } // namespace android |
| 93 | |
| 94 | #endif // ANDROID_HARDWARE_AUTOMOTIVE_EVS_V1_1_EVSCAMERAENUMERATOR_H |