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 #include "script_loadscript.h"
16 #include "dump.h"
17 #include "script_instruction.h"
18 #include "script_instructionhelper.h"
19 #include "script_manager.h"
20 #include "script_utils.h"
21
22 using namespace Uscript;
23
24 namespace BasicInstruction {
Execute(UScriptEnv & env,UScriptContext & context)25 int32_t ScriptLoadScript::Execute(UScriptEnv &env, UScriptContext &context)
26 {
27 Updater::UPDATER_INIT_RECORD;
28 ScriptInstructionHelper* helper = ScriptInstructionHelper::GetBasicInstructionHelper();
29 if (helper == nullptr) {
30 USCRIPT_LOGE("Failed to get instruction helper");
31 UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM, "Failed to get instruction helper");
32 return USCRIPT_INVALID_PARAM;
33 }
34
35 std::string scriptName;
36 int32_t priority = 0;
37 int32_t ret = context.GetParam(0, scriptName);
38 if (ret != USCRIPT_SUCCESS) {
39 USCRIPT_LOGE("Failed to get param");
40 UPDATER_LAST_WORD(ret, "Failed to get scriptName");
41 return ret;
42 }
43 ret = context.GetParam(1, priority);
44 if (ret != USCRIPT_SUCCESS) {
45 USCRIPT_LOGE("Failed to get param");
46 UPDATER_LAST_WORD(ret, "Failed to get priority");
47 return ret;
48 }
49 USCRIPT_LOGI("ScriptLoadScript %s priority:%d", scriptName.c_str(), priority);
50 return helper->AddScript(scriptName, priority);
51 }
52 } // namespace BasicInstruction
53