• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef _SCRIPT_MANAGER_H
16 #define _SCRIPT_MANAGER_H
17 
18 #include <cstdlib>
19 #include <memory>
20 #include "hash_data_verifier.h"
21 #include "pkg_manager.h"
22 #include "script_instruction.h"
23 
24 namespace Uscript {
25 enum {
26     USCRIPT_SUCCESS = 0,
27     USCRIPT_BASE = 500,
28     USCRIPT_INVALID_PARAM = USCRIPT_BASE,
29     USCRIPT_INVALID_SCRIPT,
30     USCRIPT_INVALID_PRIORITY,
31     USCRIPT_NOTEXIST_INSTRUCTION,
32     USCRIPT_ERROR_CREATE_OBJ,
33     USCRIPT_ERROR_REVERED,
34     USCRIPT_ASSERT,
35     USCRIPT_ABOART,
36     USCRIPT_ERROR_EXECUTE,
37     USCRIPT_ERROR_INTERPRET,
38     USCRIPT_ERROR_CREATE_THREAD,
39     USCRIPT_UPDATER_MODE_VALUE,
40 };
41 
42 /**
43  * Script Manager
44  * 1, Management of script instruction and instruction registration
45  * 2, Management of parsing and executing the script
46  **/
47 class ScriptManager {
48 public:
49     static const int32_t MAX_PRIORITY = 4;
50 
51     virtual ~ScriptManager() = default;
52 
53     /**
54      * Execute all script under this priority
55      * priority:        The priority of the script to run
56      */
57     virtual int32_t ExecuteScript(int32_t priority) = 0;
58 
59     /**
60      * Get script manager
61      */
62     static ScriptManager* GetScriptManager(UScriptEnv *env, const Hpackage::HashDataVerifier *verifier);
63     static void ReleaseScriptManager();
64 };
65 } // namespace Uscript
66 #endif
67