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 @
class LoggingController
;
21 @interface DebuggerConnection
: NSObject
23 // The port to connect on.
26 // If the connection to the debugger engine is currently active.
29 // The raw CFSocket on which the two streams are based. Strong.
32 // The read stream that is scheduled on the main run loop. Weak.
33 CFReadStreamRef readStream_
;
35 // The write stream. Weak.
36 CFWriteStreamRef writeStream_
;
38 // An ever-increasing integer that gives each transaction a unique ID for the
40 NSUInteger transactionID
;
42 // The most recently received transaction ID.
43 NSUInteger lastReadTransaction_
;
45 // The last transactionID written to the stream.
46 NSUInteger lastWrittenTransaction_
;
48 // Callback table. This maps transaction IDs to selectors. When the engine
49 // returns a response to the debugger, we will dispatch the response XML to
50 // the selector, based on transaction_id.
51 NSMutableDictionary
* callTable_
;
53 // To prevent blocked writing, we enqueue all writes and then wait for the
54 // write stream to tell us it's ready. We store the pending commands in this
55 // array. We use this as a stack (FIFO), with index 0 being first.
56 NSMutableArray
* queuedWrites_
;
58 // We send queued writes in multiple places, sometimes off a run loop event.
59 // Because of this, we need to ensure that only one client is dequeing and
61 NSRecursiveLock
* writeQueueLock_
;
63 // Information about the current read loop. We append to |currentPacket_|
64 // until |currentPacketSize_| has reached |packetSize_|.
65 NSMutableString
* currentPacket_
;
67 int currentPacketIndex_
;
75 - (void)socketDidAccept
;
76 - (void)socketDisconnected
;
77 - (void)readStreamHasData
;
78 - (void)send
:(NSString
*)command
;
79 - (void)performSend
:(NSString
*)command
;
80 - (void)errorEncountered
:(NSString
*)error
;
82 - (void)handleResponse
:(NSXMLDocument
*)response
;
83 - (void)handlePacket
:(NSString
*)packet
;
85 - (NSNumber
*)sendCommandWithCallback
:(SEL
)callback format
:(NSString
*)format
, ...;
87 - (void)sendQueuedWrites
;
89 - (NSString
*)escapedURIPath
:(NSString
*)path
;
90 - (NSInteger
)transactionIDFromResponse
:(NSXMLDocument
*)response
;
91 - (NSInteger
)transactionIDFromCommand
:(NSString
*)command
;