From a3cf893851b2d3de8927b19a0af46ac1e919876b Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Thu, 2 Aug 2007 21:10:11 -0700 Subject: [PATCH] Cleaning up and removing remnance of the notification system. * Source/DebuggerConnection.h: Removing dead _data and prefixing socket with an _ * Source/DebuggerConnection.m: Prefixing use of socket with underscore, removing notification registration, documenting delegate methods * Source/SocketWrapper.m|h: Removing the definitions for the notification types as we no longer use them --- Source/DebuggerConnection.h | 2 -- Source/DebuggerConnection.m | 49 +++++++++++++++++-------------------- Source/SocketWrapper.h | 6 ----- Source/SocketWrapper.m | 13 +++------- 4 files changed, 27 insertions(+), 43 deletions(-) diff --git a/Source/DebuggerConnection.h b/Source/DebuggerConnection.h index 5a25a8d..9565a01 100644 --- a/Source/DebuggerConnection.h +++ b/Source/DebuggerConnection.h @@ -26,8 +26,6 @@ DebuggerWindowController *_windowController; SocketWrapper *socket; - - NSMutableData *_data; } // initializer diff --git a/Source/DebuggerConnection.m b/Source/DebuggerConnection.m index 8f6c719..a155add 100644 --- a/Source/DebuggerConnection.m +++ b/Source/DebuggerConnection.m @@ -34,26 +34,17 @@ [[_windowController window] makeKeyAndOrderFront: self]; // now that we have our host information, open the socket - socket = [[SocketWrapper alloc] initWithPort: port]; - if (socket == nil) + _socket = [[SocketWrapper alloc] initWithPort: port]; + if (_socket == nil) { // TODO - kill us somehow NSLog(@"can't proceed further... SocketWrapper is nil"); } - [socket setDelegate: self]; - /* - NSLog(@"data = %@", [socket receive]); - [socket send: @"status -i foo"]; - NSLog(@"status = %@", [socket receive]); - [socket send: @"run -i foo"]; - NSLog(@"status = %@", [socket receive]); - */ + [_socket setDelegate: self]; + [_socket receive]; - [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(dataReceived:) name: SocketWrapperDataReceivedNotification object: nil]; - [socket receive]; - - [socket release]; + [_socket release]; // clean up after ourselves [[NSNotificationCenter defaultCenter] addObserver: self @@ -64,17 +55,6 @@ return self; } -- (void)dataReceived: (NSNotification *)notif -{ - NSLog(@"hi?"); - NSLog(@"notif = %@", [notif object]); -} - -- (void)dataSent: (NSNotification *)notif -{ - NSLog(@"data sent"); -} - /** * Release ourselves when we're about to die */ @@ -89,7 +69,7 @@ - (void)dealloc { [_session release]; - [socket release]; + [_socket release]; [super dealloc]; } @@ -110,4 +90,21 @@ return _session; } +/** + * SocketWrapper delegate method that is called whenever new data is received + */ +- (void)dataReceived: (NSString *)response +{ + NSLog(@"response = %@", response); +} + +/** + * SocketWrapper delegate method that is called after data is sent. This really + * isn't useful for much. + */ +- (void)dataSent +{ + NSLog(@"data sent"); +} + @end diff --git a/Source/SocketWrapper.h b/Source/SocketWrapper.h index 027b7a1..2b10f7c 100644 --- a/Source/SocketWrapper.h +++ b/Source/SocketWrapper.h @@ -16,12 +16,6 @@ #import -extern NSString *SocketWrapperDidErrorNotification; -extern NSString *SocketWrapperSocketDidBindNotification; -extern NSString *SocketWrapperSocketDidAcceptNotification; -extern NSString *SocketWrapperDataReceivedNotification; -extern NSString *SocketWrapperDataSentNotification; - @interface SocketWrapper : NSObject { int _socket; diff --git a/Source/SocketWrapper.m b/Source/SocketWrapper.m index 16bfaec..aeec5d0 100644 --- a/Source/SocketWrapper.m +++ b/Source/SocketWrapper.m @@ -21,12 +21,6 @@ #include #include -NSString *SocketWrapperDidErrorNotification = @"errorOccurred"; -NSString *SocketWrapperSocketDidBindNotification = @"bindSuccess"; -NSString *SocketWrapperSocketDidAcceptNotification = @"acceptSuccess"; -NSString *SocketWrapperDataReceivedNotification = @"dataReceived"; -NSString *SocketWrapperDataSentNotification = @"dataSent"; - @implementation SocketWrapper /** @@ -144,13 +138,14 @@ NSString *SocketWrapperDataSentNotification = @"dataSent"; // we also want the null byte, so move us up 1 i++; - // the length of the packet - // packet is formatted in lenpacket + // the total length of the full transmission int length = atoi(packetLength); - // take our bytes and convert them to NSData + // move the packet part of the received data into it's own char[] char packet[sizeof(buffer)]; memmove(packet, &buffer[i], recvd - i); + + // convert bytes to NSData [data appendBytes: packet length: recvd]; // check if we have a partial packet -- 2.43.5