Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(983)

Side by Side Diff: runtime/bin/file_system_watcher_win.cc

Issue 98773002: Rewrite file-system-watcher to better handle the different system APIs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Last few fixes found by tests Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_WINDOWS) 6 #if defined(TARGET_OS_WINDOWS)
7 7
8 #include "bin/file_system_watcher.h" 8 #include "bin/file_system_watcher.h"
9 #include "bin/eventhandler.h" 9 #include "bin/eventhandler.h"
10 10
11 #include <WinIoCtl.h> // NOLINT 11 #include <WinIoCtl.h> // NOLINT
12 12
13 #include "bin/builtin.h" 13 #include "bin/builtin.h"
14 #include "bin/log.h" 14 #include "bin/log.h"
15 #include "bin/utils.h" 15 #include "bin/utils.h"
16 16
17 17
18 namespace dart { 18 namespace dart {
19 namespace bin { 19 namespace bin {
20 20
21 bool FileSystemWatcher::IsSupported() { 21 bool FileSystemWatcher::IsSupported() {
22 return true; 22 return true;
23 } 23 }
24 24
25 25
26 intptr_t FileSystemWatcher::WatchPath(const char* path, 26 intptr_t FileSystemWatcher::Init() {
27 return 0;
28 }
29
30
31 void FileSystemWatcher::Close(intptr_t id) {
32 USE(id);
33 }
34
35
36 intptr_t FileSystemWatcher::WatchPath(intptr_t id,
37 const char* path,
27 int events, 38 int events,
28 bool recursive) { 39 bool recursive) {
40 USE(id);
29 const wchar_t* name = StringUtils::Utf8ToWide(path); 41 const wchar_t* name = StringUtils::Utf8ToWide(path);
30 HANDLE dir = CreateFileW(name, 42 HANDLE dir = CreateFileW(name,
31 FILE_LIST_DIRECTORY, 43 FILE_LIST_DIRECTORY,
32 FILE_SHARE_READ | 44 FILE_SHARE_READ |
33 FILE_SHARE_WRITE | 45 FILE_SHARE_WRITE |
34 FILE_SHARE_DELETE, 46 FILE_SHARE_DELETE,
35 NULL, 47 NULL,
36 OPEN_EXISTING, 48 OPEN_EXISTING,
37 FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 49 FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED,
38 NULL); 50 NULL);
(...skipping 13 matching lines...) Expand all
52 DirectoryWatchHandle* handle = 64 DirectoryWatchHandle* handle =
53 new DirectoryWatchHandle(dir, list_events, recursive); 65 new DirectoryWatchHandle(dir, list_events, recursive);
54 // Issue a read directly, to be sure events are tracked from now on. This is 66 // Issue a read directly, to be sure events are tracked from now on. This is
55 // okay, since in Dart, we create the socket and start reading immidiately. 67 // okay, since in Dart, we create the socket and start reading immidiately.
56 handle->EnsureInitialized(EventHandler::delegate()); 68 handle->EnsureInitialized(EventHandler::delegate());
57 handle->IssueRead(); 69 handle->IssueRead();
58 return reinterpret_cast<intptr_t>(handle); 70 return reinterpret_cast<intptr_t>(handle);
59 } 71 }
60 72
61 73
62 void FileSystemWatcher::UnwatchPath(intptr_t id) { 74 void FileSystemWatcher::UnwatchPath(intptr_t id, intptr_t path_id) {
63 // Nothing to do. 75 USE(id);
76 USE(path_id);
64 } 77 }
65 78
66 79
67 intptr_t FileSystemWatcher::GetSocketId(intptr_t id) { 80 intptr_t FileSystemWatcher::GetSocketId(intptr_t id, intptr_t path_id) {
68 return id; 81 USE(id);
82 return path_id;
69 } 83 }
70 84
71 85
72 Dart_Handle FileSystemWatcher::ReadEvents(intptr_t id) { 86 Dart_Handle FileSystemWatcher::ReadEvents(intptr_t id, intptr_t path_id) {
87 USE(id);
73 const intptr_t kEventSize = sizeof(FILE_NOTIFY_INFORMATION); 88 const intptr_t kEventSize = sizeof(FILE_NOTIFY_INFORMATION);
74 DirectoryWatchHandle* dir = reinterpret_cast<DirectoryWatchHandle*>(id); 89 DirectoryWatchHandle* dir = reinterpret_cast<DirectoryWatchHandle*>(path_id);
75 intptr_t available = dir->Available(); 90 intptr_t available = dir->Available();
76 intptr_t max_count = available / kEventSize + 1; 91 intptr_t max_count = available / kEventSize + 1;
77 Dart_Handle events = Dart_NewList(max_count); 92 Dart_Handle events = Dart_NewList(max_count);
78 uint8_t* buffer = new uint8_t[available]; 93 uint8_t* buffer = new uint8_t[available];
79 intptr_t bytes = dir->Read(buffer, available); 94 intptr_t bytes = dir->Read(buffer, available);
80 intptr_t offset = 0; 95 intptr_t offset = 0;
81 intptr_t i = 0; 96 intptr_t i = 0;
82 while (offset < bytes) { 97 while (offset < bytes) {
83 FILE_NOTIFY_INFORMATION* e = 98 FILE_NOTIFY_INFORMATION* e =
84 reinterpret_cast<FILE_NOTIFY_INFORMATION*>(buffer + offset); 99 reinterpret_cast<FILE_NOTIFY_INFORMATION*>(buffer + offset);
85 100
86 Dart_Handle event = Dart_NewList(4); 101 Dart_Handle event = Dart_NewList(5);
87 int mask = 0; 102 int mask = 0;
88 if (e->Action == FILE_ACTION_ADDED) mask |= kCreate; 103 if (e->Action == FILE_ACTION_ADDED) mask |= kCreate;
89 if (e->Action == FILE_ACTION_REMOVED) mask |= kDelete; 104 if (e->Action == FILE_ACTION_REMOVED) mask |= kDelete;
90 if (e->Action == FILE_ACTION_MODIFIED) mask |= kModifyContent; 105 if (e->Action == FILE_ACTION_MODIFIED) mask |= kModifyContent;
91 if (e->Action == FILE_ACTION_RENAMED_OLD_NAME) mask |= kMove; 106 if (e->Action == FILE_ACTION_RENAMED_OLD_NAME) mask |= kMove;
92 if (e->Action == FILE_ACTION_RENAMED_NEW_NAME) mask |= kMove; 107 if (e->Action == FILE_ACTION_RENAMED_NEW_NAME) mask |= kMove;
93 Dart_ListSetAt(event, 0, Dart_NewInteger(mask)); 108 Dart_ListSetAt(event, 0, Dart_NewInteger(mask));
94 // Move events come in pairs. Just 'enable' by default. 109 // Move events come in pairs. Just 'enable' by default.
95 Dart_ListSetAt(event, 1, Dart_NewInteger(1)); 110 Dart_ListSetAt(event, 1, Dart_NewInteger(1));
96 Dart_ListSetAt(event, 2, Dart_NewStringFromUTF16( 111 Dart_ListSetAt(event, 2, Dart_NewStringFromUTF16(
97 reinterpret_cast<uint16_t*>(e->FileName), e->FileNameLength / 2)); 112 reinterpret_cast<uint16_t*>(e->FileName), e->FileNameLength / 2));
98 Dart_ListSetAt(event, 3, Dart_NewBoolean(true)); 113 Dart_ListSetAt(event, 3, Dart_NewBoolean(true));
114 Dart_ListSetAt(event, 4, Dart_NewInteger(path_id));
99 Dart_ListSetAt(events, i, event); 115 Dart_ListSetAt(events, i, event);
100 i++; 116 i++;
101 if (e->NextEntryOffset == 0) break; 117 if (e->NextEntryOffset == 0) break;
102 offset += e->NextEntryOffset; 118 offset += e->NextEntryOffset;
103 } 119 }
104 delete[] buffer; 120 delete[] buffer;
105 return events; 121 return events;
106 } 122 }
107 123
108 } // namespace bin 124 } // namespace bin
109 } // namespace dart 125 } // namespace dart
110 126
111 #endif // defined(TARGET_OS_WINDOWS) 127 #endif // defined(TARGET_OS_WINDOWS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698