Flutter Engine
The Flutter Engine
utils_win.h
Go to the documentation of this file.
1// Copyright (c) 2012, 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_UTILS_WIN_H_
6#define RUNTIME_BIN_UTILS_WIN_H_
7
8#include <memory>
9#include <utility>
10
11#include "platform/utils.h"
12
13#include "platform/allocation.h"
14
15#define MAX_LONG_PATH 32767
16
17namespace dart {
18namespace bin {
19
20void FormatMessageIntoBuffer(DWORD code, wchar_t* buffer, int buffer_length);
21
22// Convert from milliseconds since the Unix epoch to a FILETIME.
24
25// These string utility functions return strings that have been allocated with
26// Dart_ScopeAllocate(). They should be used only when we are inside an API
27// scope. If a string returned by one of these functions must persist beyond
28// the scope, then copy the results into a suitable buffer that you have
29// allocated.
31 public:
32 static char* WideToUtf8(wchar_t* wide,
33 intptr_t len = -1,
34 intptr_t* result_len = nullptr);
35 static const char* WideToUtf8(const wchar_t* wide,
36 intptr_t len = -1,
37 intptr_t* result_len = nullptr);
38 static wchar_t* Utf8ToWide(char* utf8,
39 intptr_t len = -1,
40 intptr_t* result_len = nullptr);
41 static const wchar_t* Utf8ToWide(const char* utf8,
42 intptr_t len = -1,
43 intptr_t* result_len = nullptr);
44
45 private:
46 DISALLOW_ALLOCATION();
47 DISALLOW_IMPLICIT_CONSTRUCTORS(StringUtilsWin);
48};
49
50// These scopes provide strings converted as indicated by the scope names.
51// The provided strings are allocated with 'malloc' and have the same lifetime
52// as the scope.
54 public:
55 explicit WideToUtf8Scope(const wchar_t* wide)
56 : utf8_(CStringUniquePtr(nullptr)) {
57 intptr_t utf8_len =
58 WideCharToMultiByte(CP_UTF8, 0, wide, -1, nullptr, 0, nullptr, nullptr);
59 char* utf8 = reinterpret_cast<char*>(malloc(utf8_len));
60 WideCharToMultiByte(CP_UTF8, 0, wide, -1, utf8, utf8_len, nullptr, nullptr);
61 length_ = utf8_len;
62 utf8_.reset(utf8);
63 }
64
65 char* utf8() const { return utf8_.get(); }
66 intptr_t length() const { return length_; }
67
68 // Release the ownership of the converted string and return it.
69 CStringUniquePtr release() { return std::move(utf8_); }
70
71 private:
72 intptr_t length_;
73 CStringUniquePtr utf8_;
74
75 DISALLOW_ALLOCATION();
76 DISALLOW_IMPLICIT_CONSTRUCTORS(WideToUtf8Scope);
77};
78
79std::unique_ptr<wchar_t[]> Utf8ToWideChar(const char* path);
80
81} // namespace bin
82} // namespace dart
83
84#endif // RUNTIME_BIN_UTILS_WIN_H_
static const wchar_t * Utf8ToWide(const char *utf8, intptr_t len=-1, intptr_t *result_len=nullptr)
static const char * WideToUtf8(const wchar_t *wide, intptr_t len=-1, intptr_t *result_len=nullptr)
static char * WideToUtf8(wchar_t *wide, intptr_t len=-1, intptr_t *result_len=nullptr)
static wchar_t * Utf8ToWide(char *utf8, intptr_t len=-1, intptr_t *result_len=nullptr)
intptr_t length() const
Definition: utils_win.h:66
char * utf8() const
Definition: utils_win.h:65
CStringUniquePtr release()
Definition: utils_win.h:69
WideToUtf8Scope(const wchar_t *wide)
Definition: utils_win.h:55
std::unique_ptr< wchar_t[]> Utf8ToWideChar(const char *path)
FILETIME GetFiletimeFromMillis(int64_t millis)
void FormatMessageIntoBuffer(DWORD code, wchar_t *buffer, int buffer_length)
Definition: dart_vm.cc:33
void * malloc(size_t size)
Definition: allocation.cc:19
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
struct _FILETIME FILETIME
unsigned long DWORD
Definition: windows_types.h:22