Data-returning AE stuff that might work.
authorAlexander Strange <astrange@ithinksw.com>
Mon, 29 Dec 2003 05:43:31 +0000 (05:43 +0000)
committerAlexander Strange <astrange@ithinksw.com>
Mon, 29 Dec 2003 05:43:31 +0000 (05:43 +0000)
ITAppleEventCenter.h
ITAppleEventCenter.m
ITDebug.m
ITFoundation.xcode/project.pbxproj

index f2eae2a..3441afa 100755 (executable)
@@ -35,6 +35,7 @@
 - (NSString*)sendAEWithSendString:(NSString*)nssendString eventClass:(NSString*)eventClass eventID:(NSString*)eventID appPSN:(ProcessSerialNumber)psn;
 - (long)sendAEWithSendStringForNumber:(NSString*)string eventClass:(NSString*)eventClass eventID:(NSString*)eventID appPSN:(ProcessSerialNumber)psn;
 - (AEArrayDataPointer)sendAEWithSendStringForArray:(NSString*)string eventClass:(NSString*)eventClass eventID:(NSString*)eventID appPSN:(ProcessSerialNumber)psn;
+- (NSData*)sendAEWithSendStringForData:(NSString*)nssendString eventClass:(NSString*)eventClass eventID:(NSString*)eventID appPSN:(ProcessSerialNumber)psn;
 
 - (void)printCarbonDesc:(AEDesc*)desc;
 @end
index 990e454..9aa0c56 100755 (executable)
@@ -626,4 +626,70 @@ return result;
 
     return result;
 }
+
+- (NSData*)sendAEWithSendStringForData:(NSString*)nssendString eventClass:(NSString*)eventClass eventID:(NSString*)eventID appPSN:(ProcessSerialNumber)psn
+{
+    //Add error checking...
+    AEEventClass eClass = *((unsigned long*)[eventClass UTF8String]);
+    AEEventID   eID    = *((unsigned long*)[eventID UTF8String]);
+    int pid;
+    
+    const char *sendString = [nssendString UTF8String];
+    NSData  *_finalData = nil;
+    
+    AppleEvent sendEvent, replyEvent;
+    
+    DescType resultType;
+    Size resultSize, charResultSize;
+    
+    AEBuildError buildError;
+    OSStatus berr,err;
+    OSErr err2, err3;
+    
+    if ((GetProcessPID(&psn, &pid) == noErr) && (pid == 0)) {
+       ITDebugLog(@"Error getting PID of application.");
+       return nil;
+    }
+    
+    berr = AEBuildAppleEvent(eClass, eID, typeProcessSerialNumber,(ProcessSerialNumber*)&psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, sendString);
+    if (!berr) [self printCarbonDesc:&sendEvent];
+    
+    if (berr) {
+        ITDebugLog(@"Error: %d:%d at \"%@\"",(int)buildError.fError,buildError.fErrorPos,[nssendString substringToIndex:buildError.fErrorPos]);
+    }
+    
+    err = AESend(&sendEvent, &replyEvent, kAEWaitReply, kAENormalPriority, kNoTimeOut, idleUPP, NULL);
+    if (!err) [self printCarbonDesc:&replyEvent];
+    
+    if (err) {
+        ITDebugLog(@"Send Error: %i",err);
+    } else {
+        unichar *result = 0;
+       
+        err2 = AESizeOfParam(&replyEvent, keyDirectObject, &resultType, &resultSize);
+        if (resultSize != 0) {
+            result = malloc(resultSize);
+        } else {
+            return nil;
+        }
+       
+        if (err2) {
+            ITDebugLog(@"Error After AESizeOfParam: %i", err2);
+        } else {
+            err3 = AEGetParamPtr(&replyEvent, keyDirectObject, resultType, NULL, result, resultSize, &charResultSize);
+           
+            if (err3) {
+                ITDebugLog(@"Error After AEGetParamPtr: %i", err3);
+            } else {
+                _finalData = [NSData dataWithBytesNoCopy:result length:charResultSize freeWhenDone:YES];
+            }
+        }
+    }
+    
+    if (!berr) AEDisposeDesc(&sendEvent);
+    if (!err) AEDisposeDesc(&replyEvent);
+    
+    return _finalData;
+}
+
 @end
\ No newline at end of file
index e7fef2b..277f91a 100755 (executable)
--- a/ITDebug.m
+++ b/ITDebug.m
@@ -9,7 +9,7 @@
 
 #import "ITDebug.h"
 
-static BOOL _ITDebugMode = NO;
+static BOOL _ITDebugMode = YES;
 
 void SetITDebugMode (BOOL mode)
 {
index 519cc95..baec463 100755 (executable)
                        sourceTree = "<group>";
                };
                0867D69BFE84028FC02AAC07 = {
-                       expectedFileType = wrapper.framework;
                        fallbackIsa = PBXFileReference;
                        isa = PBXFrameworkReference;
+                       lastKnownFileType = wrapper.framework;
                        name = Foundation.framework;
                        path = /System/Library/Frameworks/Foundation.framework;
                        refType = 0;
                        sourceTree = "<absolute>";
                };
                0867D6A5FE840307C02AAC07 = {
-                       expectedFileType = wrapper.framework;
                        fallbackIsa = PBXFileReference;
                        isa = PBXFrameworkReference;
+                       lastKnownFileType = wrapper.framework;
                        name = AppKit.framework;
                        path = /System/Library/Frameworks/AppKit.framework;
                        refType = 0;
                        sourceTree = "<group>";
                };
                089C1667FE841158C02AAC07 = {
-                       expectedFileType = text.plist.strings;
                        fileEncoding = 10;
                        isa = PBXFileReference;
+                       lastKnownFileType = text.plist.strings;
                        name = English;
                        path = English.lproj/InfoPlist.strings;
                        refType = 4;
                        sourceTree = "<group>";
                };
                1058C7B1FEA5585E11CA2CBB = {
-                       expectedFileType = wrapper.framework;
                        fallbackIsa = PBXFileReference;
                        isa = PBXFrameworkReference;
+                       lastKnownFileType = wrapper.framework;
                        name = Cocoa.framework;
                        path = /System/Library/Frameworks/Cocoa.framework;
                        refType = 0;
                        sourceTree = "<group>";
                };
                2AB93A3005705A0C007E748F = {
-                       expectedFileType = sourcecode.c.h;
                        fileEncoding = 4;
                        isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.h;
                        path = "ITCategory-NSArray.h";
                        refType = 4;
                        sourceTree = "<group>";
                };
                2AB93A3105705A0C007E748F = {
-                       expectedFileType = sourcecode.c.objc;
                        fileEncoding = 4;
                        isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.objc;
                        path = "ITCategory-NSArray.m";
                        refType = 4;
                        sourceTree = "<group>";
                        sourceTree = "<group>";
                };
                32DBCF5E0370ADEE00C91783 = {
-                       expectedFileType = sourcecode.c.h;
                        fileEncoding = 4;
                        isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.h;
                        path = ITFoundation_Prefix.pch;
                        refType = 4;
                        sourceTree = "<group>";
 //3D3
 //3D4
                3D2D8A10055E07D800F59C27 = {
-                       expectedFileType = sourcecode.c.c;
                        fileEncoding = 30;
                        isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.c;
                        path = queue.c;
                        refType = 4;
                        sourceTree = "<group>";
                };
                3D2D8A11055E07D800F59C27 = {
-                       expectedFileType = sourcecode.c.h;
                        fileEncoding = 30;
                        isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.h;
                        path = queue.h;
                        refType = 4;
                        sourceTree = "<group>";
 //7C3
 //7C4
                7CA50B2B054E77950074E1D9 = {
-                       expectedFileType = sourcecode.c.h;
                        fileEncoding = 4;
                        isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.h;
                        path = ITAppleEventCenter.h;
                        refType = 4;
                        sourceTree = "<group>";
                };
                7CA50B2C054E77950074E1D9 = {
-                       expectedFileType = sourcecode.c.objc;
                        fileEncoding = 4;
                        isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.objc;
                        path = ITAppleEventCenter.m;
                        refType = 4;
                        sourceTree = "<group>";
                        };
                };
                7CA50B2F054E77A00074E1D9 = {
-                       expectedFileType = sourcecode.c.h;
                        fileEncoding = 4;
                        isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.h;
                        path = ITDebug.h;
                        refType = 4;
                        sourceTree = "<group>";
                };
                7CA50B30054E77A00074E1D9 = {
-                       expectedFileType = sourcecode.c.objc;
                        fileEncoding = 4;
                        isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.objc;
                        path = ITDebug.m;
                        refType = 4;
                        sourceTree = "<group>";
                        };
                };
                7CA50B7F054E786E0074E1D9 = {
-                       expectedFileType = sourcecode.c.objc;
                        fileEncoding = 4;
                        isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.objc;
                        path = ITVirtualMemoryInfo.m;
                        refType = 4;
                        sourceTree = "<group>";
                };
                7CA50B80054E786E0074E1D9 = {
-                       expectedFileType = sourcecode.c.h;
                        fileEncoding = 4;
                        isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.h;
                        path = ITVirtualMemoryInfo.h;
                        refType = 4;
                        sourceTree = "<group>";
                };
                7CA50B8B054E787D0074E1D9 = {
-                       expectedFileType = sourcecode.c.objc;
                        fileEncoding = 4;
                        isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.objc;
                        path = ITByteStream.m;
                        refType = 4;
                        sourceTree = "<group>";
                };
                7CA50B8C054E787D0074E1D9 = {
-                       expectedFileType = sourcecode.c.h;
                        fileEncoding = 4;
                        isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.h;
                        path = ITByteStream.h;
                        refType = 4;
                        sourceTree = "<group>";
                };
                7CA50BAA054E794B0074E1D9 = {
-                       expectedFileType = wrapper.framework;
                        isa = PBXFileReference;
+                       lastKnownFileType = wrapper.framework;
                        name = Carbon.framework;
                        path = /System/Library/Frameworks/Carbon.framework;
                        refType = 0;
                        };
                };
                7CA50D7D054E7C600074E1D9 = {
-                       expectedFileType = sourcecode.c.h;
                        fileEncoding = 4;
                        isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.h;
                        path = ITFoundation.h;
                        refType = 4;
                        sourceTree = "<group>";
                        };
                };
                7CF6C92E057D65B0007FEC13 = {
-                       expectedFileType = sourcecode.c.h;
                        fileEncoding = 4;
                        isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.h;
                        path = ITPreference.h;
                        refType = 4;
                        sourceTree = "<group>";
                };
                7CF6C92F057D65B0007FEC13 = {
-                       expectedFileType = sourcecode.c.objc;
                        fileEncoding = 4;
                        isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.objc;
                        path = ITPreference.m;
                        refType = 4;
                        sourceTree = "<group>";
                        };
                };
                7CF6C936057D65BA007FEC13 = {
-                       expectedFileType = sourcecode.c.h;
                        fileEncoding = 4;
                        isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.h;
                        path = ITPreferenceCenter.h;
                        refType = 4;
                        sourceTree = "<group>";
                };
                7CF6C937057D65BA007FEC13 = {
-                       expectedFileType = sourcecode.c.objc;
                        fileEncoding = 4;
                        isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.objc;
                        path = ITPreferenceCenter.m;
                        refType = 4;
                        sourceTree = "<group>";
                        runOnlyForDeploymentPostprocessing = 0;
                };
                8DC2EF5A0486A6940098B216 = {
-                       expectedFileType = text.plist;
                        fileEncoding = 4;
                        isa = PBXFileReference;
+                       lastKnownFileType = text.plist;
                        path = Info.plist;
                        refType = 4;
                        sourceTree = "<group>";
                };
                8DC2EF5B0486A6940098B216 = {
-                       expectedFileType = wrapper.framework;
+                       explicitFileType = wrapper.framework;
                        includeInIndex = 0;
                        isa = PBXFileReference;
                        path = ITFoundation.framework;