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