Add a new DebuggerConnection that separates out the socket logic from the handling...
[macgdbp.git] / Source / DebuggerConnection.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 @class LoggingController;
20
21 @interface DebuggerConnection : NSObject
22 {
23 // The port to connect on.
24 NSUInteger port;
25
26 // If the connection to the debugger engine is currently active.
27 BOOL connected;
28
29 // The raw CFSocket on which the two streams are based. Strong.
30 CFSocketRef socket_;
31
32 // The read stream that is scheduled on the main run loop. Weak.
33 CFReadStreamRef readStream_;
34
35 // The write stream. Weak.
36 CFWriteStreamRef writeStream_;
37
38 // An ever-increasing integer that gives each transaction a unique ID for the
39 // debugging engine.
40 NSUInteger transactionID;
41
42 // The most recently received transaction ID.
43 NSUInteger lastReadTransaction_;
44
45 // The last transactionID written to the stream.
46 NSUInteger lastWrittenTransaction_;
47
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_;
52
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_;
57
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
60 // sending at a time.
61 NSRecursiveLock* writeQueueLock_;
62
63 // Information about the current read loop. We append to |currentPacket_|
64 // until |currentPacketSize_| has reached |packetSize_|.
65 NSMutableString* currentPacket_;
66 int packetSize_;
67 int currentPacketIndex_;
68
69 // The delegate.
70 id delegate_;
71 }
72
73 - (void)connect;
74 - (void)close;
75 - (void)socketDidAccept;
76 - (void)socketDisconnected;
77 - (void)readStreamHasData;
78 - (void)send:(NSString*)command;
79 - (void)performSend:(NSString*)command;
80 - (void)errorEncountered:(NSString*)error;
81
82 - (void)handleResponse:(NSXMLDocument*)response;
83 - (void)handlePacket:(NSString*)packet;
84
85 - (NSNumber*)sendCommandWithCallback:(SEL)callback format:(NSString*)format, ...;
86
87 - (void)sendQueuedWrites;
88
89 - (NSString*)escapedURIPath:(NSString*)path;
90 - (NSInteger)transactionIDFromResponse:(NSXMLDocument*)response;
91 - (NSInteger)transactionIDFromCommand:(NSString*)command;
92
93 @end