Changeset 811


Ignore:
Timestamp:
Aug 21, 2006, 11:47:29 PM (15 years ago)
Author:
livings124
Message:

This should be a safer implementation of the message log.

Location:
trunk/macosx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/MessageWindowController.h

    • Property svn:keywords set to Date Rev Author Id
    r810 r811  
    3131   
    3232    NSLock * fLock;
     33    NSMutableArray * fBufferArray;
     34    NSTimer * fTimer;
    3335}
    3436
    3537void addMessage(int level, const char * message);
    3638- (void) addMessage: (const char *) message level: (int) level;
     39- (void) updateLog: (NSTimer *) timer;
    3740
    3841- (void) changeLevel: (id) sender;
  • trunk/macosx/MessageWindowController.m

    • Property svn:keywords set to Date Rev Author Id
    r810 r811  
    3030#define LEVEL_DEBUG 2
    3131
     32#define UPDATE_SECONDS 1.0
     33
    3234@interface MessageWindowController (Private)
    3335
     
    4547       
    4648        fLock = [[NSLock alloc] init];
     49        fBufferArray = [[NSMutableArray alloc] init];
     50       
     51        fTimer = [NSTimer scheduledTimerWithTimeInterval: UPDATE_SECONDS target: self
     52                    selector: @selector(updateLog:) userInfo: nil repeats: YES];
    4753       
    4854        [[self window] update]; //make sure nib is loaded right away
     
    5359- (void) dealloc
    5460{
     61    [fTimer invalidate];
     62   
    5563    [fLock release];
     64    [fBufferArray release];
     65   
    5666    [super dealloc];
    5767}
     
    101111   
    102112    [fLock lock];
    103     [[fTextView textStorage] appendAttributedString: messageString];
     113    [fBufferArray addObject: messageString];
    104114    [fLock unlock];
    105115   
    106116    [pool release];
     117}
     118
     119- (void) updateLog: (NSTimer *) timer
     120{
     121    [fLock lock];
     122   
     123    NSEnumerator * enumerator = [fBufferArray objectEnumerator];
     124    NSAttributedString * messageString;
     125    while ((messageString = [enumerator nextObject]))
     126        [[fTextView textStorage] appendAttributedString: messageString];
     127   
     128    [fBufferArray removeAllObjects];
     129   
     130    [fLock unlock];
    107131}
    108132
Note: See TracChangeset for help on using the changeset viewer.