--- /dev/null
+/*
+ * ITFoundation
+ * ITAppleEvent
+ *
+ * Class that provides utilities for sending AppleEvents
+ * (and OSA scripts) using Carbon function calls in Cocoa
+ *
+ * Original Author : Joseph Spiros <joseph.spiros@ithinksw.com>
+ * Responsibility : Joseph Spiros <joseph.spiros@ithinksw.com>
+ * : Kent Sutherland <kent.sutherland@ithinksw.com>
+ *
+ * Copyright (c) 2002 iThink Software.
+ * All Rights Reserved
+ *
+ */
+
+#import <Cocoa/Cocoa.h>
+#import <Carbon/Carbon.h>
+
+
+@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
--- /dev/null
+#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
--- /dev/null
+#import <Cocoa/Cocoa.h>
+
+#import <ITFoundation/ITVirtualMemoryInfo.h>
+#import <ITFoundation/ITStringScanner.h>
+#import <ITFoundation/ITAppleEvent.h>
\ No newline at end of file
--- /dev/null
+/*
+ * ITFoundation
+ * ITStringScanner
+ *
+ * A super-fast replacement for NSScanner
+ *
+ * Original Author : Alexander Strange <alexander.strange@ithinksw.com>
+ * Responsibility : Alexander Strange <alexander.strange@ithinksw.com>
+ * : Joseph Spiros <joseph.spiros@ithinksw.com>
+ *
+ * Copyright (c) 2002 iThink Software.
+ * All Rights Reserved
+ *
+ */
+
+#import <Foundation/Foundation.h>
+#import <stdlib.h>
+
+/*!
+@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
--- /dev/null
+// 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<tmp));
+
+ if (foundIt)
+ {
+ tmpStr = [str substringWithRange:r];
+ curPos = i;
+ }
+ return tmpStr;
+ }
+}
+
+-(NSString *)scanUpToString:(NSString*)str2
+{
+ size_t i=curPos,j=0, len = [str2 length];
+ const char *str2cstr = [str2 cString];
+
+
+ if (len <= 1)
+ {
+ if (len)
+ return [self scanUpToCharacter:str2cstr[0]];
+ else
+ return AString();
+ }
+ else
+ {
+ NSRange r = {i,0};
+ NSString *tmpStr = nil;
+ const size_t tmp = size;
+ unsigned char foundIt = NO;
+
+ do
+ {
+ i++,j++;
+
+ if (0)
+ {//now we check for the rest of the string
+ foundIt = YES;
+ r.length = j;
+ }
+
+ }
+ while ((!foundIt) && (i<tmp));
+
+ if (foundIt)
+ {
+ tmpStr = [str substringWithRange:r];
+ curPos = i;
+ }
+ return tmpStr;
+ }
+
+}
+@end
--- /dev/null
+/*
+ * ITFoundation
+ * ITVirtualMemoryInfo
+ *
+ * Class that provides utilities for getting information
+ * on Mac OS X's mach kernel's Virtual Memory settings
+ * and status
+ *
+ * Original Author : Joseph Spiros <joseph.spiros@ithinksw.com>
+ * Responsibility : Joseph Spiros <joseph.spiros@ithinksw.com>
+ * : Matt Judy <matt.judy@ithinksw.com>
+ *
+ * Copyright (c) 2002 iThink Software.
+ * All Rights Reserved
+ *
+ */
+
+#import <Foundation/Foundation.h>
+#import <mach/mach.h>
+
+/* 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
--- /dev/null
+#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