Initial revision
authorJoseph Spiros <joseph.spiros@ithinksw.com>
Tue, 10 Dec 2002 06:56:29 +0000 (06:56 +0000)
committerJoseph Spiros <joseph.spiros@ithinksw.com>
Tue, 10 Dec 2002 06:56:29 +0000 (06:56 +0000)
English.lproj/InfoPlist.strings [new file with mode: 0755]
ITAppleEvent.h [new file with mode: 0755]
ITAppleEvent.m [new file with mode: 0755]
ITFoundation.h [new file with mode: 0755]
ITStringScanner.h [new file with mode: 0755]
ITStringScanner.m [new file with mode: 0755]
ITVirtualMemoryInfo.h [new file with mode: 0755]
ITVirtualMemoryInfo.m [new file with mode: 0755]

diff --git a/English.lproj/InfoPlist.strings b/English.lproj/InfoPlist.strings
new file mode 100755 (executable)
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 (executable)
index 0000000..bf54bca
--- /dev/null
@@ -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 <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
diff --git a/ITAppleEvent.m b/ITAppleEvent.m
new file mode 100755 (executable)
index 0000000..b1c2fb7
--- /dev/null
@@ -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 (executable)
index 0000000..b02082b
--- /dev/null
@@ -0,0 +1,5 @@
+#import <Cocoa/Cocoa.h>
+
+#import <ITFoundation/ITVirtualMemoryInfo.h>
+#import <ITFoundation/ITStringScanner.h>
+#import <ITFoundation/ITAppleEvent.h>
\ No newline at end of file
diff --git a/ITStringScanner.h b/ITStringScanner.h
new file mode 100755 (executable)
index 0000000..8fb0122
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ *     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
diff --git a/ITStringScanner.m b/ITStringScanner.m
new file mode 100755 (executable)
index 0000000..c3dff8e
--- /dev/null
@@ -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<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
diff --git a/ITVirtualMemoryInfo.h b/ITVirtualMemoryInfo.h
new file mode 100755 (executable)
index 0000000..f0e3bb8
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ *     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
diff --git a/ITVirtualMemoryInfo.m b/ITVirtualMemoryInfo.m
new file mode 100755 (executable)
index 0000000..4017993
--- /dev/null
@@ -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