1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_STYLUS_STYLUS_DETECTOR_LOADER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_STYLUS_STYLUS_DETECTOR_LOADER_H 18 19 #include <memory> 20 #include <string> 21 22 #include "interfaces/inner_api/ace/stylus/stylus_detector_interface.h" 23 24 namespace OHOS::Ace { 25 using StylusDetectorInstance = std::unique_ptr<StylusDetectorInterface, std::function<void(StylusDetectorInterface*)>>; 26 27 class StylusDetectorLoader final : public std::enable_shared_from_this<StylusDetectorLoader> { 28 public: 29 static std::shared_ptr<StylusDetectorLoader> Load(); 30 StylusDetectorLoader() = default; 31 virtual ~StylusDetectorLoader(); 32 33 StylusDetectorLoader(const StylusDetectorLoader&) = delete; 34 StylusDetectorLoader(StylusDetectorLoader&&) = delete; 35 StylusDetectorLoader& operator=(const StylusDetectorLoader&) = delete; 36 StylusDetectorLoader& operator=(StylusDetectorLoader&&) = delete; 37 StylusDetectorInstance CreateStylusDetector(); 38 39 private: 40 bool Init(); 41 void Close(); 42 43 void* libraryHandle_ = nullptr; 44 StylusDetectorInterface* (*createStylusDetectorInstance_)() = nullptr; 45 void (*destroyStylusDetectorInstance_)(StylusDetectorInterface*) = nullptr; 46 bool stylusSoLoaded_ = false; 47 }; 48 } // namespace OHOS::Ace 49 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_STYLUS_STYLUS_DETECTOR_DEFAULT_H