diff --git a/src/uvw/event.hpp b/src/uvw/event.hpp index a16df258..9b4e8f94 100644 --- a/src/uvw/event.hpp +++ b/src/uvw/event.hpp @@ -83,8 +83,4 @@ private: }; -template -struct TypedEvent; - - } diff --git a/src/uvw/fs.hpp b/src/uvw/fs.hpp index fecc92ed..88b87872 100644 --- a/src/uvw/fs.hpp +++ b/src/uvw/fs.hpp @@ -66,14 +66,57 @@ enum class UVDirentTypeT: std::underlying_type_t { } +/** + * @brief Default FsEvent event. + * + * Available types are: + * + * * FsRequest::Type::UNKNOWN + * * FsRequest::Type::CUSTOM + * * FsRequest::Type::OPEN + * * FsRequest::Type::CLOSE + * * FsRequest::Type::READ + * * FsRequest::Type::WRITE + * * FsRequest::Type::SENDFILE + * * FsRequest::Type::STAT + * * FsRequest::Type::LSTAT + * * FsRequest::Type::FSTAT + * * FsRequest::Type::FTRUNCATE + * * FsRequest::Type::UTIME + * * FsRequest::Type::FUTIME + * * FsRequest::Type::ACCESS + * * FsRequest::Type::CHMOD + * * FsRequest::Type::FCHMOD + * * FsRequest::Type::FSYNC + * * FsRequest::Type::FDATASYNC + * * FsRequest::Type::UNLINK + * * FsRequest::Type::RMDIR + * * FsRequest::Type::MKDIR + * * FsRequest::Type::MKDTEMP + * * FsRequest::Type::RENAME + * * FsRequest::Type::SCANDIR + * * FsRequest::Type::LINK + * * FsRequest::Type::SYMLINK + * * FsRequest::Type::READLINK + * * FsRequest::Type::CHOWN + * * FsRequest::Type::FCHOWN + * * FsRequest::Type::REALPATH + * + * It will be emitted by FsReq and/or FileReq according with their + * functionalities. + * + * See the official + * [documentation](http://docs.libuv.org/en/v1.x/fs.html#c.uv_fs_type) + * for further details. + */ template -struct TypedEvent - : Event> -{ - TypedEvent(const char *p) noexcept - : rPath{p} - { } +struct FsEvent: Event> { + FsEvent(const char *p) noexcept: rPath{p} { } + /** + * @brief Gets the path affecting the request. + * @return The path affecting the request. + */ const char * path() const noexcept { return rPath; } private: @@ -81,16 +124,36 @@ private: }; +/** + * @brief FsEvent event specialization for FsRequest::Type::READ. + * + * It will be emitted by FsReq and/or FileReq according with their + * functionalities. + */ template<> -struct TypedEvent - : Event> +struct FsEvent + : Event> { - TypedEvent(const char *p, std::unique_ptr ptr, ssize_t l) noexcept + FsEvent(const char *p, std::unique_ptr ptr, ssize_t l) noexcept : rPath{p}, dt{std::move(ptr)}, len{l} { } + /** + * @brief Gets the path affecting the request. + * @return The path affecting the request. + */ const char * path() const noexcept { return rPath; } + + /** + * @brief Gets the data read from the given path. + * @return A bunch of data read from the given path. + */ const char * data() const noexcept { return dt.get(); } + + /** + * @brief Gets the amount of data read from the given path. + * @return The amount of data read from the given path. + */ ssize_t length() const noexcept { return len; } private: @@ -100,15 +163,30 @@ private: }; +/** + * @brief FsEvent event specialization for FsRequest::Type::WRITE. + * + * It will be emitted by FsReq and/or FileReq according with their + * functionalities. + */ template<> -struct TypedEvent - : Event> +struct FsEvent + : Event> { - TypedEvent(const char *p, ssize_t s) noexcept + FsEvent(const char *p, ssize_t s) noexcept : rPath{p}, sz{s} { } + /** + * @brief Gets the path affecting the request. + * @return The path affecting the request. + */ const char * path() const noexcept { return rPath; } + + /** + * @brief Gets the amount of data written to the given path. + * @return The amount of data written to the given path. + */ ssize_t amount() const noexcept { return sz; } private: @@ -117,15 +195,30 @@ private: }; +/** + * @brief FsEvent event specialization for FsRequest::Type::SENDFILE. + * + * It will be emitted by FsReq and/or FileReq according with their + * functionalities. + */ template<> -struct TypedEvent - : Event> +struct FsEvent + : Event> { - TypedEvent(const char *p, ssize_t s) noexcept + FsEvent(const char *p, ssize_t s) noexcept : rPath{p}, sz{s} { } + /** + * @brief Gets the path affecting the request. + * @return The path affecting the request. + */ const char * path() const noexcept { return rPath; } + + /** + * @brief Gets the amount of data transferred. + * @return The amount of data transferred. + */ ssize_t amount() const noexcept { return sz; } private: @@ -134,15 +227,30 @@ private: }; +/** + * @brief FsEvent event specialization for FsRequest::Type::STAT. + * + * It will be emitted by FsReq and/or FileReq according with their + * functionalities. + */ template<> -struct TypedEvent - : Event> +struct FsEvent + : Event> { - TypedEvent(const char *p, const Stat &s) noexcept + FsEvent(const char *p, const Stat &s) noexcept : rPath{p}, fsStat(s) { } + /** + * @brief Gets the path affecting the request. + * @return The path affecting the request. + */ const char * path() const noexcept { return rPath; } + + /** + * @brief Gets an initialized instance of Stat. + * @return An initialized instance of Stat. + */ const Stat & stat() const noexcept { return fsStat; } private: @@ -151,15 +259,30 @@ private: }; +/** + * @brief FsEvent event specialization for FsRequest::Type::FSTAT. + * + * It will be emitted by FsReq and/or FileReq according with their + * functionalities. + */ template<> -struct TypedEvent - : Event> +struct FsEvent + : Event> { - TypedEvent(const char *p, const Stat &s) noexcept + FsEvent(const char *p, const Stat &s) noexcept : rPath{p}, fsStat(s) { } + /** + * @brief Gets the path affecting the request. + * @return The path affecting the request. + */ const char * path() const noexcept { return rPath; } + + /** + * @brief Gets an initialized instance of Stat. + * @return An initialized instance of Stat. + */ const Stat & stat() const noexcept { return fsStat; } private: @@ -168,15 +291,30 @@ private: }; +/** + * @brief FsEvent event specialization for FsRequest::Type::LSTAT. + * + * It will be emitted by FsReq and/or FileReq according with their + * functionalities. + */ template<> -struct TypedEvent - : Event> +struct FsEvent + : Event> { - TypedEvent(const char *p, const Stat &s) noexcept + FsEvent(const char *p, const Stat &s) noexcept : rPath{p}, fsStat(s) { } + /** + * @brief Gets the path affecting the request. + * @return The path affecting the request. + */ const char * path() const noexcept { return rPath; } + + /** + * @brief Gets an initialized instance of Stat. + * @return An initialized instance of Stat. + */ const Stat & stat() const noexcept { return fsStat; } private: @@ -185,15 +323,30 @@ private: }; +/** + * @brief FsEvent event specialization for FsRequest::Type::SCANDIR. + * + * It will be emitted by FsReq and/or FileReq according with their + * functionalities. + */ template<> -struct TypedEvent - : Event> +struct FsEvent + : Event> { - TypedEvent(const char *p, ssize_t s) noexcept + FsEvent(const char *p, ssize_t s) noexcept : rPath{p}, sz{s} { } + /** + * @brief Gets the path affecting the request. + * @return The path affecting the request. + */ const char * path() const noexcept { return rPath; } + + /** + * @brief Gets the number of directory entries selected. + * @return The number of directory entries selected. + */ ssize_t amount() const noexcept { return sz; } private: @@ -202,16 +355,36 @@ private: }; +/** + * @brief FsEvent event specialization for FsRequest::Type::READLINK. + * + * It will be emitted by FsReq and/or FileReq according with their + * functionalities. + */ template<> -struct TypedEvent - : Event> +struct FsEvent + : Event> { - explicit TypedEvent(const char *p, const char *d, ssize_t l) noexcept + explicit FsEvent(const char *p, const char *d, ssize_t l) noexcept : rPath{p}, dt{d}, len{l} { } + /** + * @brief Gets the path affecting the request. + * @return The path affecting the request. + */ const char * path() const noexcept { return rPath; } + + /** + * @brief Gets the data read from the given path. + * @return A bunch of data read from the given path. + */ const char * data() const noexcept { return dt; } + + /** + * @brief Gets the amount of data read from the given path. + * @return The amount of data read from the given path. + */ ssize_t length() const noexcept { return len; } private: @@ -221,10 +394,11 @@ private: }; -template -using FsEvent = TypedEvent; - - +/** + * @brief Base class for FsReq and/or FileReq. + * + * Not directly instantiable, should not be used by the users of the library. + */ template class FsRequest: public Request { protected: @@ -271,6 +445,16 @@ public: }; +/** + * @brief The FileReq request. + * + * Cross-platform sync and async filesystem operations.
+ * All file operations are run on the threadpool. + * + * See the official + * [documentation](http://docs.libuv.org/en/v1.x/fs.html) + * for further details. + */ class FileReq final: public FsRequest { static constexpr uv_file BAD_FD = -1; @@ -305,6 +489,11 @@ class FileReq final: public FsRequest { using FsRequest::FsRequest; public: + /** + * @brief Creates a new file request. + * @param args A pointer to the loop from which the handle generated. + * @return A pointer to the newly created request. + */ template static std::shared_ptr create(Args&&... args) { return std::shared_ptr{new FileReq{std::forward(args)...}}; @@ -314,10 +503,20 @@ public: uv_fs_req_cleanup(get()); } + /** + * @brief Async [close](http://linux.die.net/man/2/close). + * + * Emit a `FsEvent` event when completed.
+ * Emit an ErrorEvent event in case of errors. + */ void close() { cleanupAndInvoke(&uv_fs_close, parent(), get(), file, &fsCloseCallback); } + /** + * @brief Sync [close](http://linux.die.net/man/2/close). + * @return A pair `{ ErrorEvent, FsEvent }`. + */ auto closeSync() { auto req = get(); cleanupAndInvokeSync(&uv_fs_close, parent(), req, file); @@ -325,10 +524,27 @@ public: return std::make_pair(ErrorEvent{req->result}, FsEvent{req->path}); } + /** + * @brief Async [open](http://linux.die.net/man/2/open). + * + * Emit a `FsEvent` event when completed.
+ * Emit an ErrorEvent event in case of errors. + * + * @param path A valid path name for a file. + * @param flags Flags, as described in the official documentation. + * @param mode Mode, as described in the official documentation. + */ void open(std::string path, int flags, int mode) { cleanupAndInvoke(&uv_fs_open, parent(), get(), path.data(), flags, mode, &fsOpenCallback); } + /** + * @brief Sync [open](http://linux.die.net/man/2/open). + * @param path A valid path name for a file. + * @param flags Flags, as described in the official documentation. + * @param mode Mode, as described in the official documentation. + * @return A pair `{ ErrorEvent, FsEvent }`. + */ auto openSync(std::string path, int flags, int mode) { auto req = get(); cleanupAndInvokeSync(&uv_fs_open, parent(), req, path.data(), flags, mode); @@ -336,6 +552,15 @@ public: return std::make_pair(ErrorEvent{req->result}, FsEvent{req->path}); } + /** + * @brief Async [read](http://linux.die.net/man/2/preadv). + * + * Emit a `FsEvent` event when completed.
+ * Emit an ErrorEvent event in case of errors. + * + * @param offset Offset, as described in the official documentation. + * @param len Length, as described in the official documentation. + */ void read(int64_t offset, unsigned int len) { data = std::unique_ptr{new char[len]}; buffer = uv_buf_init(data.get(), len); @@ -343,6 +568,12 @@ public: cleanupAndInvoke(&uv_fs_read, parent(), get(), file, bufs, 1, offset, &fsReadCallback); } + /** + * @brief Sync [read](http://linux.die.net/man/2/preadv). + * @param offset Offset, as described in the official documentation. + * @param len Length, as described in the official documentation. + * @return A pair `{ ErrorEvent, FsEvent }`. + */ auto readSync(int64_t offset, unsigned int len) { data = std::unique_ptr{new char[len]}; buffer = uv_buf_init(data.get(), len); @@ -352,11 +583,28 @@ public: return std::make_pair(ErrorEvent{req->result}, FsEvent{req->path, std::move(data), req->result}); } + /** + * @brief Async [write](http://linux.die.net/man/2/pwritev). + * + * Emit a `FsEvent` event when completed.
+ * Emit an ErrorEvent event in case of errors. + * + * @param data The data to be written. + * @param len The lenght of the submitted data. + * @param offset Offset, as described in the official documentation. + */ void write(std::unique_ptr data, ssize_t len, int64_t offset) { uv_buf_t bufs[] = { uv_buf_init(data.get(), len) }; cleanupAndInvoke(&uv_fs_write, parent(), get(), file, bufs, 1, offset, &fsResultCallback); } + /** + * @brief Sync [write](http://linux.die.net/man/2/pwritev). + * @param data The data to be written. + * @param len The lenght of the submitted data. + * @param offset Offset, as described in the official documentation. + * @return A pair `{ ErrorEvent, FsEvent }`. + */ auto writeSync(std::unique_ptr data, ssize_t len, int64_t offset) { uv_buf_t bufs[] = { uv_buf_init(data.get(), len) }; auto req = get(); @@ -364,86 +612,201 @@ public: return std::make_pair(ErrorEvent{req->result}, FsEvent{req->path, req->result}); } + /** + * @brief Async [fstat](http://linux.die.net/man/2/fstat). + * + * Emit a `FsEvent` event when completed.
+ * Emit an ErrorEvent event in case of errors. + */ void fstat() { cleanupAndInvoke(&uv_fs_fstat, parent(), get(), file, &fsStatCallback); } + /** + * @brief Sync [fstat](http://linux.die.net/man/2/fstat). + * @return A pair `{ ErrorEvent, FsEvent }`. + */ auto fstatSync() { auto req = get(); cleanupAndInvokeSync(&uv_fs_fstat, parent(), req, file); return std::make_pair(ErrorEvent{req->result}, FsEvent{req->path, req->statbuf}); } + /** + * @brief Async [fsync](http://linux.die.net/man/2/fsync). + * + * Emit a `FsEvent` event when completed.
+ * Emit an ErrorEvent event in case of errors. + */ void fsync() { cleanupAndInvoke(&uv_fs_fsync, parent(), get(), file, &fsGenericCallback); } + /** + * @brief Sync [fsync](http://linux.die.net/man/2/fsync). + * @return A pair `{ ErrorEvent, FsEvent }`. + */ auto fsyncSync() { auto req = get(); cleanupAndInvokeSync(&uv_fs_fsync, parent(), req, file); return std::make_pair(ErrorEvent{req->result}, FsEvent{req->path}); } + /** + * @brief Async [fdatasync](http://linux.die.net/man/2/fdatasync). + * + * Emit a `FsEvent` event when completed.
+ * Emit an ErrorEvent event in case of errors. + */ void fdatasync() { cleanupAndInvoke(&uv_fs_fdatasync, parent(), get(), file, &fsGenericCallback); } + /** + * @brief Sync [fdatasync](http://linux.die.net/man/2/fdatasync). + * @return A pair `{ ErrorEvent, FsEvent }`. + */ auto fdatasyncSync() { auto req = get(); cleanupAndInvokeSync(&uv_fs_fdatasync, parent(), req, file); return std::make_pair(ErrorEvent{req->result}, FsEvent{req->path}); } + /** + * @brief Async [ftruncate](http://linux.die.net/man/2/ftruncate). + * + * Emit a `FsEvent` event when completed.
+ * Emit an ErrorEvent event in case of errors. + * + * @param offset Offset, as described in the official documentation. + */ void ftruncate(int64_t offset) { cleanupAndInvoke(&uv_fs_ftruncate, parent(), get(), file, offset, &fsGenericCallback); } + /** + * @brief Sync [ftruncate](http://linux.die.net/man/2/ftruncate). + * @param offset Offset, as described in the official documentation. + * @return A pair `{ ErrorEvent, FsEvent }`. + */ auto ftruncateSync(int64_t offset) { auto req = get(); cleanupAndInvokeSync(&uv_fs_ftruncate, parent(), req, file, offset); return std::make_pair(ErrorEvent{req->result}, FsEvent{req->path}); } + /** + * @brief Async [sendfile](http://linux.die.net/man/2/sendfile). + * + * Emit a `FsEvent` event when completed.
+ * Emit an ErrorEvent event in case of errors. + * + * @param out A valid instance of FileHandle. + * @param offset Offset, as described in the official documentation. + * @param length Length, as described in the official documentation. + */ void sendfile(FileHandle out, int64_t offset, size_t length) { cleanupAndInvoke(&uv_fs_sendfile, parent(), get(), out, file, offset, length, &fsResultCallback); } + /** + * @brief Sync [sendfile](http://linux.die.net/man/2/sendfile). + * @param out A valid instance of FileHandle. + * @param offset Offset, as described in the official documentation. + * @param length Length, as described in the official documentation. + * @return A pair `{ ErrorEvent, FsEvent }`. + */ auto sendfileSync(FileHandle out, int64_t offset, size_t length) { auto req = get(); cleanupAndInvokeSync(&uv_fs_sendfile, parent(), req, out, file, offset, length); return std::make_pair(ErrorEvent{req->result}, FsEvent{req->path, req->result}); } + /** + * @brief Async [fchmod](http://linux.die.net/man/2/fchmod). + * + * Emit a `FsEvent` event when completed.
+ * Emit an ErrorEvent event in case of errors. + * + * @param mode Mode, as described in the official documentation. + */ void fchmod(int mode) { cleanupAndInvoke(&uv_fs_fchmod, parent(), get(), file, mode, &fsGenericCallback); } + /** + * @brief Sync [fchmod](http://linux.die.net/man/2/fchmod). + * @param mode Mode, as described in the official documentation. + * @return A pair `{ ErrorEvent, FsEvent }`. + */ auto fchmodSync(int mode) { auto req = get(); cleanupAndInvokeSync(&uv_fs_fchmod, parent(), req, file, mode); return std::make_pair(ErrorEvent{req->result}, FsEvent{req->path}); } + /** + * @brief Async [futime](http://linux.die.net/man/2/futime). + * + * Emit a `FsEvent` event when completed.
+ * Emit an ErrorEvent event in case of errors. + * + * @param atime `std::chrono::seconds`, having the same meaning as described + * in the official documentation. + * @param mtime `std::chrono::seconds`, having the same meaning as described + * in the official documentation. + */ void futime(Time atime, Time mtime) { cleanupAndInvoke(&uv_fs_futime, parent(), get(), file, atime.count(), mtime.count(), &fsGenericCallback); } + /** + * @brief Sync [futime](http://linux.die.net/man/2/futime). + * @param atime `std::chrono::seconds`, having the same meaning as described + * in the official documentation. + * @param mtime `std::chrono::seconds`, having the same meaning as described + * in the official documentation. + * @return A pair `{ ErrorEvent, FsEvent }`. + */ auto futimeSync(Time atime, Time mtime) { auto req = get(); cleanupAndInvokeSync(&uv_fs_futime, parent(), req, file, atime.count(), mtime.count()); return std::make_pair(ErrorEvent{req->result}, FsEvent{req->path}); } + /** + * @brief Async [fchown](http://linux.die.net/man/2/fchown). + * + * Emit a `FsEvent` event when completed.
+ * Emit an ErrorEvent event in case of errors. + * + * @param uid UID, as described in the official documentation. + * @param gid GID, as described in the official documentation. + */ void fchown(Uid uid, Gid gid) { cleanupAndInvoke(&uv_fs_fchown, parent(), get(), file, uid, gid, &fsGenericCallback); } + /** + * @brief Sync [fchown](http://linux.die.net/man/2/fchown). + * @param uid UID, as described in the official documentation. + * @param gid GID, as described in the official documentation. + * @return A pair `{ ErrorEvent, FsEvent }`. + */ auto fchownSync(Uid uid, Gid gid) { auto req = get(); cleanupAndInvokeSync(&uv_fs_fchown, parent(), req, file, uid, gid); return std::make_pair(ErrorEvent{req->result}, FsEvent{req->path}); } + /** + * @brief Cast operator to FileHandle. + * + * Cast operator to an internal representation of the underlying file + * handle. + * + * @return A valid instance of FileHandle (the descriptor can be invalid). + */ operator FileHandle() const noexcept { return file; } private: @@ -453,6 +816,16 @@ private: }; +/** + * @brief The FsReq request. + * + * Cross-platform sync and async filesystem operations.
+ * All file operations are run on the threadpool. + * + * See the official + * [documentation](http://docs.libuv.org/en/v1.x/fs.html) + * for further details. + */ class FsReq final: public FsRequest { static void fsReadlinkCallback(uv_fs_t *req) { auto ptr = reserve(reinterpret_cast(req)); @@ -463,6 +836,11 @@ class FsReq final: public FsRequest { using FsRequest::FsRequest; public: + /** + * @brief Creates a new file request. + * @param args A pointer to the loop from which the handle generated. + * @return A pointer to the newly created request. + */ template static std::shared_ptr create(Args&&... args) { return std::shared_ptr{new FsReq{std::forward(args)...}}; @@ -472,56 +850,154 @@ public: uv_fs_req_cleanup(get()); } + /** + * @brief Async [unlink](http://linux.die.net/man/2/unlink). + * + * Emit a `FsEvent` event when completed.
+ * Emit an ErrorEvent event in case of errors. + * + * @param path Path, as described in the official documentation. + */ void unlink(std::string path) { cleanupAndInvoke(&uv_fs_unlink, parent(), get(), path.data(), &fsGenericCallback); } + /** + * @brief Sync [unlink](http://linux.die.net/man/2/unlink). + * @param path Path, as described in the official documentation. + * @return A pair `{ ErrorEvent, FsEvent }`. + */ auto unlinkSync(std::string path) { auto req = get(); cleanupAndInvokeSync(&uv_fs_unlink, parent(), req, path.data()); return std::make_pair(ErrorEvent{req->result}, FsEvent{req->path}); } + /** + * @brief Async [mkdir](http://linux.die.net/man/2/mkdir). + * + * Emit a `FsEvent` event when completed.
+ * Emit an ErrorEvent event in case of errors. + * + * @param path Path, as described in the official documentation. + * @param mode Mode, as described in the official documentation. + */ void mkdir(std::string path, int mode) { cleanupAndInvoke(&uv_fs_mkdir, parent(), get(), path.data(), mode, &fsGenericCallback); } + /** + * @brief Sync [mkdir](http://linux.die.net/man/2/mkdir). + * @param path Path, as described in the official documentation. + * @param mode Mode, as described in the official documentation. + * @return A pair `{ ErrorEvent, FsEvent }`. + */ auto mkdirSync(std::string path, int mode) { auto req = get(); cleanupAndInvokeSync(&uv_fs_mkdir, parent(), req, path.data(), mode); return std::make_pair(ErrorEvent{req->result}, FsEvent{req->path}); } + /** + * @brief Async [mktemp](http://linux.die.net/man/3/mkdtemp). + * + * Emit a `FsEvent` event when completed.
+ * Emit an ErrorEvent event in case of errors. + * + * @param tpl Template, as described in the official documentation. + */ void mkdtemp(std::string tpl) { cleanupAndInvoke(&uv_fs_mkdtemp, parent(), get(), tpl.data(), &fsGenericCallback); } + /** + * @brief Sync [mktemp](http://linux.die.net/man/3/mkdtemp). + * @param tpl Template, as described in the official documentation. + * @return A pair `{ ErrorEvent, FsEvent }`. + */ auto mkdtempSync(std::string tpl) { auto req = get(); cleanupAndInvokeSync(&uv_fs_mkdtemp, parent(), req, tpl.data()); return std::make_pair(ErrorEvent{req->result}, FsEvent{req->path}); } + /** + * @brief Async [rmdir](http://linux.die.net/man/2/rmdir). + * + * Emit a `FsEvent` event when completed.
+ * Emit an ErrorEvent event in case of errors. + * + * @param path Path, as described in the official documentation. + */ void rmdir(std::string path) { cleanupAndInvoke(&uv_fs_rmdir, parent(), get(), path.data(), &fsGenericCallback); } + /** + * @brief Sync [rmdir](http://linux.die.net/man/2/rmdir). + * @param path Path, as described in the official documentation. + * @return A pair `{ ErrorEvent, FsEvent }`. + */ auto rmdirSync(std::string path) { auto req = get(); cleanupAndInvokeSync(&uv_fs_rmdir, parent(), req, path.data()); return std::make_pair(ErrorEvent{req->result}, FsEvent{req->path}); } + /** + * @brief Async [scandir](http://linux.die.net/man/3/scandir). + * + * Emit a `FsEvent` event when completed.
+ * Emit an ErrorEvent event in case of errors. + * + * @param path Path, as described in the official documentation. + * @param flags Flags, as described in the official documentation. + */ void scandir(std::string path, int flags) { cleanupAndInvoke(&uv_fs_scandir, parent(), get(), path.data(), flags, &fsResultCallback); } + /** + * @brief Sync [scandir](http://linux.die.net/man/3/scandir). + * @param path Path, as described in the official documentation. + * @param flags Flags, as described in the official documentation. + * @return A pair `{ ErrorEvent, FsEvent }`. + */ auto scandirSync(std::string path, int flags) { auto req = get(); cleanupAndInvokeSync(&uv_fs_scandir, parent(), req, path.data(), flags); return std::make_pair(ErrorEvent{req->result}, FsEvent{req->path, req->result}); } + /** + * @brief Gets entries populated with the next directory entry data. + * + * Returns instances of Entry, that is an alias for a pair where: + * + * * The first parameter indicates the entry type (see below). + * * The second parameter is a `std::string` that contains the actual value. + * + * Available entry types are: + * + * * FsReq::EntryType::UNKNOWN + * * FsReq::EntryType::FILE + * * FsReq::EntryType::DIR + * * FsReq::EntryType::LINK + * * FsReq::EntryType::FIFO + * * FsReq::EntryType::SOCKET + * * FsReq::EntryType::CHAR + * * FsReq::EntryType::BLOCK + * + * See the official + * [documentation](http://docs.libuv.org/en/v1.x/fs.html#c.uv_dirent_t) + * for further details. + * + * @return A pair where: + * + * * The first parameter is a boolean value that indicates if the current + * entry is still valid. + * * The second parameter is an instance of Entry (see above). + */ std::pair scandirNext() { uv_dirent_t dirent; std::pair ret{false, { EntryType::UNKNOWN, "" }}; @@ -536,110 +1012,277 @@ public: return ret; } + /** + * @brief Async [stat](http://linux.die.net/man/2/stat). + * + * Emit a `FsEvent` event when completed.
+ * Emit an ErrorEvent event in case of errors. + * + * @param path Path, as described in the official documentation. + */ void stat(std::string path) { cleanupAndInvoke(&uv_fs_stat, parent(), get(), path.data(), &fsStatCallback); } + /** + * @brief Sync [stat](http://linux.die.net/man/2/stat). + * @param path Path, as described in the official documentation. + * @return A pair `{ ErrorEvent, FsEvent }`. + */ auto statSync(std::string path) { auto req = get(); cleanupAndInvokeSync(&uv_fs_stat, parent(), req, path.data()); return std::make_pair(ErrorEvent{req->result}, FsEvent{req->path, req->statbuf}); } + /** + * @brief Async [lstat](http://linux.die.net/man/2/lstat). + * + * Emit a `FsEvent` event when completed.
+ * Emit an ErrorEvent event in case of errors. + * + * @param path Path, as described in the official documentation. + */ void lstat(std::string path) { cleanupAndInvoke(&uv_fs_lstat, parent(), get(), path.data(), &fsStatCallback); } + /** + * @brief Sync [lstat](http://linux.die.net/man/2/lstat). + * @param path Path, as described in the official documentation. + * @return A pair `{ ErrorEvent, FsEvent }`. + */ auto lstatSync(std::string path) { auto req = get(); cleanupAndInvokeSync(&uv_fs_lstat, parent(), req, path.data()); return std::make_pair(ErrorEvent{req->result}, FsEvent{req->path, req->statbuf}); } + /** + * @brief Async [rename](http://linux.die.net/man/2/rename). + * + * Emit a `FsEvent` event when completed.
+ * Emit an ErrorEvent event in case of errors. + * + * @param old Old path, as described in the official documentation. + * @param path New path, as described in the official documentation. + */ void rename(std::string old, std::string path) { cleanupAndInvoke(&uv_fs_rename, parent(), get(), old.data(), path.data(), &fsGenericCallback); } + /** + * @brief Sync [rename](http://linux.die.net/man/2/rename). + * @param old Old path, as described in the official documentation. + * @param path New path, as described in the official documentation. + * @return A pair `{ ErrorEvent, FsEvent }`. + */ auto renameSync(std::string old, std::string path) { auto req = get(); cleanupAndInvokeSync(&uv_fs_rename, parent(), req, old.data(), path.data()); return std::make_pair(ErrorEvent{req->result}, FsEvent{req->path}); } + /** + * @brief Async [access](http://linux.die.net/man/2/access). + * + * Emit a `FsEvent` event when completed.
+ * Emit an ErrorEvent event in case of errors. + * + * @param path Path, as described in the official documentation. + * @param mode Mode, as described in the official documentation. + */ void access(std::string path, int mode) { cleanupAndInvoke(&uv_fs_access, parent(), get(), path.data(), mode, &fsGenericCallback); } + /** + * @brief Sync [access](http://linux.die.net/man/2/access). + * @param path Path, as described in the official documentation. + * @param mode Mode, as described in the official documentation. + * @return A pair `{ ErrorEvent, FsEvent }`. + */ auto accessSync(std::string path, int mode) { auto req = get(); cleanupAndInvokeSync(&uv_fs_access, parent(), req, path.data(), mode); return std::make_pair(ErrorEvent{req->result}, FsEvent{req->path}); } + /** + * @brief Async [chmod](http://linux.die.net/man/2/chmod). + * + * Emit a `FsEvent` event when completed.
+ * Emit an ErrorEvent event in case of errors. + * + * @param path Path, as described in the official documentation. + * @param mode Mode, as described in the official documentation. + */ void chmod(std::string path, int mode) { cleanupAndInvoke(&uv_fs_chmod, parent(), get(), path.data(), mode, &fsGenericCallback); } + /** + * @brief Sync [chmod](http://linux.die.net/man/2/chmod). + * @param path Path, as described in the official documentation. + * @param mode Mode, as described in the official documentation. + * @return A pair `{ ErrorEvent, FsEvent }`. + */ auto chmodSync(std::string path, int mode) { auto req = get(); cleanupAndInvokeSync(&uv_fs_chmod, parent(), req, path.data(), mode); return std::make_pair(ErrorEvent{req->result}, FsEvent{req->path}); } + /** + * @brief Async [utime](http://linux.die.net/man/2/utime). + * + * Emit a `FsEvent` event when completed.
+ * Emit an ErrorEvent event in case of errors. + * + * @param path Path, as described in the official documentation. + * @param atime `std::chrono::seconds`, having the same meaning as described + * in the official documentation. + * @param mtime `std::chrono::seconds`, having the same meaning as described + * in the official documentation. + */ void utime(std::string path, Time atime, Time mtime) { cleanupAndInvoke(&uv_fs_utime, parent(), get(), path.data(), atime.count(), mtime.count(), &fsGenericCallback); } + /** + * @brief Sync [utime](http://linux.die.net/man/2/utime). + * @param path Path, as described in the official documentation. + * @param atime `std::chrono::seconds`, having the same meaning as described + * in the official documentation. + * @param mtime `std::chrono::seconds`, having the same meaning as described + * in the official documentation. + * @return A pair `{ ErrorEvent, FsEvent }`. + */ auto utimeSync(std::string path, Time atime, Time mtime) { auto req = get(); cleanupAndInvokeSync(&uv_fs_utime, parent(), req, path.data(), atime.count(), mtime.count()); return std::make_pair(ErrorEvent{req->result}, FsEvent{req->path}); } + /** + * @brief Async [link](http://linux.die.net/man/2/link). + * + * Emit a `FsEvent` event when completed.
+ * Emit an ErrorEvent event in case of errors. + * + * @param old Old path, as described in the official documentation. + * @param path New path, as described in the official documentation. + */ void link(std::string old, std::string path) { cleanupAndInvoke(&uv_fs_link, parent(), get(), old.data(), path.data(), &fsGenericCallback); } + /** + * @brief Sync [link](http://linux.die.net/man/2/link). + * @param old Old path, as described in the official documentation. + * @param path New path, as described in the official documentation. + * @return A pair `{ ErrorEvent, FsEvent }`. + */ auto linkSync(std::string old, std::string path) { auto req = get(); cleanupAndInvokeSync(&uv_fs_link, parent(), req, old.data(), path.data()); return std::make_pair(ErrorEvent{req->result}, FsEvent{req->path}); } + /** + * @brief Async [symlink](http://linux.die.net/man/2/symlink). + * + * Emit a `FsEvent` event when completed.
+ * Emit an ErrorEvent event in case of errors. + * + * @param old Old path, as described in the official documentation. + * @param path New path, as described in the official documentation. + * @param flags Flags, as described in the official documentation. + */ void symlink(std::string old, std::string path, int flags) { cleanupAndInvoke(&uv_fs_symlink, parent(), get(), old.data(), path.data(), flags, &fsGenericCallback); } + /** + * @brief Sync [symlink](http://linux.die.net/man/2/symlink). + * @param old Old path, as described in the official documentation. + * @param path New path, as described in the official documentation. + * @param flags Flags, as described in the official documentation. + * @return A pair `{ ErrorEvent, FsEvent }`. + */ auto symlinkSync(std::string old, std::string path, int flags) { auto req = get(); cleanupAndInvokeSync(&uv_fs_symlink, parent(), req, old.data(), path.data(), flags); return std::make_pair(ErrorEvent{req->result}, FsEvent{req->path}); } + /** + * @brief Async [readlink](http://linux.die.net/man/2/readlink). + * + * Emit a `FsEvent` event when completed.
+ * Emit an ErrorEvent event in case of errors. + * + * @param path Path, as described in the official documentation. + */ void readlink(std::string path) { cleanupAndInvoke(&uv_fs_readlink, parent(), get(), path.data(), &fsReadlinkCallback); } + /** + * @brief Sync [readlink](http://linux.die.net/man/2/readlink). + * @param path Path, as described in the official documentation. + * @return A pair `{ ErrorEvent, FsEvent }`. + */ auto readlinkSync(std::string path) { auto req = get(); cleanupAndInvokeSync(&uv_fs_readlink, parent(), req, path.data()); return std::make_pair(ErrorEvent{req->result}, FsEvent{req->path, static_cast(req->ptr), req->result}); } + /** + * @brief Async [realpath](http://linux.die.net/man/3/realpath). + * + * Emit a `FsEvent` event when completed.
+ * Emit an ErrorEvent event in case of errors. + * + * @param path Path, as described in the official documentation. + */ void realpath(std::string path) { cleanupAndInvoke(&uv_fs_realpath, parent(), get(), path.data(), &fsGenericCallback); } + /** + * @brief Sync [realpath](http://linux.die.net/man/3/realpath). + * @param path Path, as described in the official documentation. + * @return A pair `{ ErrorEvent, FsEvent }`. + */ auto realpathSync(std::string path) { auto req = get(); cleanupAndInvokeSync(&uv_fs_realpath, parent(), req, path.data()); return std::make_pair(ErrorEvent{req->result}, FsEvent{req->path}); } + /** + * @brief Async [chown](http://linux.die.net/man/2/chown). + * + * Emit a `FsEvent` event when completed.
+ * Emit an ErrorEvent event in case of errors. + * + * @param path Path, as described in the official documentation. + * @param uid UID, as described in the official documentation. + * @param gid GID, as described in the official documentation. + */ void chown(std::string path, Uid uid, Gid gid) { cleanupAndInvoke(&uv_fs_chown, parent(), get(), path.data(), uid, gid, &fsGenericCallback); } + /** + * @brief Sync [chown](http://linux.die.net/man/2/chown). + * @param path Path, as described in the official documentation. + * @param uid UID, as described in the official documentation. + * @param gid GID, as described in the official documentation. + * @return A pair `{ ErrorEvent, FsEvent }`. + */ auto chownSync(std::string path, Uid uid, Gid gid) { auto req = get(); cleanupAndInvokeSync(&uv_fs_chown, parent(), req, path.data(), uid, gid); diff --git a/src/uvw/work.hpp b/src/uvw/work.hpp index d96a5263..4132b986 100644 --- a/src/uvw/work.hpp +++ b/src/uvw/work.hpp @@ -53,7 +53,7 @@ public: * * A valid instance of a `Task`, that is of type * `std::function`. * - * @return A pointer to the newly created handle. + * @return A pointer to the newly created request. */ template static std::shared_ptr create(Args&&... args) {