]>
Commit | Line | Data |
---|---|---|
81345200 A |
1 | /* |
2 | * Copyright (C) 2013 Apple Inc. All Rights Reserved. | |
3 | * | |
4 | * Redistribution and use in source and binary forms, with or without | |
5 | * modification, are permitted provided that the following conditions | |
6 | * are met: | |
7 | * 1. Redistributions of source code must retain the above copyright | |
8 | * notice, this list of conditions and the following disclaimer. | |
9 | * 2. Redistributions in binary form must reproduce the above copyright | |
10 | * notice, this list of conditions and the following disclaimer in the | |
11 | * documentation and/or other materials provided with the distribution. | |
12 | * | |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 | */ | |
25 | ||
26 | #if ENABLE(REMOTE_INSPECTOR) | |
27 | ||
28 | #ifndef RemoteInspectorDebuggableConnection_h | |
29 | #define RemoteInspectorDebuggableConnection_h | |
30 | ||
31 | #import "InspectorFrontendChannel.h" | |
32 | #import "RemoteInspectorDebuggable.h" | |
81345200 A |
33 | #import <mutex> |
34 | #import <wtf/RetainPtr.h> | |
35 | #import <wtf/ThreadSafeRefCounted.h> | |
36 | ||
37 | OBJC_CLASS NSString; | |
38 | ||
39 | namespace Inspector { | |
40 | ||
41 | class RemoteInspectorBlock { | |
42 | public: | |
43 | RemoteInspectorBlock(void (^task)()) | |
44 | : m_task(Block_copy(task)) | |
45 | { | |
46 | } | |
47 | ||
48 | RemoteInspectorBlock(const RemoteInspectorBlock& other) | |
49 | : m_task(Block_copy(other.m_task)) | |
50 | { | |
51 | } | |
52 | ||
53 | ~RemoteInspectorBlock() | |
54 | { | |
55 | Block_release(m_task); | |
56 | } | |
57 | ||
58 | RemoteInspectorBlock& operator=(const RemoteInspectorBlock& other) | |
59 | { | |
60 | void (^oldTask)() = m_task; | |
61 | m_task = Block_copy(other.m_task); | |
62 | Block_release(oldTask); | |
63 | return *this; | |
64 | } | |
65 | ||
66 | void operator()() const | |
67 | { | |
68 | m_task(); | |
69 | } | |
70 | ||
71 | private: | |
72 | void (^m_task)(); | |
73 | }; | |
74 | ||
75 | typedef Vector<RemoteInspectorBlock> RemoteInspectorQueue; | |
76 | ||
ed1e77d3 | 77 | class RemoteInspectorDebuggableConnection final : public ThreadSafeRefCounted<RemoteInspectorDebuggableConnection>, public FrontendChannel { |
81345200 A |
78 | public: |
79 | RemoteInspectorDebuggableConnection(RemoteInspectorDebuggable*, NSString *connectionIdentifier, NSString *destination, RemoteInspectorDebuggable::DebuggableType); | |
80 | virtual ~RemoteInspectorDebuggableConnection(); | |
81 | ||
82 | NSString *destination() const; | |
83 | NSString *connectionIdentifier() const; | |
84 | unsigned identifier() const { return m_identifier; } | |
85 | ||
ed1e77d3 | 86 | bool setup(bool isAutomaticInspection, bool automaticallyPause); |
81345200 A |
87 | |
88 | void close(); | |
89 | void closeFromDebuggable(); | |
90 | ||
91 | void sendMessageToBackend(NSString *); | |
92 | virtual bool sendMessageToFrontend(const String&) override; | |
93 | ||
94 | std::mutex& queueMutex() { return m_queueMutex; } | |
95 | RemoteInspectorQueue queue() const { return m_queue; } | |
96 | void clearQueue() { m_queue.clear(); } | |
97 | ||
98 | private: | |
99 | void dispatchAsyncOnDebuggable(void (^block)()); | |
100 | ||
101 | void setupRunLoop(); | |
102 | void teardownRunLoop(); | |
103 | void queueTaskOnPrivateRunLoop(void (^block)()); | |
104 | ||
105 | // This connection from the RemoteInspector singleton to the Debuggable | |
106 | // can be used on multiple threads. So any access to the debuggable | |
107 | // itself must take this mutex to ensure m_debuggable is valid. | |
108 | std::mutex m_debuggableMutex; | |
109 | ||
110 | // If a debuggable has a specific run loop it wants to evaluate on | |
111 | // we setup our run loop sources on that specific run loop. | |
112 | RetainPtr<CFRunLoopRef> m_runLoop; | |
113 | RetainPtr<CFRunLoopSourceRef> m_runLoopSource; | |
114 | RemoteInspectorQueue m_queue; | |
115 | std::mutex m_queueMutex; | |
116 | ||
117 | RemoteInspectorDebuggable* m_debuggable; | |
118 | RetainPtr<NSString> m_connectionIdentifier; | |
119 | RetainPtr<NSString> m_destination; | |
120 | unsigned m_identifier; | |
121 | bool m_connected; | |
122 | }; | |
123 | ||
124 | } // namespace Inspector | |
125 | ||
126 | #endif // RemoteInspectorDebuggableConnection_h | |
127 | ||
128 | #endif // ENABLE(REMOTE_INSPECTOR) |