diff --git a/src/uvw/fs.hpp b/src/uvw/fs.hpp index 5647945b..3ad46d3d 100644 --- a/src/uvw/fs.hpp +++ b/src/uvw/fs.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include "event.hpp" #include "request.hpp" @@ -15,12 +16,48 @@ namespace uvw { class Fs final: public Request { static void fsCallback(uv_fs_t *req) { - // TODO + // TODO type + /* + Fs &fs = *(static_cast(req->data)); + + auto ptr = res.shared_from_this(); + (void)ptr; + + res.reset(); + + if(req->result) { + res.publish(ErrorEvent{status}); + } else { + res.publish(FsEvent{}); + } + */ + } + + static void fsReadCallback(uv_fs_t *req) { + // TODO - uv_fs_read callback + } + + static void fsWriteCallback(uv_fs_t *req) { + // TODO - uv_fs_write callback + } + + static void fsStatCallback(uv_fs_t *req) { + // TODO - uv_fs_stat callback + } + + static void fsReadlinkCallback(uv_fs_t *req) { + // TODO - uv_fs_readlink callback } using Request::Request; public: + using Time = std::chrono::seconds; + + using Flags = int; + using Mode = int; + using Offset = int64_t; + template static std::shared_ptr create(Args&&... args) { return std::shared_ptr{new Fs{std::forward(args)...}}; @@ -35,7 +72,12 @@ public: } // TODO uv_fs_close (sync (cb null)) - // TODO uv_fs_open (sync (cb null)/async) + + void open(std::string path, Flags flags, Mode mode) { + invoke(&uv_fs_open, parent(), get(), path.data(), flags, mode, &fsCallback); + } + + // TODO uv_fs_open (sync (cb null)) // TODO uv_fs_read (sync (cb null)/async) void unlink(std::string path) { @@ -44,19 +86,34 @@ public: // TODO uv_fs_unlink (sync (cb null)) // TODO uv_fs_write (sync (cb null)/async) - // TODO uv_fs_mkdir (sync (cb null)/async) - // TODO uv_fs_mkdtemp (sync (cb null)/async) + + void mkdir(std::string path, Mode mode) { + invoke(&uv_fs_mkdir, parent(), get(), path.data(), mode, &fsCallback); + } + + // TODO uv_fs_mkdir (sync (cb null)) + + void mkdtemp(std::string tpl, Mode mode) { + invoke(&uv_fs_mkdtemp, parent(), get(), tpl.data(), &fsCallback); + } + + // TODO uv_fs_mkdtemp (sync (cb null)) void rmdir(std::string path) { invoke(&uv_fs_rmdir, parent(), get(), path.data(), &fsCallback); } // TODO uv_fs_rmdir (sync (cb null)) - // TODO uv_fs_scandir (sync (cb null)/async) + + void scandir(std::string path, Flags flags) { + invoke(&uv_fs_scandir, parent(), get(), path.data(), flags, &fsCallback); + } + + // TODO uv_fs_scandir (sync (cb null)) // TODO uv_fs_scandir_next (sync (cb null)/async) void stat(std::string path) { - invoke(&uv_fs_stat, parent(), get(), path.data(), &fsCallback); + invoke(&uv_fs_stat, parent(), get(), path.data(), &fsStatCallback); } // TODO uv_fs_stat (sync (cb null)) @@ -72,19 +129,84 @@ public: } // TODO uv_fs_lstat (sync (cb null)) - // TODO uv_fs_rename (sync (cb null)/async) - // TODO uv_fs_fsync (sync (cb null)/async) - // TODO uv_fs_fdatasync (sync (cb null)/async) - // TODO uv_fs_ftruncate (sync (cb null)/async) + + void rename(std::string old, std::string path) { + invoke(&uv_fs_rename, parent(), get(), old.data(), path.data(), &fsCallback); + } + + // TODO uv_fs_rename (sync (cb null)) + + void fsync(FileHandle file) { + invoke(&uv_fs_fsync, parent(), get(), file, &fsCallback); + } + + // TODO uv_fs_fsync (sync (cb null)) + + void fdatasync(FileHandle file) { + invoke(&uv_fs_fdatasync, parent(), get(), file, &fsCallback); + } + + // TODO uv_fs_fdatasync (sync (cb null)) + + void ftruncate(FileHandle file, Offset offset) { + invoke(&uv_fs_ftruncate, parent(), get(), file, offset, &fsCallback); + } + + // TODO uv_fs_ftruncate (sync (cb null)) // TODO uv_fs_sendfile (sync (cb null)/async) - // TODO uv_fs_access (sync (cb null)/async) - // TODO uv_fs_chmod (sync (cb null)/async) - // TODO uv_fs_fchmod (sync (cb null)/async) - // TODO uv_fs_utime (sync (cb null)/async) - // TODO uv_fs_futime (sync (cb null)/async) - // TODO uv_fs_link (sync (cb null)/async) - // TODO uv_fs_symlink (sync (cb null)/async) - // TODO uv_fs_readlink (sync (cb null)/async) + + void access(std::string path, Mode mode) { + invoke(&uv_fs_access, parent(), get(), path.data(), mode, &fsCallback); + } + + // TODO uv_fs_access (sync (cb null)) + + void chmod(std::string path, Mode mode) { + invoke(&uv_fs_chmod, parent(), get(), path.data(), mode, &fsCallback); + } + + // TODO uv_fs_chmod (sync (cb null)) + + void fchmod(FileHandle file, Mode mode) { + invoke(&uv_fs_fchmod, parent(), get(), file, mode, &fsCallback); + } + + // TODO uv_fs_fchmod (sync (cb null)) + + void utime(std::string path, Time atime, Time mtime) { + invoke(&uv_fs_utime, parent(), get(), path.data(), atime.count(), mtime.count(), &fsCallback); + } + + // TODO uv_fs_utime (sync (cb null)) + + void utime(FileHandle file, Time atime, Time mtime) { + invoke(&uv_fs_futime, parent(), get(), file, atime.count(), mtime.count(), &fsCallback); + } + + // TODO uv_fs_futime (sync (cb null)) + + void link(std::string old, std::string path) { + invoke(&uv_fs_link, parent(), get(), old.data(), path.data(), &fsCallback); + } + + // TODO uv_fs_link (sync (cb null)) + + void symlink(std::string old, std::string path, Flags flags) { + invoke(&uv_fs_symlink, parent(), get(), old.data(), path.data(), flags, &fsCallback); + } + + // TODO uv_fs_symlink (sync (cb null)) + + void readlink(std::string path) { + invoke(&uv_fs_readlink, parent(), get(), path.data(), &fsReadlinkCallback); + } + + // TODO uv_fs_readlink (sync (cb null)) + + void realpath(std::string path) { + invoke(&uv_fs_realpath, parent(), get(), path.data(), &fsCallback); + } + // TODO uv_fs_realpath (sync (cb null)/async) void chown(std::string path, Uid uid, Gid gid) {