WPILibC++  2018.4.1-20180729040223-1137-g011f0ff
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
Poll.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2018 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #ifndef WPIUTIL_WPI_UV_POLL_H_
9 #define WPIUTIL_WPI_UV_POLL_H_
10 
11 #include <uv.h>
12 
13 #include <memory>
14 
15 #include "wpi/Signal.h"
16 #include "wpi/uv/Handle.h"
17 
18 namespace wpi {
19 namespace uv {
20 
21 class Loop;
22 
26 class Poll final : public HandleImpl<Poll, uv_poll_t> {
27  struct private_init {};
28 
29  public:
30  explicit Poll(const private_init&) {}
31  ~Poll() noexcept override = default;
32 
39  static std::shared_ptr<Poll> Create(Loop& loop, int fd);
40 
47  static std::shared_ptr<Poll> Create(const std::shared_ptr<Loop>& loop,
48  int fd) {
49  return Create(*loop, fd);
50  }
51 
58  static std::shared_ptr<Poll> CreateSocket(Loop& loop, uv_os_sock_t sock);
59 
66  static std::shared_ptr<Poll> CreateSocket(const std::shared_ptr<Loop>& loop,
67  uv_os_sock_t sock) {
68  return CreateSocket(*loop, sock);
69  }
70 
77  void Start(int events);
78 
82  void Stop() { Invoke(&uv_poll_stop, GetRaw()); }
83 
88 };
89 
90 } // namespace uv
91 } // namespace wpi
92 
93 #endif // WPIUTIL_WPI_UV_POLL_H_
uv_poll_t * GetRaw() const noexcept
Get the underlying handle data structure.
Definition: Handle.h:261
Handle.
Definition: Handle.h:246
static std::shared_ptr< Poll > CreateSocket(Loop &loop, uv_os_sock_t sock)
Create a poll handle using a socket descriptor.
void Stop()
Stop polling the file descriptor.
Definition: Poll.h:82
static std::shared_ptr< Poll > CreateSocket(const std::shared_ptr< Loop > &loop, uv_os_sock_t sock)
Create a poll handle using a socket descriptor.
Definition: Poll.h:66
static std::shared_ptr< Poll > Create(const std::shared_ptr< Loop > &loop, int fd)
Create a poll handle using a file descriptor.
Definition: Poll.h:47
Poll handle.
Definition: Poll.h:26
namespace to hold default to_json function
Definition: SmallString.h:21
void Start(int events)
Start polling the file descriptor.
sig::Signal< int > pollEvent
Signal generated when a poll event occurs.
Definition: Poll.h:87
Event loop.
Definition: Loop.h:37
static std::shared_ptr< Poll > Create(Loop &loop, int fd)
Create a poll handle using a file descriptor.
SignalBase is an implementation of the observer pattern, through the use of an emitting object and sl...
Definition: Signal.h:495