diff options
author | Eugene Ostroukhov <eostroukhov@google.com> | 2018-05-21 16:59:04 -0700 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-07-13 23:42:50 +0200 |
commit | 39977db7c015e94d33885249f50e62fa8b1f1bb9 (patch) | |
tree | fb330cb04106d7a030b1599549f5503c3ea086ea /src/inspector_agent.h | |
parent | 9374a83d6983710844c5436f32c14242ba600a20 (diff) | |
download | android-node-v8-39977db7c015e94d33885249f50e62fa8b1f1bb9.tar.gz android-node-v8-39977db7c015e94d33885249f50e62fa8b1f1bb9.tar.bz2 android-node-v8-39977db7c015e94d33885249f50e62fa8b1f1bb9.zip |
inspector: split main thread interface from transport
Workers debugging will require interfacing between the "main" inspector
and per-worker isolate inspectors. This is consistent with what WS
interface does. This change is a refactoring change and does not change
the functionality.
PR-URL: https://github.com/nodejs/node/pull/21182
Fixes: https://github.com/nodejs/node/issues/21725
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/inspector_agent.h')
-rw-r--r-- | src/inspector_agent.h | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/src/inspector_agent.h b/src/inspector_agent.h index 7295d048b6..dcd6e13aba 100644 --- a/src/inspector_agent.h +++ b/src/inspector_agent.h @@ -20,7 +20,6 @@ class StringView; namespace node { // Forward declaration to break recursive dependency chain with src/env.h. class Environment; -class NodePlatform; struct ContextInfo; namespace inspector { @@ -29,12 +28,8 @@ class NodeInspectorClient; class InspectorSession { public: - InspectorSession(int session_id, std::shared_ptr<NodeInspectorClient> client); - ~InspectorSession(); - void Dispatch(const v8_inspector::StringView& message); - private: - int session_id_; - std::shared_ptr<NodeInspectorClient> client_; + virtual ~InspectorSession() {} + virtual void Dispatch(const v8_inspector::StringView& message) = 0; }; class InspectorSessionDelegate { @@ -50,15 +45,21 @@ class Agent { ~Agent(); // Create client_, may create io_ if option enabled - bool Start(const char* path, const DebugOptions& options); + bool Start(const std::string& path, const DebugOptions& options); // Stop and destroy io_ void Stop(); - bool IsStarted() { return !!client_; } - - // IO thread started, and client connected - bool IsWaitingForConnect(); - + bool IsListening() { return io_ != nullptr; } + // Returns true if the Node inspector is actually in use. It will be true + // if either the user explicitely opted into inspector (e.g. with the + // --inspect command line flag) or if inspector JS API had been used. + bool IsActive(); + + // Option is set to wait for session connection + bool WillWaitForConnect(); + // Blocks till frontend connects and sends "runIfWaitingForDebugger" + void WaitForConnect(); + // Blocks till all the sessions with "WaitForDisconnectOnShutdown" disconnect void WaitForDisconnect(); void FatalException(v8::Local<v8::Value> error, v8::Local<v8::Message> message); @@ -77,22 +78,20 @@ class Agent { void EnableAsyncHook(); void DisableAsyncHook(); - // Called by the WS protocol and JS binding to create inspector sessions. + // Called to create inspector sessions that can be used from the main thread. // The inspector responds by using the delegate to send messages back. std::unique_ptr<InspectorSession> Connect( - std::unique_ptr<InspectorSessionDelegate> delegate); + std::unique_ptr<InspectorSessionDelegate> delegate, + bool prevent_shutdown); void PauseOnNextJavascriptStatement(const std::string& reason); - // Returns true as long as there is at least one connected session. - bool HasConnectedSessions(); - InspectorIo* io() { return io_.get(); } // Can only be called from the main thread. - bool StartIoThread(bool wait_for_connect); + bool StartIoThread(); // Calls StartIoThread() from off the main thread. void RequestIoThreadStart(); @@ -105,7 +104,9 @@ class Agent { const node::Persistent<v8::Function>& fn); node::Environment* parent_env_; + // Encapsulates majority of the Inspector functionality std::shared_ptr<NodeInspectorClient> client_; + // Interface for transports, e.g. WebSocket server std::unique_ptr<InspectorIo> io_; std::string path_; DebugOptions debug_options_; |