2013-07-22 15:39:03 +00:00
|
|
|
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
|
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef VM_SERVICE_H_
|
|
|
|
#define VM_SERVICE_H_
|
|
|
|
|
|
|
|
#include "include/dart_api.h"
|
|
|
|
|
2013-12-17 21:11:18 +00:00
|
|
|
#include "vm/allocation.h"
|
2015-01-29 18:31:27 +00:00
|
|
|
#include "vm/os_thread.h"
|
2013-12-17 21:11:18 +00:00
|
|
|
|
2013-07-22 15:39:03 +00:00
|
|
|
namespace dart {
|
|
|
|
|
2014-08-18 15:35:03 +00:00
|
|
|
class Array;
|
2014-06-30 22:46:27 +00:00
|
|
|
class DebuggerEvent;
|
2014-02-18 22:38:11 +00:00
|
|
|
class EmbedderServiceHandler;
|
2014-08-18 15:35:03 +00:00
|
|
|
class GCEvent;
|
2013-07-22 15:39:03 +00:00
|
|
|
class Instance;
|
|
|
|
class Isolate;
|
2014-02-18 22:38:11 +00:00
|
|
|
class JSONStream;
|
2014-08-18 15:35:03 +00:00
|
|
|
class Object;
|
2014-01-15 20:45:39 +00:00
|
|
|
class RawInstance;
|
2014-06-30 22:46:27 +00:00
|
|
|
class String;
|
2013-07-22 15:39:03 +00:00
|
|
|
|
|
|
|
class Service : public AllStatic {
|
|
|
|
public:
|
2015-02-02 19:35:57 +00:00
|
|
|
static const char* kIsolateName;
|
2015-01-29 18:31:27 +00:00
|
|
|
static bool IsServiceIsolateName(const char* name);
|
|
|
|
|
2014-01-15 20:45:39 +00:00
|
|
|
// Handles a message which is not directed to an isolate.
|
|
|
|
static void HandleRootMessage(const Instance& message);
|
|
|
|
|
|
|
|
// Handles a message which is directed to a particular isolate.
|
2014-07-03 12:56:02 +00:00
|
|
|
static void HandleIsolateMessage(Isolate* isolate, const Array& message);
|
2014-01-15 20:45:39 +00:00
|
|
|
|
2014-01-14 22:34:43 +00:00
|
|
|
static Isolate* GetServiceIsolate(void* callback_data);
|
|
|
|
static bool SendIsolateStartupMessage();
|
|
|
|
static bool SendIsolateShutdownMessage();
|
2014-06-30 22:46:27 +00:00
|
|
|
|
2015-01-30 22:03:18 +00:00
|
|
|
static bool IsRunning();
|
|
|
|
static void SetServicePort(Dart_Port port);
|
|
|
|
static void SetServiceIsolate(Isolate* isolate);
|
|
|
|
static bool HasServiceIsolate();
|
|
|
|
static bool IsServiceIsolate(Isolate* isolate);
|
2014-09-10 22:38:33 +00:00
|
|
|
|
2015-01-29 18:31:27 +00:00
|
|
|
static Dart_Port WaitForLoadPort();
|
|
|
|
static Dart_Port LoadPort();
|
|
|
|
static void SetLoadPort(Dart_Port port);
|
|
|
|
|
2014-06-30 22:46:27 +00:00
|
|
|
static void SetEventMask(uint32_t mask);
|
|
|
|
|
|
|
|
// Is the service interested in debugger events?
|
|
|
|
static bool NeedsDebuggerEvents() {
|
|
|
|
return IsRunning() && ((event_mask_ & kEventFamilyDebugMask) != 0);
|
|
|
|
}
|
2014-08-07 23:52:18 +00:00
|
|
|
// Is the service interested in garbage collection events?
|
|
|
|
static bool NeedsGCEvents() {
|
|
|
|
return IsRunning() && ((event_mask_ & kEventFamilyGCMask) != 0);
|
|
|
|
}
|
2014-06-30 22:46:27 +00:00
|
|
|
|
|
|
|
static void HandleDebuggerEvent(DebuggerEvent* event);
|
2014-08-07 23:52:18 +00:00
|
|
|
static void HandleGCEvent(GCEvent* event);
|
2014-02-18 22:38:11 +00:00
|
|
|
|
|
|
|
static void RegisterIsolateEmbedderCallback(
|
|
|
|
const char* name,
|
|
|
|
Dart_ServiceRequestCallback callback,
|
|
|
|
void* user_data);
|
|
|
|
|
|
|
|
static void RegisterRootEmbedderCallback(
|
|
|
|
const char* name,
|
|
|
|
Dart_ServiceRequestCallback callback,
|
|
|
|
void* user_data);
|
|
|
|
|
2015-02-03 23:17:05 +00:00
|
|
|
static void SendEchoEvent(Isolate* isolate, const char* text);
|
2014-12-02 19:33:09 +00:00
|
|
|
static void SendGraphEvent(Isolate* isolate);
|
2014-08-18 15:35:03 +00:00
|
|
|
|
2015-01-29 18:31:27 +00:00
|
|
|
static void MaybeInjectVMServiceLibrary(Isolate* isolate);
|
|
|
|
|
|
|
|
static void RunService();
|
|
|
|
|
|
|
|
static void FinishedInitializing();
|
|
|
|
|
2015-02-02 19:35:57 +00:00
|
|
|
static Dart_IsolateCreateCallback create_callback() {
|
|
|
|
return create_callback_;
|
|
|
|
}
|
|
|
|
|
2014-02-18 22:38:11 +00:00
|
|
|
private:
|
2014-06-30 22:46:27 +00:00
|
|
|
// These must be kept in sync with service/constants.dart
|
|
|
|
static const int kEventFamilyDebug = 0;
|
2014-08-07 23:52:18 +00:00
|
|
|
static const int kEventFamilyGC = 1;
|
2014-06-30 22:46:27 +00:00
|
|
|
static const uint32_t kEventFamilyDebugMask = (1 << kEventFamilyDebug);
|
2014-08-07 23:52:18 +00:00
|
|
|
static const uint32_t kEventFamilyGCMask = (1 << kEventFamilyGC);
|
2014-06-30 22:46:27 +00:00
|
|
|
|
2014-02-18 22:38:11 +00:00
|
|
|
static void EmbedderHandleMessage(EmbedderServiceHandler* handler,
|
|
|
|
JSONStream* js);
|
2015-01-29 18:31:27 +00:00
|
|
|
|
2014-02-18 22:38:11 +00:00
|
|
|
static EmbedderServiceHandler* FindIsolateEmbedderHandler(const char* name);
|
|
|
|
static EmbedderServiceHandler* FindRootEmbedderHandler(const char* name);
|
2014-06-30 22:46:27 +00:00
|
|
|
static Dart_Handle GetSource(const char* name);
|
|
|
|
static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag, Dart_Handle library,
|
|
|
|
Dart_Handle url);
|
2015-01-29 18:31:27 +00:00
|
|
|
|
2014-08-18 15:35:03 +00:00
|
|
|
static void SendEvent(intptr_t eventId, const Object& eventMessage);
|
|
|
|
// Does not take ownership of 'data'.
|
|
|
|
static void SendEvent(intptr_t eventId,
|
|
|
|
const String& meta,
|
|
|
|
const uint8_t* data,
|
|
|
|
intptr_t size);
|
2014-06-30 22:46:27 +00:00
|
|
|
|
|
|
|
static EmbedderServiceHandler* isolate_service_handler_head_;
|
2014-02-18 22:38:11 +00:00
|
|
|
static EmbedderServiceHandler* root_service_handler_head_;
|
2014-06-30 22:46:27 +00:00
|
|
|
|
2015-01-30 22:03:18 +00:00
|
|
|
|
2015-02-02 19:35:57 +00:00
|
|
|
static Dart_IsolateCreateCallback create_callback_;
|
2015-01-29 18:31:27 +00:00
|
|
|
static Monitor* monitor_;
|
|
|
|
static bool initializing_;
|
2015-01-30 22:03:18 +00:00
|
|
|
static Isolate* service_isolate_;
|
|
|
|
static Dart_Port service_port_;
|
2015-01-29 18:31:27 +00:00
|
|
|
static Dart_Port load_port_;
|
2014-06-30 22:46:27 +00:00
|
|
|
static uint32_t event_mask_;
|
2013-07-22 15:39:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dart
|
|
|
|
|
|
|
|
#endif // VM_SERVICE_H_
|