Apollo 10.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"
22#include "cyber/task/task.h"
26
27namespace {
28void SigResizeHandle(int) { Screen::Instance()->Resize(); }
29void SigCtrlCHandle(int) { Screen::Instance()->Stop(); }
30
31void printHelp(const char *cmd_name) {
32 std::cout << "Usage:\n"
33 << cmd_name << " [option]\nOption:\n"
34 << " -h print help info\n"
35 << " -c specify one channel\n"
36 << "Interactive Command:\n"
37 << Screen::InteractiveCmdStr << std::endl;
38}
39
40enum COMMAND {
41 TOO_MANY_PARAMETER,
42 HELP, // 2
43 NO_OPTION, // 1
44 CHANNEL // 3 -> 4
45};
46
47COMMAND ParseOption(int argc, char *const argv[], std::string *command_val) {
48 if (argc > 4) {
49 return TOO_MANY_PARAMETER;
50 }
51 int index = 1;
52 while (true) {
53 const char *opt = argv[index];
54 if (opt == nullptr) {
55 break;
56 }
57 if (strcmp(opt, "-h") == 0) {
58 return HELP;
59 }
60 if (strcmp(opt, "-c") == 0) {
61 if (argv[index + 1]) {
62 *command_val = argv[index + 1];
63 return CHANNEL;
64 }
65 }
66
67 ++index;
68 }
69
70 return NO_OPTION;
71}
72
73} // namespace
74
75int main(int argc, char *argv[]) {
76 std::string val;
77
78 COMMAND com = ParseOption(argc, argv, &val);
79
80 switch (com) {
81 case TOO_MANY_PARAMETER:
82 std::cout << "Too many paramtes\n";
83 case HELP:
84 printHelp(argv[0]);
85 return 0;
86 default: {}
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 apollo::cyber::Async([&topology_msg, change_msg] {
99 topology_msg.TopologyChanged(change_msg);
100 });
101 };
102
103 auto channel_manager =
104 apollo::cyber::service_discovery::TopologyManager::Instance()
105 ->channel_manager();
106 if (channel_manager == nullptr) {
107 AERROR << "Cyber Service Discovery is not ready.";
108 return -1;
109 }
110 channel_manager->AddChangeListener(topology_callback);
111
112 std::vector<apollo::cyber::proto::RoleAttributes> role_vec;
113 channel_manager->GetWriters(&role_vec);
114 for (auto &role : role_vec) {
115 topology_msg.AddReaderWriter(role, true);
116 }
117
118 role_vec.clear();
119 channel_manager->GetReaders(&role_vec);
120 for (auto &role : role_vec) {
121 topology_msg.AddReaderWriter(role, false);
122 }
123
125
126 signal(SIGWINCH, SigResizeHandle);
127 signal(SIGINT, SigCtrlCHandle);
128
129 s->SetCurrentRenderMessage(&topology_msg);
130
131 s->Init();
132 s->Run();
133
134 return 0;
135}
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:75
#define AERROR
Definition log.h:44
bool Init(const char *binary_name, const std::string &dag_info)
Definition init.cc:98