Move the callTable back into DebuggerProcessor.
[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 @protocol DebuggerConnectionDelegate;
20 @class LoggingController;
21
22 @interface DebuggerConnection : NSObject
23 {
24 // The port to connect on.
25 NSUInteger port_;
26
27 // If the connection to the debugger engine is currently active.
28 BOOL connected_;
29
30 // The raw CFSocket on which the two streams are based. Strong.
31 CFSocketRef socket_;
32
33 // The read stream that is scheduled on the main run loop. Weak.
34 CFReadStreamRef readStream_;
35
36 // The write stream. Weak.
37 CFWriteStreamRef writeStream_;
38
39 // An ever-increasing integer that gives each transaction a unique ID for the
40 // debugging engine.
41 NSUInteger transactionID;
42
43 // The most recently received transaction ID.
44 NSUInteger lastReadTransaction_;
45
46 // The last transactionID written to the stream.
47 NSUInteger lastWrittenTransaction_;
48
49 // To prevent blocked writing, we enqueue all writes and then wait for the
50 // write stream to tell us it's ready. We store the pending commands in this
51 // array. We use this as a stack (FIFO), with index 0 being first.
52 NSMutableArray* queuedWrites_;
53
54 // We send queued writes in multiple places, sometimes off a run loop event.
55 // Because of this, we need to ensure that only one client is dequeing and
56 // sending at a time.
57 NSRecursiveLock* writeQueueLock_;
58
59 // Information about the current read loop. We append to |currentPacket_|
60 // until |currentPacketSize_| has reached |packetSize_|.
61 NSMutableString* currentPacket_;
62 int packetSize_;
63 int currentPacketIndex_;
64
65 // The delegate.
66 id <DebuggerConnectionDelegate> delegate_;
67 }
68
69 @property (readonly) NSUInteger port;
70 @property (readonly) BOOL connected;
71 @property (assign) id <DebuggerConnectionDelegate> delegate;
72
73 - (id)initWithPort:(NSUInteger)aPort;
74
75 - (void)connect;
76 - (void)close;
77 - (void)socketDidAccept;
78 - (void)socketDisconnected;
79 - (void)readStreamHasData;
80 - (void)send:(NSString*)command;
81 - (void)performSend:(NSString*)command;
82 - (void)errorEncountered:(NSString*)error;
83
84 - (void)handleResponse:(NSXMLDocument*)response;
85 - (void)handlePacket:(NSString*)packet;
86
87 - (NSNumber*)sendCommandWithFormat:(NSString*)format, ...;
88
89 - (void)sendQueuedWrites;
90
91 - (NSString*)escapedURIPath:(NSString*)path;
92 - (NSInteger)transactionIDFromResponse:(NSXMLDocument*)response;
93 - (NSInteger)transactionIDFromCommand:(NSString*)command;
94
95 @end
96
97 // Delegate ////////////////////////////////////////////////////////////////////
98
99 @protocol DebuggerConnectionDelegate <NSObject>
100
101 @optional
102
103 - (void)connectionDidAccept:(DebuggerConnection*)cx;
104 - (void)connectionDidCose:(DebuggerConnection*)cx;
105
106 - (void)handleInitialResponse:(NSXMLDocument*)response;
107
108 - (void)handleResponse:(NSXMLDocument*)response;
109
110 - (void)errorEncountered:(NSString*)error;
111
112 @end
113