From cbf867ef1f43f83e21ee694cbc93e64e036b21b1 Mon Sep 17 00:00:00 2001 From: Alexander Strange Date: Mon, 29 Dec 2003 05:43:31 +0000 Subject: [PATCH] Data-returning AE stuff that might work. --- ITAppleEventCenter.h | 1 + ITAppleEventCenter.m | 66 ++++++++++++++++++++++++++++++ ITDebug.m | 2 +- ITFoundation.xcode/project.pbxproj | 50 +++++++++++----------- 4 files changed, 93 insertions(+), 26 deletions(-) diff --git a/ITAppleEventCenter.h b/ITAppleEventCenter.h index f2eae2a..3441afa 100755 --- a/ITAppleEventCenter.h +++ b/ITAppleEventCenter.h @@ -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 diff --git a/ITAppleEventCenter.m b/ITAppleEventCenter.m index 990e454..9aa0c56 100755 --- a/ITAppleEventCenter.m +++ b/ITAppleEventCenter.m @@ -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 diff --git a/ITDebug.m b/ITDebug.m index e7fef2b..277f91a 100755 --- 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) { diff --git a/ITFoundation.xcode/project.pbxproj b/ITFoundation.xcode/project.pbxproj index 519cc95..baec463 100755 --- a/ITFoundation.xcode/project.pbxproj +++ b/ITFoundation.xcode/project.pbxproj @@ -104,18 +104,18 @@ sourceTree = ""; }; 0867D69BFE84028FC02AAC07 = { - expectedFileType = wrapper.framework; fallbackIsa = PBXFileReference; isa = PBXFrameworkReference; + lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; refType = 0; sourceTree = ""; }; 0867D6A5FE840307C02AAC07 = { - expectedFileType = wrapper.framework; fallbackIsa = PBXFileReference; isa = PBXFrameworkReference; + lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; refType = 0; @@ -141,9 +141,9 @@ sourceTree = ""; }; 089C1667FE841158C02AAC07 = { - expectedFileType = text.plist.strings; fileEncoding = 10; isa = PBXFileReference; + lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; refType = 4; @@ -190,9 +190,9 @@ sourceTree = ""; }; 1058C7B1FEA5585E11CA2CBB = { - expectedFileType = wrapper.framework; fallbackIsa = PBXFileReference; isa = PBXFrameworkReference; + lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; refType = 0; @@ -229,17 +229,17 @@ sourceTree = ""; }; 2AB93A3005705A0C007E748F = { - expectedFileType = sourcecode.c.h; fileEncoding = 4; isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; path = "ITCategory-NSArray.h"; refType = 4; sourceTree = ""; }; 2AB93A3105705A0C007E748F = { - expectedFileType = sourcecode.c.objc; fileEncoding = 4; isa = PBXFileReference; + lastKnownFileType = sourcecode.c.objc; path = "ITCategory-NSArray.m"; refType = 4; sourceTree = ""; @@ -282,9 +282,9 @@ sourceTree = ""; }; 32DBCF5E0370ADEE00C91783 = { - expectedFileType = sourcecode.c.h; fileEncoding = 4; isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; path = ITFoundation_Prefix.pch; refType = 4; sourceTree = ""; @@ -300,17 +300,17 @@ //3D3 //3D4 3D2D8A10055E07D800F59C27 = { - expectedFileType = sourcecode.c.c; fileEncoding = 30; isa = PBXFileReference; + lastKnownFileType = sourcecode.c.c; path = queue.c; refType = 4; sourceTree = ""; }; 3D2D8A11055E07D800F59C27 = { - expectedFileType = sourcecode.c.h; fileEncoding = 30; isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; path = queue.h; refType = 4; sourceTree = ""; @@ -338,17 +338,17 @@ //7C3 //7C4 7CA50B2B054E77950074E1D9 = { - expectedFileType = sourcecode.c.h; fileEncoding = 4; isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; path = ITAppleEventCenter.h; refType = 4; sourceTree = ""; }; 7CA50B2C054E77950074E1D9 = { - expectedFileType = sourcecode.c.objc; fileEncoding = 4; isa = PBXFileReference; + lastKnownFileType = sourcecode.c.objc; path = ITAppleEventCenter.m; refType = 4; sourceTree = ""; @@ -369,17 +369,17 @@ }; }; 7CA50B2F054E77A00074E1D9 = { - expectedFileType = sourcecode.c.h; fileEncoding = 4; isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; path = ITDebug.h; refType = 4; sourceTree = ""; }; 7CA50B30054E77A00074E1D9 = { - expectedFileType = sourcecode.c.objc; fileEncoding = 4; isa = PBXFileReference; + lastKnownFileType = sourcecode.c.objc; path = ITDebug.m; refType = 4; sourceTree = ""; @@ -400,40 +400,40 @@ }; }; 7CA50B7F054E786E0074E1D9 = { - expectedFileType = sourcecode.c.objc; fileEncoding = 4; isa = PBXFileReference; + lastKnownFileType = sourcecode.c.objc; path = ITVirtualMemoryInfo.m; refType = 4; sourceTree = ""; }; 7CA50B80054E786E0074E1D9 = { - expectedFileType = sourcecode.c.h; fileEncoding = 4; isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; path = ITVirtualMemoryInfo.h; refType = 4; sourceTree = ""; }; 7CA50B8B054E787D0074E1D9 = { - expectedFileType = sourcecode.c.objc; fileEncoding = 4; isa = PBXFileReference; + lastKnownFileType = sourcecode.c.objc; path = ITByteStream.m; refType = 4; sourceTree = ""; }; 7CA50B8C054E787D0074E1D9 = { - expectedFileType = sourcecode.c.h; fileEncoding = 4; isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; path = ITByteStream.h; refType = 4; sourceTree = ""; }; 7CA50BAA054E794B0074E1D9 = { - expectedFileType = wrapper.framework; isa = PBXFileReference; + lastKnownFileType = wrapper.framework; name = Carbon.framework; path = /System/Library/Frameworks/Carbon.framework; refType = 0; @@ -446,9 +446,9 @@ }; }; 7CA50D7D054E7C600074E1D9 = { - expectedFileType = sourcecode.c.h; fileEncoding = 4; isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; path = ITFoundation.h; refType = 4; sourceTree = ""; @@ -463,17 +463,17 @@ }; }; 7CF6C92E057D65B0007FEC13 = { - expectedFileType = sourcecode.c.h; fileEncoding = 4; isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; path = ITPreference.h; refType = 4; sourceTree = ""; }; 7CF6C92F057D65B0007FEC13 = { - expectedFileType = sourcecode.c.objc; fileEncoding = 4; isa = PBXFileReference; + lastKnownFileType = sourcecode.c.objc; path = ITPreference.m; refType = 4; sourceTree = ""; @@ -491,17 +491,17 @@ }; }; 7CF6C936057D65BA007FEC13 = { - expectedFileType = sourcecode.c.h; fileEncoding = 4; isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; path = ITPreferenceCenter.h; refType = 4; sourceTree = ""; }; 7CF6C937057D65BA007FEC13 = { - expectedFileType = sourcecode.c.objc; fileEncoding = 4; isa = PBXFileReference; + lastKnownFileType = sourcecode.c.objc; path = ITPreferenceCenter.m; refType = 4; sourceTree = ""; @@ -642,15 +642,15 @@ runOnlyForDeploymentPostprocessing = 0; }; 8DC2EF5A0486A6940098B216 = { - expectedFileType = text.plist; fileEncoding = 4; isa = PBXFileReference; + lastKnownFileType = text.plist; path = Info.plist; refType = 4; sourceTree = ""; }; 8DC2EF5B0486A6940098B216 = { - expectedFileType = wrapper.framework; + explicitFileType = wrapper.framework; includeInIndex = 0; isa = PBXFileReference; path = ITFoundation.framework; -- 2.20.1