1 /* 2 * Copyright (C) 2022 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 CPP_EVS_MANAGER_AIDL_WRAPPERS_INCLUDE_AIDLENUMERATOR_H 18 #define CPP_EVS_MANAGER_AIDL_WRAPPERS_INCLUDE_AIDLENUMERATOR_H 19 20 #include <aidl/android/hardware/automotive/evs/BnEvsEnumerator.h> 21 #include <aidl/android/hardware/automotive/evs/IEvsCamera.h> 22 #include <aidl/android/hardware/automotive/evs/IEvsDisplay.h> 23 #include <aidl/android/hardware/automotive/evs/IEvsEnumeratorStatusCallback.h> 24 #include <android/hardware/automotive/evs/1.1/IEvsDisplay.h> 25 #include <android/hardware/automotive/evs/1.1/IEvsEnumerator.h> 26 #include <system/camera_metadata.h> 27 28 namespace aidl::android::automotive::evs::implementation { 29 30 namespace aidlevs = ::aidl::android::hardware::automotive::evs; 31 namespace hidlevs = ::android::hardware::automotive::evs; 32 33 class AidlEnumerator final : public ::aidl::android::hardware::automotive::evs::BnEvsEnumerator { 34 public: 35 // Methods from ::aidl::android::hardware::automotive::evs::IEvsEnumerator 36 ::ndk::ScopedAStatus isHardware(bool* flag) override; 37 ::ndk::ScopedAStatus openCamera(const std::string& cameraId, 38 const aidlevs::Stream& streamConfig, 39 std::shared_ptr<aidlevs::IEvsCamera>* obj) override; 40 ::ndk::ScopedAStatus closeCamera(const std::shared_ptr<aidlevs::IEvsCamera>& obj) override; 41 ::ndk::ScopedAStatus getCameraList(std::vector<aidlevs::CameraDesc>* _aidl_return) override; 42 ::ndk::ScopedAStatus getStreamList(const aidlevs::CameraDesc& desc, 43 std::vector<aidlevs::Stream>* _aidl_return) override; 44 ::ndk::ScopedAStatus openDisplay(int32_t displayId, 45 std::shared_ptr<aidlevs::IEvsDisplay>* obj) override; 46 ::ndk::ScopedAStatus closeDisplay(const std::shared_ptr<aidlevs::IEvsDisplay>& obj) override; 47 ::ndk::ScopedAStatus getDisplayIdList(std::vector<uint8_t>* list) override; 48 ::ndk::ScopedAStatus getDisplayState(aidlevs::DisplayState* state) override; 49 ::ndk::ScopedAStatus openUltrasonicsArray( 50 const std::string& id, std::shared_ptr<aidlevs::IEvsUltrasonicsArray>* obj) override; 51 ::ndk::ScopedAStatus closeUltrasonicsArray( 52 const std::shared_ptr<aidlevs::IEvsUltrasonicsArray>& obj) override; 53 ::ndk::ScopedAStatus getUltrasonicsArrayList( 54 std::vector<aidlevs::UltrasonicsArrayDesc>* list) override; 55 ::ndk::ScopedAStatus registerStatusCallback( 56 const std::shared_ptr<aidlevs::IEvsEnumeratorStatusCallback>& callback) override; 57 58 explicit AidlEnumerator(const ::android::sp<hidlevs::V1_0::IEvsEnumerator>& svc); ~AidlEnumerator()59 virtual ~AidlEnumerator() { mImpl = nullptr; } 60 61 // Implementation details 62 bool init(const char* hardwareServiceName); 63 64 private: 65 class IHidlEnumerator; 66 class ImplV0; 67 class ImplV1; 68 69 std::shared_ptr<IHidlEnumerator> mImpl; 70 ::android::wp<hidlevs::V1_0::IEvsDisplay> mHidlDisplay; 71 std::weak_ptr<aidlevs::IEvsDisplay> mAidlDisplay; 72 }; 73 74 class AidlEnumerator::IHidlEnumerator { 75 public: 76 virtual ::ndk::ScopedAStatus closeCamera( 77 const ::android::sp<hidlevs::V1_0::IEvsCamera>& cameraObj) = 0; 78 virtual ::ndk::ScopedAStatus closeDisplay( 79 const ::android::sp<hidlevs::V1_0::IEvsDisplay>& display) = 0; 80 virtual ::ndk::ScopedAStatus getCameraList(std::vector<aidlevs::CameraDesc>* _aidl_return) = 0; 81 virtual ::ndk::ScopedAStatus getDisplayIdList(std::vector<uint8_t>* list) = 0; getHidlEnumerator()82 virtual ::android::sp<hidlevs::V1_0::IEvsEnumerator> getHidlEnumerator() { 83 return mHidlEnumerator; 84 }; 85 virtual ::ndk::ScopedAStatus openCamera(const std::string& cameraId, 86 const aidlevs::Stream& streamConfig, 87 std::shared_ptr<aidlevs::IEvsCamera>* obj) = 0; 88 virtual ::android::sp<hidlevs::V1_0::IEvsDisplay> openDisplay(int32_t displayId) = 0; 89 IHidlEnumerator(const::android::sp<hidlevs::V1_0::IEvsEnumerator> & svc)90 explicit IHidlEnumerator(const ::android::sp<hidlevs::V1_0::IEvsEnumerator>& svc) : 91 mHidlEnumerator(svc) {} ~IHidlEnumerator()92 virtual ~IHidlEnumerator() { mHidlEnumerator = nullptr; } 93 94 protected: 95 ::android::sp<hidlevs::V1_0::IEvsEnumerator> mHidlEnumerator; 96 }; 97 98 class AidlEnumerator::ImplV0 final : public IHidlEnumerator { 99 public: 100 virtual ::ndk::ScopedAStatus closeCamera( 101 const ::android::sp<hidlevs::V1_0::IEvsCamera>& cameraObj) override; 102 virtual ::ndk::ScopedAStatus closeDisplay( 103 const ::android::sp<hidlevs::V1_0::IEvsDisplay>& display) override; 104 virtual ::ndk::ScopedAStatus getCameraList( 105 std::vector<aidlevs::CameraDesc>* _aidl_return) override; 106 virtual ::ndk::ScopedAStatus getDisplayIdList(std::vector<uint8_t>* list) override; 107 virtual ::ndk::ScopedAStatus openCamera(const std::string& cameraId, 108 const aidlevs::Stream& streamConfig, 109 std::shared_ptr<aidlevs::IEvsCamera>* obj) override; 110 virtual ::android::sp<hidlevs::V1_0::IEvsDisplay> openDisplay(int32_t displayId) override; 111 ImplV0(const::android::sp<hidlevs::V1_0::IEvsEnumerator> & svc)112 explicit ImplV0(const ::android::sp<hidlevs::V1_0::IEvsEnumerator>& svc) : 113 IHidlEnumerator(svc) {} 114 }; 115 116 class AidlEnumerator::ImplV1 final : public IHidlEnumerator { 117 public: 118 virtual ::ndk::ScopedAStatus closeCamera( 119 const ::android::sp<hidlevs::V1_0::IEvsCamera>& cameraObj) override; 120 virtual ::ndk::ScopedAStatus closeDisplay( 121 const ::android::sp<hidlevs::V1_0::IEvsDisplay>& display) override; 122 virtual ::ndk::ScopedAStatus getCameraList( 123 std::vector<aidlevs::CameraDesc>* _aidl_return) override; 124 virtual ::ndk::ScopedAStatus getDisplayIdList(std::vector<uint8_t>* list) override; 125 virtual ::ndk::ScopedAStatus openCamera(const std::string& cameraId, 126 const aidlevs::Stream& streamConfig, 127 std::shared_ptr<aidlevs::IEvsCamera>* obj) override; 128 virtual ::android::sp<hidlevs::V1_0::IEvsDisplay> openDisplay(int32_t displayId) override; 129 ImplV1(const::android::sp<hidlevs::V1_1::IEvsEnumerator> & svc)130 explicit ImplV1(const ::android::sp<hidlevs::V1_1::IEvsEnumerator>& svc) : 131 IHidlEnumerator(svc), mHidlEnumerator(svc) {} ~ImplV1()132 virtual ~ImplV1() { mHidlEnumerator = nullptr; } 133 134 private: 135 ::android::sp<hidlevs::V1_1::IEvsEnumerator> mHidlEnumerator; 136 }; 137 138 } // namespace aidl::android::automotive::evs::implementation 139 140 #endif // CPP_EVS_MANAGER_AIDL_WRAPPERS_INCLUDE_AIDLENUMERATOR_H 141