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*, std::string&)>; 28 using CallbackTypeSetClipboardData = std::function<void(const std::string&)>; 29 using CallbackTypeGetClipboardData = std::function<const std::string(void)>; 30 using CallbackFlushEmpty = std::function<bool(const uint64_t)>; 31 class ACE_FORCE_EXPORT AcePreviewHelper { 32 public: 33 static AcePreviewHelper* GetInstance(); 34 ~AcePreviewHelper() = default; 35 SetCallbackFlushEmpty(const CallbackFlushEmpty && flushEmpty)36 void SetCallbackFlushEmpty(const CallbackFlushEmpty&& flushEmpty) 37 { 38 flushEmpty_ = flushEmpty; 39 } 40 GetCallbackFlushEmpty()41 CallbackFlushEmpty GetCallbackFlushEmpty() 42 { 43 return flushEmpty_; 44 } 45 SetCallbackOfPostTask(const CallbackTypePostTask && postTask)46 void SetCallbackOfPostTask(const CallbackTypePostTask&& postTask) 47 { 48 postTask_ = postTask; 49 } 50 GetCallbackOfPostTask()51 CallbackTypePostTask GetCallbackOfPostTask() 52 { 53 return postTask_; 54 } 55 SetCallbackOfIsCurrentRunnerThread(const CallbackTypeIsCurrentRunnerThread && isCurrentRunnerThread)56 void SetCallbackOfIsCurrentRunnerThread(const CallbackTypeIsCurrentRunnerThread&& isCurrentRunnerThread) 57 { 58 isCurrentRunnerThread_ = isCurrentRunnerThread; 59 } 60 GetCallbackOfIsCurrentRunnerThread()61 CallbackTypeIsCurrentRunnerThread GetCallbackOfIsCurrentRunnerThread() 62 { 63 return isCurrentRunnerThread_; 64 } 65 SetCallbackOfHspBufferTracker(const CallbackTypeHspBufferTracker && hspBufferTracker)66 void SetCallbackOfHspBufferTracker(const CallbackTypeHspBufferTracker&& hspBufferTracker) 67 { 68 hspBufferTracker_ = hspBufferTracker; 69 } 70 GetCallbackOfHspBufferTracker()71 CallbackTypeHspBufferTracker GetCallbackOfHspBufferTracker() 72 { 73 return hspBufferTracker_; 74 } 75 SetCallbackOfSetClipboardData(const CallbackTypeSetClipboardData && setClipboardData)76 void SetCallbackOfSetClipboardData(const CallbackTypeSetClipboardData&& setClipboardData) 77 { 78 setClipboardData_ = std::move(setClipboardData); 79 } 80 GetCallbackOfSetClipboardData()81 CallbackTypeSetClipboardData GetCallbackOfSetClipboardData() 82 { 83 return setClipboardData_; 84 } 85 SetCallbackOfGetClipboardData(const CallbackTypeGetClipboardData && getClipboardData)86 void SetCallbackOfGetClipboardData(const CallbackTypeGetClipboardData&& getClipboardData) 87 { 88 getClipboardData_ = std::move(getClipboardData); 89 } 90 GetCallbackOfGetClipboardData()91 CallbackTypeGetClipboardData GetCallbackOfGetClipboardData() 92 { 93 return getClipboardData_; 94 } 95 96 private: 97 AcePreviewHelper() = default; 98 AcePreviewHelper(const AcePreviewHelper&) = delete; 99 AcePreviewHelper& operator=(const AcePreviewHelper&) = delete; 100 101 CallbackTypePostTask postTask_ = nullptr; 102 CallbackTypeIsCurrentRunnerThread isCurrentRunnerThread_ = nullptr; 103 CallbackTypeHspBufferTracker hspBufferTracker_ = nullptr; 104 CallbackTypeSetClipboardData setClipboardData_ = nullptr; 105 CallbackTypeGetClipboardData getClipboardData_ = nullptr; 106 CallbackFlushEmpty flushEmpty_ = nullptr; 107 }; 108 } // namespace OHOS::Ace::Platform 109 #endif // FOUNDATION_ACE_ADAPTER_PREVIEW_ACE_PREVIEW_HELPER_H 110