11cb0ef41Sopenharmony_ci#ifndef SRC_INSPECTOR_SOCKET_H_
21cb0ef41Sopenharmony_ci#define SRC_INSPECTOR_SOCKET_H_
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ci#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ci#include "util.h"
71cb0ef41Sopenharmony_ci#include "uv.h"
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci#include <string>
101cb0ef41Sopenharmony_ci#include <vector>
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cinamespace node {
131cb0ef41Sopenharmony_cinamespace inspector {
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciclass ProtocolHandler;
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci// HTTP Wrapper around a uv_tcp_t
181cb0ef41Sopenharmony_ciclass InspectorSocket {
191cb0ef41Sopenharmony_ci public:
201cb0ef41Sopenharmony_ci  class Delegate {
211cb0ef41Sopenharmony_ci   public:
221cb0ef41Sopenharmony_ci    virtual void OnHttpGet(const std::string& host,
231cb0ef41Sopenharmony_ci                           const std::string& path) = 0;
241cb0ef41Sopenharmony_ci    virtual void OnSocketUpgrade(const std::string& host,
251cb0ef41Sopenharmony_ci                                 const std::string& path,
261cb0ef41Sopenharmony_ci                                 const std::string& accept_key) = 0;
271cb0ef41Sopenharmony_ci    virtual void OnWsFrame(const std::vector<char>& frame) = 0;
281cb0ef41Sopenharmony_ci    virtual ~Delegate() = default;
291cb0ef41Sopenharmony_ci  };
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci  using DelegatePointer = std::unique_ptr<Delegate>;
321cb0ef41Sopenharmony_ci  using Pointer = std::unique_ptr<InspectorSocket>;
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ci  static Pointer Accept(uv_stream_t* server, DelegatePointer delegate);
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci  ~InspectorSocket();
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ci  void AcceptUpgrade(const std::string& accept_key);
391cb0ef41Sopenharmony_ci  void CancelHandshake();
401cb0ef41Sopenharmony_ci  void Write(const char* data, size_t len);
411cb0ef41Sopenharmony_ci  void SwitchProtocol(ProtocolHandler* handler);
421cb0ef41Sopenharmony_ci  std::string GetHost();
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_ci  InspectorSocket(const InspectorSocket&) = delete;
451cb0ef41Sopenharmony_ci  InspectorSocket& operator=(const InspectorSocket&) = delete;
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ci private:
481cb0ef41Sopenharmony_ci  static void Shutdown(ProtocolHandler*);
491cb0ef41Sopenharmony_ci  InspectorSocket() = default;
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_ci  DeleteFnPtr<ProtocolHandler, Shutdown> protocol_handler_;
521cb0ef41Sopenharmony_ci};
531cb0ef41Sopenharmony_ci
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ci}  // namespace inspector
561cb0ef41Sopenharmony_ci}  // namespace node
571cb0ef41Sopenharmony_ci
581cb0ef41Sopenharmony_ci#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_ci#endif  // SRC_INSPECTOR_SOCKET_H_
61