• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 
16 #include "drawing_command.h"
17 #include <sstream>
18 #include <vector>
19 
20 namespace OHOS {
21 namespace Rosen {
DCLCommand(int32_t argc,char * argv[])22 DCLCommand::DCLCommand(int32_t argc, char* argv[])
23 {
24     std::vector<std::string> argvNew(argv, argv + argc);
25     ParseCommand(argvNew);
26 }
27 
ParseCommand(std::vector<std::string> argv)28 void DCLCommand::ParseCommand(std::vector<std::string> argv)
29 {
30     const size_t twoParam = 2;
31     const size_t threeParam = 3;
32     switch (argv.size()) {
33         case twoParam:
34             std::cout << "iterate frame by default, beginFrame = " << beginFrame_ << ", endFrame = " <<
35             endFrame_ << std::endl;
36             break;
37         case threeParam:
38             if (strcmp(argv.back().c_str(), "--help") != 0 || strcmp(argv.back().c_str(), "-h") != 0) {
39                 std::cout << dclMsg_ << std::endl;
40             }
41             break;
42         default:
43             for (size_t i = 2; i < argv.size(); ++i) {
44                 std::string option = argv[i];
45                 std::string augment;
46                 if (i < argv.size() - 1) {
47                     augment = argv[i + 1];
48                 }
49                 if (commandMap_.count(option) > 0) {
50                     HandleCommand(option, augment);
51                 }
52             }
53             CheckParameter();
54             break;
55     }
56 }
57 
DCLCommand(std::string commandLine)58 DCLCommand::DCLCommand(std::string commandLine)
59 {
60     std::istringstream ss(commandLine);
61     std::string param;
62     std::vector<std::string> params;
63     if (commandLine.find("drawing_ending_sample") == std::string::npos) {
64         params.emplace_back("drawing_engine_sample");
65         params.emplace_back("dcl");
66     }
67     while (ss >> param) {
68         params.emplace_back(param);
69     }
70     ParseCommand(params);
71 }
72 
HandleCommandIterateType(const std::string & inputStr)73 void DCLCommand::HandleCommandIterateType(const std::string& inputStr)
74 {
75     switch (std::stoi(inputStr.c_str())) {
76         case static_cast<int>(IterateType::ITERATE_FRAME):
77             iterateType_ = IterateType::ITERATE_FRAME;
78             break;
79         case static_cast<int>(IterateType::ITERATE_OPITEM):
80             iterateType_ = IterateType::ITERATE_OPITEM;
81             break;
82         case static_cast<int>(IterateType::ITERATE_OPITEM_MANUALLY):
83             iterateType_ = IterateType::ITERATE_OPITEM_MANUALLY;
84             break;
85         default:
86             std::cout <<"Wrong Parameter: iterateType" << std::endl;
87             return;
88     }
89 }
90 
HandleCommand(std::string option,const std::string & augment)91 void DCLCommand::HandleCommand(std::string option, const std::string& augment)
92 {
93     int inputNum = 0;
94     switch (commandMap_.at(option)) {
95         case CommandType::CT_T:
96             HandleCommandIterateType(augment);
97             break;
98         case CommandType::CT_B:
99             inputNum = std::stoi(augment.c_str());
100             beginFrame_ = inputNum > 0 ? inputNum : 0;
101             break;
102         case CommandType::CT_E:
103             inputNum = std::stoi(augment.c_str());
104             endFrame_ = inputNum > 0 ? inputNum : 0;
105             break;
106         case CommandType::CT_L:
107             inputNum = std::stoi(augment.c_str());
108             loop_ = inputNum > 0 ? inputNum : 0;
109             break;
110         case CommandType::CT_S:
111             opItemStep_ = std::stod(augment.c_str());
112             opItemStep_ = opItemStep_ > 0 ? opItemStep_ : 1;
113             break;
114         case CommandType::CT_I:
115             inputFilePath_ = augment;
116             if (inputFilePath_.back() != '/') {
117                 inputFilePath_ += '/';
118             }
119             break;
120         case CommandType::CT_O:
121             outputFilePath_ = augment;
122             if (outputFilePath_.back() != '/') {
123                 outputFilePath_ += '/';
124             }
125             break;
126         case CommandType::CT_H:
127             std::cout << dclMsg_ <<std::endl;
128             break;
129         default:
130             std::cout << "other unknown args:" <<std::endl;
131             break;
132     }
133 }
134 
CheckParameter()135 void DCLCommand::CheckParameter()
136 {
137     if (beginFrame_ > endFrame_) {
138         std::cout << "Wrong Parameter: beginFrame or endFrame!" << std::endl;
139         beginFrame_ = 0;
140         endFrame_ = 0;
141     }
142     if (opItemStep_ < 0) {
143         std::cout << "Wrong Parameter: opItemStep!" << std::endl;
144         opItemStep_ = 1;
145     }
146 }
147 }
148 }