3 * Copyright (c) 2007 - 2010, Blue Static <http://www.bluestatic.org>
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.
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.
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
17 #import <Cocoa/Cocoa.h>
19 #import "Breakpoint.h"
20 #import "StackFrame.h"
22 @
class LoggingController
;
24 @protocol DebuggerConnectionDelegate
;
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 DebuggerConnection
: NSObject
35 // The port to connect on.
38 // If the connection to the debugger engine is currently active.
41 // Human-readable status of the connection.
44 // The connection's delegate.
45 id
<DebuggerConnectionDelegate
> delegate
;
47 // The raw CFSocket on which the two streams are based. Strong.
50 // The read stream that is scheduled on the main run loop. Weak.
51 CFReadStreamRef readStream_
;
53 // The write stream. Weak.
54 CFWriteStreamRef writeStream_
;
56 // An ever-increasing integer that gives each transaction a unique ID for the
58 NSUInteger transactionID
;
60 // The most recently received transaction ID.
61 NSUInteger lastReadTransaction_
;
63 // The last transactionID written to the stream.
64 NSUInteger lastWrittenTransaction_
;
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_
;
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_
;
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
79 NSRecursiveLock
* writeQueueLock_
;
81 // Information about the current read loop. We append to |currentPacket_|
82 // until |currentPacketSize_| has reached |packetSize_|.
83 NSMutableString
* currentPacket_
;
85 int currentPacketIndex_
;
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_
;
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_
;
100 @
property (readonly
, copy
) NSString
* status
;
101 @
property (assign
) id
<DebuggerConnectionDelegate
> delegate
;
104 - (id
)initWithPort
:(NSUInteger
)aPort
;
108 - (NSString
*)remoteHost
;
117 - (void)addBreakpoint
:(Breakpoint
*)bp
;
118 - (void)removeBreakpoint
:(Breakpoint
*)bp
;
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
;
126 // Delegate ////////////////////////////////////////////////////////////////////
128 @protocol DebuggerConnectionDelegate
<NSObject
>
130 // Passes up errors from SocketWrapper and any other errors generated by the
132 - (void)errorEncountered
:(NSString
*)error
;
134 // Called when the socket connects. Passed up from SocketWrapper.
135 - (void)debuggerConnected
;
137 // Called when we disconnect.
138 - (void)debuggerDisconnected
;
140 // Tells the debugger to destroy the current stack display.
141 - (void)clobberStack
;
143 // Tells the debugger that a new stack frame is avaliable.
144 - (void)newStackFrame
:(StackFrame
*)frame
;
146 // Tells the debugger that new source is available for the given frame.
147 - (void)sourceUpdated
:(StackFrame
*)frame
;
149 // Callback from |-getProperty:|.
150 - (void)receivedProperties
:(NSArray
*)properties forTransaction
:(NSInteger
)transaction
;