| 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 "bin/file_system_watcher.h" | 5 #include "bin/file_system_watcher.h" |
| 6 | 6 |
| 7 #include "bin/builtin.h" | 7 #include "bin/builtin.h" |
| 8 #include "bin/dartutils.h" | 8 #include "bin/dartutils.h" |
| 9 | 9 |
| 10 #include "include/dart_api.h" | 10 #include "include/dart_api.h" |
| 11 | 11 |
| 12 namespace dart { | 12 namespace dart { |
| 13 namespace bin { | 13 namespace bin { |
| 14 | 14 |
| 15 static const int kWatcherNativeField = 0; | |
| 16 | |
| 17 | |
| 18 void SetWatcherIdNativeField(Dart_Handle watcher, intptr_t id) { | |
| 19 ThrowIfError(Dart_SetNativeInstanceField(watcher, kWatcherNativeField, id)); | |
| 20 } | |
| 21 | |
| 22 | |
| 23 void GetWatcherIdNativeField(Dart_Handle watcher, intptr_t* id) { | |
| 24 ThrowIfError(Dart_GetNativeInstanceField(watcher, kWatcherNativeField, id)); | |
| 25 } | |
| 26 | |
| 27 void FUNCTION_NAME(FileSystemWatcher_IsSupported)(Dart_NativeArguments args) { | 15 void FUNCTION_NAME(FileSystemWatcher_IsSupported)(Dart_NativeArguments args) { |
| 28 Dart_SetReturnValue(args, Dart_NewBoolean(FileSystemWatcher::IsSupported())); | 16 Dart_SetReturnValue(args, Dart_NewBoolean(FileSystemWatcher::IsSupported())); |
| 29 } | 17 } |
| 30 | 18 |
| 19 |
| 20 void FUNCTION_NAME(FileSystemWatcher_InitWatcher)(Dart_NativeArguments args) { |
| 21 Dart_SetReturnValue(args, Dart_NewInteger(FileSystemWatcher::Init())); |
| 22 } |
| 23 |
| 24 |
| 25 void FUNCTION_NAME(FileSystemWatcher_CloseWatcher)(Dart_NativeArguments args) { |
| 26 intptr_t id = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0)); |
| 27 FileSystemWatcher::Close(id); |
| 28 } |
| 29 |
| 30 |
| 31 void FUNCTION_NAME(FileSystemWatcher_WatchPath)(Dart_NativeArguments args) { | 31 void FUNCTION_NAME(FileSystemWatcher_WatchPath)(Dart_NativeArguments args) { |
| 32 Dart_Handle watcher = Dart_GetNativeArgument(args, 0); | 32 intptr_t id = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0)); |
| 33 const char* path = DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1)); | 33 const char* path = DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1)); |
| 34 int events = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); | 34 int events = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); |
| 35 bool recursive = DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 3)); | 35 bool recursive = DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 3)); |
| 36 intptr_t id = FileSystemWatcher::WatchPath(path, events, recursive); | 36 intptr_t path_id = FileSystemWatcher::WatchPath(id, path, events, recursive); |
| 37 if (id == -1) { | 37 if (path_id == -1) { |
| 38 Dart_ThrowException(DartUtils::NewDartOSError()); | 38 Dart_ThrowException(DartUtils::NewDartOSError()); |
| 39 } else { | |
| 40 SetWatcherIdNativeField(watcher, id); | |
| 41 } | 39 } |
| 42 intptr_t socket_id = FileSystemWatcher::GetSocketId(id); | 40 Dart_SetReturnValue(args, Dart_NewInteger(path_id)); |
| 43 Dart_SetReturnValue(args, Dart_NewInteger(socket_id)); | |
| 44 } | 41 } |
| 45 | 42 |
| 46 | 43 |
| 47 void FUNCTION_NAME(FileSystemWatcher_UnwatchPath)(Dart_NativeArguments args) { | 44 void FUNCTION_NAME(FileSystemWatcher_UnwatchPath)(Dart_NativeArguments args) { |
| 48 Dart_Handle watcher = Dart_GetNativeArgument(args, 0); | 45 intptr_t id = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0)); |
| 49 intptr_t id; | 46 intptr_t path_id = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 1)); |
| 50 GetWatcherIdNativeField(watcher, &id); | 47 FileSystemWatcher::UnwatchPath(id, path_id); |
| 51 FileSystemWatcher::UnwatchPath(id); | |
| 52 } | 48 } |
| 53 | 49 |
| 54 | 50 |
| 55 void FUNCTION_NAME(FileSystemWatcher_ReadEvents)(Dart_NativeArguments args) { | 51 void FUNCTION_NAME(FileSystemWatcher_ReadEvents)(Dart_NativeArguments args) { |
| 56 Dart_Handle watcher = Dart_GetNativeArgument(args, 0); | 52 intptr_t id = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0)); |
| 57 intptr_t id; | 53 intptr_t path_id = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 1)); |
| 58 GetWatcherIdNativeField(watcher, &id); | 54 Dart_Handle handle = FileSystemWatcher::ReadEvents(id, path_id); |
| 59 Dart_Handle handle = FileSystemWatcher::ReadEvents(id); | |
| 60 ThrowIfError(handle); | 55 ThrowIfError(handle); |
| 61 Dart_SetReturnValue(args, handle); | 56 Dart_SetReturnValue(args, handle); |
| 62 } | 57 } |
| 63 | 58 |
| 59 |
| 60 void FUNCTION_NAME(FileSystemWatcher_GetSocketId)(Dart_NativeArguments args) { |
| 61 intptr_t id = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0)); |
| 62 intptr_t path_id = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 1)); |
| 63 int socket_id = FileSystemWatcher::GetSocketId(id, path_id); |
| 64 Dart_SetReturnValue(args, Dart_NewInteger(socket_id)); |
| 65 } |
| 66 |
| 64 } // namespace bin | 67 } // namespace bin |
| 65 } // namespace dart | 68 } // namespace dart |
| OLD | NEW |