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