1 #pragma once 2 3 #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 4 5 #if !HAVE_INSPECTOR 6 #error("This header can only be used when inspector is enabled") 7 #endif 8 9 #include "inspector_socket_server.h" 10 #include "node_mutex.h" 11 12 #include "uv.h" 13 14 #include <cstddef> 15 #include <memory> 16 17 namespace node { 18 // Forward declaration to break recursive dependency chain with src/env.h. 19 class Environment; 20 namespace inspector { 21 22 class MainThreadHandle; 23 class RequestQueue; 24 25 class InspectorIo { 26 public: 27 // Start the inspector agent thread, waiting for it to initialize 28 // bool Start(); 29 // Returns empty pointer if thread was not started 30 static std::unique_ptr<InspectorIo> Start( 31 std::shared_ptr<MainThreadHandle> main_thread, 32 const std::string& path, 33 std::shared_ptr<ExclusiveAccess<HostPort>> host_port, 34 const InspectPublishUid& inspect_publish_uid); 35 36 // Will block till the transport thread shuts down 37 ~InspectorIo(); 38 39 void StopAcceptingNewConnections(); 40 std::string GetWsUrl() const; 41 42 private: 43 InspectorIo(std::shared_ptr<MainThreadHandle> handle, 44 const std::string& path, 45 std::shared_ptr<ExclusiveAccess<HostPort>> host_port, 46 const InspectPublishUid& inspect_publish_uid); 47 48 // Wrapper for agent->ThreadMain() 49 static void ThreadMain(void* agent); 50 51 // Runs a uv_loop_t 52 void ThreadMain(); 53 54 // This is a thread-safe object that will post async tasks. It lives as long 55 // as an Inspector object lives (almost as long as an Isolate). 56 std::shared_ptr<MainThreadHandle> main_thread_; 57 // Used to post on a frontend interface thread, lives while the server is 58 // running 59 std::shared_ptr<RequestQueue> request_queue_; 60 std::shared_ptr<ExclusiveAccess<HostPort>> host_port_; 61 InspectPublishUid inspect_publish_uid_; 62 63 // The IO thread runs its own uv_loop to implement the TCP server off 64 // the main thread. 65 uv_thread_t thread_; 66 67 // For setting up interthread communications 68 Mutex thread_start_lock_; 69 ConditionVariable thread_start_condition_; 70 std::string script_name_; 71 // May be accessed from any thread 72 const std::string id_; 73 }; 74 75 } // namespace inspector 76 } // namespace node 77 78 #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 79