• 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 };
39 
40 /**
41  * Script Manager
42  * 1, Management of script instruction and instruction registration
43  * 2, Management of parsing and executing the script
44  **/
45 class ScriptManager {
46 public:
47     static const int32_t MAX_PRIORITY = 4;
48 
49     virtual ~ScriptManager() = default;
50 
51     /**
52      * Execute all script under this priority
53      * priority:        The priority of the script to run
54      */
55     virtual int32_t ExecuteScript(int32_t priority) = 0;
56 
57     /**
58      * Get script manager
59      */
60     static ScriptManager* GetScriptManager(UScriptEnv *env, const Hpackage::HashDataVerifier *verifier);
61     static void ReleaseScriptManager();
62 };
63 } // namespace Uscript
64 #endif
65