| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #if !defined(DART_IO_DISABLED) | 5 #if !defined(DART_IO_DISABLED) |
| 6 | 6 |
| 7 #include "platform/globals.h" | 7 #include "platform/globals.h" |
| 8 #if defined(HOST_OS_MACOS) | 8 #if defined(HOST_OS_MACOS) |
| 9 | 9 |
| 10 #include "bin/file_system_watcher.h" | 10 #include "bin/file_system_watcher.h" |
| 11 | 11 |
| 12 #if !HOST_OS_IOS | 12 #if !HOST_OS_IOS |
| 13 | 13 |
| 14 #include <CoreServices/CoreServices.h> // NOLINT |
| 14 #include <errno.h> // NOLINT | 15 #include <errno.h> // NOLINT |
| 15 #include <fcntl.h> // NOLINT | 16 #include <fcntl.h> // NOLINT |
| 16 #include <unistd.h> // NOLINT | 17 #include <unistd.h> // NOLINT |
| 17 #include <CoreServices/CoreServices.h> // NOLINT | |
| 18 | 18 |
| 19 #include "bin/eventhandler.h" | 19 #include "bin/eventhandler.h" |
| 20 #include "bin/fdutils.h" | 20 #include "bin/fdutils.h" |
| 21 #include "bin/file.h" | 21 #include "bin/file.h" |
| 22 #include "bin/socket.h" | 22 #include "bin/socket.h" |
| 23 #include "bin/thread.h" | 23 #include "bin/thread.h" |
| 24 #include "platform/signal_blocker.h" | 24 #include "platform/signal_blocker.h" |
| 25 | 25 |
| 26 #ifndef MAC_OS_X_VERSION_10_7 | 26 #ifndef MAC_OS_X_VERSION_10_7 |
| 27 enum { kFSEventStreamCreateFlagFileEvents = 0x00000010 }; | 27 enum { kFSEventStreamCreateFlagFileEvents = 0x00000010 }; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 45 | 45 |
| 46 union FSEvent { | 46 union FSEvent { |
| 47 struct { | 47 struct { |
| 48 uint32_t exists; | 48 uint32_t exists; |
| 49 uint32_t flags; | 49 uint32_t flags; |
| 50 char path[PATH_MAX]; | 50 char path[PATH_MAX]; |
| 51 } data; | 51 } data; |
| 52 uint8_t bytes[PATH_MAX + 8]; | 52 uint8_t bytes[PATH_MAX + 8]; |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 | |
| 56 class FSEventsWatcher { | 55 class FSEventsWatcher { |
| 57 public: | 56 public: |
| 58 class Node { | 57 class Node { |
| 59 public: | 58 public: |
| 60 Node(FSEventsWatcher* watcher, | 59 Node(FSEventsWatcher* watcher, |
| 61 char* base_path, | 60 char* base_path, |
| 62 int read_fd, | 61 int read_fd, |
| 63 int write_fd, | 62 int write_fd, |
| 64 bool recursive) | 63 bool recursive) |
| 65 : watcher_(watcher), | 64 : watcher_(watcher), |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 intptr_t base_path_length_; | 169 intptr_t base_path_length_; |
| 171 CFStringRef path_ref_; | 170 CFStringRef path_ref_; |
| 172 int read_fd_; | 171 int read_fd_; |
| 173 int write_fd_; | 172 int write_fd_; |
| 174 bool recursive_; | 173 bool recursive_; |
| 175 FSEventStreamRef ref_; | 174 FSEventStreamRef ref_; |
| 176 | 175 |
| 177 DISALLOW_COPY_AND_ASSIGN(Node); | 176 DISALLOW_COPY_AND_ASSIGN(Node); |
| 178 }; | 177 }; |
| 179 | 178 |
| 180 | |
| 181 FSEventsWatcher() : run_loop_(0) { Start(); } | 179 FSEventsWatcher() : run_loop_(0) { Start(); } |
| 182 | 180 |
| 183 void Start() { | 181 void Start() { |
| 184 Thread::Start(Run, reinterpret_cast<uword>(this)); | 182 Thread::Start(Run, reinterpret_cast<uword>(this)); |
| 185 monitor_.Enter(); | 183 monitor_.Enter(); |
| 186 while (run_loop_ == NULL) { | 184 while (run_loop_ == NULL) { |
| 187 monitor_.Wait(Monitor::kNoTimeout); | 185 monitor_.Wait(Monitor::kNoTimeout); |
| 188 } | 186 } |
| 189 monitor_.Exit(); | 187 monitor_.Exit(); |
| 190 } | 188 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 } | 290 } |
| 293 } | 291 } |
| 294 | 292 |
| 295 Monitor monitor_; | 293 Monitor monitor_; |
| 296 CFRunLoopRef run_loop_; | 294 CFRunLoopRef run_loop_; |
| 297 ThreadId threadId_; | 295 ThreadId threadId_; |
| 298 | 296 |
| 299 DISALLOW_COPY_AND_ASSIGN(FSEventsWatcher); | 297 DISALLOW_COPY_AND_ASSIGN(FSEventsWatcher); |
| 300 }; | 298 }; |
| 301 | 299 |
| 302 | |
| 303 #define kCFCoreFoundationVersionNumber10_7 635.00 | 300 #define kCFCoreFoundationVersionNumber10_7 635.00 |
| 304 bool FileSystemWatcher::IsSupported() { | 301 bool FileSystemWatcher::IsSupported() { |
| 305 return kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_7; | 302 return kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_7; |
| 306 } | 303 } |
| 307 | 304 |
| 308 | |
| 309 intptr_t FileSystemWatcher::Init() { | 305 intptr_t FileSystemWatcher::Init() { |
| 310 return reinterpret_cast<intptr_t>(new FSEventsWatcher()); | 306 return reinterpret_cast<intptr_t>(new FSEventsWatcher()); |
| 311 } | 307 } |
| 312 | 308 |
| 313 | |
| 314 void FileSystemWatcher::Close(intptr_t id) { | 309 void FileSystemWatcher::Close(intptr_t id) { |
| 315 delete reinterpret_cast<FSEventsWatcher*>(id); | 310 delete reinterpret_cast<FSEventsWatcher*>(id); |
| 316 } | 311 } |
| 317 | 312 |
| 318 | |
| 319 intptr_t FileSystemWatcher::WatchPath(intptr_t id, | 313 intptr_t FileSystemWatcher::WatchPath(intptr_t id, |
| 320 const char* path, | 314 const char* path, |
| 321 int events, | 315 int events, |
| 322 bool recursive) { | 316 bool recursive) { |
| 323 FSEventsWatcher* watcher = reinterpret_cast<FSEventsWatcher*>(id); | 317 FSEventsWatcher* watcher = reinterpret_cast<FSEventsWatcher*>(id); |
| 324 return reinterpret_cast<intptr_t>(watcher->AddPath(path, events, recursive)); | 318 return reinterpret_cast<intptr_t>(watcher->AddPath(path, events, recursive)); |
| 325 } | 319 } |
| 326 | 320 |
| 327 | |
| 328 void FileSystemWatcher::UnwatchPath(intptr_t id, intptr_t path_id) { | 321 void FileSystemWatcher::UnwatchPath(intptr_t id, intptr_t path_id) { |
| 329 USE(id); | 322 USE(id); |
| 330 delete reinterpret_cast<FSEventsWatcher::Node*>(path_id); | 323 delete reinterpret_cast<FSEventsWatcher::Node*>(path_id); |
| 331 } | 324 } |
| 332 | 325 |
| 333 | |
| 334 intptr_t FileSystemWatcher::GetSocketId(intptr_t id, intptr_t path_id) { | 326 intptr_t FileSystemWatcher::GetSocketId(intptr_t id, intptr_t path_id) { |
| 335 return reinterpret_cast<FSEventsWatcher::Node*>(path_id)->read_fd(); | 327 return reinterpret_cast<FSEventsWatcher::Node*>(path_id)->read_fd(); |
| 336 } | 328 } |
| 337 | 329 |
| 338 | |
| 339 Dart_Handle FileSystemWatcher::ReadEvents(intptr_t id, intptr_t path_id) { | 330 Dart_Handle FileSystemWatcher::ReadEvents(intptr_t id, intptr_t path_id) { |
| 340 intptr_t fd = GetSocketId(id, path_id); | 331 intptr_t fd = GetSocketId(id, path_id); |
| 341 intptr_t avail = FDUtils::AvailableBytes(fd); | 332 intptr_t avail = FDUtils::AvailableBytes(fd); |
| 342 int count = avail / sizeof(FSEvent); | 333 int count = avail / sizeof(FSEvent); |
| 343 if (count <= 0) { | 334 if (count <= 0) { |
| 344 return Dart_NewList(0); | 335 return Dart_NewList(0); |
| 345 } | 336 } |
| 346 Dart_Handle events = Dart_NewList(count); | 337 Dart_Handle events = Dart_NewList(count); |
| 347 FSEvent e; | 338 FSEvent e; |
| 348 for (int i = 0; i < count; i++) { | 339 for (int i = 0; i < count; i++) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 #else // !HOST_OS_IOS | 391 #else // !HOST_OS_IOS |
| 401 | 392 |
| 402 namespace dart { | 393 namespace dart { |
| 403 namespace bin { | 394 namespace bin { |
| 404 | 395 |
| 405 // FSEvents are unavailable on iOS. Stub out related methods | 396 // FSEvents are unavailable on iOS. Stub out related methods |
| 406 Dart_Handle FileSystemWatcher::ReadEvents(intptr_t id, intptr_t path_id) { | 397 Dart_Handle FileSystemWatcher::ReadEvents(intptr_t id, intptr_t path_id) { |
| 407 return DartUtils::NewDartOSError(); | 398 return DartUtils::NewDartOSError(); |
| 408 } | 399 } |
| 409 | 400 |
| 410 | |
| 411 intptr_t FileSystemWatcher::GetSocketId(intptr_t id, intptr_t path_id) { | 401 intptr_t FileSystemWatcher::GetSocketId(intptr_t id, intptr_t path_id) { |
| 412 return -1; | 402 return -1; |
| 413 } | 403 } |
| 414 | 404 |
| 415 | |
| 416 bool FileSystemWatcher::IsSupported() { | 405 bool FileSystemWatcher::IsSupported() { |
| 417 return false; | 406 return false; |
| 418 } | 407 } |
| 419 | 408 |
| 420 | |
| 421 void FileSystemWatcher::UnwatchPath(intptr_t id, intptr_t path_id) {} | 409 void FileSystemWatcher::UnwatchPath(intptr_t id, intptr_t path_id) {} |
| 422 | 410 |
| 423 | |
| 424 intptr_t FileSystemWatcher::Init() { | 411 intptr_t FileSystemWatcher::Init() { |
| 425 return -1; | 412 return -1; |
| 426 } | 413 } |
| 427 | 414 |
| 428 | |
| 429 void FileSystemWatcher::Close(intptr_t id) {} | 415 void FileSystemWatcher::Close(intptr_t id) {} |
| 430 | 416 |
| 431 | |
| 432 intptr_t FileSystemWatcher::WatchPath(intptr_t id, | 417 intptr_t FileSystemWatcher::WatchPath(intptr_t id, |
| 433 const char* path, | 418 const char* path, |
| 434 int events, | 419 int events, |
| 435 bool recursive) { | 420 bool recursive) { |
| 436 return -1; | 421 return -1; |
| 437 } | 422 } |
| 438 | 423 |
| 439 } // namespace bin | 424 } // namespace bin |
| 440 } // namespace dart | 425 } // namespace dart |
| 441 | 426 |
| 442 #endif // !HOST_OS_IOS | 427 #endif // !HOST_OS_IOS |
| 443 #endif // defined(HOST_OS_MACOS) | 428 #endif // defined(HOST_OS_MACOS) |
| 444 | 429 |
| 445 #endif // !defined(DART_IO_DISABLED) | 430 #endif // !defined(DART_IO_DISABLED) |
| OLD | NEW |