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

Unified Diff: runtime/bin/namespace.h

Issue 3001963002: [dart:io] Namespaces for file IO (Closed)
Patch Set: Fuchsia fix Created 3 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/main.cc ('k') | runtime/bin/namespace.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/namespace.h
diff --git a/runtime/bin/namespace.h b/runtime/bin/namespace.h
new file mode 100644
index 0000000000000000000000000000000000000000..7b36245a6e36ae88ddb37f0988b319f835f8246e
--- /dev/null
+++ b/runtime/bin/namespace.h
@@ -0,0 +1,98 @@
+// Copyright (c) 2017, 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.
+
+#ifndef RUNTIME_BIN_NAMESPACE_H_
+#define RUNTIME_BIN_NAMESPACE_H_
+
+#include "bin/builtin.h"
+#include "bin/dartutils.h"
+#include "bin/log.h"
+#include "bin/reference_counting.h"
+
+namespace dart {
+namespace bin {
+
+class Namespace : public ReferenceCounted<Namespace> {
+ public:
+ // Assumes napespc is a value that can be directly used as namespc_.
+ static Namespace* Create(intptr_t namespc) {
+ return new Namespace(namespc);
+ }
+
+ // Uses path to compute a value that can be used as namespc_.
+ static Namespace* Create(const char* path);
+
+ // Gives a safe defautl value for namespc_ for the standalone Dart VM.
+ static intptr_t Default();
+
+ // Tells whether the given namespace is the default namespace.
+ static bool IsDefault(Namespace* namespc);
+
+ // Returns the native namespace wrapper if the argument at the supplied index
+ // is a _NamespaceImpl object. If it is not, calls Dart_PropagateError().
+ static Namespace* GetNamespace(Dart_NativeArguments args, intptr_t index);
+
+ // Get and set the current working directory through the namespace if there
+ // is one.
+ static const char* GetCurrent(Namespace* namespc);
+ static bool SetCurrent(Namespace* namespc, const char* path);
+
+ intptr_t namespc() const { return namespc_; }
+
+ private:
+ // When namespc_ has this value, it indicates that there is currently
+ // no namespace for resolving absolute paths.
+ static const intptr_t kNone = 0;
+
+ explicit Namespace(intptr_t namespc)
+ : ReferenceCounted(), namespc_(namespc) {}
+
+ ~Namespace();
+
+ // When the native argument at |index| is a _NamespaceImpl object,
+ // write the valueof its native field into |namespc|.
+ static Dart_Handle GetNativeNamespaceArgument(Dart_NativeArguments args,
+ intptr_t index,
+ Namespace** namespc);
+
+ // Given a namespace and a path, computes the information needed to access the
+ // path relative to the namespace. This can include massaging the path and
+ // returning a platform specific value in dirfd that together are used to
+ // access the path. Returns true if the caller should take ownership of
+ // dirfd, and false if the namespace retains ownership of dirfd.
+ static bool ResolvePath(Namespace* namespc,
+ const char* path,
+ intptr_t* dirfd,
+ const char** resolved_path);
+
+ intptr_t namespc_;
+ // TODO(zra): When Isolate-specific cwds are added, we'll need some more
+ // fields here to track them.
+
+ friend class NamespaceScope;
+ friend class ReferenceCounted<Namespace>;
+ DISALLOW_COPY_AND_ASSIGN(Namespace);
+};
+
+class NamespaceScope {
+ public:
+ explicit NamespaceScope(Namespace* namespc, const char* path);
+ ~NamespaceScope();
+
+ intptr_t fd() const { return fd_; }
+ const char* path() const { return path_; }
+
+ private:
+ intptr_t fd_;
+ const char* path_;
+ bool owns_fd_;
+
+ DISALLOW_ALLOCATION();
+ DISALLOW_COPY_AND_ASSIGN(NamespaceScope);
+};
+
+} // namespace bin
+} // namespace dart
+
+#endif // RUNTIME_BIN_NAMESPACE_H_
« no previous file with comments | « runtime/bin/main.cc ('k') | runtime/bin/namespace.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698