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 OHOS_ABILITY_JS_ENVIRONMENT_JS_ENVIRONMENT_IMPL_H
17 #define OHOS_ABILITY_JS_ENVIRONMENT_JS_ENVIRONMENT_IMPL_H
18 
19 #include <string>
20 #include "event_handler.h"
21 #include "native_engine/native_engine.h"
22 
23 #include "native_engine/native_engine.h"
24 
25 #include "libpandafile/data_protect.h"
26 
27 namespace OHOS {
28 namespace JsEnv {
29 struct WorkerInfo {
30     panda::panda_file::StringPacProtect codePath;
31     bool isDebugVersion = false;
32     bool isBundle = true;
33     std::string packagePathStr;
34     std::vector<std::string> assetBasePathStr;
35     panda::panda_file::StringPacProtect hapPath;
36     panda::panda_file::BoolPacProtect isStageModel = panda::panda_file::BoolPacProtect(true);
37     std::string moduleName;
38     panda::panda_file::DataProtect apiTargetVersion = panda::panda_file::DataProtect();
39 };
40 
41 class JsEnvironmentImpl {
42 public:
JsEnvironmentImpl()43     JsEnvironmentImpl() {}
~JsEnvironmentImpl()44     virtual ~JsEnvironmentImpl() {}
45 
46     virtual void PostTask(const std::function<void()>& task, const std::string& name, int64_t delayTime) = 0;
47 
48     virtual void PostSyncTask(const std::function<void()>& task, const std::string& name) = 0;
49 
50     virtual void RemoveTask(const std::string& name) = 0;
51 
52     virtual void InitTimerModule(NativeEngine* engine) = 0;
53 
54     virtual void InitConsoleModule(NativeEngine* engine) = 0;
55 
56     virtual bool InitLoop(NativeEngine* engine, bool isStage = true) = 0;
57 
58     virtual void DeInitLoop(NativeEngine* engine) = 0;
59 
60     virtual void InitWorkerModule(NativeEngine* engine, std::shared_ptr<WorkerInfo> workerInfo) = 0;
61 
62     virtual void InitSyscapModule() = 0;
63 };
64 } // namespace JsEnv
65 } // namespace OHOS
66 #endif // OHOS_ABILITY_JS_ENVIRONMENT_JS_ENVIRONMENT_IMPL_H