Apollo 10.0
自动驾驶开放平台
service.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 "cyber/examples/proto/examples.pb.h"
18
19#include "cyber/cyber.h"
20
22
23int main(int argc, char* argv[]) {
24 apollo::cyber::Init(argv[0]);
25 std::shared_ptr<apollo::cyber::Node> node(
26 apollo::cyber::CreateNode("start_node"));
27 auto server = node->CreateService<Driver, Driver>(
28 "test_server", [](const std::shared_ptr<Driver>& request,
29 std::shared_ptr<Driver>& response) {
30 AINFO << "server: i am driver server";
31 static uint64_t id = 0;
32 ++id;
33 response->set_msg_id(id);
34 response->set_timestamp(0);
35 });
36 auto client = node->CreateClient<Driver, Driver>("test_server");
37 auto driver_msg = std::make_shared<Driver>();
38 driver_msg->set_msg_id(0);
39 driver_msg->set_timestamp(0);
40 while (apollo::cyber::OK()) {
41 auto res = client->SendRequest(driver_msg);
42 if (res != nullptr) {
43 AINFO << "client: response: " << res->ShortDebugString();
44 } else {
45 AINFO << "client: service may not ready.";
46 }
47 sleep(1);
48 }
49
51 return 0;
52}
#define AINFO
Definition log.h:42
void WaitForShutdown()
Definition state.h:50
bool Init(const char *binary_name, const std::string &dag_info)
Definition init.cc:98
bool OK()
Definition state.h:44
std::unique_ptr< Node > CreateNode(const std::string &node_name, const std::string &name_space)
Definition cyber.cc:33
int main(int argc, char *argv[])
Definition service.cc:23