8 #ifndef WPIUTIL_WPI_UV_REQUEST_H_
9 #define WPIUTIL_WPI_UV_REQUEST_H_
16 #include "wpi/uv/Error.h"
25 class Request :
public std::enable_shared_from_this<Request> {
27 using Type = uv_req_type;
33 virtual ~
Request() noexcept =
default;
44 Type
GetType() const noexcept {
return m_uv_req->type; }
50 return uv_req_type_name(m_uv_req->type);
62 bool Cancel() {
return uv_cancel(m_uv_req) == 0; }
68 size_t RawSize() const noexcept {
return uv_req_size(m_uv_req->type); }
91 virtual void Keep() noexcept { m_self = shared_from_this(); }
100 virtual void Release() noexcept { m_self.reset(); }
120 m_uv_req->data =
this;
124 std::shared_ptr<Request> m_self;
133 template <
typename T,
typename U>
136 std::shared_ptr<T> shared_from_this() {
137 return std::static_pointer_cast<T>(this->shared_from_this());
140 std::shared_ptr<const T> shared_from_this()
const {
141 return std::static_pointer_cast<
const T>(this->shared_from_this());
149 U*
GetRaw() noexcept {
return &m_uv_req; }
156 const U*
GetRaw() const noexcept {
return &m_uv_req; }
171 #endif // WPIUTIL_WPI_UV_REQUEST_H_
virtual void Keep() noexcept
Keep this request in memory even if no outside shared_ptr references remain.
Definition: Request.h:91
Request(uv_req_t *uv_req)
Constructor.
Definition: Request.h:119
const uv_req_t * GetRawReq() const noexcept
Get the underlying request data structure.
Definition: Request.h:82
WPILib C++ utilities (wpiutil) namespace.
Definition: SmallString.h:21
Request.
Definition: Request.h:25
U * GetRaw() noexcept
Get the underlying request data structure.
Definition: Request.h:149
bool Cancel()
Cancel a pending request.
Definition: Request.h:62
virtual void Release() noexcept
No longer force holding this request in memory.
Definition: Request.h:100
const U * GetRaw() const noexcept
Get the underlying request data structure.
Definition: Request.h:156
std::function< void(Error)> error
Error callback.
Definition: Request.h:107
Type GetType() const noexcept
Get the type of the request.
Definition: Request.h:44
uv_req_t * GetRawReq() noexcept
Get the underlying request data structure.
Definition: Request.h:75
Error code.
Definition: Error.h:19
Request.
Definition: Request.h:134
RequestImpl()
Constructor.
Definition: Request.h:162
void ReportError(int err)
Report an error.
Definition: Request.h:113
const char * GetTypeName() const noexcept
Get the name of the type of the request.
Definition: Request.h:49
size_t RawSize() const noexcept
Return the size of the underlying request type.
Definition: Request.h:68