Apollo 11.0
自动驾驶开放平台
main.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
17#include <csignal>
18#include <iostream>
19
20#include "cyber/init.h"
25
26namespace {
27void SigResizeHandle(int) { Screen::Instance()->Resize(); }
28void SigCtrlCHandle(int) { Screen::Instance()->Stop(); }
29
30void printHelp(const char *cmd_name) {
31 std::cout << "Usage:\n"
32 << cmd_name << " [option]\nOption:\n"
33 << " -h print help info\n"
34 << " -c specify one channel\n"
35 << "Interactive Command:\n"
36 << Screen::InteractiveCmdStr << std::endl;
37}
38
39enum COMMAND {
40 TOO_MANY_PARAMETER,
41 HELP, // 2
42 NO_OPTION, // 1
43 CHANNEL // 3 -> 4
44};
45
46COMMAND ParseOption(int argc, char *const argv[], std::string *command_val) {
47 if (argc > 4) {
48 return TOO_MANY_PARAMETER;
49 }
50 int index = 1;
51 while (true) {
52 const char *opt = argv[index];
53 if (opt == nullptr) {
54 break;
55 }
56 if (strcmp(opt, "-h") == 0) {
57 return HELP;
58 }
59 if (strcmp(opt, "-c") == 0) {
60 if (argv[index + 1]) {
61 *command_val = argv[index + 1];
62 return CHANNEL;
63 }
64 }
65
66 ++index;
67 }
68
69 return NO_OPTION;
70}
71
72} // namespace
73
74int main(int argc, char *argv[]) {
75 std::string val;
76
77 COMMAND com = ParseOption(argc, argv, &val);
78
79 switch (com) {
80 case TOO_MANY_PARAMETER:
81 std::cout << "Too many paramtes\n";
82 case HELP:
83 printHelp(argv[0]);
84 return 0;
85 default: {
86 }
87 }
88
89 apollo::cyber::Init(argv[0]);
90 FLAGS_minloglevel = 3;
91 FLAGS_alsologtostderr = 0;
92 FLAGS_colorlogtostderr = 0;
93
94 CyberTopologyMessage topology_msg(val);
95
96 auto topology_callback =
97 [&topology_msg](const apollo::cyber::proto::ChangeMsg &change_msg) {
98 topology_msg.TopologyChanged(change_msg);
99 };
100
101 auto channel_manager =
102 apollo::cyber::service_discovery::TopologyManager::Instance()
103 ->channel_manager();
104 channel_manager->AddChangeListener(topology_callback);
105
106 std::vector<apollo::cyber::proto::RoleAttributes> role_vec;
107 channel_manager->GetWriters(&role_vec);
108 for (auto &role : role_vec) {
109 topology_msg.AddReaderWriter(role, true);
110 }
111
112 role_vec.clear();
113 channel_manager->GetReaders(&role_vec);
114 for (auto &role : role_vec) {
115 topology_msg.AddReaderWriter(role, false);
116 }
117
119
120 signal(SIGWINCH, SigResizeHandle);
121 signal(SIGINT, SigCtrlCHandle);
122
123 s->SetCurrentRenderMessage(&topology_msg);
124
125 s->Init();
126 s->Run();
127
128 return 0;
129}
void AddReaderWriter(const apollo::cyber::proto::RoleAttributes &role, bool isWriter)
void TopologyChanged(const apollo::cyber::proto::ChangeMsg &change_msg)
void Init(void)
Definition screen.cc:94
void Run(void)
Definition screen.cc:210
void Resize()
Definition screen.cc:242
void SetCurrentRenderMessage(RenderableMessage *const render_obj)
Definition screen.h:63
static const char InteractiveCmdStr[]
Definition screen.h:32
void Stop(void)
Definition screen.h:49
static Screen * Instance(void)
Definition screen.cc:39
int main(int argc, char *argv[])
Definition main.cc:74
bool Init(const char *binary_name, const std::string &dag_info)
Definition init.cc:99