| 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 #include "vm/service.h" | 5 #include "vm/service.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
| 9 #include "platform/globals.h" | 9 #include "platform/globals.h" |
| 10 | 10 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 // TODO(johnmccutchan): Unify embedder service handler lists and their APIs. | 96 // TODO(johnmccutchan): Unify embedder service handler lists and their APIs. |
| 97 EmbedderServiceHandler* Service::isolate_service_handler_head_ = NULL; | 97 EmbedderServiceHandler* Service::isolate_service_handler_head_ = NULL; |
| 98 EmbedderServiceHandler* Service::root_service_handler_head_ = NULL; | 98 EmbedderServiceHandler* Service::root_service_handler_head_ = NULL; |
| 99 struct ServiceMethodDescriptor; | 99 struct ServiceMethodDescriptor; |
| 100 ServiceMethodDescriptor* FindMethod(const char* method_name); | 100 ServiceMethodDescriptor* FindMethod(const char* method_name); |
| 101 | 101 |
| 102 | 102 |
| 103 // Support for streams defined in embedders. | 103 // Support for streams defined in embedders. |
| 104 Dart_ServiceStreamListenCallback Service::stream_listen_callback_ = NULL; | 104 Dart_ServiceStreamListenCallback Service::stream_listen_callback_ = NULL; |
| 105 Dart_ServiceStreamCancelCallback Service::stream_cancel_callback_ = NULL; | 105 Dart_ServiceStreamCancelCallback Service::stream_cancel_callback_ = NULL; |
| 106 | 106 Dart_GetVMServiceAssetsArchive Service::get_service_assets_callback_ = NULL; |
| 107 | 107 |
| 108 // These are the set of streams known to the core VM. | 108 // These are the set of streams known to the core VM. |
| 109 StreamInfo Service::vm_stream("VM"); | 109 StreamInfo Service::vm_stream("VM"); |
| 110 StreamInfo Service::isolate_stream("Isolate"); | 110 StreamInfo Service::isolate_stream("Isolate"); |
| 111 StreamInfo Service::debug_stream("Debug"); | 111 StreamInfo Service::debug_stream("Debug"); |
| 112 StreamInfo Service::gc_stream("GC"); | 112 StreamInfo Service::gc_stream("GC"); |
| 113 StreamInfo Service::echo_stream("_Echo"); | 113 StreamInfo Service::echo_stream("_Echo"); |
| 114 StreamInfo Service::graph_stream("_Graph"); | 114 StreamInfo Service::graph_stream("_Graph"); |
| 115 StreamInfo Service::logging_stream("_Logging"); | 115 StreamInfo Service::logging_stream("_Logging"); |
| 116 | 116 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 137 streams_[i]->set_enabled(true); | 137 streams_[i]->set_enabled(true); |
| 138 return true; | 138 return true; |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 if (stream_listen_callback_) { | 141 if (stream_listen_callback_) { |
| 142 return (*stream_listen_callback_)(stream_id); | 142 return (*stream_listen_callback_)(stream_id); |
| 143 } | 143 } |
| 144 return false; | 144 return false; |
| 145 } | 145 } |
| 146 | 146 |
| 147 |
| 147 void Service::CancelStream(const char* stream_id) { | 148 void Service::CancelStream(const char* stream_id) { |
| 148 if (FLAG_trace_service) { | 149 if (FLAG_trace_service) { |
| 149 OS::Print("vm-service: stopping stream '%s'\n", | 150 OS::Print("vm-service: stopping stream '%s'\n", |
| 150 stream_id); | 151 stream_id); |
| 151 } | 152 } |
| 152 intptr_t num_streams = sizeof(streams_) / | 153 intptr_t num_streams = sizeof(streams_) / |
| 153 sizeof(streams_[0]); | 154 sizeof(streams_[0]); |
| 154 for (intptr_t i = 0; i < num_streams; i++) { | 155 for (intptr_t i = 0; i < num_streams; i++) { |
| 155 if (strcmp(stream_id, streams_[i]->id()) == 0) { | 156 if (strcmp(stream_id, streams_[i]->id()) == 0) { |
| 156 streams_[i]->set_enabled(false); | 157 streams_[i]->set_enabled(false); |
| 157 return; | 158 return; |
| 158 } | 159 } |
| 159 } | 160 } |
| 160 if (stream_cancel_callback_) { | 161 if (stream_cancel_callback_) { |
| 161 return (*stream_cancel_callback_)(stream_id); | 162 return (*stream_cancel_callback_)(stream_id); |
| 162 } | 163 } |
| 163 } | 164 } |
| 164 | 165 |
| 166 RawObject* Service::RequestAssets() { |
| 167 Thread* T = Thread::Current(); |
| 168 Api::Scope api_scope(T); |
| 169 if (get_service_assets_callback_ == NULL) { |
| 170 return Object::null(); |
| 171 } |
| 172 Dart_Handle handle = get_service_assets_callback_(); |
| 173 if (Dart_IsError(handle)) { |
| 174 Dart_PropagateError(handle); |
| 175 } |
| 176 const Object& object = Object::Handle(Api::UnwrapHandle(handle)); |
| 177 if (object.IsNull()) { |
| 178 return Object::null(); |
| 179 } |
| 180 if (!object.IsTypedData()) { |
| 181 const String& error_message = |
| 182 String::Handle( |
| 183 String::New("An implementation of Dart_GetVMServiceAssetsArchive " |
| 184 "should return a Uint8Array or null.")); |
| 185 const Error& error = Error::Handle(ApiError::New(error_message)); |
| 186 Exceptions::PropagateError(error); |
| 187 return Object::null(); |
| 188 } |
| 189 const TypedData& typed_data = TypedData::Cast(object); |
| 190 if (typed_data.ElementSizeInBytes() != 1) { |
| 191 const String& error_message = |
| 192 String::Handle( |
| 193 String::New("An implementation of Dart_GetVMServiceAssetsArchive " |
| 194 "should return a Uint8Array or null.")); |
| 195 const Error& error = Error::Handle(ApiError::New(error_message)); |
| 196 Exceptions::PropagateError(error); |
| 197 return Object::null(); |
| 198 } |
| 199 return Api::UnwrapHandle(handle); |
| 200 } |
| 201 |
| 202 |
| 165 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | 203 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { |
| 166 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); | 204 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); |
| 167 return reinterpret_cast<uint8_t*>(new_ptr); | 205 return reinterpret_cast<uint8_t*>(new_ptr); |
| 168 } | 206 } |
| 169 | 207 |
| 208 |
| 170 static void PrintMissingParamError(JSONStream* js, | 209 static void PrintMissingParamError(JSONStream* js, |
| 171 const char* param) { | 210 const char* param) { |
| 172 js->PrintError(kInvalidParams, | 211 js->PrintError(kInvalidParams, |
| 173 "%s expects the '%s' parameter", js->method(), param); | 212 "%s expects the '%s' parameter", js->method(), param); |
| 174 } | 213 } |
| 175 | 214 |
| 176 | 215 |
| 177 static void PrintInvalidParamError(JSONStream* js, | 216 static void PrintInvalidParamError(JSONStream* js, |
| 178 const char* param) { | 217 const char* param) { |
| 179 js->PrintError(kInvalidParams, | 218 js->PrintError(kInvalidParams, |
| (...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 918 | 957 |
| 919 | 958 |
| 920 void Service::SetEmbedderStreamCallbacks( | 959 void Service::SetEmbedderStreamCallbacks( |
| 921 Dart_ServiceStreamListenCallback listen_callback, | 960 Dart_ServiceStreamListenCallback listen_callback, |
| 922 Dart_ServiceStreamCancelCallback cancel_callback) { | 961 Dart_ServiceStreamCancelCallback cancel_callback) { |
| 923 stream_listen_callback_ = listen_callback; | 962 stream_listen_callback_ = listen_callback; |
| 924 stream_cancel_callback_ = cancel_callback; | 963 stream_cancel_callback_ = cancel_callback; |
| 925 } | 964 } |
| 926 | 965 |
| 927 | 966 |
| 967 void Service::SetGetServiceAssetsCallback( |
| 968 Dart_GetVMServiceAssetsArchive get_service_assets) { |
| 969 get_service_assets_callback_ = get_service_assets; |
| 970 } |
| 971 |
| 972 |
| 928 EmbedderServiceHandler* Service::FindRootEmbedderHandler( | 973 EmbedderServiceHandler* Service::FindRootEmbedderHandler( |
| 929 const char* name) { | 974 const char* name) { |
| 930 EmbedderServiceHandler* current = root_service_handler_head_; | 975 EmbedderServiceHandler* current = root_service_handler_head_; |
| 931 while (current != NULL) { | 976 while (current != NULL) { |
| 932 if (strcmp(name, current->name()) == 0) { | 977 if (strcmp(name, current->name()) == 0) { |
| 933 return current; | 978 return current; |
| 934 } | 979 } |
| 935 current = current->next(); | 980 current = current->next(); |
| 936 } | 981 } |
| 937 return NULL; | 982 return NULL; |
| (...skipping 2389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3327 ServiceMethodDescriptor& method = service_methods_[i]; | 3372 ServiceMethodDescriptor& method = service_methods_[i]; |
| 3328 if (strcmp(method_name, method.name) == 0) { | 3373 if (strcmp(method_name, method.name) == 0) { |
| 3329 return &method; | 3374 return &method; |
| 3330 } | 3375 } |
| 3331 } | 3376 } |
| 3332 return NULL; | 3377 return NULL; |
| 3333 } | 3378 } |
| 3334 | 3379 |
| 3335 | 3380 |
| 3336 } // namespace dart | 3381 } // namespace dart |
| OLD | NEW |