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 16fb299fa2Sopenharmony_ci#include <cstdio> 17fb299fa2Sopenharmony_ci#include <cstdlib> 18fb299fa2Sopenharmony_ci#include <iostream> 19fb299fa2Sopenharmony_ci#include <string> 20fb299fa2Sopenharmony_ci#include <unistd.h> 21fb299fa2Sopenharmony_ci#include <vector> 22fb299fa2Sopenharmony_ci 23fb299fa2Sopenharmony_cienum EXIT_CODES { 24fb299fa2Sopenharmony_ci EXIT_INVALID_ARGS = EXIT_SUCCESS + 1, 25fb299fa2Sopenharmony_ci EXIT_READ_PACKAGE_ERROR = 2, 26fb299fa2Sopenharmony_ci EXIT_FOUND_SCRIPT_ERROR = 3, 27fb299fa2Sopenharmony_ci EXIT_PARSE_SCRIPT_ERROR = 4, 28fb299fa2Sopenharmony_ci EXIT_EXEC_SCRIPT_ERROR = 5, 29fb299fa2Sopenharmony_ci}; 30fb299fa2Sopenharmony_ci 31fb299fa2Sopenharmony_ciint main(int argc, char **argv) 32fb299fa2Sopenharmony_ci{ 33fb299fa2Sopenharmony_ci constexpr int lessArgIndex = 2; 34fb299fa2Sopenharmony_ci constexpr int withRetry = 3; 35fb299fa2Sopenharmony_ci constexpr int decimal = 10; 36fb299fa2Sopenharmony_ci if (argc < lessArgIndex) { 37fb299fa2Sopenharmony_ci std::cout << "Invalid arguments\n"; 38fb299fa2Sopenharmony_ci return EXIT_INVALID_ARGS; 39fb299fa2Sopenharmony_ci } 40fb299fa2Sopenharmony_ci 41fb299fa2Sopenharmony_ci bool retry = false; 42fb299fa2Sopenharmony_ci int pipeFd = static_cast<int>(std::strtol(argv[1], nullptr, decimal)); 43fb299fa2Sopenharmony_ci if (argc >= withRetry && strcmp(argv[withRetry - 1], "retry") == 0) { 44fb299fa2Sopenharmony_ci retry = true; 45fb299fa2Sopenharmony_ci } 46fb299fa2Sopenharmony_ci FILE *pipeWrite = fdopen(pipeFd, "w"); 47fb299fa2Sopenharmony_ci if (pipeWrite == nullptr) { 48fb299fa2Sopenharmony_ci std::cout << "Failed to fdopen\n"; 49fb299fa2Sopenharmony_ci return EXIT_INVALID_ARGS; 50fb299fa2Sopenharmony_ci } 51fb299fa2Sopenharmony_ci 52fb299fa2Sopenharmony_ci setlinebuf(pipeWrite); 53fb299fa2Sopenharmony_ci fprintf(pipeWrite, "ui_log: This is ui output\n"); 54fb299fa2Sopenharmony_ci fprintf(pipeWrite, "write_log: Write logs\n"); 55fb299fa2Sopenharmony_ci if (retry) { 56fb299fa2Sopenharmony_ci fprintf(pipeWrite, "retry_update\n"); 57fb299fa2Sopenharmony_ci } 58fb299fa2Sopenharmony_ci fprintf(pipeWrite, "show_progress: 1 2\n"); 59fb299fa2Sopenharmony_ci fprintf(pipeWrite, "show_progress: 1\n"); 60fb299fa2Sopenharmony_ci fprintf(pipeWrite, "nonexist: 1 2\n"); 61fb299fa2Sopenharmony_ci fclose(pipeWrite); 62fb299fa2Sopenharmony_ci return 0; 63fb299fa2Sopenharmony_ci} 64fb299fa2Sopenharmony_ci 65