Apollo  6.0
Open source self driving car software
poll_handler.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  *****************************************************************************/
16 
17 #ifndef CYBER_IO_POLL_HANDLER_H_
18 #define CYBER_IO_POLL_HANDLER_H_
19 
20 #include <atomic>
21 #include <memory>
22 
24 #include "cyber/io/poll_data.h"
25 
26 namespace apollo {
27 namespace cyber {
28 namespace io {
29 
30 class PollHandler {
31  public:
32  explicit PollHandler(int fd);
33  virtual ~PollHandler() = default;
34 
35  bool Block(int timeout_ms, bool is_read);
36  bool Unblock();
37 
38  int fd() const { return fd_; }
39  void set_fd(int fd) { fd_ = fd; }
40 
41  private:
42  bool Check(int timeout_ms);
43  void Fill(int timeout_ms, bool is_read);
44  void ResponseCallback(const PollResponse& rsp);
45 
46  int fd_;
47  PollRequest request_;
48  PollResponse response_;
49  std::atomic<bool> is_read_;
50  std::atomic<bool> is_blocking_;
51  croutine::CRoutine* routine_;
52 };
53 
54 } // namespace io
55 } // namespace cyber
56 } // namespace apollo
57 
58 #endif // CYBER_IO_POLL_HANDLER_H_
Definition: croutine.h:40
Definition: poll_handler.h:30
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
bool Block(int timeout_ms, bool is_read)
Definition: poll_data.h:35
void set_fd(int fd)
Definition: poll_handler.h:39
virtual ~PollHandler()=default
int fd() const
Definition: poll_handler.h:38
Definition: poll_data.h:29