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_tools_api.h" | 8 #include "include/dart_tools_api.h" |
9 | 9 |
10 #include "vm/allocation.h" | 10 #include "vm/allocation.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 ObjectIdRing::IdPolicy policy() const { | 52 ObjectIdRing::IdPolicy policy() const { |
53 return policy_; | 53 return policy_; |
54 } | 54 } |
55 | 55 |
56 private: | 56 private: |
57 ObjectIdRing* ring_; | 57 ObjectIdRing* ring_; |
58 ObjectIdRing::IdPolicy policy_; | 58 ObjectIdRing::IdPolicy policy_; |
59 }; | 59 }; |
60 | 60 |
61 | 61 |
| 62 class StreamInfo { |
| 63 public: |
| 64 explicit StreamInfo(const char* id) : id_(id), enabled_(false) {} |
| 65 |
| 66 const char* id() { return id_; } |
| 67 |
| 68 void set_enabled(bool value) { enabled_ = value; } |
| 69 bool enabled() { return enabled_; } |
| 70 |
| 71 private: |
| 72 const char* id_; |
| 73 bool enabled_; |
| 74 }; |
| 75 |
| 76 |
62 class Service : public AllStatic { | 77 class Service : public AllStatic { |
63 public: | 78 public: |
64 // Handles a message which is not directed to an isolate. | 79 // Handles a message which is not directed to an isolate. |
65 static void HandleRootMessage(const Array& message); | 80 static void HandleRootMessage(const Array& message); |
66 | 81 |
67 // Handles a message which is directed to a particular isolate. | 82 // Handles a message which is directed to a particular isolate. |
68 static void HandleIsolateMessage(Isolate* isolate, const Array& message); | 83 static void HandleIsolateMessage(Isolate* isolate, const Array& message); |
69 | 84 |
70 static bool NeedsIsolateEvents() { return needs_isolate_events_; } | |
71 static bool NeedsDebugEvents() { return needs_debug_events_; } | |
72 static bool NeedsGCEvents() { return needs_gc_events_; } | |
73 static bool NeedsEchoEvents() { return needs_echo_events_; } | |
74 static bool NeedsGraphEvents() { return needs_graph_events_; } | |
75 | |
76 static void ListenStream(const char* stream_id); | |
77 static void CancelStream(const char* stream_id); | |
78 | |
79 static void HandleEvent(ServiceEvent* event); | 85 static void HandleEvent(ServiceEvent* event); |
80 | 86 |
81 static void RegisterIsolateEmbedderCallback( | 87 static void RegisterIsolateEmbedderCallback( |
82 const char* name, | 88 const char* name, |
83 Dart_ServiceRequestCallback callback, | 89 Dart_ServiceRequestCallback callback, |
84 void* user_data); | 90 void* user_data); |
85 | 91 |
86 static void RegisterRootEmbedderCallback( | 92 static void RegisterRootEmbedderCallback( |
87 const char* name, | 93 const char* name, |
88 Dart_ServiceRequestCallback callback, | 94 Dart_ServiceRequestCallback callback, |
89 void* user_data); | 95 void* user_data); |
90 | 96 |
| 97 static void SetEmbedderStreamCallbacks( |
| 98 Dart_ServiceStreamListenCallback listen_callback, |
| 99 Dart_ServiceStreamCancelCallback cancel_callback); |
| 100 |
91 static void SendEchoEvent(Isolate* isolate, const char* text); | 101 static void SendEchoEvent(Isolate* isolate, const char* text); |
92 static void SendGraphEvent(Isolate* isolate); | 102 static void SendGraphEvent(Isolate* isolate); |
93 static void SendInspectEvent(Isolate* isolate, const Object& inspectee); | 103 static void SendInspectEvent(Isolate* isolate, const Object& inspectee); |
94 | 104 |
| 105 static void SendEmbedderEvent(Isolate* isolate, |
| 106 const char* stream_id, |
| 107 const char* event_kind, |
| 108 const uint8_t* bytes, |
| 109 intptr_t bytes_len); |
| 110 |
| 111 // Well-known streams. |
| 112 static StreamInfo isolate_stream; |
| 113 static StreamInfo debug_stream; |
| 114 static StreamInfo gc_stream; |
| 115 static StreamInfo echo_stream; |
| 116 static StreamInfo graph_stream; |
| 117 |
| 118 static bool ListenStream(const char* stream_id); |
| 119 static void CancelStream(const char* stream_id); |
| 120 |
| 121 static Dart_ServiceStreamListenCallback stream_listen_callback() { |
| 122 return stream_listen_callback_; |
| 123 } |
| 124 static Dart_ServiceStreamCancelCallback stream_cancel_callback() { |
| 125 return stream_cancel_callback_; |
| 126 } |
| 127 |
95 private: | 128 private: |
96 static void InvokeMethod(Isolate* isolate, const Array& message); | 129 static void InvokeMethod(Isolate* isolate, const Array& message); |
97 | 130 |
98 static void EmbedderHandleMessage(EmbedderServiceHandler* handler, | 131 static void EmbedderHandleMessage(EmbedderServiceHandler* handler, |
99 JSONStream* js); | 132 JSONStream* js); |
100 | 133 |
101 static EmbedderServiceHandler* FindIsolateEmbedderHandler(const char* name); | 134 static EmbedderServiceHandler* FindIsolateEmbedderHandler(const char* name); |
102 static EmbedderServiceHandler* FindRootEmbedderHandler(const char* name); | 135 static EmbedderServiceHandler* FindRootEmbedderHandler(const char* name); |
103 | 136 |
104 static void SendEvent(const char* stream_id, | 137 static void SendEvent(const char* stream_id, |
105 const char* event_type, | 138 const char* event_type, |
106 const Object& eventMessage); | 139 const Object& eventMessage); |
107 // Does not take ownership of 'data'. | 140 // Does not take ownership of 'data'. |
108 static void SendEventWithData(const char* stream_id, | 141 static void SendEventWithData(const char* stream_id, |
109 const char* event_type, | 142 const char* event_type, |
110 const String& meta, | 143 const String& meta, |
111 const uint8_t* data, | 144 const uint8_t* data, |
112 intptr_t size); | 145 intptr_t size); |
113 | 146 |
114 static EmbedderServiceHandler* isolate_service_handler_head_; | 147 static EmbedderServiceHandler* isolate_service_handler_head_; |
115 static EmbedderServiceHandler* root_service_handler_head_; | 148 static EmbedderServiceHandler* root_service_handler_head_; |
| 149 static Dart_ServiceStreamListenCallback stream_listen_callback_; |
| 150 static Dart_ServiceStreamCancelCallback stream_cancel_callback_; |
116 | 151 |
117 static bool needs_isolate_events_; | 152 static bool needs_isolate_events_; |
118 static bool needs_debug_events_; | 153 static bool needs_debug_events_; |
119 static bool needs_gc_events_; | 154 static bool needs_gc_events_; |
120 static bool needs_echo_events_; | 155 static bool needs_echo_events_; |
121 static bool needs_graph_events_; | 156 static bool needs_graph_events_; |
122 }; | 157 }; |
123 | 158 |
124 } // namespace dart | 159 } // namespace dart |
125 | 160 |
126 #endif // VM_SERVICE_H_ | 161 #endif // VM_SERVICE_H_ |
OLD | NEW |