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 void FUNCTION_NAME(FileSystemWatcher_Init)(Dart_NativeArguments args) { |
| 16 intptr_t id = FileSystemWatcher::Init(); |
| 17 if (id == -1) { |
| 18 Dart_ThrowException(DartUtils::NewDartOSError()); |
| 19 } |
| 20 Dart_SetReturnValue(args, Dart_NewInteger(id)); |
| 21 } |
| 22 |
| 23 |
| 24 void FUNCTION_NAME(FileSystemWatcher_Stop)(Dart_NativeArguments args) { |
| 25 intptr_t id = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 1)); |
| 26 FileSystemWatcher::Stop(id); |
| 27 } |
| 28 |
| 29 |
| 30 void FUNCTION_NAME(FileSystemWatcher_GetSocketId)(Dart_NativeArguments args) { |
| 31 intptr_t id = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 1)); |
| 32 intptr_t path_id = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 2)); |
| 33 intptr_t socket_id = FileSystemWatcher::GetSocketId(id, path_id); |
| 34 Dart_SetReturnValue(args, Dart_NewInteger(socket_id)); |
| 35 } |
| 36 |
| 37 |
| 38 void FUNCTION_NAME(FileSystemWatcher_AddPath)(Dart_NativeArguments args) { |
| 39 intptr_t id = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 1)); |
| 40 const char* path = DartUtils::GetStringValue(Dart_GetNativeArgument(args, 2)); |
| 41 int events = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); |
| 42 bool recursive = DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 4)); |
| 43 intptr_t path_id = FileSystemWatcher::AddPath(id, path, events, recursive); |
| 44 if (path_id == -1) { |
| 45 Dart_ThrowException(DartUtils::NewDartOSError()); |
| 46 } |
| 47 Dart_SetReturnValue(args, Dart_NewInteger(path_id)); |
| 48 } |
| 49 |
| 50 |
| 51 void FUNCTION_NAME(FileSystemWatcher_RemovePath)(Dart_NativeArguments args) { |
| 52 intptr_t id = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 1)); |
| 53 intptr_t path_id = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 2)); |
| 54 if (!FileSystemWatcher::RemovePath(id, path_id)) { |
| 55 Dart_ThrowException(DartUtils::NewDartOSError()); |
| 56 } |
| 57 } |
| 58 |
| 59 |
| 60 void FUNCTION_NAME(FileSystemWatcher_ReadNextEvent)(Dart_NativeArguments args) { |
| 61 FileSystemWatcher::Event* events = NULL; |
| 62 intptr_t id = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 1)); |
| 63 intptr_t path_id = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 2)); |
| 64 intptr_t count = FileSystemWatcher::ReadEvents(id, path_id, &events); |
| 65 if (count < 0) { |
| 66 Dart_ThrowException(DartUtils::NewDartOSError()); |
| 67 } |
| 68 Dart_Handle result = Dart_NewList(count); |
| 69 for (intptr_t i = 0; i < count; i++) { |
| 70 Dart_Handle event = Dart_NewList(4); |
| 71 Dart_ListSetAt(event, 0, Dart_NewInteger(events[i].event)); |
| 72 Dart_ListSetAt(event, 1, Dart_NewInteger(events[i].path_id)); |
| 73 if (events[i].filename != NULL) { |
| 74 Dart_ListSetAt(event, 2, Dart_NewStringFromCString(events[i].filename)); |
| 75 free(const_cast<char*>(events[i].filename)); |
| 76 } else { |
| 77 Dart_ListSetAt(event, 2, Dart_Null()); |
| 78 } |
| 79 Dart_ListSetAt(event, 3, Dart_NewInteger(events[i].link)); |
| 80 Dart_ListSetAt(result, i, event); |
| 81 } |
| 82 delete[] events; |
| 83 Dart_SetReturnValue(args, result); |
| 84 } |
| 85 |
| 86 } // namespace bin |
| 87 } // namespace dart |
OLD | NEW |