/* * Copyright (C) 2022 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef CPP_EVS_MANAGER_AIDL_WRAPPERS_INCLUDE_AIDLENUMERATOR_H #define CPP_EVS_MANAGER_AIDL_WRAPPERS_INCLUDE_AIDLENUMERATOR_H #include #include #include #include #include #include #include namespace aidl::android::automotive::evs::implementation { namespace aidlevs = ::aidl::android::hardware::automotive::evs; namespace hidlevs = ::android::hardware::automotive::evs; class AidlEnumerator final : public ::aidl::android::hardware::automotive::evs::BnEvsEnumerator { public: // Methods from ::aidl::android::hardware::automotive::evs::IEvsEnumerator ::ndk::ScopedAStatus isHardware(bool* flag) override; ::ndk::ScopedAStatus openCamera(const std::string& cameraId, const aidlevs::Stream& streamConfig, std::shared_ptr* obj) override; ::ndk::ScopedAStatus closeCamera(const std::shared_ptr& obj) override; ::ndk::ScopedAStatus getCameraList(std::vector* _aidl_return) override; ::ndk::ScopedAStatus getStreamList(const aidlevs::CameraDesc& desc, std::vector* _aidl_return) override; ::ndk::ScopedAStatus openDisplay(int32_t displayId, std::shared_ptr* obj) override; ::ndk::ScopedAStatus closeDisplay(const std::shared_ptr& obj) override; ::ndk::ScopedAStatus getDisplayIdList(std::vector* list) override; ::ndk::ScopedAStatus getDisplayState(aidlevs::DisplayState* state) override; ::ndk::ScopedAStatus getDisplayStateById(int32_t displayId, aidlevs::DisplayState* state) override; ::ndk::ScopedAStatus openUltrasonicsArray( const std::string& id, std::shared_ptr* obj) override; ::ndk::ScopedAStatus closeUltrasonicsArray( const std::shared_ptr& obj) override; ::ndk::ScopedAStatus getUltrasonicsArrayList( std::vector* list) override; ::ndk::ScopedAStatus registerStatusCallback( const std::shared_ptr& callback) override; explicit AidlEnumerator(const ::android::sp& svc, bool forceV1_0 = false); virtual ~AidlEnumerator() { mImpl = nullptr; } // Implementation details bool init(const char* hardwareServiceName); private: class IHidlEnumerator; class ImplV0; class ImplV1; std::shared_ptr mImpl; ::android::wp mHidlDisplay; std::weak_ptr mAidlDisplay; }; class AidlEnumerator::IHidlEnumerator { public: virtual ::ndk::ScopedAStatus closeCamera( const ::android::sp& cameraObj) = 0; virtual ::ndk::ScopedAStatus closeDisplay( const ::android::sp& display) = 0; virtual ::ndk::ScopedAStatus getCameraList(std::vector* _aidl_return) = 0; virtual ::ndk::ScopedAStatus getDisplayIdList(std::vector* list) = 0; virtual ::ndk::ScopedAStatus openCamera(const std::string& cameraId, const aidlevs::Stream& streamConfig, std::shared_ptr* obj) = 0; virtual ::android::sp openDisplay(int32_t displayId) = 0; explicit IHidlEnumerator(const ::android::sp& svc) : mHidlEnumerator(svc) {} virtual ~IHidlEnumerator() { mHidlEnumerator = nullptr; } protected: ::android::sp mHidlEnumerator; ::android::wp mActiveHidlDisplay; }; class AidlEnumerator::ImplV0 final : public IHidlEnumerator { public: virtual ::ndk::ScopedAStatus closeCamera( const ::android::sp& cameraObj) override; virtual ::ndk::ScopedAStatus closeDisplay( const ::android::sp& display) override; virtual ::ndk::ScopedAStatus getCameraList( std::vector* _aidl_return) override; virtual ::ndk::ScopedAStatus getDisplayIdList(std::vector* list) override; virtual ::ndk::ScopedAStatus openCamera(const std::string& cameraId, const aidlevs::Stream& streamConfig, std::shared_ptr* obj) override; virtual ::android::sp openDisplay(int32_t displayId) override; explicit ImplV0(const ::android::sp& svc) : IHidlEnumerator(svc) {} }; class AidlEnumerator::ImplV1 final : public IHidlEnumerator { public: virtual ::ndk::ScopedAStatus closeCamera( const ::android::sp& cameraObj) override; virtual ::ndk::ScopedAStatus closeDisplay( const ::android::sp& display) override; virtual ::ndk::ScopedAStatus getCameraList( std::vector* _aidl_return) override; virtual ::ndk::ScopedAStatus getDisplayIdList(std::vector* list) override; virtual ::ndk::ScopedAStatus openCamera(const std::string& cameraId, const aidlevs::Stream& streamConfig, std::shared_ptr* obj) override; virtual ::android::sp openDisplay(int32_t displayId) override; explicit ImplV1(const ::android::sp& svc) : IHidlEnumerator(svc), mHidlEnumerator(svc) {} virtual ~ImplV1() { mHidlEnumerator = nullptr; } private: ::android::sp mHidlEnumerator; }; } // namespace aidl::android::automotive::evs::implementation #endif // CPP_EVS_MANAGER_AIDL_WRAPPERS_INCLUDE_AIDLENUMERATOR_H