Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
namespace.h
Go to the documentation of this file.
1// Copyright (c) 2017, 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#ifndef RUNTIME_BIN_NAMESPACE_H_
6#define RUNTIME_BIN_NAMESPACE_H_
7
8#include "bin/builtin.h"
9#include "bin/dartutils.h"
11#include "platform/syslog.h"
12
13namespace dart {
14namespace bin {
15
16class NamespaceImpl;
17
18class Namespace : public ReferenceCounted<Namespace> {
19 public:
20 // Assumes namespc is a value that can be directly used as namespc_.
21 static Namespace* Create(intptr_t namespc);
22
23 // Uses path to compute a value that can be used as namespc_.
24 static Namespace* Create(const char* path);
25
26 // Gives a safe default value for namespc_ for the standalone Dart VM.
27 static intptr_t Default();
28
29 // Tells whether the given namespace is the default namespace.
30 static bool IsDefault(Namespace* namespc);
31
32 // Returns the native namespace wrapper if the argument at the supplied index
33 // is a _NamespaceImpl object. If it is not, calls Dart_PropagateError().
34 static Namespace* GetNamespace(Dart_NativeArguments args, intptr_t index);
35
36 // Get and set the current working directory through the namespace if there
37 // is one.
38 static const char* GetCurrent(Namespace* namespc);
39 static bool SetCurrent(Namespace* namespc, const char* path);
40
41 NamespaceImpl* namespc() const { return namespc_; }
42
43 private:
44 // When namespc_ has this value, it indicates that there is currently
45 // no namespace for resolving absolute paths.
46 static constexpr intptr_t kNone = 0;
47
49 : ReferenceCounted(), namespc_(namespc) {}
50
51 ~Namespace();
52
53 // When the native argument at |index| is a _NamespaceImpl object,
54 // write the valueof its native field into |namespc|.
55 static Dart_Handle GetNativeNamespaceArgument(Dart_NativeArguments args,
56 intptr_t index,
58
59 // Given a namespace and a path, computes the information needed to access the
60 // path relative to the namespace. This can include massaging the path and
61 // returning a platform specific value in dirfd that together are used to
62 // access the path.
63 static void ResolvePath(Namespace* namespc,
64 const char* path,
65 intptr_t* dirfd,
66 const char** resolved_path);
67
68 NamespaceImpl* namespc_;
69 // TODO(zra): When Isolate-specific cwds are added, we'll need some more
70 // fields here to track them.
71
72 friend class NamespaceScope;
73 friend class ReferenceCounted<Namespace>;
75};
76
78 public:
79 NamespaceScope(Namespace* namespc, const char* path);
81
82 intptr_t fd() const { return fd_; }
83 const char* path() const { return path_; }
84
85 private:
86 intptr_t fd_;
87 const char* path_;
88
89 DISALLOW_ALLOCATION();
91};
92
93} // namespace bin
94} // namespace dart
95
96#endif // RUNTIME_BIN_NAMESPACE_H_
const char * path() const
Definition namespace.h:83
intptr_t fd() const
Definition namespace.h:82
NamespaceScope(Namespace *namespc, const char *path)
static bool IsDefault(Namespace *namespc)
Definition namespace.cc:111
static Namespace * Create(intptr_t namespc)
static Namespace * GetNamespace(Dart_NativeArguments args, intptr_t index)
Definition namespace.cc:101
static const char * GetCurrent(Namespace *namespc)
NamespaceImpl * namespc() const
Definition namespace.h:41
static intptr_t Default()
static Namespace * Create(const char *path)
static bool SetCurrent(Namespace *namespc, const char *path)
struct _Dart_Handle * Dart_Handle
Definition dart_api.h:258
struct _Dart_NativeArguments * Dart_NativeArguments
Definition dart_api.h:3010
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition globals.h:581