/* * 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_SAMPLEDRIVER_AIDL_INCLUDE_EVSENUMERATOR_H #define CPP_EVS_SAMPLEDRIVER_AIDL_INCLUDE_EVSENUMERATOR_H #include "ConfigManager.h" #include "EvsGlDisplay.h" #include "EvsV4lCamera.h" #include #include #include #include #include #include #include #include #include #include #include namespace aidl::android::hardware::automotive::evs::implementation { namespace aidlevs = ::aidl::android::hardware::automotive::evs; class EvsEnumerator 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 registerStatusCallback( const std::shared_ptr& callback) 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; // Methods from ndk::ICInterface binder_status_t dump(int fd, const char** args, uint32_t numArgs) override; // Implementation details EvsEnumerator(const std::shared_ptr< ::aidl::android::frameworks::automotive::display::ICarDisplayProxy>& proxyService); void notifyDeviceStatusChange(const std::string_view& deviceName, aidlevs::DeviceStatusType type); // Monitor hotplug devices static void EvsHotplugThread(std::shared_ptr service, std::atomic& running); private: struct CameraRecord { aidlevs::CameraDesc desc; std::weak_ptr activeInstance; CameraRecord(const char* cameraId) : desc() { desc.id = cameraId; } }; bool checkPermission(); void closeCamera_impl(const std::shared_ptr& pCamera, const std::string& cameraId); static bool qualifyCaptureDevice(const char* deviceName); static CameraRecord* findCameraById(const std::string& cameraId); static void enumerateCameras(); static bool addCaptureDevice(const std::string& deviceName); static bool removeCaptureDevice(const std::string& deviceName); // Enumerate available displays and return an id of the internal display static uint64_t enumerateDisplays(); // NOTE: All members values are static so that all clients operate on the same state // That is to say, this is effectively a singleton despite the fact that HIDL // constructs a new instance for each client. // Because our server has a single thread in the thread pool, these values are // never accessed concurrently despite potentially having multiple instance objects // using them. static std::unordered_map sCameraList; static std::weak_ptr sActiveDisplay; // Weak pointer. // Object destructs if client dies. static std::mutex sLock; // Mutex on shared camera device list. static std::condition_variable sCameraSignal; // Signal on camera device addition. static std::unique_ptr sConfigManager; // ConfigManager static std::shared_ptr<::aidl::android::frameworks::automotive::display::ICarDisplayProxy> sDisplayProxy; static std::unordered_map sDisplayPortList; uint64_t mInternalDisplayId; std::shared_ptr mCallback; // Dumpsys commands binder_status_t parseCommand(int fd, const std::vector& options); binder_status_t cmdDump(int fd, const std::vector& options); void cmdHelp(int fd); }; } // namespace aidl::android::hardware::automotive::evs::implementation #endif // CPP_EVS_SAMPLEDRIVER_AIDL_INCLUDE_EVSENUMERATOR_H