RemoteInspectorDebuggableConnection.h [plain text]
#if ENABLE(REMOTE_INSPECTOR)
#ifndef RemoteInspectorDebuggableConnection_h
#define RemoteInspectorDebuggableConnection_h
#import "InspectorFrontendChannel.h"
#import "RemoteInspectorDebuggable.h"
#import <mutex>
#import <wtf/RetainPtr.h>
#import <wtf/ThreadSafeRefCounted.h>
OBJC_CLASS NSString;
namespace Inspector {
class RemoteInspectorBlock {
public:
RemoteInspectorBlock(void (^task)())
: m_task(Block_copy(task))
{
}
RemoteInspectorBlock(const RemoteInspectorBlock& other)
: m_task(Block_copy(other.m_task))
{
}
~RemoteInspectorBlock()
{
Block_release(m_task);
}
RemoteInspectorBlock& operator=(const RemoteInspectorBlock& other)
{
void (^oldTask)() = m_task;
m_task = Block_copy(other.m_task);
Block_release(oldTask);
return *this;
}
void operator()() const
{
m_task();
}
private:
void (^m_task)();
};
typedef Vector<RemoteInspectorBlock> RemoteInspectorQueue;
class RemoteInspectorDebuggableConnection final : public ThreadSafeRefCounted<RemoteInspectorDebuggableConnection>, public FrontendChannel {
public:
RemoteInspectorDebuggableConnection(RemoteInspectorDebuggable*, NSString *connectionIdentifier, NSString *destination, RemoteInspectorDebuggable::DebuggableType);
virtual ~RemoteInspectorDebuggableConnection();
NSString *destination() const;
NSString *connectionIdentifier() const;
unsigned identifier() const { return m_identifier; }
bool setup(bool isAutomaticInspection, bool automaticallyPause);
void close();
void closeFromDebuggable();
void sendMessageToBackend(NSString *);
virtual bool sendMessageToFrontend(const String&) override;
std::mutex& queueMutex() { return m_queueMutex; }
RemoteInspectorQueue queue() const { return m_queue; }
void clearQueue() { m_queue.clear(); }
private:
void dispatchAsyncOnDebuggable(void (^block)());
void setupRunLoop();
void teardownRunLoop();
void queueTaskOnPrivateRunLoop(void (^block)());
std::mutex m_debuggableMutex;
RetainPtr<CFRunLoopRef> m_runLoop;
RetainPtr<CFRunLoopSourceRef> m_runLoopSource;
RemoteInspectorQueue m_queue;
std::mutex m_queueMutex;
RemoteInspectorDebuggable* m_debuggable;
RetainPtr<NSString> m_connectionIdentifier;
RetainPtr<NSString> m_destination;
unsigned m_identifier;
bool m_connected;
};
}
#endif // RemoteInspectorDebuggableConnection_h
#endif // ENABLE(REMOTE_INSPECTOR)