From: Joseph Spiros Date: Tue, 10 Dec 2002 06:56:29 +0000 (+0000) Subject: Initial revision X-Git-Tag: v0.1~71 X-Git-Url: http://git.ithinksw.org/ITFoundation.git/commitdiff_plain/a38dee0c58dae0d276ab663eddf7124c2ce9acc5 Initial revision --- a38dee0c58dae0d276ab663eddf7124c2ce9acc5 diff --git a/English.lproj/InfoPlist.strings b/English.lproj/InfoPlist.strings new file mode 100755 index 0000000..edf2266 Binary files /dev/null and b/English.lproj/InfoPlist.strings differ diff --git a/ITAppleEvent.h b/ITAppleEvent.h new file mode 100755 index 0000000..bf54bca --- /dev/null +++ b/ITAppleEvent.h @@ -0,0 +1,53 @@ +/* + * ITFoundation + * ITAppleEvent + * + * Class that provides utilities for sending AppleEvents + * (and OSA scripts) using Carbon function calls in Cocoa + * + * Original Author : Joseph Spiros + * Responsibility : Joseph Spiros + * : Kent Sutherland + * + * Copyright (c) 2002 iThink Software. + * All Rights Reserved + * + */ + +#import +#import + + +@interface ITAppleEvent : NSObject { + long int osaScriptID; + AppleEvent event, reply; +} +/* + * INITIALIZATION METHODS - AppleScript + * + * These methods initialize an instance of ITAppleEvent + * with AppleScript/OpenScripting data + */ +- (id)initWithOSASource:(NSString *)source; +- (id)initWithOSACompiledData:(NSData *)data; +- (id)initWithOSAFromContentsOfURL:(NSURL *)url; +- (id)initWithOSAFromContentsOfPath:(NSString *)path; +/* +`* INITIALIZATION METHODS - AppleEvent + * + * This method initializes an instance of ITAppleEvent + * with an AppleEvent class (usually the creator id + * of the AppleEvent's target) and an AppleEvent ID + */ +- (id)initWithAppleEventClass:(AEEventClass)eventClass appleEventID:(AEEventID)eventID; +/* + * INSTANCE METHODS + */ +- (NSString *)OSASource; +- (void)setOSASource:(NSString *)source; +- (NSData *)OSACompiledData; +- (void)setOSACompiledData:(NSData *)data; +- (AEEventClass)appleEventClass; +- (AEEventID)appleEventID; +- (NSString *)execute; +@end diff --git a/ITAppleEvent.m b/ITAppleEvent.m new file mode 100755 index 0000000..b1c2fb7 --- /dev/null +++ b/ITAppleEvent.m @@ -0,0 +1,49 @@ +#import "ITAppleEvent.h" + + +@implementation ITAppleEvent + + +- (id)initWithOSASource:(NSString *)source +{ +} +- (id)initWithOSACompiledData:(NSData *)data +{ +} +- (id)initWithOSAFromContentsOfURL:(NSURL *)url +{ +} +- (id)initWithOSAFromContentsOfPath:(NSString *)path +{ +} +- (id)initWithAppleEventClass:(AEEventClass)eventClass appleEventID:(AEEventID)eventID +{ + OSType AppType = eventClass; + AEBuildAppleEvent(eventClass, eventID, typeApplSignature, &AppType, sizeof(AppType), kAutoGenerateReturnID, kAnyTransactionID, &event, nil, ""); +} +- (NSString *)OSASource +{ +} +- (void)setOSASource:(NSString *)source +{ +} +- (NSData *)OSACompiledData +{ +} +- (void)setOSACompiledData:(NSData *)data +{ +} +- (AEEventClass)appleEventClass +{ +} +- (AEEventID)appleEventID +{ +} +- (NSString *)execute +{ + AESend(&event, &reply, kAENoReply, kAENormalPriority, kAEDefaultTimeout, nil, nil); + // AEDisposeDesc(&event); + // AEDisposeDesc(&reply); +} + +@end diff --git a/ITFoundation.h b/ITFoundation.h new file mode 100755 index 0000000..b02082b --- /dev/null +++ b/ITFoundation.h @@ -0,0 +1,5 @@ +#import + +#import +#import +#import \ No newline at end of file diff --git a/ITStringScanner.h b/ITStringScanner.h new file mode 100755 index 0000000..8fb0122 --- /dev/null +++ b/ITStringScanner.h @@ -0,0 +1,33 @@ +/* + * ITFoundation + * ITStringScanner + * + * A super-fast replacement for NSScanner + * + * Original Author : Alexander Strange + * Responsibility : Alexander Strange + * : Joseph Spiros + * + * Copyright (c) 2002 iThink Software. + * All Rights Reserved + * + */ + +#import +#import + +/*! +@class ITStringScanner +@discussion A super-fast replacement for NSScanner +*/ + +@interface ITStringScanner : NSObject { + NSString *str; + char *strCStr; + size_t curPos; + size_t size; +} +-(id)initWithString:(NSString*)str2; +-(NSString *)scanUpToCharacter:(char)c; +-(NSString *)scanUpToString:(NSString*)str; +@end diff --git a/ITStringScanner.m b/ITStringScanner.m new file mode 100755 index 0000000..c3dff8e --- /dev/null +++ b/ITStringScanner.m @@ -0,0 +1,114 @@ +// I *could* use OWStringScanner, but I don't want to. Shut up, sabi :) + +#import "ITStringScanner.h" + +static NSString *AString(void) +{ + return [NSString string]; +} + +@implementation ITStringScanner +-(id)init +{ + if (self = [super init]) + { + strCStr = NULL; + str = nil; + curPos = size = 0; + } + return self; +} + +-(id)initWithString:(NSString*)str2 +{ + if (self = [super init]) + { + strCStr = (char *)[str2 cString]; + str = [str2 retain]; + curPos = 0; + size = [str2 length]; + } + return self; +} + +-(NSString *)scanUpToCharacter:(char)c +{ + size_t i=curPos,j=0; + + if (strCStr[i] == c) + { + i++; + return AString(); + } + else + { + NSRange r = {i,0}; + NSString *tmpStr = nil; + const size_t tmp = size; + unsigned char foundIt = NO; + + do + { + i++,j++; + + if (strCStr[i] == c) + { + foundIt = YES; + r.length = j; + } + + } + while ((!foundIt) && (i + * Responsibility : Joseph Spiros + * : Matt Judy + * + * Copyright (c) 2002 iThink Software. + * All Rights Reserved + * + */ + +#import +#import + +/* For this platform, as of this Mach version, + * the default page size is 4096, or 4k */ +#define DEFAULT_PAGE_SIZE 4096 + + +@interface ITVirtualMemoryInfo : NSObject { + vm_statistics_data_t stat; +} + +- (id)init; +- (int)pageSize; +- (int)freePages; +- (int)activePages; +- (int)inactivePages; +- (int)wiredPages; +- (int)faults; +- (int)copyOnWritePages; +- (int)zeroFilledPages; +- (int)reactivatedPages; +- (int)pageins; +- (int)pageouts; +- (int)hits; +- (int)lookups; +- (int)hitratePercentage; + +@end diff --git a/ITVirtualMemoryInfo.m b/ITVirtualMemoryInfo.m new file mode 100755 index 0000000..4017993 --- /dev/null +++ b/ITVirtualMemoryInfo.m @@ -0,0 +1,129 @@ +#import "ITVirtualMemoryInfo.h" + +@interface ITVirtualMemoryInfo (Private) +- (BOOL)refreshStats; +@end + +@implementation ITVirtualMemoryInfo + +- (id)init +{ + if ( ( self = [super init] ) ) { + if ([self refreshStats:&stat] == NO) { + return nil; + } + } + return self; +} + +- (int)pageSize +{ + int pageSize = 0; + + if ( host_page_size(mach_host_self(), &pageSize) != KERN_SUCCESS ) { + NSLog(@"Failed to get page size, defaulting to 4096/4k"); + pageSize = DEFAULT_PAGE_SIZE; + } + + return pageSize; +} + +- (int)freePages +{ + [self refreshStats:&stat]; + return stat.free_count; +} + +- (int)activePages +{ + [self refreshStats:&stat]; + return stat.active_count; +} + +- (int)inactivePages +{ + [self refreshStats:&stat]; + return stat.inactive_count; +} + +- (int)wiredPages +{ + [self refreshStats:&stat]; + return stat.wire_count; +} + +- (int)faults +{ + [self refreshStats:&stat]; + return stat.faults; +} + +- (int)copyOnWritePages +{ + [self refreshStats:&stat]; + return stat.cow_faults; +} + +- (int)zeroFilledPages +{ + [self refreshStats:&stat]; + return stat.zero_fill_count; +} + +- (int)reactivatedPages +{ + [self refreshStats:&stat]; + return stat.reactivations; +} + +- (int)pageins +{ + [self refreshStats:&stat]; + return stat.pageins; +} + +- (int)pageouts +{ + [self refreshStats:&stat]; + return stat.pageouts; +} + +- (int)hits +{ + [self refreshStats:&stat]; + return stat.hits; +} + +- (int)lookups +{ + [self refreshStats:&stat]; + return stat.lookups; +} + +- (int)hitratePercentage +{ + [self refreshStats:&stat]; + if ( stat.lookups == 0 ) { + return 0; + } else { + return ( ( stat.hits * 100 ) / stat.lookups ); + } +} + +- (BOOL)refreshStats:(struct vm_statistics *)myStat +{ + bzero(&myStat,sizeof(myStat)); + mach_port_t myHost = mach_host_self(); + int count = HOST_VM_INFO_COUNT; + NSLog(@"%i",count); + int returned = host_statistics(myHost, HOST_VM_INFO, myStat, &count); + if ( returned != KERN_SUCCESS ) { + NSLog(@"Failed to get Statistics in -refreshStats method of ITVirtualMemoryInfo"); + NSLog(@"%s",strerror(returned)); + return NO; + } else { + return YES; + } +} + +@end