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 #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 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 const wchar_t* name = StringUtilsWin::Utf8ToWide(path); | 42 const wchar_t* name = StringUtilsWin::Utf8ToWide(path); |
43 HANDLE dir = CreateFileW(name, | 43 HANDLE dir = CreateFileW(name, |
44 FILE_LIST_DIRECTORY, | 44 FILE_LIST_DIRECTORY, |
45 FILE_SHARE_READ | | 45 FILE_SHARE_READ | |
46 FILE_SHARE_WRITE | | 46 FILE_SHARE_WRITE | |
47 FILE_SHARE_DELETE, | 47 FILE_SHARE_DELETE, |
48 NULL, | 48 NULL, |
49 OPEN_EXISTING, | 49 OPEN_EXISTING, |
50 FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, | 50 FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, |
51 NULL); | 51 NULL); |
52 free(const_cast<wchar_t*>(name)); | |
53 | 52 |
54 if (dir == INVALID_HANDLE_VALUE) { | 53 if (dir == INVALID_HANDLE_VALUE) { |
55 return -1; | 54 return -1; |
56 } | 55 } |
57 | 56 |
58 int list_events = 0; | 57 int list_events = 0; |
59 if (events & (kCreate | kMove | kDelete)) { | 58 if (events & (kCreate | kMove | kDelete)) { |
60 list_events |= FILE_NOTIFY_CHANGE_FILE_NAME | | 59 list_events |= FILE_NOTIFY_CHANGE_FILE_NAME | |
61 FILE_NOTIFY_CHANGE_DIR_NAME; | 60 FILE_NOTIFY_CHANGE_DIR_NAME; |
62 } | 61 } |
(...skipping 23 matching lines...) Expand all Loading... |
86 } | 85 } |
87 | 86 |
88 | 87 |
89 Dart_Handle FileSystemWatcher::ReadEvents(intptr_t id, intptr_t path_id) { | 88 Dart_Handle FileSystemWatcher::ReadEvents(intptr_t id, intptr_t path_id) { |
90 USE(id); | 89 USE(id); |
91 const intptr_t kEventSize = sizeof(FILE_NOTIFY_INFORMATION); | 90 const intptr_t kEventSize = sizeof(FILE_NOTIFY_INFORMATION); |
92 DirectoryWatchHandle* dir = reinterpret_cast<DirectoryWatchHandle*>(path_id); | 91 DirectoryWatchHandle* dir = reinterpret_cast<DirectoryWatchHandle*>(path_id); |
93 intptr_t available = dir->Available(); | 92 intptr_t available = dir->Available(); |
94 intptr_t max_count = available / kEventSize + 1; | 93 intptr_t max_count = available / kEventSize + 1; |
95 Dart_Handle events = Dart_NewList(max_count); | 94 Dart_Handle events = Dart_NewList(max_count); |
96 uint8_t* buffer = new uint8_t[available]; | 95 uint8_t* buffer = Dart_ScopeAllocate(available); |
97 intptr_t bytes = dir->Read(buffer, available); | 96 intptr_t bytes = dir->Read(buffer, available); |
98 intptr_t offset = 0; | 97 intptr_t offset = 0; |
99 intptr_t i = 0; | 98 intptr_t i = 0; |
100 while (offset < bytes) { | 99 while (offset < bytes) { |
101 FILE_NOTIFY_INFORMATION* e = | 100 FILE_NOTIFY_INFORMATION* e = |
102 reinterpret_cast<FILE_NOTIFY_INFORMATION*>(buffer + offset); | 101 reinterpret_cast<FILE_NOTIFY_INFORMATION*>(buffer + offset); |
103 | 102 |
104 Dart_Handle event = Dart_NewList(5); | 103 Dart_Handle event = Dart_NewList(5); |
105 int mask = 0; | 104 int mask = 0; |
106 if (e->Action == FILE_ACTION_ADDED) mask |= kCreate; | 105 if (e->Action == FILE_ACTION_ADDED) mask |= kCreate; |
107 if (e->Action == FILE_ACTION_REMOVED) mask |= kDelete; | 106 if (e->Action == FILE_ACTION_REMOVED) mask |= kDelete; |
108 if (e->Action == FILE_ACTION_MODIFIED) mask |= kModifyContent; | 107 if (e->Action == FILE_ACTION_MODIFIED) mask |= kModifyContent; |
109 if (e->Action == FILE_ACTION_RENAMED_OLD_NAME) mask |= kMove; | 108 if (e->Action == FILE_ACTION_RENAMED_OLD_NAME) mask |= kMove; |
110 if (e->Action == FILE_ACTION_RENAMED_NEW_NAME) mask |= kMove; | 109 if (e->Action == FILE_ACTION_RENAMED_NEW_NAME) mask |= kMove; |
111 Dart_ListSetAt(event, 0, Dart_NewInteger(mask)); | 110 Dart_ListSetAt(event, 0, Dart_NewInteger(mask)); |
112 // Move events come in pairs. Just 'enable' by default. | 111 // Move events come in pairs. Just 'enable' by default. |
113 Dart_ListSetAt(event, 1, Dart_NewInteger(1)); | 112 Dart_ListSetAt(event, 1, Dart_NewInteger(1)); |
114 Dart_ListSetAt(event, 2, Dart_NewStringFromUTF16( | 113 Dart_ListSetAt(event, 2, Dart_NewStringFromUTF16( |
115 reinterpret_cast<uint16_t*>(e->FileName), e->FileNameLength / 2)); | 114 reinterpret_cast<uint16_t*>(e->FileName), e->FileNameLength / 2)); |
116 Dart_ListSetAt(event, 3, Dart_NewBoolean(true)); | 115 Dart_ListSetAt(event, 3, Dart_NewBoolean(true)); |
117 Dart_ListSetAt(event, 4, Dart_NewInteger(path_id)); | 116 Dart_ListSetAt(event, 4, Dart_NewInteger(path_id)); |
118 Dart_ListSetAt(events, i, event); | 117 Dart_ListSetAt(events, i, event); |
119 i++; | 118 i++; |
120 if (e->NextEntryOffset == 0) break; | 119 if (e->NextEntryOffset == 0) break; |
121 offset += e->NextEntryOffset; | 120 offset += e->NextEntryOffset; |
122 } | 121 } |
123 delete[] buffer; | |
124 return events; | 122 return events; |
125 } | 123 } |
126 | 124 |
127 } // namespace bin | 125 } // namespace bin |
128 } // namespace dart | 126 } // namespace dart |
129 | 127 |
130 #endif // defined(TARGET_OS_WINDOWS) | 128 #endif // defined(TARGET_OS_WINDOWS) |
OLD | NEW |