Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

windows: file watcher

  • Loading branch information...
Igor Zinkovsky
Igor Zinkovsky committed Sep 16, 2011
1 parent 12d3680 commit 1e0757ffda47c625b0f7feeeb91c399864787f9e
Showing with 675 additions and 2 deletions.
  1. +12 −1 include/uv-private/uv-win.h
  2. +37 −1 include/uv.h
  3. +382 −0 src/win/fs-event.c
  4. +8 −0 src/win/handle.c
  5. +8 −0 src/win/internal.h
  6. +4 −0 src/win/req.c
  7. +215 −0 test/test-fs-event.c
  8. +6 −0 test/test-list.h
  9. +3 −0 uv.gyp
@@ -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 { \
@@ -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 */

@@ -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__)
@@ -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 {
@@ -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 {
@@ -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 */
@@ -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 {
@@ -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;
};


@@ -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
}

0 comments on commit 1e0757f

Please sign in to comment.
You can’t perform that action at this time.