Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1338)

Side by Side Diff: runtime/bin/file_system_watcher.cc

Issue 19263003: Add FileSystemWatcher class to dart:io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Simplify watching by removing FileSystemWatcher and adding FileSystemEntity.watch. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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_WatchPath)(Dart_NativeArguments args) {
16 const char* path = DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1));
17 int events = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2));
18 bool recursive = DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 3));
19 intptr_t path_id = FileSystemWatcher::WatchPath(path, events, recursive);
20 if (path_id == -1) {
21 Dart_SetReturnValue(args, DartUtils::NewDartOSError());
22 } else {
23 Dart_SetReturnValue(args, Dart_NewInteger(path_id));
24 }
25 }
26
27
28 void FUNCTION_NAME(FileSystemWatcher_UnwatchPath)(Dart_NativeArguments args) {
29 intptr_t id = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 1));
30 FileSystemWatcher::UnwatchPath(id);
31 }
32
33
34 void FUNCTION_NAME(FileSystemWatcher_GetSocketId)(Dart_NativeArguments args) {
35 intptr_t id = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 1));
36 intptr_t socket_id = FileSystemWatcher::GetSocketId(id);
37 Dart_SetReturnValue(args, Dart_NewInteger(socket_id));
38 }
39
40 void FUNCTION_NAME(FileSystemWatcher_ReadEvents)(Dart_NativeArguments args) {
41 intptr_t id = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 1));
42 FileSystemWatcher::Event* events = NULL;
43 intptr_t count = FileSystemWatcher::ReadEvents(id, &events);
44 if (count < 0) {
45 Dart_ThrowException(DartUtils::NewDartOSError());
46 }
47 Dart_Handle result = Dart_NewList(count);
48 for (intptr_t i = 0; i < count; i++) {
49 Dart_Handle event = Dart_NewList(4);
50 Dart_ListSetAt(event, 0, Dart_NewInteger(events[i].event));
51 Dart_ListSetAt(event, 1, Dart_NewInteger(events[i].path_id));
52 if (events[i].filename != NULL) {
53 Dart_ListSetAt(event, 2, Dart_NewStringFromCString(events[i].filename));
54 free(const_cast<char*>(events[i].filename));
55 } else {
56 Dart_ListSetAt(event, 2, Dart_Null());
57 }
58 Dart_ListSetAt(event, 3, Dart_NewInteger(events[i].link));
59 Dart_ListSetAt(result, i, event);
60 }
61 delete[] events;
62 Dart_SetReturnValue(args, result);
63 }
64
65 } // namespace bin
66 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698