GCC Code Coverage Report
Directory: ../src/ Exec Total Coverage
File: /home/node-core-coverage/node-core-coverage/workdir/node/out/../src/inspector_socket_server.h Lines: 1 3 33.3 %
Date: 2017-01-02 Branches: 0 0 0.0 %

Line Branch Exec Source
1
#ifndef SRC_INSPECTOR_SOCKET_SERVER_H_
2
#define SRC_INSPECTOR_SOCKET_SERVER_H_
3
4
#include "inspector_agent.h"
5
#include "inspector_socket.h"
6
#include "uv.h"
7
8
#include <map>
9
#include <string>
10
#include <vector>
11
12
#if !HAVE_INSPECTOR
13
#error("This header can only be used when inspector is enabled")
14
#endif
15
16
namespace node {
17
namespace inspector {
18
19
class Closer;
20
class SocketSession;
21
22
7
class SocketServerDelegate {
23
 public:
24
  virtual bool StartSession(int session_id, const std::string& target_id) = 0;
25
  virtual void EndSession(int session_id) = 0;
26
  virtual void MessageReceived(int session_id, const std::string& message) = 0;
27
  virtual std::vector<std::string> GetTargetIds() = 0;
28
  virtual std::string GetTargetTitle(const std::string& id) = 0;
29
  virtual std::string GetTargetUrl(const std::string& id) = 0;
30
};
31
32
class InspectorSocketServer {
33
 public:
34
  using ServerCallback = void (*)(InspectorSocketServer*);
35
  InspectorSocketServer(SocketServerDelegate* delegate, int port);
36
  bool Start(uv_loop_t* loop);
37
  void Stop(ServerCallback callback);
38
  void Send(int session_id, const std::string& message);
39
  void TerminateConnections(ServerCallback callback);
40
41
 private:
42
  static bool HandshakeCallback(InspectorSocket* socket,
43
                                enum inspector_handshake_event state,
44
                                const std::string& path);
45
  static void SocketConnectedCallback(uv_stream_t* server, int status);
46
  static void ServerClosedCallback(uv_handle_t* server);
47
  template<typename SomeUvStruct>
48
  static InspectorSocketServer* From(SomeUvStruct* server) {
49
    return node::ContainerOf(&InspectorSocketServer::server_,
50
                             reinterpret_cast<uv_tcp_t*>(server));
51
  }
52
  bool RespondToGet(InspectorSocket* socket, const std::string& path);
53
  void SendListResponse(InspectorSocket* socket);
54
  void ReadCallback(InspectorSocket* socket, ssize_t read, const uv_buf_t* buf);
55
  bool SessionStarted(SocketSession* session, const std::string& id);
56
  void SessionTerminated(int id);
57
  bool TargetExists(const std::string& id);
58
  static void SocketSessionDeleter(SocketSession*);
59
  SocketServerDelegate* Delegate() { return delegate_; }
60
61
  uv_loop_t* loop_;
62
  SocketServerDelegate* const delegate_;
63
  const int port_;
64
  std::string path_;
65
  uv_tcp_t server_;
66
  Closer* closer_;
67
  std::map<int, SocketSession*> connected_sessions_;
68
  int next_session_id_;
69
70
  friend class SocketSession;
71
  friend class Closer;
72
};
73
74
}  // namespace inspector
75
}  // namespace node
76
77
#endif  // SRC_INSPECTOR_SOCKET_SERVER_H_