Changeset 3110
- Timestamp:
- 01/01/06 23:41:35 (3 years ago)
- Files:
-
- branches/cocoa-networking/Additions/NSDataAdditions.h (modified) (1 diff)
- branches/cocoa-networking/Additions/NSDataAdditions.m (modified) (1 diff)
- branches/cocoa-networking/Additions/NSNotificationAdditions.h (modified) (1 diff)
- branches/cocoa-networking/Additions/NSNotificationAdditions.m (modified) (4 diffs)
- branches/cocoa-networking/Additions/NSStringAdditions.m (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/cocoa-networking/Additions/NSDataAdditions.h
r3072 r3110 5 5 - (NSString *) base64Encoding; 6 6 - (NSString *) base64EncodingWithLineLength:(unsigned int) lineLength; 7 8 - (BOOL) hasPrefix:(NSData *) prefix; 9 - (BOOL) hasPrefixBytes:(void *) prefix length:(unsigned int) length; 7 10 @end branches/cocoa-networking/Additions/NSDataAdditions.m
r3072 r3110 144 144 return [NSString stringWithString:result]; 145 145 } 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 } 146 159 @end branches/cocoa-networking/Additions/NSNotificationAdditions.h
r3072 r3110 2 2 - (void) postNotificationOnMainThread:(NSNotification *) notification; 3 3 - (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; 4 8 @end 5 9 branches/cocoa-networking/Additions/NSNotificationAdditions.m
r3072 r3110 1 1 #import "NSNotificationAdditions.h" 2 #import <pthread.h> 2 3 3 4 @implementation NSNotificationCenter (NSNotificationCenterAdditions) 4 5 - (void) postNotificationOnMainThread:(NSNotification *) notification { 6 if( pthread_main_np() ) return [self postNotification:notification]; 5 7 [self postNotificationOnMainThread:notification waitUntilDone:NO]; 6 8 } 7 9 8 10 - (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]; 10 47 } 11 48 @end … … 13 50 @implementation NSNotificationQueue (NSNotificationQueueAdditions) 14 51 - (void) enqueueNotificationOnMainThread:(NSNotification *) notification postingStyle:(NSPostingStyle) postingStyle { 52 if( pthread_main_np() ) return [self enqueueNotification:notification postingStyle:postingStyle coalesceMask:( NSNotificationCoalescingOnName | NSNotificationCoalescingOnSender ) forModes:nil]; 15 53 [self enqueueNotificationOnMainThread:notification postingStyle:postingStyle coalesceMask:( NSNotificationCoalescingOnName | NSNotificationCoalescingOnSender ) forModes:nil]; 16 54 } 17 55 18 56 - (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 19 59 NSMutableDictionary *info = [[NSMutableDictionary allocWithZone:nil] init]; 20 60 [info setObject:notification forKey:@"notification"]; … … 23 63 if( modes ) [info setObject:modes forKey:@"modes"]; 24 64 25 [ selfperformSelectorOnMainThread:@selector( _enqueueNotification: ) withObject:info waitUntilDone:NO];65 [[self class] performSelectorOnMainThread:@selector( _enqueueNotification: ) withObject:info waitUntilDone:NO]; 26 66 [info release]; 27 67 } 28 68 29 -(void) _enqueueNotification:(NSDictionary *) info {69 + (void) _enqueueNotification:(NSDictionary *) info { 30 70 NSNotification *notification = [info objectForKey:@"notification"]; 31 71 NSPostingStyle postingStyle = [[info objectForKey:@"postingStyle"] unsignedIntValue]; … … 33 73 NSArray *modes = [info objectForKey:@"modes"]; 34 74 35 [[ [self class]defaultQueue] enqueueNotification:notification postingStyle:postingStyle coalesceMask:coalesceMask forModes:modes];75 [[self defaultQueue] enqueueNotification:notification postingStyle:postingStyle coalesceMask:coalesceMask forModes:modes]; 36 76 } 37 77 @end branches/cocoa-networking/Additions/NSStringAdditions.m
r3072 r3110 197 197 if( bytes ) { 198 198 id ret = [self initWithBytes:bytes length:strlen( bytes ) encoding:encoding]; 199 if( ! ret ) ret = [self initWithCString:bytes];200 199 if( ! ret ) [self release]; 201 200 return ret; … … 209 208 if( bytes ) { 210 209 id ret = [self initWithBytesNoCopy:bytes length:strlen( bytes ) encoding:encoding freeWhenDone:free]; 211 if( ! ret ) ret = [self initWithCString:bytes];212 210 if( ! ret ) [self release]; 213 211 return ret;
