-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathinspector_agent.h
137 lines (108 loc) · 4.22 KB
/
inspector_agent.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
* Copyright Node.js contributors. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifndef SRC_INSPECTOR_AGENT_H_
#define SRC_INSPECTOR_AGENT_H_
#include <memory>
#include <string>
#include <functional>
#include "v8.h"
#include "v8-inspector.h"
#include <stddef.h>
#ifdef WIN32
#define EXPORT_ATTRIBUTE __declspec(dllexport)
#else
#define EXPORT_ATTRIBUTE __attribute__((visibility("default")))
#endif
namespace inspector {
using namespace v8;
class InspectorSessionDelegate {
public:
virtual ~InspectorSessionDelegate() = default;
virtual bool WaitForFrontendMessageWhilePaused() = 0;
virtual void SendMessageToFrontend(const v8_inspector::StringView& message)
= 0;
};
class InspectorIo;
class CBInspectorClient;
class Agent {
public:
EXPORT_ATTRIBUTE static void SetLogFileStream(FILE *file);
EXPORT_ATTRIBUTE Agent(const std::string &host_name, const std::string &file_path, const std::string &target_id = std::string());
EXPORT_ATTRIBUTE ~Agent();
// Create client_, may create io_ if option enabled
EXPORT_ATTRIBUTE bool Start(Isolate* isolate, Platform* platform, const char* file_path = nullptr)
{
if(! Prepare(isolate, platform, file_path))
return false;
return Run();
}
EXPORT_ATTRIBUTE bool Prepare(Isolate* isolate, Platform* platform, const char* file_path = nullptr);
EXPORT_ATTRIBUTE bool Run();
EXPORT_ATTRIBUTE const std::string &GetFrontendURL();
// Stop and destroy io_
EXPORT_ATTRIBUTE void Stop();
bool IsStarted() { return !!client_; }
bool IsValid();
// IO thread started, and client connected
bool IsConnected();
void WaitForDisconnect();
EXPORT_ATTRIBUTE void FatalException(Local<Value> error,
v8::Local<v8::Message> message);
// These methods are called by the WS protocol and JS binding to create
// inspector sessions. The inspector responds by using the delegate to send
// messages back.
void Connect(InspectorSessionDelegate* delegate);
void Disconnect();
void Dispatch(const v8_inspector::StringView& message);
InspectorSessionDelegate* delegate();
void RunMessageLoop();
bool enabled() { return enabled_; }
EXPORT_ATTRIBUTE void PauseOnNextJavascriptStatement(const std::string& reason);
// Initialize 'inspector' module bindings
static void InitInspector(Local<Object> target,
Local<Value> unused,
Local<Context> context,
void* priv);
InspectorIo* io() {
return io_.get();
}
// Can only be called from the the main thread.
bool StartIoThread(bool wait_for_connect);
// Calls StartIoThread() from off the main thread.
void RequestIoThreadStart();
private:
std::unique_ptr<CBInspectorClient> client_;
std::unique_ptr<InspectorIo> io_;
Platform* platform_;
Isolate* isolate_;
bool enabled_;
std::string path_;
std::string host_name_;
std::string file_path_;
std::string target_id_;
std::string frontend_url_buff_;
static const int VALID_MAGIC = 0xF0F0F0F0;
static const int BAD_MAGIC = 0xDE11C0DE;
int magic_ = VALID_MAGIC;
};
} // namespace inspector
#endif // SRC_INSPECTOR_AGENT_H_