Make logging threadsafe.
authorRobert Sesek <rsesek@bluestatic.org>
Sun, 31 Oct 2010 14:13:22 +0000 (10:13 -0400)
committerRobert Sesek <rsesek@bluestatic.org>
Sun, 31 Oct 2010 14:13:22 +0000 (10:13 -0400)
Source/DebuggerConnection.m
Source/LoggingController.h
Source/LoggingController.m

index 7908bc9a1ee3b8ee26ca5100ea6ab411d34e572d..f17697dc7fe3409c2d684a66e24ace2f99d5cc7f 100644 (file)
@@ -426,20 +426,26 @@ void SocketAcceptCallback(CFSocketRef socket,
 - (LogEntry*)recordSend:(NSString*)command
 {
   LoggingController* logger = [(AppDelegate*)[NSApp delegate] loggingController];
-  [logger performSelectorOnMainThread:@selector(recordSend:)
-                           withObject:command
+  LogEntry* entry = [LogEntry newSendEntry:command];
+  entry.lastReadTransactionID = lastReadTransaction_;
+  entry.lastWrittenTransactionID = lastWrittenTransaction_;
+  [logger performSelectorOnMainThread:@selector(recordEntry:)
+                           withObject:entry
                         waitUntilDone:NO];
-  return [logger.logEntries lastObject];
+  return [entry autorelease];
 }
 
 - (LogEntry*)recordReceive:(NSString*)command
 {
   LoggingController* logger = [(AppDelegate*)[NSApp delegate] loggingController];
-  [logger performSelectorOnMainThread:@selector(recordReceive:)
-                           withObject:command
+  LogEntry* entry = [LogEntry newReceiveEntry:command];
+  entry.lastReadTransactionID = lastReadTransaction_;
+  entry.lastWrittenTransactionID = lastWrittenTransaction_;
+  [logger performSelectorOnMainThread:@selector(recordEntry:)
+                           withObject:entry
                         waitUntilDone:NO];
-  return [logger.logEntries lastObject];
-}  
+  return [entry autorelease];
+}
 
 // Stream Managers /////////////////////////////////////////////////////////////
 
@@ -577,8 +583,6 @@ void SocketAcceptCallback(CFSocketRef socket,
   // Log this receive event.
   LogEntry* log = [self recordReceive:currentPacket_];
   log.error = error;
-  log.lastWrittenTransactionID = lastWrittenTransaction_;
-  log.lastReadTransactionID = lastReadTransaction_;
   
   // Finally, dispatch the handler for this response.
   [self handleResponse:[xmlTest autorelease]];  
@@ -662,9 +666,7 @@ void SocketAcceptCallback(CFSocketRef socket,
   }
   
   // Log this trancation.
-  LogEntry* log = [self recordSend:command];
-  log.lastWrittenTransactionID = lastWrittenTransaction_;
-  log.lastReadTransactionID = lastReadTransaction_;
+  [self recordSend:command];
 }
 
 /**
index 658716aff682f006d3c47e25bb3e619df68dda21..cb104de0212cf123b2713066ab02da86613e0c49 100644 (file)
 // Designated initializer.
 - (id)init;
 
-// Creates a new log entry with the specified command, adds it to the entries
-// list, and returns the new entry as a weak pointer. Callers can then set
-// additional properties.
-- (LogEntry*)recordSend:(NSString*)command;
-
-// Creates a new log entry with the specified response data, adds it to the list
-// of entries, and returns the new entry as a weak pointer. Callers can then set
-// additional properties.
-- (LogEntry*)recordReceive:(NSString*)response;
+// Records a log entry. This will add it to the list and will update the UI.
+// This will take ownership of |entry|.
+- (void)recordEntry:(LogEntry*)entry;
 
 @end
 
@@ -74,5 +68,10 @@ typedef enum _LogEntryDirection {
 @property (retain) NSError* error;
 @property (assign) NSUInteger lastWrittenTransactionID;
 @property (assign) NSUInteger lastReadTransactionID;
+
 - (NSString*)directionName;
+
++ (LogEntry*)newSendEntry:(NSString*)command;
++ (LogEntry*)newReceiveEntry:(NSString*)command;
+
 @end
index 730cfbffb467044d4e970304d5afb6861de3968a..a8099a3792e5c2f66bed21a7d5ea7ebc3ac65842 100644 (file)
   [super dealloc];
 }
 
-- (LogEntry*)recordSend:(NSString*)command
+- (void)recordEntry:(LogEntry*)entry
 {
-  LogEntry* entry = [LogEntry new];
-  entry.direction = kLogEntrySending;
-  entry.contents = command;
   [logEntries_ addObject:entry];
-  [logEntriesController_ rearrangeObjects];
-  return [entry autorelease];
-}
-
-- (LogEntry*)recordReceive:(NSString*)response
-{
-  LogEntry* entry = [LogEntry new];
-  entry.direction = kLogEntryReceiving;
-  entry.contents = response;
-  [logEntries_ addObject:entry];
-  [logEntriesController_ rearrangeObjects];
-  return [entry autorelease];
+  [logEntriesController_ rearrangeObjects];  
 }
 
 @end
 @synthesize lastWrittenTransactionID = lastWrittenTransactionID_;
 @synthesize lastReadTransactionID = lastReadTransactionID_;
 
++ (LogEntry*)newSendEntry:(NSString*)command
+{
+  LogEntry* entry = [LogEntry new];
+  entry.direction = kLogEntrySending;
+  entry.contents  = command;
+  return entry;
+}
+
++ (LogEntry*)newReceiveEntry:(NSString*)command
+{
+  LogEntry* entry = [LogEntry new];
+  entry.direction = kLogEntryReceiving;
+  entry.contents  = command;
+  return entry;
+}
+
 - (void)dealloc
 {
   self.contents = nil;