1fb299fa2Sopenharmony_ci/* 2fb299fa2Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 3fb299fa2Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4fb299fa2Sopenharmony_ci * you may not use this file except in compliance with the License. 5fb299fa2Sopenharmony_ci * You may obtain a copy of the License at 6fb299fa2Sopenharmony_ci * 7fb299fa2Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8fb299fa2Sopenharmony_ci * 9fb299fa2Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10fb299fa2Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11fb299fa2Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fb299fa2Sopenharmony_ci * See the License for the specific language governing permissions and 13fb299fa2Sopenharmony_ci * limitations under the License. 14fb299fa2Sopenharmony_ci */ 15fb299fa2Sopenharmony_ci#include "script_updateprocesser.h" 16fb299fa2Sopenharmony_ci#include <sstream> 17fb299fa2Sopenharmony_ci#include "script_instruction.h" 18fb299fa2Sopenharmony_ci#include "script_manager.h" 19fb299fa2Sopenharmony_ci#include "script_utils.h" 20fb299fa2Sopenharmony_ci#include "thread_pool.h" 21fb299fa2Sopenharmony_ci 22fb299fa2Sopenharmony_ciusing namespace Uscript; 23fb299fa2Sopenharmony_ci 24fb299fa2Sopenharmony_cinamespace BasicInstruction { 25fb299fa2Sopenharmony_ciint32_t UScriptInstructionSetProcess::Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context) 26fb299fa2Sopenharmony_ci{ 27fb299fa2Sopenharmony_ci float setProcess = 0.0f; 28fb299fa2Sopenharmony_ci int32_t ret = context.GetParam(0, setProcess); 29fb299fa2Sopenharmony_ci if (ret != USCRIPT_SUCCESS) { 30fb299fa2Sopenharmony_ci USCRIPT_LOGE("Failed to get param"); 31fb299fa2Sopenharmony_ci return ret; 32fb299fa2Sopenharmony_ci } 33fb299fa2Sopenharmony_ci std::string content; 34fb299fa2Sopenharmony_ci std::stringstream sstream; 35fb299fa2Sopenharmony_ci sstream << setProcess; 36fb299fa2Sopenharmony_ci sstream >> content; 37fb299fa2Sopenharmony_ci env.PostMessage("set_progress", content); 38fb299fa2Sopenharmony_ci return USCRIPT_SUCCESS; 39fb299fa2Sopenharmony_ci} 40fb299fa2Sopenharmony_ci 41fb299fa2Sopenharmony_ciint32_t UScriptInstructionShowProcess::Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context) 42fb299fa2Sopenharmony_ci{ 43fb299fa2Sopenharmony_ci float startProcess = 0.0f; 44fb299fa2Sopenharmony_ci float endProcess = 0.0f; 45fb299fa2Sopenharmony_ci int32_t ret = context.GetParam(0, startProcess); 46fb299fa2Sopenharmony_ci if (ret != USCRIPT_SUCCESS) { 47fb299fa2Sopenharmony_ci USCRIPT_LOGE("Failed to get param"); 48fb299fa2Sopenharmony_ci return ret; 49fb299fa2Sopenharmony_ci } 50fb299fa2Sopenharmony_ci ret = context.GetParam(1, endProcess); 51fb299fa2Sopenharmony_ci if (ret != USCRIPT_SUCCESS) { 52fb299fa2Sopenharmony_ci USCRIPT_LOGE("Failed to get param"); 53fb299fa2Sopenharmony_ci return ret; 54fb299fa2Sopenharmony_ci } 55fb299fa2Sopenharmony_ci std::string content; 56fb299fa2Sopenharmony_ci std::stringstream sstream; 57fb299fa2Sopenharmony_ci sstream << startProcess; 58fb299fa2Sopenharmony_ci sstream << ","; 59fb299fa2Sopenharmony_ci sstream << endProcess; 60fb299fa2Sopenharmony_ci sstream >> content; 61fb299fa2Sopenharmony_ci env.PostMessage("show_progress", content); 62fb299fa2Sopenharmony_ci return USCRIPT_SUCCESS; 63fb299fa2Sopenharmony_ci} 64fb299fa2Sopenharmony_ci 65fb299fa2Sopenharmony_ciint32_t UScriptInstructionUiPrint::Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context) 66fb299fa2Sopenharmony_ci{ 67fb299fa2Sopenharmony_ci std::string message; 68fb299fa2Sopenharmony_ci int32_t ret = context.GetParam(0, message); 69fb299fa2Sopenharmony_ci if (ret != USCRIPT_SUCCESS) { 70fb299fa2Sopenharmony_ci USCRIPT_LOGE("Failed to get param"); 71fb299fa2Sopenharmony_ci return ret; 72fb299fa2Sopenharmony_ci } 73fb299fa2Sopenharmony_ci env.PostMessage("ui_log", message); 74fb299fa2Sopenharmony_ci return USCRIPT_SUCCESS; 75fb299fa2Sopenharmony_ci} 76fb299fa2Sopenharmony_ci 77fb299fa2Sopenharmony_ciint32_t UScriptInstructionSetProportion::Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context) 78fb299fa2Sopenharmony_ci{ 79fb299fa2Sopenharmony_ci float proportion = 0.0f; 80fb299fa2Sopenharmony_ci int32_t ret = context.GetParam(0, proportion); 81fb299fa2Sopenharmony_ci if (ret != USCRIPT_SUCCESS) { 82fb299fa2Sopenharmony_ci USCRIPT_LOGE("Failed to get proportion param"); 83fb299fa2Sopenharmony_ci return ret; 84fb299fa2Sopenharmony_ci } 85fb299fa2Sopenharmony_ci SetScriptProportion(proportion); 86fb299fa2Sopenharmony_ci return USCRIPT_SUCCESS; 87fb299fa2Sopenharmony_ci} 88fb299fa2Sopenharmony_ci} // namespace BasicInstruction 89