1 |
3a515b92
|
cagy
|
/*
|
2 |
|
|
** © 2014 by Philipp Dunkel <pip@pipobscure.com>
|
3 |
|
|
** Licensed under MIT License.
|
4 |
|
|
*/
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
void async_propagate(uv_async_t *async) {
|
8 |
|
|
if (!async->data) return;
|
9 |
|
|
FSEvents *fse = (FSEvents *)async->data;
|
10 |
|
|
CFIndex idx, cnt;
|
11 |
|
|
fse_event *event;
|
12 |
|
|
char pathbuf[1024];
|
13 |
|
|
const char *pathptr = NULL;
|
14 |
|
|
uv_mutex_lock(&fse->mutex);
|
15 |
|
|
cnt = fse->events.size();
|
16 |
|
|
for (idx=0; idx<cnt; idx++) {
|
17 |
|
|
event = fse->events.at(idx);
|
18 |
|
|
if (event == NULL) continue;
|
19 |
|
|
pathptr = CFStringGetCStringPtr(event->path, kCFStringEncodingUTF8);
|
20 |
|
|
if (!pathptr) CFStringGetCString(event->path, pathbuf, 1024, kCFStringEncodingUTF8);
|
21 |
|
|
fse->emitEvent(pathptr ? pathptr : pathbuf, event->flags, event->id);
|
22 |
|
|
delete event;
|
23 |
|
|
}
|
24 |
|
|
if (cnt>0) fse->events.clear();
|
25 |
|
|
uv_mutex_unlock(&fse->mutex);
|
26 |
|
|
}
|
27 |
|
|
|
28 |
|
|
void FSEvents::asyncStart() {
|
29 |
|
|
if (async.data == this) return;
|
30 |
|
|
async.data = this;
|
31 |
|
|
uv_async_init(uv_default_loop(), &async, (uv_async_cb) async_propagate);
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
void FSEvents::asyncTrigger() {
|
35 |
|
|
if (async.data != this) return;
|
36 |
|
|
uv_async_send(&async);
|
37 |
|
|
}
|
38 |
|
|
|
39 |
|
|
void FSEvents::asyncStop() {
|
40 |
|
|
if (async.data != this) return;
|
41 |
|
|
async.data = NULL;
|
42 |
|
|
uv_close((uv_handle_t *) &async, NULL);
|
43 |
|
|
}
|