/* * * @APPLE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this * file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. * * @APPLE_LICENSE_HEADER_END@ */ #import "USBLoggerController.h" @implementation LoggerEntry #define NUM_FRESH_ENTRIES 20000 static NSMutableArray * freshEntries = nil; static int remainingFreshEntries = 0; + (void)initialize { freshEntries = [[NSMutableArray alloc] initWithCapacity:NUM_FRESH_ENTRIES]; [self replenishFreshEntries]; } + (void)replenishFreshEntries { LoggerEntry *temp; int i; [freshEntries removeAllObjects]; for (i=0; i 0) { NSRange endMarker = NSMakeRange([[LoggerOutputTV string] length], 0); NSScroller *scroller = [[LoggerOutputTV enclosingScrollView] verticalScroller]; BOOL isScrolledToEnd = (![scroller isEnabled] || [scroller floatValue] == 1); [LoggerOutputTV replaceCharactersInRange:endMarker withString:_outputBuffer]; if (isScrolledToEnd) { endMarker.location += [_outputBuffer length]; [LoggerOutputTV scrollRangeToVisible:endMarker]; } [_outputBuffer setString:@""]; [LoggerOutputTV setNeedsDisplay:YES]; } [_outputLock unlock]; } [_bufferLock unlock]; } } - (void)appendOutput:(NSString *)aString atLevel:(NSNumber *)level { LoggerEntry *entry = [[LoggerEntry alloc] initWithText:aString level:[level intValue]]; [_outputLock lock]; [_outputLines addObject:entry]; [_outputLock unlock]; [entry release]; if (_dumpingFile != NULL) { fprintf(_dumpingFile, [aString cString]); fflush(_dumpingFile); } [_bufferLock lock]; if (_currentFilterString == nil || [aString rangeOfString:_currentFilterString options:NSCaseInsensitiveSearch].location != NSNotFound) { [_outputBuffer appendString:aString]; } [_bufferLock unlock]; } - (void)appendLoggerEntry:(LoggerEntry *)entry { NSString *text = [entry text]; [_outputLock lock]; [_outputLines addObject:entry]; [_outputLock unlock]; if (_dumpingFile != NULL) { fprintf(_dumpingFile, [text cString]); fflush(_dumpingFile); } [_bufferLock lock]; if (_currentFilterString == nil || [text rangeOfString:_currentFilterString options:NSCaseInsensitiveSearch].location != NSNotFound) { [_outputBuffer appendString:text]; } [_bufferLock unlock]; } - (void)usbLoggerTextAvailable:(NSString *)text forLevel:(int)level { LoggerEntry *entry = [LoggerEntry cachedFreshEntry]; [entry setText:text level:level]; [self performSelectorOnMainThread:@selector(appendLoggerEntry:) withObject:entry waitUntilDone:NO]; } @end