Apollo  6.0
Open source self driving car software
grpc_server.h
Go to the documentation of this file.
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/perception/proto/perception_obstacle.pb.h"
31 #include "modules/perception/proto/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/v2x/proto/v2x_traffic_light.pb.h"
35 
36 #include "cyber/cyber.h"
37 
38 namespace apollo {
39 namespace v2x {
40 
41 class 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,
81  ::apollo::v2x::StatusResponse *response);
82 
83  void GetMsgFromGrpc(
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_;
97  ::apollo::v2x::obu::ObuRsi latest_rsi_;
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
~GrpcServerImpl()
Definition: grpc_server.h:47
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
bool InitFlag()
Definition: grpc_server.h:52
::apollo::v2x::obu::ObuRsi ObuRsi
Definition: proto_adapter.h:60
void GetMsgFromGrpc(std::shared_ptr<::apollo::v2x::obu::ObuTrafficLight > *ptr)
grpc::Status SendV2xTrafficLight(grpc::ServerContext *context, const ::apollo::v2x::obu::ObuTrafficLight *request, ::apollo::v2x::StatusResponse *response) override
grpc::Status SendPerceptionObstacles(grpc::ServerContext *context, const apollo::v2x::V2XObstacles *request, StatusResponse *response) override
grpc::Status SendV2xRSI(grpc::ServerContext *context, const ::apollo::v2x::obu::ObuRsi *request, ::apollo::v2x::StatusResponse *response)
grpc::Status SendObuAlarm(grpc::ServerContext *context, const ::apollo::v2x::ObuAlarm *request, ::apollo::v2x::StatusResponse *response) override
Definition: grpc_server.h:41