Rename DebuggerConnection to DebuggerProcessor in preparation for the separation...
[macgdbp.git] / Source / DebuggerProcessor.h
1 /*
2 * MacGDBp
3 * Copyright (c) 2007 - 2010, Blue Static <http://www.bluestatic.org>
4 *
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17 #import <Cocoa/Cocoa.h>
18
19 #import "Breakpoint.h"
20 #import "StackFrame.h"
21
22 @class LoggingController;
23
24 @protocol DebuggerProcessorDelegate;
25
26 // The DebuggerConnection is the communication layer between the application
27 // and the Xdebug engine. Clients can issue debugger commands using this class,
28 // which are sent in an asynchronous manner. Reads are also asynchronous and
29 // the primary client of this class should set itself as the delegate. The
30 // primary unit that this class deals with is the StackFrame; clients should
31 // maintain a stack structure and the Connection will inform the delegate when
32 // a new frame is created or the stack should be destroyed.
33 @interface DebuggerProcessor : NSObject
34 {
35 // The port to connect on.
36 NSUInteger port;
37
38 // If the connection to the debugger engine is currently active.
39 BOOL connected;
40
41 // Human-readable status of the connection.
42 NSString* status;
43
44 // The connection's delegate.
45 id <DebuggerProcessorDelegate> delegate;
46
47 // The raw CFSocket on which the two streams are based. Strong.
48 CFSocketRef socket_;
49
50 // The read stream that is scheduled on the main run loop. Weak.
51 CFReadStreamRef readStream_;
52
53 // The write stream. Weak.
54 CFWriteStreamRef writeStream_;
55
56 // An ever-increasing integer that gives each transaction a unique ID for the
57 // debugging engine.
58 NSUInteger transactionID;
59
60 // The most recently received transaction ID.
61 NSUInteger lastReadTransaction_;
62
63 // The last transactionID written to the stream.
64 NSUInteger lastWrittenTransaction_;
65
66 // Callback table. This maps transaction IDs to selectors. When the engine
67 // returns a response to the debugger, we will dispatch the response XML to
68 // the selector, based on transaction_id.
69 NSMutableDictionary* callTable_;
70
71 // To prevent blocked writing, we enqueue all writes and then wait for the
72 // write stream to tell us it's ready. We store the pending commands in this
73 // array. We use this as a stack (FIFO), with index 0 being first.
74 NSMutableArray* queuedWrites_;
75
76 // We send queued writes in multiple places, sometimes off a run loop event.
77 // Because of this, we need to ensure that only one client is dequeing and
78 // sending at a time.
79 NSRecursiveLock* writeQueueLock_;
80
81 // Information about the current read loop. We append to |currentPacket_|
82 // until |currentPacketSize_| has reached |packetSize_|.
83 NSMutableString* currentPacket_;
84 int packetSize_;
85 int currentPacketIndex_;
86
87 // A dictionary that maps routingIDs to StackFrame objects.
88 NSMutableDictionary* stackFrames_;
89 // The stack depth for the current build of |stackFrames_|.
90 NSInteger stackDepth_;
91 // The earliest transaction ID for the current build of |stackFrames_|.
92 NSInteger stackFirstTransactionID_;
93
94 // This stores additional context information for the callback selector.
95 // This dictionary is keyed by the same transaction IDs in |callTable_|, but
96 // also stores some other object that can be accessed in the callback.
97 NSMutableDictionary* callbackContext_;
98 }
99
100 @property (readonly, copy) NSString* status;
101 @property (assign) id <DebuggerProcessorDelegate> delegate;
102
103 // initializer
104 - (id)initWithPort:(NSUInteger)aPort;
105
106 // getter
107 - (NSUInteger)port;
108 - (NSString*)remoteHost;
109 - (BOOL)isConnected;
110
111 // communication
112 - (void)reconnect;
113 - (void)run;
114 - (void)stepIn;
115 - (void)stepOut;
116 - (void)stepOver;
117 - (void)addBreakpoint:(Breakpoint*)bp;
118 - (void)removeBreakpoint:(Breakpoint*)bp;
119
120 // Gets a property by name from the debugger engine. Returns a transaction ID
121 // which used in the delegate callback.
122 - (NSInteger)getProperty:(NSString*)property;
123
124 @end
125
126 // Delegate ////////////////////////////////////////////////////////////////////
127
128 @protocol DebuggerProcessorDelegate <NSObject>
129
130 // Passes up errors from SocketWrapper and any other errors generated by the
131 // GDBpConnection.
132 - (void)errorEncountered:(NSString*)error;
133
134 // Called when the socket connects. Passed up from SocketWrapper.
135 - (void)debuggerConnected;
136
137 // Called when we disconnect.
138 - (void)debuggerDisconnected;
139
140 // Tells the debugger to destroy the current stack display.
141 - (void)clobberStack;
142
143 // Tells the debugger that a new stack frame is avaliable.
144 - (void)newStackFrame:(StackFrame*)frame;
145
146 // Tells the debugger that new source is available for the given frame.
147 - (void)sourceUpdated:(StackFrame*)frame;
148
149 // Callback from |-getProperty:|.
150 - (void)receivedProperties:(NSArray*)properties forTransaction:(NSInteger)transaction;
151
152 @end
153