21#include <boost/algorithm/string.hpp>
22#include <boost/filesystem.hpp>
24#include "yaml-cpp/yaml.h"
36 YAML::Node node = YAML::LoadFile(FLAGS_client_conf_yaml);
37 std::string bin_path = boost::filesystem::current_path().string();
38 data_collect_time_flag_file_ =
39 bin_path +
"/" + node[
"time_flag_file"].as<std::string>();
40 channel_checker_stop_flag_file_ =
42 node[
"channel_check"][
"stop_flag_file"].as<std::string>();
43 AINFO <<
"bin_path: " << bin_path
44 <<
", data_collect_time_flag_file_: " << data_collect_time_flag_file_
45 <<
", channel_checker_stop_flag_file_: "
46 << channel_checker_stop_flag_file_;
50 std::string stage = FLAGS_stage;
51 AINFO <<
"stage [" << stage <<
"]";
53 if (
"record_check" == stage) {
54 ret = RecordCheckStage();
55 }
else if (
"static_align" == stage) {
56 ret = StaticAlignStage();
57 }
else if (
"eight_route" == stage) {
58 ret = EightRouteStage();
59 }
else if (
"data_collect" == stage) {
60 ret = DataCollectStage();
61 }
else if (
"loops_check" == stage) {
62 ret = LoopsCheckStage();
63 }
else if (
"clean" == stage) {
69int Client::RecordCheckStage() {
70 std::string cmd = FLAGS_cmd;
72 AINFO <<
"cmd [" << cmd <<
"]";
74 std::string record_path = FLAGS_record_path;
75 AINFO <<
"record_path [" << record_path <<
"]";
76 if (!boost::filesystem::exists(record_path)) {
77 AERROR <<
"record_path does not exist";
81 ret = channel_checker.SyncStart(record_path);
83 AERROR <<
"SyncStart channel chacker failed, record_path [" << record_path
89 ret = channel_checker.SyncStop();
91 AERROR <<
"SyncStop channel chacker failed";
98int Client::StaticAlignStage() {
99 std::string cmd = FLAGS_cmd;
100 AINFO <<
"cmd [" << cmd <<
"]";
101 StaticAlign static_align;
102 if (
"start" == cmd) {
104 ret = static_align.SyncStart();
106 AERROR <<
"SyncStart static align failed";
109 AINFO <<
"Static aligh succeed";
111 "Static aligh succeed. Next, you may want to run: bash client.sh "
112 "-- stage eight_route\n");
116 ret = static_align.SyncStop();
118 AERROR <<
"SyncStop static align failed";
125int Client::EightRouteStage() {
126 std::string cmd = FLAGS_cmd;
127 AINFO <<
"cmd [" << cmd <<
"]";
128 EightRoute eight_route;
129 if (
"start" == cmd) {
131 ret = eight_route.SyncStart();
133 AERROR <<
"SyncStart static align failed";
136 AINFO <<
"Eight route succeed";
138 "Eight route succeed. Next, you may want to run: bash client.sh "
139 "--stage data_collect\n");
143 ret = eight_route.SyncStop();
145 AERROR <<
"SyncStop static align failed";
152int Client::DataCollectStage() {
153 std::string cmd = FLAGS_cmd;
154 AINFO <<
"cmd [" << cmd <<
"]";
155 std::vector<std::string> lines =
GetFileLines(data_collect_time_flag_file_);
156 std::ofstream time_file_handler(data_collect_time_flag_file_);
158 if (cmd ==
"start") {
160 time_file_handler << now <<
" start\n";
161 AINFO <<
"write [" << now <<
" start] to file "
162 << data_collect_time_flag_file_;
164 "Start success. At the end of the collection, you should run: "
165 "bash client.sh data_collect stop\n");
167 std::string& the_last_line = lines.back();
168 std::vector<std::string> s;
169 boost::split(s, the_last_line, boost::is_any_of(
" ,\t\n"));
170 if (s[1] ==
"start") {
171 AINFO <<
"This progress has been already started, this command will be "
174 "This progress has been already started, this command will be "
177 time_file_handler << now <<
" start\n";
178 AINFO <<
"write [" << now <<
" start] to file "
179 << data_collect_time_flag_file_;
181 "Start success. At the end of the collection, you should run: "
182 "bash client.sh --stage data_collect --cmd stop\n");
185 }
else if (cmd ==
"stop") {
187 AINFO <<
"Start first, this command will be ignored";
189 std::string& the_last_line = lines.back();
190 std::vector<std::string> s;
191 boost::split(s, the_last_line, boost::is_any_of(
" ,\t\n"));
192 if (s[1] ==
"start") {
193 time_file_handler << now <<
" stop\n";
194 AINFO <<
"write [" << now <<
" stop] to file "
195 << data_collect_time_flag_file_;
197 "Stop success. Next you may want to run: bash client.sh "
198 "loops_check start\n");
200 AINFO <<
"This progress has been already stopped, this command will be "
203 "This progress has been already stopped, this command will be "
208 AINFO <<
"Error command, expected command are [start|stop], current "
212 "Error command, expected command are [start|stop], current command "
219int Client::LoopsCheckStage() {
220 LoopsChecker loops_checker(data_collect_time_flag_file_);
221 bool reached =
false;
222 int ret = loops_checker.SyncStart(&reached);
224 AINFO <<
"loops_check failed";
228 AINFO <<
"loops meet requirements";
230 "Loops meet requirements. Next you may want to run: bash client.sh "
231 "--stage eight_route\n");
233 AINFO <<
"loops do not meet requirements";
235 "Next you may need to run: bash client.sh --stage data_collect\n");
240int Client::CleanStage() {
241 if (boost::filesystem::exists(data_collect_time_flag_file_)) {
242 boost::filesystem::remove(data_collect_time_flag_file_);
243 AINFO <<
"removed " << data_collect_time_flag_file_;
245 if (boost::filesystem::exists(channel_checker_stop_flag_file_)) {
246 boost::filesystem::remove(channel_checker_stop_flag_file_);
247 AINFO <<
"removed " << channel_checker_stop_flag_file_;
std::vector< std::string > GetFileLines(const std::string &path)