| Index: runtime/bin/file_system_watcher.cc
|
| diff --git a/runtime/bin/file_system_watcher.cc b/runtime/bin/file_system_watcher.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3354a32b274c45cae610211aabee0f73a8cb4c96
|
| --- /dev/null
|
| +++ b/runtime/bin/file_system_watcher.cc
|
| @@ -0,0 +1,87 @@
|
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +
|
| +#include "bin/file_system_watcher.h"
|
| +
|
| +#include "bin/builtin.h"
|
| +#include "bin/dartutils.h"
|
| +
|
| +#include "include/dart_api.h"
|
| +
|
| +namespace dart {
|
| +namespace bin {
|
| +
|
| +void FUNCTION_NAME(FileSystemWatcher_Init)(Dart_NativeArguments args) {
|
| + intptr_t id = FileSystemWatcher::Init();
|
| + if (id == -1) {
|
| + Dart_ThrowException(DartUtils::NewDartOSError());
|
| + }
|
| + Dart_SetReturnValue(args, Dart_NewInteger(id));
|
| +}
|
| +
|
| +
|
| +void FUNCTION_NAME(FileSystemWatcher_Stop)(Dart_NativeArguments args) {
|
| + intptr_t id = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 1));
|
| + FileSystemWatcher::Stop(id);
|
| +}
|
| +
|
| +
|
| +void FUNCTION_NAME(FileSystemWatcher_GetSocketId)(Dart_NativeArguments args) {
|
| + intptr_t id = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 1));
|
| + intptr_t path_id = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 2));
|
| + intptr_t socket_id = FileSystemWatcher::GetSocketId(id, path_id);
|
| + Dart_SetReturnValue(args, Dart_NewInteger(socket_id));
|
| +}
|
| +
|
| +
|
| +void FUNCTION_NAME(FileSystemWatcher_AddPath)(Dart_NativeArguments args) {
|
| + intptr_t id = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 1));
|
| + const char* path = DartUtils::GetStringValue(Dart_GetNativeArgument(args, 2));
|
| + int events = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3));
|
| + bool recursive = DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 4));
|
| + intptr_t path_id = FileSystemWatcher::AddPath(id, path, events, recursive);
|
| + if (path_id == -1) {
|
| + Dart_ThrowException(DartUtils::NewDartOSError());
|
| + }
|
| + Dart_SetReturnValue(args, Dart_NewInteger(path_id));
|
| +}
|
| +
|
| +
|
| +void FUNCTION_NAME(FileSystemWatcher_RemovePath)(Dart_NativeArguments args) {
|
| + intptr_t id = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 1));
|
| + intptr_t path_id = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 2));
|
| + if (!FileSystemWatcher::RemovePath(id, path_id)) {
|
| + Dart_ThrowException(DartUtils::NewDartOSError());
|
| + }
|
| +}
|
| +
|
| +
|
| +void FUNCTION_NAME(FileSystemWatcher_ReadNextEvent)(Dart_NativeArguments args) {
|
| + FileSystemWatcher::Event* events = NULL;
|
| + intptr_t id = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 1));
|
| + intptr_t path_id = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 2));
|
| + intptr_t count = FileSystemWatcher::ReadEvents(id, path_id, &events);
|
| + if (count < 0) {
|
| + Dart_ThrowException(DartUtils::NewDartOSError());
|
| + }
|
| + Dart_Handle result = Dart_NewList(count);
|
| + for (intptr_t i = 0; i < count; i++) {
|
| + Dart_Handle event = Dart_NewList(4);
|
| + Dart_ListSetAt(event, 0, Dart_NewInteger(events[i].event));
|
| + Dart_ListSetAt(event, 1, Dart_NewInteger(events[i].path_id));
|
| + if (events[i].filename != NULL) {
|
| + Dart_ListSetAt(event, 2, Dart_NewStringFromCString(events[i].filename));
|
| + free(const_cast<char*>(events[i].filename));
|
| + } else {
|
| + Dart_ListSetAt(event, 2, Dart_Null());
|
| + }
|
| + Dart_ListSetAt(event, 3, Dart_NewInteger(events[i].link));
|
| + Dart_ListSetAt(result, i, event);
|
| + }
|
| + delete[] events;
|
| + Dart_SetReturnValue(args, result);
|
| +}
|
| +
|
| +} // namespace bin
|
| +} // namespace dart
|
|
|