OSErr isMissingValue(const AppleEvent *ev, AEKeyword theKey, Boolean *ismsng) { OSErr err; DescType typeCode; Size dataSize; *ismsng = false; err = AESizeOfParam(ev, theKey, &typeCode, &dataSize); if ((err != noErr) || (typeCode == typeNull)){ goto bail; } if (typeCode == typeType) { OSType type_data; err = AEGetParamPtr(ev, theKey, typeCode, NULL, &type_data, dataSize, NULL); if (err != noErr) { fputs("Failed to AEGetParamPtr in isMissingValue", stderr); goto bail; } if (type_data == cMissingValue) { *ismsng = true; } } if (typeCode == cMissingValue) { *ismsng = true; } bail: return noErr; }
OSStatus macCallbackUrlHandler( const AppleEvent *ae, AppleEvent *, long /*handlerRefCon*/) { DEBUG_BLOCK OSErr error = noErr; Size actualSize = 0; DescType descType = typeUTF8Text; if( ( error = AESizeOfParam( ae, keyDirectObject, &descType, &actualSize ) ) == noErr ) { QByteArray ba; ba.resize( actualSize + 1 ); error = AEGetParamPtr( ae, keyDirectObject, typeUTF8Text, 0, ba.data(), actualSize, &actualSize ); if( error == noErr ) { KUrl url( QString::fromUtf8( ba.data() ) ); if( url.protocol() == "amarok" ) { AmarokUrl aUrl( url.url() ); aUrl.run(); } else { TrackLoader *loader = new TrackLoader(); // FIXME: this has no effect, one has to connect to finished() signal loader->init( url ); } } } return error; }
OSErr getFSRef(const AppleEvent *ev, AEKeyword theKey, FSRef *outFSRef_p) { OSErr err = noErr; DescType typeCode; Size dataSize; err = AESizeOfParam(ev, keyDirectObject, &typeCode, &dataSize); if (err != noErr) goto bail; switch (typeCode) { case typeAlias: #if !__LP64__ case typeFSS: #endif case typeFileURL: case cObjectSpecifier: err = getFSRefFromAE(ev, theKey, outFSRef_p); break; case typeChar: case typeUTF8Text: case typeUnicodeText: err = getFSRefFromUTextAE(ev, theKey, outFSRef_p); break; default: err = errAEWrongDataType; } bail: return err; }
CFMutableArrayRef CFMutableArrayCreatePOSIXPathsWithEvent( const AppleEvent *ev, AEKeyword theKey, OSErr *errPtr) { CFMutableArrayRef outArray = NULL; DescType typeCode; Size dataSize; AEDescList aeList = {typeNull, NULL}; *errPtr = AESizeOfParam(ev, theKey, &typeCode, &dataSize); if ((*errPtr != noErr) || (typeCode == typeNull)){ goto bail; } *errPtr = AEGetParamDesc(ev, theKey, typeAEList, &aeList); if (*errPtr != noErr) goto bail; long count = 0; *errPtr = AECountItems(&aeList, &count); if (*errPtr != noErr) goto bail; outArray = CFArrayCreateMutable(NULL, count, &kCFTypeArrayCallBacks); for(long index = 1; index <= count; index++) { void *value_ptr = NULL; Size data_size; *errPtr = AEGetNthPtr(&aeList, index, typeFileURL, NULL, NULL, value_ptr, 0, &data_size); if (*errPtr == noErr) { value_ptr = malloc(data_size); *errPtr = AEGetNthPtr(&aeList, index, typeFileURL, NULL, NULL, value_ptr, data_size, NULL); } if (*errPtr != noErr) { fputs("Fail to AEGetNthPtr in CFMutableArrayCreatePOSIXPathsWithEvent", stderr); goto bail; } CFURLRef file_url = CFURLCreateAbsoluteURLWithBytes( NULL, (const UInt8 *)value_ptr, data_size, kCFStringEncodingUTF8, NULL, false); CFStringRef path = CFURLCopyFileSystemPath(file_url, kCFURLPOSIXPathStyle); CFArrayAppendValue(outArray, path); CFRelease(file_url); CFRelease(path); free(value_ptr); } bail: AEDisposeDesc(&aeList); return outArray; }
static void AttachErrorCode(AppleEvent *event,OSStatus err) { OSStatus returnVal; if ( event==NULL ) return; if (event->descriptorType != typeNull) { /* Check there isn't already an error attached */ returnVal = AESizeOfParam(event, keyErrorNumber, NULL, NULL); if (returnVal != noErr ) { /* Add success if no previous error */ AEPutParamPtr(event, keyErrorNumber, typeSInt32, &err, sizeof(err)); } } }
OSErr FetchParamAnySize(AEKeyword plop,AppleEvent *appIn,Ptr *dest,DescType theType) { OSErr err; Size size; DescType actualType; err=AESizeOfParam(appIn,plop, &actualType, &size); if (err) return err; *dest=NewPtr(size); err=AEGetParamPtr(appIn, plop, theType, &actualType, *dest, size, &size); return err; }
OSErr getFloatArray(const AppleEvent *ev, AEKeyword theKey, CFMutableArrayRef *outArray) { OSErr err; DescType typeCode; Size dataSize; AEDescList aeList = {typeNull, NULL}; err = AESizeOfParam(ev, theKey, &typeCode, &dataSize); if ((err != noErr) || (typeCode == typeNull)){ fputs("Failed to AESizeOfParam in getFloatArray", stderr); goto bail; } err = AEGetParamDesc(ev, theKey, typeAEList, &aeList); if (err != noErr) { fputs("Failed to AEGetParamDesc in getFloatArray", stderr); goto bail; } long count = 0; err = AECountItems(&aeList, &count); if (err != noErr) { fputs("Failed to AECountItems in getFloatArray", stderr); goto bail; } *outArray = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); for(long index = 1; index <= count; index++) { float value; err = AEGetNthPtr(&aeList, index, typeIEEE32BitFloatingPoint, NULL, NULL, &value, sizeof(value), NULL); if (err != noErr) { fputs("Fail to AEGetNthPtr in getFloatArray", stderr); goto bail; } CFNumberRef cfnum = CFNumberCreate(NULL, kCFNumberFloat32Type, &value); CFArrayAppendValue(*outArray, cfnum); CFRelease(cfnum); } bail: AEDisposeDesc(&aeList); #if useLog CFShow(*outArray); fputs("end of getFloatArray", stderr); #endif return err; }
static OSErr NativeCallback(const AppleEvent *appleEvt, AppleEvent* reply, UInt32 refcon) { OSErr anErr = noErr; Size actualSize = 0; DescType descType = typeChar; if ((anErr = AESizeOfParam(appleEvt, keyDirectObject, &descType, &actualSize)) == noErr) { if (0 != actualSize) { // must be + 1 to allow the closing null character, otherwise // we don't know where the string ends. Size length = actualSize * sizeof(char) + 1; char *dataPtr = (char*)malloc(length); if (0 != dataPtr) { memset(dataPtr, 0, length); //probably not necessary, but safest. anErr = AEGetParamPtr(appleEvt, keyDirectObject, typeChar, 0, dataPtr, actualSize, &actualSize); if (noErr == anErr) { JNIEnv *env; (*jvm)->AttachCurrentThread(jvm, (void **)&env, NULL); jstring theURL = (*env)->NewStringUTF(env, dataPtr); (*env)->CallVoidMethod(env, ref, mid, theURL); } free(dataPtr); } // else we could throw an OutOfMemoryError here. } } return anErr; }
static pascal OSErr MacCallbackGetUrl(const AppleEvent *in,AppleEvent *out,long ptr) { Size l=0; OSErr err=noErr; DescType type=typeChar; if ((err=AESizeOfParam(in,keyDirectObject,&type,&l))==noErr && l) { char buf[l+1]; if ((err=AEGetParamPtr(in,keyDirectObject,type,0,&buf,l,&l))==noErr && l) { buf[l]=0; const CslApp& app=::wxGetApp(); app.IpcCall(C2U(buf),app.GetTopWindow()); } } return noErr; }
OSErr getBoolValue(const AppleEvent *ev, AEKeyword theKey, Boolean *outValue) { OSErr err; DescType typeCode; Size dataSize; err = AESizeOfParam(ev, theKey, &typeCode, &dataSize); if ((err != noErr) || (typeCode == typeNull)){ goto bail; } if (typeCode == typeTrue) { *outValue = true; } else if(typeCode == typeFalse) { *outValue = false; } bail: return err; }
/** * Callback from OS X with URL. * Reference: * http://developer.apple.com/documentation/Carbon/Reference/Apple_Event_Manager/Reference/reference.html#//apple_ref/c/func/NewAEEventHandlerUPP * http://developer.apple.com/documentation/Carbon/Reference/Apple_Event_Manager/Reference/reference.html#//apple_ref/c/tdef/AEEventHandlerUPP * http://developer.apple.com/documentation/Carbon/Reference/Apple_Event_Manager/Reference/reference.html#//apple_ref/c/tdef/AEEventHandlerProcPtr * * @param theAppleEvent Pointer to apple event handle * @param reply Pointer to default reply event * @param handlerRefcon Reference constant for this callback. (Ignored) */ static OSErr openURLCallback(const AppleEvent *theAppleEvent, AppleEvent* reply, long handlerRefcon) { OSErr result = noErr; Size givenLength = 0; DescType type = typeChar; // Get the size of the string the callback wants to give us, and then // check that it is > 0 in length. result = AESizeOfParam(theAppleEvent, keyDirectObject, &type, &givenLength); if (result == noErr && givenLength != 0) { // Allocate a buffer for the result // givenLength +1 for the \0 Size length = givenLength + 1; char *dataPtr = (char*)malloc(length); if (dataPtr != 0) { // Empty the buffer memset(dataPtr, 0, length); // Get the url result = AEGetParamPtr(theAppleEvent, keyDirectObject, typeChar, 0, dataPtr, givenLength, &givenLength); // Did we get it? if (result == noErr) { // Get the java environment for the jvm we want to callback to JNIEnv *env; (*jvm)->AttachCurrentThread(jvm, (void **)&env, NULL); // Convert the url into a java string jstring theURL = (*env)->NewStringUTF(env, dataPtr); // Call the method! (*env)->CallVoidMethod(env, apple, callbackMethod, theURL); } // Free the buffer free(dataPtr); } } // And return! return result; }
static PyObject *AEDesc_AESizeOfParam(AEDescObject *_self, PyObject *_args) { PyObject *_res = NULL; OSErr _err; AEKeyword theAEKeyword; DescType typeCode; Size dataSize; #ifndef AESizeOfParam PyMac_PRECHECK(AESizeOfParam); #endif if (!PyArg_ParseTuple(_args, "O&", PyMac_GetOSType, &theAEKeyword)) return NULL; _err = AESizeOfParam(&_self->ob_itself, theAEKeyword, &typeCode, &dataSize); if (_err != noErr) return PyMac_Error(_err); _res = Py_BuildValue("O&l", PyMac_BuildOSType, typeCode, dataSize); return _res; }
CFStringRef CFStringCreateWithEvent(const AppleEvent *ev, AEKeyword theKey, OSErr *errPtr) { CFStringRef outStr = NULL; DescType typeCode; DescType returnedType; Size actualSize; Size dataSize; CFStringEncoding encodeKey; OSType a_type; *errPtr = AESizeOfParam(ev, theKey, &typeCode, &dataSize); if ((*errPtr != noErr) || (typeCode == typeNull)){ goto bail; } #if useLog showAEDesc(ev); #endif if (dataSize == 0) { outStr = CFSTR(""); goto bail; } switch (typeCode) { case typeChar: encodeKey = CFStringGetSystemEncoding(); break; case typeUTF8Text: encodeKey = kCFStringEncodingUTF8; break; case typeType: *errPtr = AEGetParamPtr(ev, theKey, typeCode, &returnedType, &a_type, dataSize, &actualSize); if (a_type == cMissingValue) { goto bail; } //break; default : typeCode = typeUnicodeText; encodeKey = kCFStringEncodingUnicode; } UInt8 *dataPtr = malloc(dataSize); if (dataPtr == NULL) { *errPtr = errAEEventFailed; fputs("Failed to malloc.", stderr); goto bail; } *errPtr = AEGetParamPtr(ev, theKey, typeCode, &returnedType, dataPtr, dataSize, &actualSize); if (*errPtr != noErr) { free(dataPtr); goto bail; } if (actualSize > dataSize) { #if useLog printf("buffere size is allocated. data:%i actual:%i\n", (int)dataSize, (int)actualSize); #endif dataSize = actualSize; dataPtr = (UInt8 *)realloc(dataPtr, dataSize); if (dataPtr == NULL) { fputs("Failed to reallocate memory", stderr); goto bail; } *errPtr = AEGetParamPtr(ev, theKey, typeCode, &returnedType, dataPtr, dataSize, &actualSize); } if (*errPtr == noErr) { outStr = CFStringCreateWithBytes(NULL, dataPtr, dataSize, encodeKey, false); } free(dataPtr); bail: return outStr; }