Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions src/accessoryaccess.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
using System;

using CoreFoundation;
using Foundation;
using ObjCRuntime;

// 'IOUSBHostDevice' comes from the IOUSBHost framework, which macios intentionally does not bind:
// it's a low-level IOKit/DriverKit-adjacent framework whose API is almost entirely
// NS_REFINED_FOR_SWIFT (see IGNORED_MACOS_FRAMEWORKS in tests/xtro-sharpie/Makefile). The instance
// returned by AAUSBAccessory.Open is a valid IOUSBHostDevice handle; consumers that need to perform
// USB I/O on it should hand the accessory to a native/Swift XPC service using CreateXpcRepresentation.
using IOUSBHostDevice = Foundation.NSObject;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think IOUSBHostDevice is a C++ class, not an Objective-C class, in which case it should be bound as IntPtr not NSObject.


// 'xpc_object_t' is an opaque OS_object that's shuttled across XPC boundaries; it has no managed API
// surface of its own, so macios binds it as NSObject everywhere (see src/browserenginekit.cs).
using OS_xpc_object = Foundation.NSObject;

namespace AccessoryAccess {

[Mac (27, 0)]
[Native]
[ErrorDomain ("AAErrorDomain")]
public enum AAErrorCode : long {
Internal = 1,
AccessoryListenerAlreadyRegistered = 2,
AccessoryNotAccessible = 3,
InvalidAccessoryState = 4,
}

[Mac (27, 0)]
[Native]
public enum AAUSBAccessoryMatchingCriteriaInterfaceMatchingOption : long {
MatchAll,
MatchAny,
}

delegate void AAUSBAccessoryOpenCompletionHandler ([NullAllowed] IOUSBHostDevice device, [NullAllowed] NSError error);
delegate void AAUSBAccessoryCloseCompletionHandler ([NullAllowed] NSError error);

[Mac (27, 0)]
[BaseType (typeof (NSObject))]
[DisableDefaultCtor]
interface AAUSBAccessory : NSSecureCoding {
[Export ("initWithXPCRepresentation:")]
[DesignatedInitializer]
NativeHandle Constructor (OS_xpc_object xpcRepresentation);

[Export ("registryID")]
ulong RegistryId { get; }

[Export ("deviceDescriptorData")]
NSData DeviceDescriptorData { get; }

[NullAllowed, Export ("configurationDescriptorData")]
NSData ConfigurationDescriptorData { get; }

[Export ("createXPCRepresentation")]
OS_xpc_object CreateXpcRepresentation ();

// The completion handler receives a live IOUSBHostDevice (typed as NSObject; see the
// IOUSBHostDevice alias at the top of this file). To perform USB I/O, forward the accessory to
// a native/Swift XPC service via CreateXpcRepresentation, or bridge the handle through IOUSBHost.
[Export ("openWithServiceQueue:completionHandler:")]
[Async]
void Open ([NullAllowed] DispatchQueue serviceQueue, AAUSBAccessoryOpenCompletionHandler completionHandler);

[Export ("closeWithCompletionHandler:")]
[Async]
void Close (AAUSBAccessoryCloseCompletionHandler completionHandler);
}

interface IAAUSBAccessoryListener { }

[Mac (27, 0)]
[Protocol (BackwardsCompatibleCodeGeneration = false), Model]
[BaseType (typeof (NSObject))]
interface AAUSBAccessoryListener {
[Export ("usbAccessoryDidConnect:")]
void UsbAccessoryDidConnect (AAUSBAccessory usbAccessory);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Casing mismatch: "USB" in the type name and "Usb" in method name. I believe this should all be "Usb" everywhere.


[Export ("usbAccessoryDidDisconnect:")]
void UsbAccessoryDidDisconnect (AAUSBAccessory usbAccessory);
}

delegate void AAUSBAccessoryManagerRegisterListenerCompletionHandler (AAUSBAccessory [] accessories, [NullAllowed] NSError error);
delegate void AAUSBAccessoryManagerUnregisterListenerCompletionHandler ();

[Mac (27, 0)]
[BaseType (typeof (NSObject))]
[DisableDefaultCtor]
interface AAUSBAccessoryManager {
[Static]
[Export ("sharedManager", ArgumentSemantic.Strong)]
AAUSBAccessoryManager SharedManager { get; }

[Export ("registerListener:withMatchingCriteria:completionHandler:")]
[Async]
void RegisterListener (IAAUSBAccessoryListener listener, AAUSBAccessoryMatchingCriteria [] matchingCriteria, AAUSBAccessoryManagerRegisterListenerCompletionHandler completionHandler);

[Export ("unregisterListener:completionHandler:")]
[Async]
void UnregisterListener (IAAUSBAccessoryListener listener, AAUSBAccessoryManagerUnregisterListenerCompletionHandler completionHandler);
}

[Mac (27, 0)]
[BaseType (typeof (NSObject))]
[DisableDefaultCtor]
interface AAUSBAccessoryMatchingCriteria : NSCopying {
[Export ("initWithDeviceMatchingDictionary:")]
[DesignatedInitializer]
NativeHandle Constructor (NSDictionary<NSString, NSObject> dictionary);

[Export ("initWithDeviceMatchingDictionary:interfaceMatchingDictionaries:interfaceMatchingOption:")]
[DesignatedInitializer]
NativeHandle Constructor ([NullAllowed] NSDictionary<NSString, NSObject> deviceMatchingDictionary, NSDictionary<NSString, NSObject> [] interfaceMatchingDictionaries, AAUSBAccessoryMatchingCriteriaInterfaceMatchingOption interfaceMatchingOption);
}
}
3 changes: 3 additions & 0 deletions src/build/dotnet/generator-frameworks.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ partial class Frameworks {
internal readonly HashSet<string> macosframeworks = new HashSet<string> {
"Accelerate",
"Accessibility",
"AccessoryAccess",
"Accounts",
"AdServices",
"AdSupport",
Expand Down Expand Up @@ -532,6 +533,7 @@ partial class Frameworks {
};
bool? _Accelerate;
bool? _Accessibility;
bool? _AccessoryAccess;
bool? _AccessorySetupKit;
bool? _Accounts;
bool? _AddressBook;
Expand Down Expand Up @@ -706,6 +708,7 @@ partial class Frameworks {
bool? _XKit;
public bool HaveAccelerate { get { if (!_Accelerate.HasValue) _Accelerate = GetValue ("Accelerate"); return _Accelerate.Value; } }
public bool HaveAccessibility { get { if (!_Accessibility.HasValue) _Accessibility = GetValue ("Accessibility"); return _Accessibility.Value; } }
public bool HaveAccessoryAccess { get { if (!_AccessoryAccess.HasValue) _AccessoryAccess = GetValue ("AccessoryAccess"); return _AccessoryAccess.Value; } }
public bool HaveAccessorySetupKit { get { if (!_AccessorySetupKit.HasValue) _AccessorySetupKit = GetValue ("AccessorySetupKit"); return _AccessorySetupKit.Value; } }
public bool HaveAccounts { get { if (!_Accounts.HasValue) _Accounts = GetValue ("Accounts"); return _Accounts.Value; } }
public bool HaveAddressBook { get { if (!_AddressBook.HasValue) _AddressBook = GetValue ("AddressBook"); return _AddressBook.Value; } }
Expand Down
1 change: 1 addition & 0 deletions src/frameworks.sources
Original file line number Diff line number Diff line change
Expand Up @@ -2022,6 +2022,7 @@ COMMON_FRAMEWORKS = \

MACOS_FRAMEWORKS = \
$(COMMON_FRAMEWORKS) \
AccessoryAccess \
Accounts \
AdServices \
AdSupport \
Expand Down
1 change: 1 addition & 0 deletions src/rsp/dotnet/macos-defines-dotnet.rsp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-d:HAS_ACCELERATE
-d:HAS_ACCESSIBILITY
-d:HAS_ACCESSORYACCESS
-d:HAS_ACCOUNTS
-d:HAS_ADSERVICES
-d:HAS_ADSUPPORT
Expand Down
35 changes: 35 additions & 0 deletions tests/cecil-tests/Documentation.KnownFailures.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ F:Accessibility.AXTechnology.SwitchControl
F:Accessibility.AXTechnology.VoiceControl
F:Accessibility.AXTechnology.VoiceOver
F:Accessibility.AXTechnology.Zoom
F:AccessoryAccess.AAErrorCode.AccessoryListenerAlreadyRegistered
F:AccessoryAccess.AAErrorCode.AccessoryNotAccessible
F:AccessoryAccess.AAErrorCode.Internal
F:AccessoryAccess.AAErrorCode.InvalidAccessoryState
F:AccessoryAccess.AAUSBAccessoryMatchingCriteriaInterfaceMatchingOption.MatchAll
F:AccessoryAccess.AAUSBAccessoryMatchingCriteriaInterfaceMatchingOption.MatchAny
F:AccessorySetupKit.ASAccessoryEventType.AccessoryAdded
F:AccessorySetupKit.ASAccessoryEventType.AccessoryChanged
F:AccessorySetupKit.ASAccessoryEventType.AccessoryRemoved
Expand Down Expand Up @@ -8345,6 +8351,22 @@ M:Accessibility.AXPrefers.ActionSliderAlternative
M:Accessibility.AXPrefers.HorizontalTextEnabled
M:Accessibility.AXPrefers.NonBlinkingTextInsertionIndicator
M:Accessibility.AXSettings.ShowBordersEnabled
M:AccessoryAccess.AAUSBAccessory.#ctor(Foundation.NSObject)
M:AccessoryAccess.AAUSBAccessory.Close(AccessoryAccess.AAUSBAccessoryCloseCompletionHandler)
M:AccessoryAccess.AAUSBAccessory.CloseAsync
M:AccessoryAccess.AAUSBAccessory.CreateXpcRepresentation
M:AccessoryAccess.AAUSBAccessory.Open(CoreFoundation.DispatchQueue,AccessoryAccess.AAUSBAccessoryOpenCompletionHandler)
M:AccessoryAccess.AAUSBAccessory.OpenAsync(CoreFoundation.DispatchQueue)
M:AccessoryAccess.AAUSBAccessoryListener.UsbAccessoryDidConnect(AccessoryAccess.AAUSBAccessory)
M:AccessoryAccess.AAUSBAccessoryListener.UsbAccessoryDidDisconnect(AccessoryAccess.AAUSBAccessory)
M:AccessoryAccess.AAUSBAccessoryManager.RegisterListener(AccessoryAccess.IAAUSBAccessoryListener,AccessoryAccess.AAUSBAccessoryMatchingCriteria[],AccessoryAccess.AAUSBAccessoryManagerRegisterListenerCompletionHandler)
M:AccessoryAccess.AAUSBAccessoryManager.RegisterListenerAsync(AccessoryAccess.IAAUSBAccessoryListener,AccessoryAccess.AAUSBAccessoryMatchingCriteria[])
M:AccessoryAccess.AAUSBAccessoryManager.UnregisterListener(AccessoryAccess.IAAUSBAccessoryListener,AccessoryAccess.AAUSBAccessoryManagerUnregisterListenerCompletionHandler)
M:AccessoryAccess.AAUSBAccessoryManager.UnregisterListenerAsync(AccessoryAccess.IAAUSBAccessoryListener)
M:AccessoryAccess.AAUSBAccessoryMatchingCriteria.#ctor(Foundation.NSDictionary{Foundation.NSString,Foundation.NSObject},Foundation.NSDictionary{Foundation.NSString,Foundation.NSObject}[],AccessoryAccess.AAUSBAccessoryMatchingCriteriaInterfaceMatchingOption)
M:AccessoryAccess.AAUSBAccessoryMatchingCriteria.#ctor(Foundation.NSDictionary{Foundation.NSString,Foundation.NSObject})
M:AccessoryAccess.IAAUSBAccessoryListener.UsbAccessoryDidConnect(AccessoryAccess.AAUSBAccessory)
M:AccessoryAccess.IAAUSBAccessoryListener.UsbAccessoryDidDisconnect(AccessoryAccess.AAUSBAccessory)
M:AccessorySetupKit.ASAccessorySession.Activate(CoreFoundation.DispatchQueue,System.Action{AccessorySetupKit.ASAccessoryEvent})
M:AccessorySetupKit.ASAccessorySession.FailAuthorization(AccessorySetupKit.ASAccessory,AccessorySetupKit.ASAccessorySessionCompletionHandler)
M:AccessorySetupKit.ASAccessorySession.FailAuthorizationAsync(AccessorySetupKit.ASAccessory)
Expand Down Expand Up @@ -31411,6 +31433,10 @@ P:Accessibility.IAXCustomContentProvider.AccessibilityCustomContentHandler
P:Accessibility.IAXDataAxisDescriptor.AttributedTitle
P:Accessibility.IAXDataAxisDescriptor.Title
P:Accessibility.IAXMathExpressionProvider.AccessibilityMathExpression
P:AccessoryAccess.AAUSBAccessory.ConfigurationDescriptorData
P:AccessoryAccess.AAUSBAccessory.DeviceDescriptorData
P:AccessoryAccess.AAUSBAccessory.RegistryId
P:AccessoryAccess.AAUSBAccessoryManager.SharedManager
P:AccessorySetupKit.ASAccessory.BluetoothIdentifier
P:AccessorySetupKit.ASAccessory.BluetoothTransportBridgingIdentifier
P:AccessorySetupKit.ASAccessory.Descriptor
Expand Down Expand Up @@ -55842,6 +55868,15 @@ T:Accessibility.AXSettings
T:Accessibility.AXSettingsFeature
T:Accessibility.AXTechnology
T:Accessibility.ValueDescriptionProviderHandler
T:AccessoryAccess.AAErrorCode
T:AccessoryAccess.AAUSBAccessory
T:AccessoryAccess.AAUSBAccessoryCloseCompletionHandler
T:AccessoryAccess.AAUSBAccessoryManager
T:AccessoryAccess.AAUSBAccessoryManagerRegisterListenerCompletionHandler
T:AccessoryAccess.AAUSBAccessoryManagerUnregisterListenerCompletionHandler
T:AccessoryAccess.AAUSBAccessoryMatchingCriteria
T:AccessoryAccess.AAUSBAccessoryMatchingCriteriaInterfaceMatchingOption
T:AccessoryAccess.AAUSBAccessoryOpenCompletionHandler
T:AccessorySetupKit.ASAccessory
T:AccessorySetupKit.ASAccessoryEvent
T:AccessorySetupKit.ASAccessoryEventType
Expand Down
1 change: 1 addition & 0 deletions tests/dotnet/UnitTests/ProjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3377,6 +3377,7 @@ public void AppendRuntimeIdentifierToOutputPath_DisableDirectoryBuildProps (Appl
"@executable_path/../../Contents/MonoBundle/libSystem.Security.Cryptography.Native.Apple.dylib",
"/System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate",
"/System/Library/Frameworks/Accessibility.framework/Versions/A/Accessibility",
"/System/Library/Frameworks/AccessoryAccess.framework/Versions/A/AccessoryAccess",
"/System/Library/Frameworks/Accounts.framework/Versions/A/Accounts",
"/System/Library/Frameworks/AdServices.framework/Versions/A/AdServices",
"/System/Library/Frameworks/AdSupport.framework/Versions/A/AdSupport",
Expand Down

This file was deleted.

2 changes: 2 additions & 0 deletions tools/common/Frameworks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ public static Frameworks MacFrameworks {
{ "SecurityUI", "SecurityUI", 15, 4 },

{ "GameSave", "GameSave", 26, 0 },

{ "AccessoryAccess", "AccessoryAccess", 27, 0 },
};
}
return mac_frameworks;
Expand Down
Loading