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#include "thread_pool.h"
21
22using namespace Uscript;
23
24namespace BasicInstruction {
25int32_t UScriptInstructionSetProcess::Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context)
26{
27    float setProcess = 0.0f;
28    int32_t ret = context.GetParam(0, setProcess);
29    if (ret != USCRIPT_SUCCESS) {
30        USCRIPT_LOGE("Failed to get param");
31        return ret;
32    }
33    std::string content;
34    std::stringstream sstream;
35    sstream << setProcess;
36    sstream >> content;
37    env.PostMessage("set_progress", content);
38    return USCRIPT_SUCCESS;
39}
40
41int32_t UScriptInstructionShowProcess::Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context)
42{
43    float startProcess = 0.0f;
44    float endProcess = 0.0f;
45    int32_t ret = context.GetParam(0, startProcess);
46    if (ret != USCRIPT_SUCCESS) {
47        USCRIPT_LOGE("Failed to get param");
48        return ret;
49    }
50    ret = context.GetParam(1, endProcess);
51    if (ret != USCRIPT_SUCCESS) {
52        USCRIPT_LOGE("Failed to get param");
53        return ret;
54    }
55    std::string content;
56    std::stringstream sstream;
57    sstream << startProcess;
58    sstream << ",";
59    sstream << endProcess;
60    sstream >> content;
61    env.PostMessage("show_progress", content);
62    return USCRIPT_SUCCESS;
63}
64
65int32_t UScriptInstructionUiPrint::Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context)
66{
67    std::string message;
68    int32_t ret = context.GetParam(0, message);
69    if (ret != USCRIPT_SUCCESS) {
70        USCRIPT_LOGE("Failed to get param");
71        return ret;
72    }
73    env.PostMessage("ui_log", message);
74    return USCRIPT_SUCCESS;
75}
76
77int32_t UScriptInstructionSetProportion::Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context)
78{
79    float proportion = 0.0f;
80    int32_t ret = context.GetParam(0, proportion);
81    if (ret != USCRIPT_SUCCESS) {
82        USCRIPT_LOGE("Failed to get proportion param");
83        return ret;
84    }
85    SetScriptProportion(proportion);
86    return USCRIPT_SUCCESS;
87}
88} // namespace BasicInstruction
89