OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 #include "bin/file_system_watcher.h" |
| 6 |
| 7 #include "bin/builtin.h" |
| 8 #include "bin/dartutils.h" |
| 9 |
| 10 #include "include/dart_api.h" |
| 11 |
| 12 namespace dart { |
| 13 namespace bin { |
| 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 |
| 28 void FUNCTION_NAME(FileSystemWatcher_WatchPath)(Dart_NativeArguments args) { |
| 29 Dart_Handle watcher = Dart_GetNativeArgument(args, 0); |
| 30 const char* path = DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1)); |
| 31 int events = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); |
| 32 bool recursive = DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 3)); |
| 33 intptr_t id = FileSystemWatcher::WatchPath(path, events, recursive); |
| 34 if (id == -1) { |
| 35 Dart_PropagateError(DartUtils::NewDartOSError()); |
| 36 } else { |
| 37 SetWatcherIdNativeField(watcher, id); |
| 38 } |
| 39 intptr_t socket_id = FileSystemWatcher::GetSocketId(id); |
| 40 Dart_SetReturnValue(args, Dart_NewInteger(socket_id)); |
| 41 } |
| 42 |
| 43 |
| 44 void FUNCTION_NAME(FileSystemWatcher_UnwatchPath)(Dart_NativeArguments args) { |
| 45 Dart_Handle watcher = Dart_GetNativeArgument(args, 0); |
| 46 intptr_t id; |
| 47 GetWatcherIdNativeField(watcher, &id); |
| 48 FileSystemWatcher::UnwatchPath(id); |
| 49 } |
| 50 |
| 51 |
| 52 void FUNCTION_NAME(FileSystemWatcher_ReadEvents)(Dart_NativeArguments args) { |
| 53 Dart_Handle watcher = Dart_GetNativeArgument(args, 0); |
| 54 intptr_t id; |
| 55 GetWatcherIdNativeField(watcher, &id); |
| 56 Dart_Handle handle = FileSystemWatcher::ReadEvents(id); |
| 57 ThrowIfError(handle); |
| 58 Dart_SetReturnValue(args, handle); |
| 59 } |
| 60 |
| 61 } // namespace bin |
| 62 } // namespace dart |
OLD | NEW |