2017-05-03 04:29:04 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2016-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2017-05-03 04:29:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2017-10-03 12:45:31 +00:00
|
|
|
#include <functional>
|
2017-05-03 04:29:04 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2017-10-03 12:45:31 +00:00
|
|
|
|
2017-05-03 04:29:04 +00:00
|
|
|
namespace facebook {
|
|
|
|
namespace react {
|
|
|
|
|
|
|
|
class IDestructible {
|
2017-12-15 17:10:47 +00:00
|
|
|
public:
|
2017-05-03 04:29:04 +00:00
|
|
|
virtual ~IDestructible() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct InspectorPage {
|
|
|
|
const int id;
|
|
|
|
const std::string title;
|
2018-02-13 16:06:43 +00:00
|
|
|
const std::string vm;
|
2017-05-03 04:29:04 +00:00
|
|
|
};
|
|
|
|
|
2017-12-15 17:10:47 +00:00
|
|
|
/// IRemoteConnection allows the VM to send debugger messages to the client.
|
2017-05-03 04:29:04 +00:00
|
|
|
class IRemoteConnection : public IDestructible {
|
2017-12-15 17:10:47 +00:00
|
|
|
public:
|
2017-11-27 15:05:22 +00:00
|
|
|
virtual ~IRemoteConnection() = 0;
|
2017-05-03 04:29:04 +00:00
|
|
|
virtual void onMessage(std::string message) = 0;
|
|
|
|
virtual void onDisconnect() = 0;
|
|
|
|
};
|
|
|
|
|
2017-12-15 17:10:47 +00:00
|
|
|
/// ILocalConnection allows the client to send debugger messages to the VM.
|
2017-05-03 04:29:04 +00:00
|
|
|
class ILocalConnection : public IDestructible {
|
2017-12-15 17:10:47 +00:00
|
|
|
public:
|
2017-05-03 04:29:04 +00:00
|
|
|
virtual ~ILocalConnection() = 0;
|
|
|
|
virtual void sendMessage(std::string message) = 0;
|
|
|
|
virtual void disconnect() = 0;
|
|
|
|
};
|
|
|
|
|
2017-12-15 17:10:47 +00:00
|
|
|
/// IInspector tracks debuggable JavaScript targets (pages).
|
2018-01-26 04:09:09 +00:00
|
|
|
class IInspector : public IDestructible {
|
2017-12-15 17:10:47 +00:00
|
|
|
public:
|
|
|
|
using ConnectFunc = std::function<std::unique_ptr<ILocalConnection>(
|
|
|
|
std::unique_ptr<IRemoteConnection>)>;
|
2017-05-03 04:29:04 +00:00
|
|
|
|
2018-01-26 04:09:09 +00:00
|
|
|
virtual ~IInspector() = 0;
|
|
|
|
|
2017-12-15 17:10:47 +00:00
|
|
|
/// addPage is called by the VM to add a page to the list of debuggable pages.
|
2018-02-13 16:06:43 +00:00
|
|
|
virtual int addPage(const std::string& title, const std::string& vm, ConnectFunc connectFunc) = 0;
|
2017-12-15 17:10:47 +00:00
|
|
|
|
|
|
|
/// removePage is called by the VM to remove a page from the list of
|
|
|
|
/// debuggable pages.
|
|
|
|
virtual void removePage(int pageId) = 0;
|
|
|
|
|
|
|
|
/// getPages is called by the client to list all debuggable pages.
|
2017-05-03 04:29:04 +00:00
|
|
|
virtual std::vector<InspectorPage> getPages() const = 0;
|
2017-12-15 17:10:47 +00:00
|
|
|
|
|
|
|
/// connect is called by the client to initiate a debugging session on the
|
|
|
|
/// given page.
|
|
|
|
virtual std::unique_ptr<ILocalConnection> connect(
|
|
|
|
int pageId,
|
|
|
|
std::unique_ptr<IRemoteConnection> remote) = 0;
|
2017-05-03 04:29:04 +00:00
|
|
|
};
|
|
|
|
|
2017-12-15 17:10:47 +00:00
|
|
|
/// getInspectorInstance retrieves the singleton inspector that tracks all
|
|
|
|
/// debuggable pages in this process.
|
|
|
|
extern IInspector& getInspectorInstance();
|
|
|
|
|
|
|
|
/// makeTestInspectorInstance creates an independent inspector instance that
|
|
|
|
/// should only be used in tests.
|
|
|
|
extern std::unique_ptr<IInspector> makeTestInspectorInstance();
|
|
|
|
|
|
|
|
} // namespace react
|
|
|
|
} // namespace facebook
|