dec87b98f0
Instead of requiring embedder to initialize dart:io by bits and pieces by invoking various hooks and setting fields provide a structured C++ API for preparing dart:io for execution. TEST=ci CoreLibraryReviewExempt: VM specific changes only Change-Id: I66e95c0a451d384b4f7582d1df059e506a6a6964 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/454062 Reviewed-by: Ryan Macnak <rmacnak@google.com> Commit-Queue: Slava Egorov <vegorov@google.com>
108 lines
3.7 KiB
C++
108 lines
3.7 KiB
C++
// Copyright (c) 2015, 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_INCLUDE_BIN_DART_IO_API_H_
|
|
#define RUNTIME_INCLUDE_BIN_DART_IO_API_H_
|
|
|
|
#include "../dart_tools_api.h"
|
|
|
|
namespace dart {
|
|
namespace bin {
|
|
|
|
// Bootstraps 'dart:io'.
|
|
void BootstrapDartIo();
|
|
|
|
// Cleans up 'dart:io'.
|
|
void CleanupDartIo();
|
|
|
|
// Lets dart:io know where the system temporary directory is located.
|
|
// Currently only wired up on Android.
|
|
void SetSystemTempDirectory(const char* system_temp);
|
|
|
|
// Tells the system whether to capture Stdout events.
|
|
void SetCaptureStdout(bool value);
|
|
|
|
// Tells the system whether to capture Stderr events.
|
|
void SetCaptureStderr(bool value);
|
|
|
|
// Should Stdout events be captured?
|
|
bool ShouldCaptureStdout();
|
|
|
|
// Should Stderr events be captured?
|
|
bool ShouldCaptureStderr();
|
|
|
|
// Set the executable name used by Platform.executable.
|
|
void SetExecutableName(const char* executable_name);
|
|
|
|
// Set the arguments used by Platform.executableArguments.
|
|
void SetExecutableArguments(int script_index, char** argv);
|
|
|
|
// Set dart:io implementation specific fields of Dart_EmbedderInformation.
|
|
void GetIOEmbedderInformation(Dart_EmbedderInformation* info);
|
|
|
|
// Appropriate to assign to Dart_InitializeParams.file_open/read/write/close.
|
|
void* OpenFile(const char* name, bool write);
|
|
void ReadFile(uint8_t** data, intptr_t* file_len, void* stream);
|
|
void WriteFile(const void* buffer, intptr_t num_bytes, void* stream);
|
|
void CloseFile(void* stream);
|
|
|
|
// Generates 'length' random bytes into 'buffer'. Returns true on success
|
|
// and false on failure. This is appropriate to assign to
|
|
// Dart_InitializeParams.entropy_source.
|
|
bool GetEntropy(uint8_t* buffer, intptr_t length);
|
|
|
|
// Performs a lookup of the I/O Dart_NativeFunction with a specified 'name' and
|
|
// 'argument_count'. Returns NULL if no I/O native function with a matching
|
|
// name and parameter count is found.
|
|
Dart_NativeFunction LookupIONative(Dart_Handle name,
|
|
int argument_count,
|
|
bool* auto_setup_scope);
|
|
|
|
// Performs a lookup of the I/O function with a specified 'name' and
|
|
// 'argument_count'. Returns nullptr if matching function is not found.
|
|
void* LookupIOFfiNative(const char* name, uintptr_t argument_count);
|
|
|
|
// Returns the symbol for I/O native function 'nf'. Returns NULL if 'nf' is not
|
|
// a valid I/O native function.
|
|
const uint8_t* LookupIONativeSymbol(Dart_NativeFunction nf);
|
|
|
|
// Configuration for embedder extension points provided by `dart:io`.
|
|
struct DartIoSettings {
|
|
// Value for `dart:_http` `_httpConnectionHook`, `nullptr` means default.
|
|
//
|
|
// Must be a function of type `void Function(Uri)`.
|
|
Dart_Handle http_connection_hook = nullptr;
|
|
|
|
// Callback to intercept `_Platform.localeName`, `nullptr` means default.
|
|
//
|
|
// Must be a function of type `String Function()`.
|
|
Dart_Handle locale_name_callback = nullptr;
|
|
|
|
// Namespace root to pass to `_Namespace._setupNamespace`.
|
|
//
|
|
// Must be either an string (path) or an integer (dirfd).
|
|
Dart_Handle namespace_root = nullptr;
|
|
|
|
// Value for `Platform.script`.
|
|
const char* script_uri = nullptr;
|
|
|
|
// Setting this to `true` will disable `exit`.
|
|
//
|
|
// When disabled `exit` throws an `UnsupportedError`.
|
|
bool disable_exit = false;
|
|
|
|
// Register service extensions for profiling networking traffic.
|
|
//
|
|
// See `_NetworkProfile` for the list of extensions.
|
|
bool enable_network_profiling = true;
|
|
};
|
|
|
|
// Prepare 'dart:io' library for running.
|
|
Dart_Handle SetupDartIoLibrary(const DartIoSettings& settings);
|
|
|
|
} // namespace bin
|
|
} // namespace dart
|
|
|
|
#endif // RUNTIME_INCLUDE_BIN_DART_IO_API_H_
|