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 if (ret != USCRIPT_SUCCESS) {
29 USCRIPT_LOGE("Failed to get param");
30 return ret;
31 }
32 std::string content;
33 std::stringstream sstream;
34 sstream << setProcess;
35 sstream >> content;
36 env.PostMessage("set_progress", content);
37 return USCRIPT_SUCCESS;
38 }
39
Execute(Uscript::UScriptEnv & env,Uscript::UScriptContext & context)40 int32_t UScriptInstructionShowProcess::Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context)
41 {
42 float startProcess = 0.0f;
43 float endProcess = 0.0f;
44 int32_t ret = context.GetParam(0, startProcess);
45 if (ret != USCRIPT_SUCCESS) {
46 USCRIPT_LOGE("Failed to get param");
47 return ret;
48 }
49 ret = context.GetParam(1, endProcess);
50 if (ret != USCRIPT_SUCCESS) {
51 USCRIPT_LOGE("Failed to get param");
52 return ret;
53 }
54 std::string content;
55 std::stringstream sstream;
56 sstream << startProcess;
57 sstream << ",";
58 sstream << endProcess;
59 sstream >> content;
60 env.PostMessage("show_progress", content);
61 return USCRIPT_SUCCESS;
62 }
63
Execute(Uscript::UScriptEnv & env,Uscript::UScriptContext & context)64 int32_t UScriptInstructionUiPrint::Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context)
65 {
66 std::string message;
67 int32_t ret = context.GetParam(0, message);
68 if (ret != USCRIPT_SUCCESS) {
69 USCRIPT_LOGE("Failed to get param");
70 return ret;
71 }
72 env.PostMessage("ui_log", message);
73 return USCRIPT_SUCCESS;
74 }
75 } // namespace BasicInstruction
76