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