3 * Copyright (c) 2002 - 2007, 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 "DebuggerConnection.h"
20 @implementation DebuggerConnection
23 * Creates a new DebuggerConnection and initializes the socket from the given connection
26 - (id)initWithHost
: (NSString
*)host port
: (int)port session
: (NSString
*)session
28 NSLog(@
"initWithHost");
29 if (self = [super init
])
31 _host
= [host retain
];
33 _session
= [session retain
];
35 _windowController
= [[DebuggerWindowController alloc
] initWithConnection
: self];
36 [[_windowController window
] makeKeyAndOrderFront
: self];
38 // now that we have our host information, open the streams and put them in the run loop
39 [NSStream getStreamsToHost
: [NSHost hostWithName
: _host
] port
: _port inputStream
: &_input outputStream
: &_output
];
43 [_input setDelegate
: self];
44 [_output setDelegate
: self];
46 [_input scheduleInRunLoop
: [NSRunLoop currentRunLoop
] forMode
: NSDefaultRunLoopMode
];
47 [_output scheduleInRunLoop
: [NSRunLoop currentRunLoop
] forMode
: NSDefaultRunLoopMode
];
52 // clean up after ourselves
53 [[NSNotificationCenter defaultCenter
] addObserver
: self
54 selector
: @selector(applicationWillTerminate
:)
55 name
: NSApplicationWillTerminateNotification
62 * Release ourselves when we're about to die
64 - (void)applicationWillTerminate
: (NSNotification
*)notif
70 * Releases all of the object's data members and closes the streams
93 * Gets the port number
101 * Gets the session name
103 - (NSString
*)session
109 * Handles stream events. This is the delegate method implemented for NSStream and it
110 * merely calls other methods to do it's bidding
112 - (void)stream
: (NSStream
*)stream handleEvent
: (NSStreamEvent
)event
115 if (event
== NSStreamEventHasBytesAvailable
)
119 _data
= [[NSMutableData data
] retain
];
122 unsigned int len
= 0;
123 len
= [(NSInputStream
*)stream read
: buf maxLength
: 1024];
126 [_data appendBytes
: (const void *)buf length
: len
];
130 [self _readFromStream
: _data
];
135 else if (event
== NSStreamEventEndEncountered
)
137 NSLog(@
"we need to close and die right now");
139 else if (event
== NSStreamEventErrorOccurred
)
141 NSLog(@
"error = %@", [stream streamError
]);
143 NSLog(@
"status = %d", [stream streamStatus
]);
147 * Called when the stream event handler has finished reading all of the data and
148 * passes it a data object
150 - (void)_readFromStream
: (NSData
*)data
153 NSLog(@
"data = %@", data
);