Changeset 3110

Show
Ignore:
Timestamp:
01/01/06 23:41:35 (3 years ago)
Author:
timothy
Message:

Merge over to the branch.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/cocoa-networking/Additions/NSDataAdditions.h

    r3072 r3110  
    55- (NSString *) base64Encoding; 
    66- (NSString *) base64EncodingWithLineLength:(unsigned int) lineLength; 
     7 
     8- (BOOL) hasPrefix:(NSData *) prefix; 
     9- (BOOL) hasPrefixBytes:(void *) prefix length:(unsigned int) length; 
    710@end 
  • branches/cocoa-networking/Additions/NSDataAdditions.m

    r3072 r3110  
    144144        return [NSString stringWithString:result]; 
    145145} 
     146 
     147#pragma mark - 
     148 
     149- (BOOL) hasPrefix:(NSData *) prefix { 
     150        unsigned int length = [prefix length]; 
     151        if( ! prefix || ! length || [self length] < length ) return NO; 
     152        return ( memcmp( [self bytes], [prefix bytes], length ) == 0 ); 
     153} 
     154 
     155- (BOOL) hasPrefixBytes:(void *) prefix length:(unsigned int) length { 
     156        if( ! prefix || ! length || [self length] < length ) return NO; 
     157        return ( memcmp( [self bytes], prefix, length ) == 0 ); 
     158} 
    146159@end 
  • branches/cocoa-networking/Additions/NSNotificationAdditions.h

    r3072 r3110  
    22- (void) postNotificationOnMainThread:(NSNotification *) notification; 
    33- (void) postNotificationOnMainThread:(NSNotification *) notification waitUntilDone:(BOOL) wait; 
     4 
     5- (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object; 
     6- (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object userInfo:(NSDictionary *) userInfo; 
     7- (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object userInfo:(NSDictionary *) userInfo waitUntilDone:(BOOL) wait; 
    48@end 
    59 
  • branches/cocoa-networking/Additions/NSNotificationAdditions.m

    r3072 r3110  
    11#import "NSNotificationAdditions.h" 
     2#import <pthread.h> 
    23 
    34@implementation NSNotificationCenter (NSNotificationCenterAdditions) 
    45- (void) postNotificationOnMainThread:(NSNotification *) notification { 
     6        if( pthread_main_np() ) return [self postNotification:notification]; 
    57        [self postNotificationOnMainThread:notification waitUntilDone:NO]; 
    68} 
    79 
    810- (void) postNotificationOnMainThread:(NSNotification *) notification waitUntilDone:(BOOL) wait { 
    9         [self performSelectorOnMainThread:@selector( postNotification: ) withObject:notification waitUntilDone:wait]; 
     11        if( pthread_main_np() ) return [self postNotification:notification]; 
     12        [[self class] performSelectorOnMainThread:@selector( _postNotification: ) withObject:notification waitUntilDone:wait]; 
     13
     14 
     15+ (void) _postNotification:(NSNotification *) notification { 
     16        [[self defaultCenter] postNotification:notification]; 
     17
     18 
     19- (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object { 
     20        if( pthread_main_np() ) return [self postNotificationName:name object:object userInfo:nil]; 
     21        [self postNotificationOnMainThreadWithName:name object:object userInfo:nil waitUntilDone:NO]; 
     22
     23 
     24- (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object userInfo:(NSDictionary *) userInfo { 
     25        if( pthread_main_np() ) return [self postNotificationName:name object:object userInfo:userInfo]; 
     26        [self postNotificationOnMainThreadWithName:name object:object userInfo:userInfo waitUntilDone:NO]; 
     27
     28 
     29- (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object userInfo:(NSDictionary *) userInfo waitUntilDone:(BOOL) wait { 
     30        if( pthread_main_np() ) return [self postNotificationName:name object:object userInfo:userInfo]; 
     31 
     32        NSMutableDictionary *info = [[NSMutableDictionary allocWithZone:nil] init]; 
     33        [info setObject:name forKey:@"name"]; 
     34        if( object ) [info setObject:object forKey:@"object"]; 
     35        if( userInfo ) [info setObject:userInfo forKey:@"userInfo"]; 
     36 
     37        [[self class] performSelectorOnMainThread:@selector( _postNotificationName: ) withObject:info waitUntilDone:wait]; 
     38        [info release]; 
     39
     40 
     41+ (void) _postNotificationName:(NSDictionary *) info { 
     42        NSString *name = [info objectForKey:@"name"]; 
     43        id object = [info objectForKey:@"object"]; 
     44        NSDictionary *userInfo = [info objectForKey:@"userInfo"]; 
     45 
     46        [[self defaultCenter] postNotificationName:name object:object userInfo:userInfo]; 
    1047} 
    1148@end 
     
    1350@implementation NSNotificationQueue (NSNotificationQueueAdditions) 
    1451- (void) enqueueNotificationOnMainThread:(NSNotification *) notification postingStyle:(NSPostingStyle) postingStyle { 
     52        if( pthread_main_np() ) return [self enqueueNotification:notification postingStyle:postingStyle coalesceMask:( NSNotificationCoalescingOnName | NSNotificationCoalescingOnSender ) forModes:nil]; 
    1553        [self enqueueNotificationOnMainThread:notification postingStyle:postingStyle coalesceMask:( NSNotificationCoalescingOnName | NSNotificationCoalescingOnSender ) forModes:nil]; 
    1654} 
    1755 
    1856- (void) enqueueNotificationOnMainThread:(NSNotification *) notification postingStyle:(NSPostingStyle) postingStyle coalesceMask:(unsigned) coalesceMask forModes:(NSArray *) modes { 
     57        if( pthread_main_np() ) return [self enqueueNotification:notification postingStyle:postingStyle coalesceMask:coalesceMask forModes:modes]; 
     58 
    1959        NSMutableDictionary *info = [[NSMutableDictionary allocWithZone:nil] init]; 
    2060        [info setObject:notification forKey:@"notification"]; 
     
    2363        if( modes ) [info setObject:modes forKey:@"modes"]; 
    2464 
    25         [self performSelectorOnMainThread:@selector( _enqueueNotification: ) withObject:info waitUntilDone:NO]; 
     65        [[self class] performSelectorOnMainThread:@selector( _enqueueNotification: ) withObject:info waitUntilDone:NO]; 
    2666        [info release]; 
    2767} 
    2868 
    29 - (void) _enqueueNotification:(NSDictionary *) info { 
     69+ (void) _enqueueNotification:(NSDictionary *) info { 
    3070        NSNotification *notification = [info objectForKey:@"notification"]; 
    3171        NSPostingStyle postingStyle = [[info objectForKey:@"postingStyle"] unsignedIntValue]; 
     
    3373        NSArray *modes = [info objectForKey:@"modes"]; 
    3474 
    35         [[[self class] defaultQueue] enqueueNotification:notification postingStyle:postingStyle coalesceMask:coalesceMask forModes:modes]; 
     75        [[self defaultQueue] enqueueNotification:notification postingStyle:postingStyle coalesceMask:coalesceMask forModes:modes]; 
    3676} 
    3777@end 
  • branches/cocoa-networking/Additions/NSStringAdditions.m

    r3072 r3110  
    197197        if( bytes ) { 
    198198                id ret = [self initWithBytes:bytes length:strlen( bytes ) encoding:encoding]; 
    199                 if( ! ret ) ret = [self initWithCString:bytes]; 
    200199                if( ! ret ) [self release]; 
    201200                return ret; 
     
    209208        if( bytes ) { 
    210209                id ret = [self initWithBytesNoCopy:bytes length:strlen( bytes ) encoding:encoding freeWhenDone:free]; 
    211                 if( ! ret ) ret = [self initWithCString:bytes]; 
    212210                if( ! ret ) [self release]; 
    213211                return ret;