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 SANDBOX_MANAGER_EVENT_HANDLER_MOCK_H 17 #define SANDBOX_MANAGER_EVENT_HANDLER_MOCK_H 18 #include <cstdint> 19 #include <string> 20 21 namespace OHOS { 22 namespace AppExecFwk { 23 enum class ThreadMode: uint32_t { 24 NEW_THREAD = 0, // for new thread mode, event handler create thread 25 FFRT, // for new thread mode, use ffrt 26 }; 27 28 class EventRunner final { 29 public: 30 EventRunner() = default; 31 ~EventRunner() = default; 32 Create(bool inNewThread,ThreadMode mode)33 static std::shared_ptr<EventRunner> Create(bool inNewThread, ThreadMode mode) 34 { 35 return std::make_shared<EventRunner>(); 36 } 37 }; 38 39 class EventHandler { 40 public: 41 using Callback = std::function<void()>; 42 43 explicit EventHandler(const std::shared_ptr<EventRunner> &runner = nullptr) : runner_(runner) {}; 44 RemoveTask(const std::string & name)45 void RemoveTask(const std::string &name) {}; 46 47 bool PostTask(const Callback &callback, const std::string &name = std::string(), 48 int64_t delayTime = 0) 49 { 50 return true; 51 }; 52 53 private: 54 std::shared_ptr<EventRunner> runner_; 55 }; 56 } // AppExecFwk 57 } // OHOS 58 #endif // SANDBOX_MANAGER_EVENT_HANDLER_MOCK_H 59