WPILibC++  2020.3.2-60-g3011ebe
GetAddrInfo.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_GETADDRINFO_H_
9 #define WPIUTIL_WPI_UV_GETADDRINFO_H_
10 
11 #include <uv.h>
12 
13 #include <functional>
14 #include <memory>
15 
16 #include "wpi/Signal.h"
17 #include "wpi/Twine.h"
18 #include "wpi/uv/Request.h"
19 
20 namespace wpi {
21 namespace uv {
22 
23 class Loop;
24 
29 class GetAddrInfoReq : public RequestImpl<GetAddrInfoReq, uv_getaddrinfo_t> {
30  public:
32 
33  Loop& GetLoop() const { return *static_cast<Loop*>(GetRaw()->loop->data); }
34 
40 };
41 
56 void GetAddrInfo(Loop& loop, const std::shared_ptr<GetAddrInfoReq>& req,
57  const Twine& node, const Twine& service = Twine::createNull(),
58  const addrinfo* hints = nullptr);
59 
74 inline void GetAddrInfo(const std::shared_ptr<Loop>& loop,
75  const std::shared_ptr<GetAddrInfoReq>& req,
76  const Twine& node,
77  const Twine& service = Twine::createNull(),
78  const addrinfo* hints = nullptr) {
79  GetAddrInfo(*loop, req, node, service, hints);
80 }
81 
96 void GetAddrInfo(Loop& loop, std::function<void(const addrinfo&)> callback,
97  const Twine& node, const Twine& service = Twine::createNull(),
98  const addrinfo* hints = nullptr);
99 
114 inline void GetAddrInfo(const std::shared_ptr<Loop>& loop,
115  std::function<void(const addrinfo&)> callback,
116  const Twine& node,
117  const Twine& service = Twine::createNull(),
118  const addrinfo* hints = nullptr) {
119  GetAddrInfo(*loop, callback, node, service, hints);
120 }
121 
122 } // namespace uv
123 } // namespace wpi
124 
125 #endif // WPIUTIL_WPI_UV_GETADDRINFO_H_
wpi::Twine::createNull
static Twine createNull()
Create a 'null' string, which is an empty string that always concatenates to form another empty strin...
Definition: Twine.h:364
wpi::uv::GetAddrInfoReq::resolved
sig::Signal< const addrinfo & > resolved
Resolved lookup signal.
Definition: GetAddrInfo.h:39
wpi::uv::RequestImpl< GetAddrInfoReq, uv_getaddrinfo_t >::GetRaw
uv_getaddrinfo_t * GetRaw() noexcept
Get the underlying request data structure.
Definition: Request.h:149
wpi
WPILib C++ utilities (wpiutil) namespace.
Definition: Endian.h:31
wpi::uv::RequestImpl
Request.
Definition: Request.h:134
wpi::uv::GetAddrInfoReq
GetAddrInfo request.
Definition: GetAddrInfo.h:29
wpi::uv::Loop
Event loop.
Definition: Loop.h:39
wpi::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:85
wpi::sig::SignalBase
SignalBase is an implementation of the observer pattern, through the use of an emitting object and sl...
Definition: Signal.h:495