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