Flutter Engine
The Flutter Engine
service_isolate.h
Go to the documentation of this file.
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#ifndef RUNTIME_VM_SERVICE_ISOLATE_H_
6#define RUNTIME_VM_SERVICE_ISOLATE_H_
7
8#include "include/dart_api.h"
9
10#include "vm/allocation.h"
11#include "vm/object.h"
12#include "vm/os_thread.h"
13
14namespace dart {
15
16class Isolate;
17class ObjectPointerVisitor;
18class SendPort;
19
20class ServiceIsolate : public AllStatic {
21#if !defined(PRODUCT)
22
23 public:
24 static const char* kName;
25
26 static bool Exists();
27 static bool IsRunning();
28 static bool IsServiceIsolate(const Isolate* isolate);
29 static bool IsServiceIsolateDescendant(Isolate* isolate);
30 static Dart_Port Port();
31 static void WaitForServiceIsolateStartup();
32
33 // Returns `true` if the request was successfully sent. If it was, the
34 // [reply_port] will receive a Dart_TypedData_kUint8 response json.
35 //
36 // If sending the rpc failed and [error] is not `nullptr` then [error] might
37 // be set to a string containing the reason for the failure. If so, the
38 // caller is responsible for free()ing the error.
39 static bool SendServiceRpc(uint8_t* request_json,
40 intptr_t request_json_length,
41 Dart_Port reply_port,
42 char** error);
43
44 static void Run();
45 static bool SendIsolateStartupMessage();
46 static bool SendIsolateShutdownMessage();
47 static bool SendServiceControlMessage(Thread* thread,
48 Dart_Port port_id,
49 intptr_t code,
50 const char* name);
51 static void SendServiceExitMessage();
52 static void Shutdown();
53
54 static void BootVmServiceLibrary();
55
56 static void RegisterRunningIsolates(
57 const GrowableArray<Dart_Port>& isolate_ports,
58 const GrowableArray<const String*>& isolate_names);
59
60 static void RequestServerInfo(const SendPort& sp);
61 static void ControlWebServer(const SendPort& sp,
62 bool enable,
63 const Bool& silenceOutput);
64
65 static void SetServerAddress(const char* address);
66
67 // Returns the server's web address or nullptr if none is running.
68 static const char* server_address() { return server_address_; }
69
70 static void VisitObjectPointers(ObjectPointerVisitor* visitor);
71
72 private:
73 static void KillServiceIsolate();
74
75 protected:
76 static void SetServicePort(Dart_Port port);
77 static void SetServiceIsolate(Isolate* isolate);
78 static void FinishedExiting();
79 static void FinishedInitializing();
80 static void InitializingFailed(char* error);
81 static void MaybeMakeServiceIsolate(Isolate* isolate);
84 }
85
88 enum State {
93 };
94 static State state_;
98 static char* server_address_;
99
100 // If starting the service-isolate failed, this error might provide the reason
101 // for the failure.
103#else
104
105 public:
106 static bool Exists() { return false; }
107 static bool IsRunning() { return false; }
108 static bool IsServiceIsolate(const Isolate* isolate) { return false; }
109 static bool IsServiceIsolateDescendant(Isolate* isolate) { return false; }
110 static void Run() {}
111 static bool SendIsolateStartupMessage() { return false; }
112 static bool SendIsolateShutdownMessage() { return false; }
113 static void SendServiceExitMessage() {}
114 static void Shutdown() {}
115 static void RegisterRunningIsolate(Isolate* isolate) {}
116 static void VisitObjectPointers(ObjectPointerVisitor* visitor) {}
117
118 protected:
119 static void SetServiceIsolate(Isolate* isolate) { UNREACHABLE(); }
120#endif // !defined(PRODUCT)
121
122 friend class Dart;
123 friend class Isolate;
124 friend class RunServiceTask;
126};
127
128} // namespace dart
129
130#endif // RUNTIME_VM_SERVICE_ISOLATE_H_
#define UNREACHABLE()
Definition: assert.h:248
static Dart_Port origin_
static void FinishedExiting()
static void ControlWebServer(const SendPort &sp, bool enable, const Bool &silenceOutput)
static void SetServiceIsolate(Isolate *isolate)
static void RequestServerInfo(const SendPort &sp)
static bool SendIsolateStartupMessage()
static void VisitObjectPointers(ObjectPointerVisitor *visitor)
static Monitor * monitor_
static const char * kName
static bool SendServiceControlMessage(Thread *thread, Dart_Port port_id, intptr_t code, const char *name)
static void FinishedInitializing()
static bool SendIsolateShutdownMessage()
static char * server_address_
static Dart_IsolateGroupCreateCallback create_group_callback()
static bool IsServiceIsolateDescendant(Isolate *isolate)
static bool IsServiceIsolate(const Isolate *isolate)
static void RegisterRunningIsolates(const GrowableArray< Dart_Port > &isolate_ports, const GrowableArray< const String * > &isolate_names)
static Dart_Port Port()
static Dart_Port port_
static const char * server_address()
static Dart_IsolateGroupCreateCallback create_group_callback_
static void WaitForServiceIsolateStartup()
static bool SendServiceRpc(uint8_t *request_json, intptr_t request_json_length, Dart_Port reply_port, char **error)
static void SetServerAddress(const char *address)
static void InitializingFailed(char *error)
static void SetServicePort(Dart_Port port)
static Isolate * isolate_
static void MaybeMakeServiceIsolate(Isolate *isolate)
static void SendServiceExitMessage()
static void BootVmServiceLibrary()
static char * startup_failure_reason_
friend class ServiceIsolateNatives
Dart_Isolate(* Dart_IsolateGroupCreateCallback)(const char *script_uri, const char *main, const char *package_root, const char *package_config, Dart_IsolateFlags *flags, void *isolate_data, char **error)
Definition: dart_api.h:654
int64_t Dart_Port
Definition: dart_api.h:1525
const uint8_t uint32_t uint32_t GError ** error
Definition: dart_vm.cc:33
const char *const name
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 port
Definition: switches.h:87