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_updateprocesser.h"
16 #include <sstream>
17 #include "script_instruction.h"
18 #include "script_manager.h"
19 #include "script_utils.h"
20
21 using namespace Uscript;
22
23 namespace BasicInstruction {
Execute(Uscript::UScriptEnv & env,Uscript::UScriptContext & context)24 int32_t UScriptInstructionSetProcess::Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context)
25 {
26 float setProcess = 0.0f;
27 int32_t ret = context.GetParam(0, setProcess);
28 USCRIPT_CHECK(ret == USCRIPT_SUCCESS, return ret, "Failed to get param");
29 std::string content;
30 std::stringstream sstream;
31 sstream << setProcess;
32 sstream >> content;
33 env.PostMessage("set_progress", content);
34 return USCRIPT_SUCCESS;
35 }
36
Execute(Uscript::UScriptEnv & env,Uscript::UScriptContext & context)37 int32_t UScriptInstructionShowProcess::Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context)
38 {
39 float startProcess = 0.0f;
40 float endProcess = 0.0f;
41 int32_t ret = context.GetParam(0, startProcess);
42 USCRIPT_CHECK(ret == USCRIPT_SUCCESS, return ret, "Failed to get param");
43 ret = context.GetParam(1, endProcess);
44 USCRIPT_CHECK(ret == USCRIPT_SUCCESS, return ret, "Failed to get param");
45 std::string content;
46 std::stringstream sstream;
47 sstream << startProcess;
48 sstream << ",";
49 sstream << endProcess;
50 sstream >> content;
51 env.PostMessage("show_progress", content);
52 return USCRIPT_SUCCESS;
53 }
54
Execute(Uscript::UScriptEnv & env,Uscript::UScriptContext & context)55 int32_t UScriptInstructionUiPrint::Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context)
56 {
57 std::string message;
58 int32_t ret = context.GetParam(0, message);
59 USCRIPT_CHECK(ret == USCRIPT_SUCCESS, return ret, "Failed to get param");
60 env.PostMessage("ui_log", message);
61 return USCRIPT_SUCCESS;
62 }
63 } // namespace BasicInstruction
64