1 /* 2 * Copyright (c) 2021 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 FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_MODULES_JSI_TIMER_MODULE_H 17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_MODULES_JSI_TIMER_MODULE_H 18 19 #include <mutex> 20 #include <string> 21 #include <unordered_map> 22 23 #include "base/utils/noncopyable.h" 24 #include "frameworks/bridge/js_frontend/engine/jsi/js_runtime.h" 25 #include "frameworks/bridge/js_frontend/engine/jsi/js_value.h" 26 27 namespace OHOS::Ace::Framework { 28 29 class JsiTimerModule { 30 public: 31 JsiTimerModule() = default; 32 ~JsiTimerModule() = default; 33 static JsiTimerModule* GetInstance(); 34 void InitTimerModule(const shared_ptr<JsRuntime>& runtime, shared_ptr<JsValue>& moduleObj); 35 uint32_t AddCallBack(const shared_ptr<JsValue>& func, const std::vector<shared_ptr<JsValue>>& params); 36 void RemoveCallBack(uint32_t callBackId); 37 bool GetCallBack(uint32_t callBackId, shared_ptr<JsValue>& func, std::vector<shared_ptr<JsValue>>& params); 38 39 private: 40 ACE_DISALLOW_COPY_AND_MOVE(JsiTimerModule); 41 42 mutable std::mutex moduleMutex_; 43 uint32_t callBackId_ = 0; 44 std::unordered_map<uint32_t, shared_ptr<JsValue>> callBackFuncMap_; 45 std::unordered_map<uint32_t, std::vector<shared_ptr<JsValue>>> callBackParamsMap_; 46 }; 47 48 } // namespace OHOS::Ace::Framework 49 50 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_MODULES_JSI_TIMER_MODULE_H 51