Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also add the importCFString/importCFStringAs functions.
- Loading branch information
Showing
4 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
-- | Interface to CoreFoundation's @CFError@ C type. | ||
-- It is toll-free bridged with the @NSData@ type. | ||
module System.CoreFoundation.Error ( | ||
-- * The Error type | ||
Error, | ||
ErrorRef, | ||
newError, | ||
-- * Error properties | ||
errorDescription, | ||
errorFailureReason, | ||
errorRecoverySuggestion, | ||
userInfo, | ||
errorDomain, | ||
errorCode, | ||
-- * Error domains | ||
domainPOSIX, | ||
domainOSStatus, | ||
domainMach, | ||
domainCocoa, | ||
-- * User info keys | ||
localizedDescriptionKey, | ||
localizedFailureReasonKey, | ||
localizedRecoverySuggestionKey, | ||
descriptionKey, | ||
underlyingErrorKey, | ||
) where | ||
|
||
import Foreign | ||
import Foreign.C | ||
|
||
import Prelude hiding (String) | ||
|
||
import System.CoreFoundation.Base | ||
import System.CoreFoundation.Dictionary | ||
import System.CoreFoundation.String as CF | ||
import System.CoreFoundation.Internal.TH | ||
|
||
#include <CoreFoundation/CoreFoundation.h> | ||
|
||
declareCFType "Error" | ||
|
||
importCFStringAs "kCFErrorLocalizedDescriptionKey" "localizedDescriptionKey" | ||
importCFStringAs "kCFErrorLocalizedFailureReasonKey" "localizedFailureReasonKey" | ||
importCFStringAs "kCFErrorLocalizedRecoverySuggestionKey" "localizedRecoverySuggestionKey" | ||
importCFStringAs "kCFErrorDescriptionKey" "descriptionKey" | ||
importCFStringAs "kCFErrorUnderlyingErrorKey" "underlyingErrorKey" | ||
|
||
importCFStringAs "kCFErrorDomainPOSIX" "domainPOSIX" | ||
importCFStringAs "kCFErrorDomainOSStatus" "domainOSStatus" | ||
importCFStringAs "kCFErrorDomainMach" "domainMach" | ||
importCFStringAs "kCFErrorDomainCocoa" "domainCocoa" | ||
|
||
{#fun CFErrorCreate as newError | ||
{ withDefaultAllocator- `AllocatorPtr' | ||
, withObject* `String' | ||
, `Int' | ||
, maybeWithObject* `Maybe Dictionary' | ||
} -> `Error' getOwned* #} | ||
|
||
maybeWithObject Nothing = ($ nullPtr) | ||
maybeWithObject (Just o) = withObject o | ||
|
||
{#fun pure CFErrorCopyDescription as errorDescription | ||
{ withObject* `Error' } -> `String' getAndRetain* #} | ||
-- The docs say that the CFErrorCopyDescription will never return NULL. | ||
|
||
{#fun pure CFErrorCopyFailureReason as errorFailureReason | ||
{ withObject* `Error' } -> `Maybe String' maybeGetAndRetain* #} | ||
|
||
{#fun pure CFErrorCopyRecoverySuggestion as errorRecoverySuggestion | ||
{ withObject* `Error' } -> `Maybe String' maybeGetAndRetain* #} | ||
|
||
{#fun pure CFErrorCopyUserInfo as userInfo | ||
{ withObject* `Error' } -> `Maybe Dictionary' maybeGetAndRetain* #} | ||
|
||
{#fun pure CFErrorGetDomain as errorDomain | ||
{ withObject* `Error' } -> `String' getAndRetain* #} | ||
|
||
{#fun pure CFErrorGetCode as errorCode | ||
{ withObject* `Error' } -> `CFIndex' id #} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters