OLD | NEW |
| (Empty) |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef V8_DEBUG_AGENT_H_ | |
6 #define V8_DEBUG_AGENT_H_ | |
7 | |
8 #include "../include/v8-debug.h" | |
9 #include "platform.h" | |
10 | |
11 namespace v8 { | |
12 namespace internal { | |
13 | |
14 // Forward decelrations. | |
15 class DebuggerAgentSession; | |
16 class Socket; | |
17 | |
18 | |
19 // Debugger agent which starts a socket listener on the debugger port and | |
20 // handles connection from a remote debugger. | |
21 class DebuggerAgent: public Thread { | |
22 public: | |
23 DebuggerAgent(Isolate* isolate, const char* name, int port); | |
24 ~DebuggerAgent(); | |
25 | |
26 void Shutdown(); | |
27 void WaitUntilListening(); | |
28 | |
29 Isolate* isolate() { return isolate_; } | |
30 | |
31 private: | |
32 void Run(); | |
33 void CreateSession(Socket* socket); | |
34 void DebuggerMessage(const v8::Debug::Message& message); | |
35 void CloseSession(); | |
36 void OnSessionClosed(DebuggerAgentSession* session); | |
37 | |
38 Isolate* isolate_; | |
39 SmartArrayPointer<const char> name_; // Name of the embedding application. | |
40 int port_; // Port to use for the agent. | |
41 Socket* server_; // Server socket for listen/accept. | |
42 bool terminate_; // Termination flag. | |
43 RecursiveMutex session_access_; // Mutex guarding access to session_. | |
44 DebuggerAgentSession* session_; // Current active session if any. | |
45 Semaphore terminate_now_; // Semaphore to signal termination. | |
46 Semaphore listening_; | |
47 | |
48 friend class DebuggerAgentSession; | |
49 friend void DebuggerAgentMessageHandler(const v8::Debug::Message& message); | |
50 | |
51 DISALLOW_COPY_AND_ASSIGN(DebuggerAgent); | |
52 }; | |
53 | |
54 | |
55 // Debugger agent session. The session receives requests from the remote | |
56 // debugger and sends debugger events/responses to the remote debugger. | |
57 class DebuggerAgentSession: public Thread { | |
58 public: | |
59 DebuggerAgentSession(DebuggerAgent* agent, Socket* client) | |
60 : Thread("v8:DbgAgntSessn"), | |
61 agent_(agent), client_(client) {} | |
62 ~DebuggerAgentSession(); | |
63 | |
64 void DebuggerMessage(Vector<uint16_t> message); | |
65 void Shutdown(); | |
66 | |
67 private: | |
68 void Run(); | |
69 | |
70 void DebuggerMessage(Vector<char> message); | |
71 | |
72 DebuggerAgent* agent_; | |
73 Socket* client_; | |
74 | |
75 DISALLOW_COPY_AND_ASSIGN(DebuggerAgentSession); | |
76 }; | |
77 | |
78 | |
79 // Utility methods factored out to be used by the D8 shell as well. | |
80 class DebuggerAgentUtil { | |
81 public: | |
82 static const char* const kContentLength; | |
83 | |
84 static SmartArrayPointer<char> ReceiveMessage(Socket* conn); | |
85 static bool SendConnectMessage(Socket* conn, const char* embedding_host); | |
86 static bool SendMessage(Socket* conn, const Vector<uint16_t> message); | |
87 static bool SendMessage(Socket* conn, const v8::Handle<v8::String> message); | |
88 static int ReceiveAll(Socket* conn, char* data, int len); | |
89 }; | |
90 | |
91 } } // namespace v8::internal | |
92 | |
93 #endif // V8_DEBUG_AGENT_H_ | |
OLD | NEW |