Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
windows: file watcher
  • Loading branch information
Igor Zinkovsky committed Sep 21, 2011
1 parent 12d3680 commit 1e0757f
Show file tree
Hide file tree
Showing 9 changed files with 675 additions and 2 deletions.
13 changes: 12 additions & 1 deletion include/uv-private/uv-win.h
Expand Up @@ -86,7 +86,8 @@ RB_HEAD(uv_timer_tree_s, uv_timer_s);
UV_GETADDRINFO_REQ, \
UV_PROCESS_EXIT, \
UV_PROCESS_CLOSE, \
UV_UDP_RECV
UV_UDP_RECV, \
UV_FS_EVENT_REQ

#define UV_REQ_PRIVATE_FIELDS \
union { \
Expand Down Expand Up @@ -261,6 +262,16 @@ RB_HEAD(uv_timer_tree_s, uv_timer_s);

#define UV_WORK_PRIVATE_FIELDS \

#define UV_FS_EVENT_PRIVATE_FIELDS \
struct uv_fs_event_req_s { \
UV_REQ_FIELDS \
} req; \
HANDLE dir_handle; \
int req_pending; \
uv_fs_event_cb cb; \
wchar_t* filew; \
int is_path_dir; \
char* buffer;

#define UV_TTY_PRIVATE_FIELDS /* empty */

Expand Down
38 changes: 37 additions & 1 deletion include/uv.h
Expand Up @@ -65,6 +65,8 @@ typedef struct uv_write_s uv_write_t;
typedef struct uv_connect_s uv_connect_t;
typedef struct uv_udp_send_s uv_udp_send_t;
typedef struct uv_fs_s uv_fs_t;
/* uv_fs_event_t is a subclass of uv_handle_t. */
typedef struct uv_fs_event_s uv_fs_event_t;
typedef struct uv_work_s uv_work_t;

#if defined(__unix__) || defined(__POSIX__) || defined(__APPLE__)
Expand Down Expand Up @@ -137,6 +139,15 @@ typedef void (*uv_fs_cb)(uv_fs_t* req);
typedef void (*uv_work_cb)(uv_work_t* req);
typedef void (*uv_after_work_cb)(uv_work_t* req);

/*
* This will be called repeatedly after the uv_fs_event_t is initialized.
* If uv_fs_event_t was initialized with a directory the filename parameter
* will be a relative path to a file contained in the directory.
* The events paramenter is an ORed mask of enum uv_fs_event elements.
*/
typedef void (*uv_fs_event_cb)(uv_fs_event_t* handle, const char* filename,
int events, int status);


/* Expand this list if necessary. */
typedef enum {
Expand Down Expand Up @@ -201,7 +212,8 @@ typedef enum {
UV_ASYNC,
UV_ARES_TASK,
UV_ARES_EVENT,
UV_PROCESS
UV_PROCESS,
UV_FS_EVENT
} uv_handle_type;

typedef enum {
Expand Down Expand Up @@ -1002,6 +1014,27 @@ int uv_fs_fchown(uv_loop_t* loop, uv_fs_t* req, uv_file file, int uid,
int gid, uv_fs_cb cb);


enum uv_fs_event {
UV_RENAME = 1,
UV_CHANGE = 2
};


struct uv_fs_event_s {
UV_HANDLE_FIELDS
char* filename;
UV_FS_EVENT_PRIVATE_FIELDS
};


/*
* If filename is a directory then we will watch for all events in that
* directory. If filename is a file - we will only get events from that
* file. Subdirectories are not watched.
*/
int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle,
const char* filename, uv_fs_event_cb cb);

/* Utility */

/* Convert string ip addresses to binary structures */
Expand Down Expand Up @@ -1037,6 +1070,7 @@ union uv_any_handle {
uv_async_t async;
uv_timer_t timer;
uv_getaddrinfo_t getaddrinfo;
uv_fs_event_t fs_event;
};

union uv_any_req {
Expand Down Expand Up @@ -1064,6 +1098,7 @@ struct uv_counters_s {
uint64_t async_init;
uint64_t timer_init;
uint64_t process_init;
uint64_t fs_event_init;
};


Expand Down Expand Up @@ -1097,6 +1132,7 @@ struct uv_loop_s {
#undef UV_GETADDRINFO_PRIVATE_FIELDS
#undef UV_FS_REQ_PRIVATE_FIELDS
#undef UV_WORK_PRIVATE_FIELDS
#undef UV_FS_EVENT_PRIVATE_FIELDS

#ifdef __cplusplus
}
Expand Down

0 comments on commit 1e0757f

Please sign in to comment.