Apollo 11.0
自动驾驶开放平台
grpc_server.h
浏览该文件的文档.
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 *****************************************************************************/
21#pragma once
22
23#include <condition_variable>
24#include <memory>
25#include <mutex>
26#include <thread>
27
28#include <grpc++/grpc++.h>
29
30#include "modules/common_msgs/perception_msgs/perception_obstacle.pb.h"
31#include "modules/common_msgs/perception_msgs/traffic_light_detection.pb.h"
32#include "modules/v2x/proto/v2x_obu_rsi.pb.h"
33#include "modules/v2x/proto/v2x_service_obu_to_car.grpc.pb.h"
34#include "modules/common_msgs/v2x_msgs/v2x_traffic_light.pb.h"
35
36#include "cyber/cyber.h"
37
38namespace apollo {
39namespace v2x {
40
41class GrpcServerImpl final : public ::apollo::v2x::ObuToCar::Service {
42 public:
43 /* construct function
44 */
46
48 traffic_light_condition_.notify_all();
49 rsi_condition_.notify_all();
50 }
51
52 bool InitFlag() { return init_flag_; }
53
54 /* function that send v2x traffic_light through grpc
55 @param input v2x traffic_light grpc request
56 @param output grpc response
57 */
58 grpc::Status SendV2xTrafficLight(
59 grpc::ServerContext *context,
60 const ::apollo::v2x::obu::ObuTrafficLight *request,
61 ::apollo::v2x::StatusResponse *response) override;
62
63 /* function that send v2x monitor messages through grpc
64 @param input v2x monitor grpc request
65 @param output grpc response
66 */
67 grpc::Status SendObuAlarm(grpc::ServerContext *context,
68 const ::apollo::v2x::ObuAlarm *request,
69 ::apollo::v2x::StatusResponse *response) override;
70
71 /* function that send perception obstacles through grpc
72 @param input perception obstacles grpc request
73 @param output grpc response
74 */
75 grpc::Status SendPerceptionObstacles(grpc::ServerContext *context,
76 const apollo::v2x::V2XObstacles *request,
77 StatusResponse *response) override;
78
79 grpc::Status SendV2xRSI(grpc::ServerContext *context,
80 const ::apollo::v2x::obu::ObuRsi *request,
81 ::apollo::v2x::StatusResponse *response);
82
84 std::shared_ptr<::apollo::v2x::obu::ObuTrafficLight> *ptr);
85
86 void GetMsgFromGrpc(std::shared_ptr<::apollo::v2x::obu::ObuRsi> *ptr);
87 void GetMsgFromGrpc(std::shared_ptr<::apollo::v2x::V2XObstacles> *ptr);
88
89 private:
90 std::mutex traffic_light_mutex_;
91 std::mutex rsi_mutex_;
92 std::mutex obstacles_mutex_;
93 std::condition_variable traffic_light_condition_;
94 std::condition_variable rsi_condition_;
95 std::condition_variable obs_condition_;
96 ::apollo::v2x::obu::ObuTrafficLight latest_traffic_light_;
98 ::apollo::v2x::V2XObstacles latest_obstacles_;
99
100 bool init_flag_ = false;
101 bool refresh_ = false;
102 bool rsi_refresh_ = false;
103 bool obs_refresh_ = false;
104 std::unique_ptr<::apollo::cyber::Node> node_ = nullptr;
105};
106
107} // namespace v2x
108} // namespace apollo
grpc::Status SendPerceptionObstacles(grpc::ServerContext *context, const apollo::v2x::V2XObstacles *request, StatusResponse *response) override
grpc::Status SendObuAlarm(grpc::ServerContext *context, const ::apollo::v2x::ObuAlarm *request, ::apollo::v2x::StatusResponse *response) override
grpc::Status SendV2xRSI(grpc::ServerContext *context, const ::apollo::v2x::obu::ObuRsi *request, ::apollo::v2x::StatusResponse *response)
grpc::Status SendV2xTrafficLight(grpc::ServerContext *context, const ::apollo::v2x::obu::ObuTrafficLight *request, ::apollo::v2x::StatusResponse *response) override
void GetMsgFromGrpc(std::shared_ptr<::apollo::v2x::obu::ObuTrafficLight > *ptr)
void GetMsgFromGrpc(std::shared_ptr<::apollo::v2x::obu::ObuRsi > *ptr)
class register implement
Definition arena_queue.h:37