Mercurial > hg > easyhg
comparison src/fswatcher.cpp @ 585:fa242885a233 fswatcher
Partially working FSEvents implementation: ignores some file changes it should be taking into account, at the moment
author | Chris Cannam |
---|---|
date | Tue, 13 Mar 2012 17:58:17 +0000 |
parents | 09b9849b9800 |
children | 687d9e700e81 |
comparison
equal
deleted
inserted
replaced
584:09b9849b9800 | 585:fa242885a233 |
---|---|
26 #include "fswatcher.h" | 26 #include "fswatcher.h" |
27 #include "debug.h" | 27 #include "debug.h" |
28 | 28 |
29 #include <deque> | 29 #include <deque> |
30 | 30 |
31 //#define DEBUG_FSWATCHER 1 | 31 #define DEBUG_FSWATCHER 1 |
32 | 32 |
33 /* | 33 /* |
34 * Watching the filesystem is trickier than it seems at first glance. | 34 * Watching the filesystem is trickier than it seems at first glance. |
35 * | 35 * |
36 * We ideally should watch every directory, and every file that is | 36 * We ideally should watch every directory, and every file that is |
140 #endif | 140 #endif |
141 } | 141 } |
142 | 142 |
143 #ifdef Q_OS_MAC | 143 #ifdef Q_OS_MAC |
144 static void | 144 static void |
145 fsEventsCallback(FSEventStreamRef streamRef, | 145 fsEventsCallback(ConstFSEventStreamRef streamRef, |
146 void *clientCallBackInfo, | 146 void *clientCallBackInfo, |
147 int numEvents, | 147 size_t numEvents, |
148 const char *const eventPaths[], | 148 void *paths, |
149 const FSEventStreamEventFlags *eventFlags, | 149 const FSEventStreamEventFlags eventFlags[], |
150 const uint64_t *eventIDs) | 150 const FSEventStreamEventId eventIDs[]) |
151 { | 151 { |
152 FsWatcher *watcher = reinterpret_cast<FsWatcher *>(clientCallBackInfo); | |
153 const char *const *cpaths = reinterpret_cast<const char *const *>(paths); | |
154 for (size_t i = 0; i < numEvents; ++i) { | |
155 watcher->fsDirectoryChanged(QString::fromLocal8Bit(cpaths[i])); | |
156 } | |
152 } | 157 } |
153 #endif | 158 #endif |
154 | 159 |
155 void | 160 void |
156 FsWatcher::addWorkDirectory(QString path) | 161 FsWatcher::addWorkDirectory(QString path) |
157 { | 162 { |
158 #ifdef Q_OS_MAC | 163 #ifdef Q_OS_MAC |
164 | |
165 CFStringRef cfPath = CFStringCreateWithCharacters | |
166 (0, reinterpret_cast<const UniChar *>(path.unicode()), | |
167 path.length()); | |
168 | |
169 CFArrayRef cfPaths = CFArrayCreate(0, (const void **)&cfPath, 1, 0); | |
170 | |
171 FSEventStreamContext ctx = { 0, 0, 0, 0, 0 }; | |
172 ctx.info = this; | |
173 | |
159 FSEventStreamRef stream = | 174 FSEventStreamRef stream = |
160 FSEventStreamCreate(kCFAllocatorDefault, | 175 FSEventStreamCreate(kCFAllocatorDefault, |
161 (FSEventStreamCallback)&fsEventsCallback, | 176 &fsEventsCallback, |
162 this, | 177 &ctx, |
163 cfPaths, | 178 cfPaths, |
164 kFSEventStreamEventIdSinceNow, | 179 kFSEventStreamEventIdSinceNow, |
165 1.0, // latency, seconds | 180 1.0, // latency, seconds |
166 kFSEventStreamCreateFlagNone); | 181 kFSEventStreamCreateFlagNone); |
167 | 182 |
375 | 390 |
376 void | 391 void |
377 FsWatcher::debugPrint() | 392 FsWatcher::debugPrint() |
378 { | 393 { |
379 #ifdef DEBUG_FSWATCHER | 394 #ifdef DEBUG_FSWATCHER |
395 #ifndef Q_OS_MAC | |
380 std::cerr << "FsWatcher: Now watching " << m_watcher.directories().size() | 396 std::cerr << "FsWatcher: Now watching " << m_watcher.directories().size() |
381 << " directories and " << m_watcher.files().size() | 397 << " directories and " << m_watcher.files().size() |
382 << " files" << std::endl; | 398 << " files" << std::endl; |
383 #endif | 399 #endif |
384 } | 400 #endif |
401 } |