added Prepare

This commit is contained in:
Michele Caini 2016-06-28 08:55:26 +02:00
parent 07d89327ff
commit fc17af440f
2 changed files with 48 additions and 0 deletions

View File

@ -1,5 +1,6 @@
#include "uvw/check.hpp"
#include "uvw/loop.hpp"
#include "uvw/prepare.hpp"
#include "uvw/stream.hpp"
#include "uvw/tcp.hpp"
#include "uvw/timer.hpp"

47
src/uvw/prepare.hpp Normal file
View File

@ -0,0 +1,47 @@
#pragma once
#include <utility>
#include <memory>
#include <uv.h>
#include "resource.hpp"
#include "util.hpp"
namespace uvw {
class Prepare final: public Resource<Prepare> {
static void startCallback(Prepare &prepare, std::function<void(UVWError, Prepare &)> &cb, uv_prepare_t *) {
cb(UVWError{}, prepare);
}
explicit Prepare(std::shared_ptr<Loop> ref)
: Resource{HandleType<uv_prepare_t>{}, std::move(ref)}
{
initialized = (uv_prepare_init(parent(), get<uv_prepare_t>()) == 0);
}
public:
template<typename... Args>
static std::shared_ptr<Prepare> create(Args&&... args) {
return std::shared_ptr<Prepare>{new Prepare{std::forward<Args>(args)...}};
}
void start(std::function<void(UVWError, Prepare &)> cb) noexcept {
using CBF = CallbackFactory<void(uv_prepare_t *)>;
auto func = CBF::on<&Prepare::startCallback>(*this, cb);
auto err = uv_prepare_start(get<uv_prepare_t>(), func);
if(err) { error(err); }
}
UVWError stop() noexcept { return UVWError{uv_prepare_stop(get<uv_prepare_t>())}; }
explicit operator bool() const noexcept { return initialized; }
private:
bool initialized;
};
}