# HG changeset patch # User Jens Alfke # Date 1213739868 25200 # Node ID 1af6415650bfd1e0af0affa7d811c8d46258620c # Parent c59dec0889900265db5eef5a1e3f9df916f18240 Added AudioUtils. diff -r c59dec088990 -r 1af6415650bf AudioUtils.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AudioUtils.h Tue Jun 17 14:57:48 2008 -0700 @@ -0,0 +1,44 @@ +// +// AudioUtils.h +// Cloudy +// +// Created by Jens Alfke on 6/17/08. +// Copyright 2008 Jens Alfke. All rights reserved. +// + +#import + +#ifdef __cplusplus +extern "C" { +#endif + + #define MYCoreAudioErrorDomain @"MYCoreAudioDomain" + + NSString* MYCAErrorString( OSStatus coreAudioError ); + NSError* MYCAError( OSStatus coreAudioError, NSString *message ); + +#ifdef __cplusplus +} +#endif + + + +#define XWarnIfError(error, operation) \ + do { \ + OSStatus __err = error; \ + if (__err) _MYWarnCAError(__err,@""operation); \ + } while (0) + +void _MYWarnCAError( OSStatus error, NSString *operation ); + +#ifdef __cplusplus + + #define XThrowIfError(error, operation) \ + do { \ + OSStatus __err = error; \ + if (__err) _MYThrowCAError(__err,@""operation); \ + } while (0) + + void _MYThrowCAError( OSStatus error, NSString *operation ) throw(NSError*) __attribute__((noreturn)); + +#endif __cplusplus diff -r c59dec088990 -r 1af6415650bf AudioUtils.mm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AudioUtils.mm Tue Jun 17 14:57:48 2008 -0700 @@ -0,0 +1,44 @@ +// +// AudioUtils.mm +// Cloudy +// +// Created by Jens Alfke on 6/17/08. +// Copyright 2008 Jens Alfke. All rights reserved. +// + +#import "AudioUtils.h" + + +NSString* MYCAErrorString( OSStatus coreAudioError ) +{ + if( coreAudioError >= 0x20202020 ) + return NSFileTypeForHFSTypeCode(coreAudioError); + else + return [NSString stringWithFormat: @"%i",coreAudioError]; +} + +NSError* MYCAError( OSStatus coreAudioError, NSString *message ) +{ + NSString *errStr = $sprintf(@"CoreAudio error %@", MYCAErrorString(coreAudioError)); + if( message ) + message = [message stringByAppendingFormat: @" [%@]", errStr]; + else + message = errStr; + NSString *domain = (coreAudioError >= 0x20202020) ?MYCoreAudioErrorDomain :NSOSStatusErrorDomain; + return [NSError errorWithDomain: domain code: coreAudioError + userInfo: $dict({NSLocalizedDescriptionKey, message})]; +} + + +void _MYThrowCAError( OSStatus err, NSString *operation ) throw(NSError*) +{ + NSError *error = MYCAError(err, $sprintf(@"Error in %@", operation)); + Warn(@"EXCEPTION: %@",error.localizedDescription); + throw error; +} + +void _MYWarnCAError( OSStatus err, NSString *operation ) +{ + NSError *error = MYCAError(err, $sprintf(@"Error in %@", operation)); + Warn(@"%@",error.localizedDescription); +} diff -r c59dec088990 -r 1af6415650bf ConcurrentOperation.m --- a/ConcurrentOperation.m Sun Jun 01 14:01:44 2008 -0700 +++ b/ConcurrentOperation.m Tue Jun 17 14:57:48 2008 -0700 @@ -8,7 +8,7 @@ #import "ConcurrentOperation.h" -// See file:///Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/NSOperation_class/Reference/Reference.html#//apple_ref/doc/uid/TP40004591-RH2-DontLinkElementID_4 +// See file:///Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/NSOperation_class/Reference/Reference.html @implementation ConcurrentOperation