1 /* 2 * Copyright (c) 2023 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_ADAPTER_PREVIEW_ACE_PREVIEW_HELPER_H 17 #define FOUNDATION_ACE_ADAPTER_PREVIEW_ACE_PREVIEW_HELPER_H 18 19 #include <functional> 20 #include <string> 21 22 #include "base/utils/macros.h" 23 24 namespace OHOS::Ace::Platform { 25 using CallbackTypeIsCurrentRunnerThread = std::function<bool(void)>; 26 using CallbackTypePostTask = std::function<void(const std::function<void()>&, int64_t)>; 27 using CallbackTypeHspBufferTracker = std::function<bool(const std::string&, uint8_t**, size_t*)>; 28 using CallbackTypeSetClipboardData = std::function<void(const std::string&)>; 29 using CallbackTypeGetClipboardData = std::function<const std::string(void)>; 30 class ACE_FORCE_EXPORT AcePreviewHelper { 31 public: 32 static AcePreviewHelper* GetInstance(); 33 ~AcePreviewHelper() = default; 34 SetCallbackOfPostTask(const CallbackTypePostTask && postTask)35 void SetCallbackOfPostTask(const CallbackTypePostTask&& postTask) 36 { 37 postTask_ = postTask; 38 } 39 GetCallbackOfPostTask()40 CallbackTypePostTask GetCallbackOfPostTask() 41 { 42 return postTask_; 43 } 44 SetCallbackOfIsCurrentRunnerThread(const CallbackTypeIsCurrentRunnerThread && isCurrentRunnerThread)45 void SetCallbackOfIsCurrentRunnerThread(const CallbackTypeIsCurrentRunnerThread&& isCurrentRunnerThread) 46 { 47 isCurrentRunnerThread_ = isCurrentRunnerThread; 48 } 49 GetCallbackOfIsCurrentRunnerThread()50 CallbackTypeIsCurrentRunnerThread GetCallbackOfIsCurrentRunnerThread() 51 { 52 return isCurrentRunnerThread_; 53 } 54 SetCallbackOfHspBufferTracker(const CallbackTypeHspBufferTracker && hspBufferTracker)55 void SetCallbackOfHspBufferTracker(const CallbackTypeHspBufferTracker&& hspBufferTracker) 56 { 57 hspBufferTracker_ = hspBufferTracker; 58 } 59 GetCallbackOfHspBufferTracker()60 CallbackTypeHspBufferTracker GetCallbackOfHspBufferTracker() 61 { 62 return hspBufferTracker_; 63 } 64 SetCallbackOfSetClipboardData(const CallbackTypeSetClipboardData && setClipboardData)65 void SetCallbackOfSetClipboardData(const CallbackTypeSetClipboardData&& setClipboardData) 66 { 67 setClipboardData_ = std::move(setClipboardData); 68 } 69 GetCallbackOfSetClipboardData()70 CallbackTypeSetClipboardData GetCallbackOfSetClipboardData() 71 { 72 return setClipboardData_; 73 } 74 SetCallbackOfGetClipboardData(const CallbackTypeGetClipboardData && getClipboardData)75 void SetCallbackOfGetClipboardData(const CallbackTypeGetClipboardData&& getClipboardData) 76 { 77 getClipboardData_ = std::move(getClipboardData); 78 } 79 GetCallbackOfGetClipboardData()80 CallbackTypeGetClipboardData GetCallbackOfGetClipboardData() 81 { 82 return getClipboardData_; 83 } 84 85 private: 86 AcePreviewHelper() = default; 87 AcePreviewHelper(const AcePreviewHelper&) = delete; 88 AcePreviewHelper& operator=(const AcePreviewHelper&) = delete; 89 90 CallbackTypePostTask postTask_ = nullptr; 91 CallbackTypeIsCurrentRunnerThread isCurrentRunnerThread_ = nullptr; 92 CallbackTypeHspBufferTracker hspBufferTracker_ = nullptr; 93 CallbackTypeSetClipboardData setClipboardData_ = nullptr; 94 CallbackTypeGetClipboardData getClipboardData_ = nullptr; 95 }; 96 } // namespace OHOS::Ace::Platform 97 #endif // FOUNDATION_ACE_ADAPTER_PREVIEW_ACE_PREVIEW_HELPER_H 98