OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef VM_SERVICE_H_ | 5 #ifndef VM_SERVICE_H_ |
6 #define VM_SERVICE_H_ | 6 #define VM_SERVICE_H_ |
7 | 7 |
8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
9 | 9 |
10 #include "vm/allocation.h" | 10 #include "vm/allocation.h" |
| 11 #include "vm/os_thread.h" |
11 | 12 |
12 namespace dart { | 13 namespace dart { |
13 | 14 |
14 class Array; | 15 class Array; |
15 class DebuggerEvent; | 16 class DebuggerEvent; |
16 class EmbedderServiceHandler; | 17 class EmbedderServiceHandler; |
17 class GCEvent; | 18 class GCEvent; |
18 class Instance; | 19 class Instance; |
19 class Isolate; | 20 class Isolate; |
20 class JSONStream; | 21 class JSONStream; |
21 class Object; | 22 class Object; |
22 class RawInstance; | 23 class RawInstance; |
23 class String; | 24 class String; |
24 | 25 |
25 class Service : public AllStatic { | 26 class Service : public AllStatic { |
26 public: | 27 public: |
| 28 static const char* kServiceIsolateName; |
| 29 static bool IsServiceIsolateName(const char* name); |
| 30 |
27 // Handles a message which is not directed to an isolate. | 31 // Handles a message which is not directed to an isolate. |
28 static void HandleRootMessage(const Instance& message); | 32 static void HandleRootMessage(const Instance& message); |
29 | 33 |
30 // Handles a message which is directed to a particular isolate. | 34 // Handles a message which is directed to a particular isolate. |
31 static void HandleIsolateMessage(Isolate* isolate, const Array& message); | 35 static void HandleIsolateMessage(Isolate* isolate, const Array& message); |
32 | 36 |
33 static Isolate* GetServiceIsolate(void* callback_data); | 37 static Isolate* GetServiceIsolate(void* callback_data); |
34 static bool SendIsolateStartupMessage(); | 38 static bool SendIsolateStartupMessage(); |
35 static bool SendIsolateShutdownMessage(); | 39 static bool SendIsolateShutdownMessage(); |
36 | 40 |
37 static bool IsRunning() { | 41 static bool IsRunning() { |
38 return port_ != ILLEGAL_PORT; | 42 return port_ != ILLEGAL_PORT; |
39 } | 43 } |
40 | 44 |
41 static void set_port(Dart_Port port) { | 45 static void set_port(Dart_Port port) { |
42 port_ = port; | 46 port_ = port; |
43 } | 47 } |
44 | 48 |
| 49 static Dart_Port WaitForLoadPort(); |
| 50 static bool IsServicePort(Dart_Port port) { |
| 51 return (port == port_) || (port == load_port_); |
| 52 } |
| 53 static Dart_Port LoadPort(); |
| 54 |
| 55 static void SetLoadPort(Dart_Port port); |
| 56 |
45 static void SetEventMask(uint32_t mask); | 57 static void SetEventMask(uint32_t mask); |
46 | 58 |
47 // Is the service interested in debugger events? | 59 // Is the service interested in debugger events? |
48 static bool NeedsDebuggerEvents() { | 60 static bool NeedsDebuggerEvents() { |
49 return IsRunning() && ((event_mask_ & kEventFamilyDebugMask) != 0); | 61 return IsRunning() && ((event_mask_ & kEventFamilyDebugMask) != 0); |
50 } | 62 } |
51 // Is the service interested in garbage collection events? | 63 // Is the service interested in garbage collection events? |
52 static bool NeedsGCEvents() { | 64 static bool NeedsGCEvents() { |
53 return IsRunning() && ((event_mask_ & kEventFamilyGCMask) != 0); | 65 return IsRunning() && ((event_mask_ & kEventFamilyGCMask) != 0); |
54 } | 66 } |
(...skipping 11 matching lines...) Expand all Loading... |
66 Dart_ServiceRequestCallback callback, | 78 Dart_ServiceRequestCallback callback, |
67 void* user_data); | 79 void* user_data); |
68 | 80 |
69 static bool IsServiceIsolate(Isolate* isolate) { | 81 static bool IsServiceIsolate(Isolate* isolate) { |
70 return isolate == service_isolate_; | 82 return isolate == service_isolate_; |
71 } | 83 } |
72 | 84 |
73 static void SendEchoEvent(Isolate* isolate); | 85 static void SendEchoEvent(Isolate* isolate); |
74 static void SendGraphEvent(Isolate* isolate); | 86 static void SendGraphEvent(Isolate* isolate); |
75 | 87 |
| 88 static void MaybeInjectVMServiceLibrary(Isolate* isolate); |
| 89 |
| 90 static void RunService(); |
| 91 |
| 92 static void FinishedInitializing(); |
| 93 |
76 private: | 94 private: |
77 // These must be kept in sync with service/constants.dart | 95 // These must be kept in sync with service/constants.dart |
78 static const int kEventFamilyDebug = 0; | 96 static const int kEventFamilyDebug = 0; |
79 static const int kEventFamilyGC = 1; | 97 static const int kEventFamilyGC = 1; |
80 static const uint32_t kEventFamilyDebugMask = (1 << kEventFamilyDebug); | 98 static const uint32_t kEventFamilyDebugMask = (1 << kEventFamilyDebug); |
81 static const uint32_t kEventFamilyGCMask = (1 << kEventFamilyGC); | 99 static const uint32_t kEventFamilyGCMask = (1 << kEventFamilyGC); |
82 | 100 |
83 static void EmbedderHandleMessage(EmbedderServiceHandler* handler, | 101 static void EmbedderHandleMessage(EmbedderServiceHandler* handler, |
84 JSONStream* js); | 102 JSONStream* js); |
| 103 |
85 static EmbedderServiceHandler* FindIsolateEmbedderHandler(const char* name); | 104 static EmbedderServiceHandler* FindIsolateEmbedderHandler(const char* name); |
86 static EmbedderServiceHandler* FindRootEmbedderHandler(const char* name); | 105 static EmbedderServiceHandler* FindRootEmbedderHandler(const char* name); |
87 static Dart_Handle GetSource(const char* name); | 106 static Dart_Handle GetSource(const char* name); |
88 static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag, Dart_Handle library, | 107 static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag, Dart_Handle library, |
89 Dart_Handle url); | 108 Dart_Handle url); |
| 109 |
90 static void SendEvent(intptr_t eventId, const Object& eventMessage); | 110 static void SendEvent(intptr_t eventId, const Object& eventMessage); |
91 // Does not take ownership of 'data'. | 111 // Does not take ownership of 'data'. |
92 static void SendEvent(intptr_t eventId, | 112 static void SendEvent(intptr_t eventId, |
93 const String& meta, | 113 const String& meta, |
94 const uint8_t* data, | 114 const uint8_t* data, |
95 intptr_t size); | 115 intptr_t size); |
96 | 116 |
97 static EmbedderServiceHandler* isolate_service_handler_head_; | 117 static EmbedderServiceHandler* isolate_service_handler_head_; |
98 static EmbedderServiceHandler* root_service_handler_head_; | 118 static EmbedderServiceHandler* root_service_handler_head_; |
99 | 119 |
100 static Isolate* service_isolate_; | 120 static Isolate* service_isolate_; |
101 static Dart_LibraryTagHandler embedder_provided_handler_; | |
102 static Dart_Port port_; | 121 static Dart_Port port_; |
| 122 static Monitor* monitor_; |
| 123 static bool initializing_; |
| 124 static Dart_Port load_port_; |
103 static uint32_t event_mask_; | 125 static uint32_t event_mask_; |
104 }; | 126 }; |
105 | 127 |
106 } // namespace dart | 128 } // namespace dart |
107 | 129 |
108 #endif // VM_SERVICE_H_ | 130 #endif // VM_SERVICE_H_ |
OLD | NEW |