From d57265a110291ca5b11db17d6f2960c90d370177 Mon Sep 17 00:00:00 2001 From: Whitney Schmidt Date: Fri, 7 Aug 2020 11:52:52 -0400 Subject: [PATCH 01/11] nichanges + apiclassptrtest debugging code --- src/Constants.iOS.cs.in | 1 + src/Constants.mac.cs.in | 1 + src/frameworks.sources | 8 +++++++- tests/introspection/ApiClassPtrTest.cs | 15 ++++++++++++++- tools/common/Frameworks.cs | 1 + 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/Constants.iOS.cs.in b/src/Constants.iOS.cs.in index c74e843ea248..8a5a151cb35f 100644 --- a/src/Constants.iOS.cs.in +++ b/src/Constants.iOS.cs.in @@ -149,6 +149,7 @@ namespace ObjCRuntime { public const string AppClipLibrary = "/System/Library/Frameworks/AppClip.framework/AppClip"; public const string MediaSetupLibrary = "/System/Library/Frameworks/MediaSetup.framework/MediaSetup"; public const string MLComputeLibrary = "/System/Library/Frameworks/MLCompute.framework/MLCompute"; + public const string NearbyInteractionLibrary = "/System/Library/Frameworks/NearbyInteraction.framework/NearbyInteraction"; public const string SensorKitLibrary = "/System/Library/Frameworks/SensorKit.framework/SensorKit"; public const string UniformTypeIdentifiersLibrary = "/System/Library/Frameworks/UniformTypeIdentifiers.framework/UniformTypeIdentifiers"; } diff --git a/src/Constants.mac.cs.in b/src/Constants.mac.cs.in index 702602c18be8..5f13efe6dcf9 100644 --- a/src/Constants.mac.cs.in +++ b/src/Constants.mac.cs.in @@ -175,6 +175,7 @@ namespace ObjCRuntime { public const string AccessibilityLibrary = "/System/Library/Frameworks/Accessibility.framework/Accessibility"; public const string ClassKitLibrary = "/System/Library/Frameworks/ClassKit.framework/ClassKit"; public const string MLComputeLibrary = "/System/Library/Frameworks/MLCompute.framework/MLCompute"; + public const string NearbyInteractionLibrary = "/System/Library/Frameworks/NearbyInteraction.framework/NearbyInteraction"; public const string ReplayKitLibrary = "/System/Library/Frameworks/ReplayKit.framework/ReplayKit"; public const string UniformTypeIdentifiersLibrary = "/System/Library/Frameworks/UniformTypeIdentifiers.framework/UniformTypeIdentifiers"; public const string UserNotificationsUILibrary = "/System/Library/Frameworks/UserNotificationsUI.framework/UserNotificationsUI"; diff --git a/src/frameworks.sources b/src/frameworks.sources index 282dcb89d53e..1ac844bba055 100644 --- a/src/frameworks.sources +++ b/src/frameworks.sources @@ -1197,7 +1197,11 @@ NETWORK_SOURCES = \ Network/NWWebSocketOptions.cs \ Network/NWWebSocketRequest.cs \ Network/NWWebSocketResponse.cs \ - + +# NearbyInteraction +NEARBYINTERACTION_API_SOURCES = \ + NearbyInteraction/Enums.cs \ + # NetworkExtension NETWORKEXTENSION_API_SOURCES = \ @@ -1881,6 +1885,7 @@ MAC_FRAMEWORKS = \ MobileCoreServices \ ModelIO \ MultipeerConnectivity \ + NearbyInteraction \ NetworkExtension \ NotificationCenter \ OpenGL \ @@ -1981,6 +1986,7 @@ IOS_FRAMEWORKS = \ MobileCoreServices \ ModelIO \ MultipeerConnectivity \ + NearbyInteraction \ NetworkExtension \ NewsstandKit \ NotificationCenter \ diff --git a/tests/introspection/ApiClassPtrTest.cs b/tests/introspection/ApiClassPtrTest.cs index 79beef80b3bf..a481dbc76113 100644 --- a/tests/introspection/ApiClassPtrTest.cs +++ b/tests/introspection/ApiClassPtrTest.cs @@ -16,6 +16,7 @@ using Foundation; using ObjCRuntime; +using System.Runtime.InteropServices; namespace Introspection { @@ -66,6 +67,9 @@ IntPtr GetClassPtrFromRegister (Type t) return IntPtr.Zero; } + [DllImport (Constants.FoundationLibrary)] + extern static IntPtr NSStringFromClass (IntPtr ptr); + [Test] public void VerifyClassPtr () { @@ -85,7 +89,16 @@ public void VerifyClassPtr () IntPtr class_ptr = (IntPtr) fi.GetValue (null); IntPtr register_class_ptr = GetClassPtrFromRegister (t); - Assert.AreEqual (class_ptr, register_class_ptr, "class_ptr and RegisterAttribute are different: " + t.Name); + /////// + var ret1 = (string) Runtime.GetNSObject (NSStringFromClass (class_ptr)); + var ret2 = (string) Runtime.GetNSObject (NSStringFromClass (register_class_ptr)); + var ret3 = Runtime.GetNSObject (NSStringFromClass (class_ptr)); + /////// + /// + + //Console.WriteLine ($"This is ret2: {ret2}"); + + Assert.AreEqual (class_ptr, register_class_ptr, $"class_ptr and RegisterAttribute are different: t.Name: {t.Name} ret1: {ret1} ret2: {ret2} ret3: {ret3}"); } } diff --git a/tools/common/Frameworks.cs b/tools/common/Frameworks.cs index 1c68a2f0a265..52124c15ed5e 100644 --- a/tools/common/Frameworks.cs +++ b/tools/common/Frameworks.cs @@ -341,6 +341,7 @@ public static Frameworks GetiOSFrameworks (Application app) { "AppClip", "AppClip", 14,0 }, { "MediaSetup", "MediaSetup", new Version (14, 0), NotAvailableInSimulator /* no headers in beta 3 */ }, { "MLCompute", "MLCompute", new Version (14,0), NotAvailableInSimulator }, + { "NearbyInteraction", "NearbyInteraction", 14,0 }, { "SensorKit", "SensorKit", 14,0 }, { "UniformTypeIdentifiers", "UniformTypeIdentifiers", 14,0 }, From 23ec6674875de6b332b7e38b83cc751750f9066d Mon Sep 17 00:00:00 2001 From: Whitney Schmidt Date: Fri, 7 Aug 2020 13:45:08 -0400 Subject: [PATCH 02/11] actually add ni bindings --- src/NearbyInteraction/Enums.cs | 35 +++++++++ src/nearbyinteraction.cs | 132 +++++++++++++++++++++++++++++++++ 2 files changed, 167 insertions(+) create mode 100644 src/NearbyInteraction/Enums.cs create mode 100644 src/nearbyinteraction.cs diff --git a/src/NearbyInteraction/Enums.cs b/src/NearbyInteraction/Enums.cs new file mode 100644 index 000000000000..64ba2e5d2662 --- /dev/null +++ b/src/NearbyInteraction/Enums.cs @@ -0,0 +1,35 @@ +// +// NearbyInteraction bindings +// +// Authors: +// Whitney Schmidt +// +// Copyright 2020 Microsoft Inc. +// + +using ObjCRuntime; +using Foundation; +using System; + +namespace NearbyInteraction { + + [NoWatch, NoTV, NoMac, iOS (14,0)] + [Native] + public enum NIErrorCode : long + { + UnsupportedPlatform = -5889, + InvalidConfiguration = -5888, + SessionFailed = -5887, + ResourceUsageTimeout = -5886, + ActiveSessionsLimitExceeded = -5885, + UserDidNotAllow = -5884, + } + + [NoWatch, NoTV, NoMac, iOS (14,0)] + [Native] + public enum NINearbyObjectRemovalReason : long + { + Timeout, + PeerEnded, + } +} diff --git a/src/nearbyinteraction.cs b/src/nearbyinteraction.cs new file mode 100644 index 000000000000..47bd8289c5d8 --- /dev/null +++ b/src/nearbyinteraction.cs @@ -0,0 +1,132 @@ +// +// NearbyInteraction bindings +// +// Authors: +// Whitney Schmidt +// +// Copyright 2020 Microsoft Inc. +// + +using ObjCRuntime; +using Foundation; +using CoreFoundation; +using System; +using Vector3 = global::OpenTK.Vector3; + +namespace NearbyInteraction { + + [NoWatch, NoTV, NoMac, iOS (14, 0)] + [Static] + interface NIErrorDomain + { + [Field ("NIErrorDomain")] + NSString Domain { get; } + } + + [NoWatch, NoTV, NoMac, iOS (14,0)] + [BaseType (typeof (NSObject))] + [DisableDefaultCtor] + interface NIConfiguration : NSCopying, NSSecureCoding {} + + [NoWatch, NoTV, NoMac, iOS (14,0)] + [BaseType (typeof (NSObject))] + [DisableDefaultCtor] + interface NIDiscoveryToken : NSCopying, NSSecureCoding {} + + [NoWatch, NoTV, NoMac, iOS (14,0)] + [BaseType (typeof (NIConfiguration))] + [DisableDefaultCtor] + interface NINearbyPeerConfiguration + { + [Export ("peerDiscoveryToken", ArgumentSemantic.Copy)] + NIDiscoveryToken PeerDiscoveryToken { get; } + + [Export ("initWithPeerToken:")] + IntPtr Constructor (NIDiscoveryToken peerToken); + } + + [NoWatch, NoTV, NoMac, iOS (14,0)] + [BaseType (typeof (NSObject))] + [DisableDefaultCtor] + partial interface NINearbyObject : NSCopying, NSSecureCoding + { + [Export ("discoveryToken", ArgumentSemantic.Copy)] + NIDiscoveryToken DiscoveryToken { get; } + + [Export ("distance")] + float Distance { get; } + + [Export ("direction")] + Vector3 Direction { get; } + + [Field ("NINearbyObjectDistanceNotAvailable")] + float DistanceNotAvailable { get; } + + // TODO: Currently we do not have generator support to trampoline Vector3 -> vector_float3 for Fields + // There is support for Properties + // error BI1014: bgen: Unsupported type for Fields: global::OpenTK.Vector3 for 'NearbyInteraction.NINearbyObjectDistance DirectionNotAvailable'. + // extern simd_float3 NINearbyObjectDirectionNotAvailable __attribute__((availability(ios, introduced=14.0))) __attribute__((availability(macos, unavailable))) __attribute__((availability(watchos, unavailable))) __attribute__((availability(tvos, unavailable))) __attribute__((visibility("default"))) __attribute__((availability(swift, unavailable))); + // [Unavailable (PlatformName.Swift)] + // [NoWatch, NoTV, NoMac, iOS (14, 0)] + // [Field ("NINearbyObjectDirectionNotAvailable")] + // [unsupported ExtVector: float __attribute__((ext_vector_type(3)))] NINearbyObjectDirectionNotAvailable { get; } + } + + [NoWatch, NoTV, NoMac, iOS (14,0)] + [BaseType (typeof (NSObject))] + interface NISession + { + [Static] + [Export ("supported")] + bool IsSupported { [Bind ("isSupported")] get; } + + [Wrap ("WeakDelegate")] + [NullAllowed] + INISessionDelegate Delegate { get; set; } + + [NullAllowed, Export ("delegate", ArgumentSemantic.Weak)] + NSObject WeakDelegate { get; set; } + + [NullAllowed, Export ("delegateQueue", ArgumentSemantic.Strong)] + DispatchQueue DelegateQueue { get; set; } + + [NullAllowed, Export ("discoveryToken", ArgumentSemantic.Copy)] + NIDiscoveryToken DiscoveryToken { get; } + + [NullAllowed, Export ("configuration", ArgumentSemantic.Copy)] + NIConfiguration Configuration { get; } + + [Export ("runWithConfiguration:")] + void Run (NIConfiguration configuration); + + [Export ("pause")] + void Pause (); + + [Export ("invalidate")] + void Invalidate (); + } + + interface INISessionDelegate {} + + [NoWatch, NoTV, NoMac, iOS (14,0)] + [Protocol] + [Model (AutoGeneratedName = true)] + [BaseType (typeof (NSObject))] + interface NISessionDelegate + { + [Export ("session:didUpdateNearbyObjects:")] + void Session (NISession session, NINearbyObject[] nearbyObjects); + + [Export ("session:didRemoveNearbyObjects:withReason:")] + void Session (NISession session, NINearbyObject[] nearbyObjects, NINearbyObjectRemovalReason reason); + + [Export ("sessionWasSuspended:")] + void SessionWasSuspended (NISession session); + + [Export ("sessionSuspensionEnded:")] + void SessionSuspensionEnded (NISession session); + + [Export ("session:didInvalidateWithError:")] + void Session (NISession session, NSError error); + } +} From 281fb3f0c30600473856ab6b1831be79ad2b1069 Mon Sep 17 00:00:00 2001 From: Whitney Schmidt Date: Fri, 7 Aug 2020 18:13:44 -0400 Subject: [PATCH 03/11] updates to fix intro failure --- src/NearbyInteraction/Enums.cs | 2 +- src/nearbyinteraction.cs | 15 ++++++----- tests/introspection/ApiClassPtrTest.cs | 15 +---------- tests/introspection/ApiCtorInitTest.cs | 7 +++++ .../xtro-sharpie/iOS-NearbyInteraction.ignore | 2 ++ tests/xtro-sharpie/iOS-NearbyInteraction.todo | 26 ------------------- ...on.todo => macOS-NearbyInteraction.ignore} | 1 + tools/mtouch/Makefile | 1 + 8 files changed, 22 insertions(+), 47 deletions(-) create mode 100644 tests/xtro-sharpie/iOS-NearbyInteraction.ignore delete mode 100644 tests/xtro-sharpie/iOS-NearbyInteraction.todo rename tests/xtro-sharpie/{macOS-NearbyInteraction.todo => macOS-NearbyInteraction.ignore} (65%) diff --git a/src/NearbyInteraction/Enums.cs b/src/NearbyInteraction/Enums.cs index 64ba2e5d2662..a61d4cc904ba 100644 --- a/src/NearbyInteraction/Enums.cs +++ b/src/NearbyInteraction/Enums.cs @@ -1,5 +1,5 @@ // -// NearbyInteraction bindings +// NearbyInteraction enums // // Authors: // Whitney Schmidt diff --git a/src/nearbyinteraction.cs b/src/nearbyinteraction.cs index 47bd8289c5d8..d37e9c84187b 100644 --- a/src/nearbyinteraction.cs +++ b/src/nearbyinteraction.cs @@ -57,13 +57,16 @@ partial interface NINearbyObject : NSCopying, NSSecureCoding float Distance { get; } [Export ("direction")] - Vector3 Direction { get; } + Vector3 Direction { + [MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")] + get; + } [Field ("NINearbyObjectDistanceNotAvailable")] float DistanceNotAvailable { get; } - // TODO: Currently we do not have generator support to trampoline Vector3 -> vector_float3 for Fields - // There is support for Properties + // TODO: We do not have generator support to trampoline Vector3 -> vector_float3 for Fields + // There is support for Vector3 -> vector_float3 for properties // error BI1014: bgen: Unsupported type for Fields: global::OpenTK.Vector3 for 'NearbyInteraction.NINearbyObjectDistance DirectionNotAvailable'. // extern simd_float3 NINearbyObjectDirectionNotAvailable __attribute__((availability(ios, introduced=14.0))) __attribute__((availability(macos, unavailable))) __attribute__((availability(watchos, unavailable))) __attribute__((availability(tvos, unavailable))) __attribute__((visibility("default"))) __attribute__((availability(swift, unavailable))); // [Unavailable (PlatformName.Swift)] @@ -115,10 +118,10 @@ interface INISessionDelegate {} interface NISessionDelegate { [Export ("session:didUpdateNearbyObjects:")] - void Session (NISession session, NINearbyObject[] nearbyObjects); + void DidSessionUpdateNearbyObjects (NISession session, NINearbyObject[] nearbyObjects); [Export ("session:didRemoveNearbyObjects:withReason:")] - void Session (NISession session, NINearbyObject[] nearbyObjects, NINearbyObjectRemovalReason reason); + void DidSessionRemoveNearbyObjects (NISession session, NINearbyObject[] nearbyObjects, NINearbyObjectRemovalReason reason); [Export ("sessionWasSuspended:")] void SessionWasSuspended (NISession session); @@ -127,6 +130,6 @@ interface NISessionDelegate void SessionSuspensionEnded (NISession session); [Export ("session:didInvalidateWithError:")] - void Session (NISession session, NSError error); + void DidSessionInvalidate (NISession session, NSError error); } } diff --git a/tests/introspection/ApiClassPtrTest.cs b/tests/introspection/ApiClassPtrTest.cs index a481dbc76113..79beef80b3bf 100644 --- a/tests/introspection/ApiClassPtrTest.cs +++ b/tests/introspection/ApiClassPtrTest.cs @@ -16,7 +16,6 @@ using Foundation; using ObjCRuntime; -using System.Runtime.InteropServices; namespace Introspection { @@ -67,9 +66,6 @@ IntPtr GetClassPtrFromRegister (Type t) return IntPtr.Zero; } - [DllImport (Constants.FoundationLibrary)] - extern static IntPtr NSStringFromClass (IntPtr ptr); - [Test] public void VerifyClassPtr () { @@ -89,16 +85,7 @@ public void VerifyClassPtr () IntPtr class_ptr = (IntPtr) fi.GetValue (null); IntPtr register_class_ptr = GetClassPtrFromRegister (t); - /////// - var ret1 = (string) Runtime.GetNSObject (NSStringFromClass (class_ptr)); - var ret2 = (string) Runtime.GetNSObject (NSStringFromClass (register_class_ptr)); - var ret3 = Runtime.GetNSObject (NSStringFromClass (class_ptr)); - /////// - /// - - //Console.WriteLine ($"This is ret2: {ret2}"); - - Assert.AreEqual (class_ptr, register_class_ptr, $"class_ptr and RegisterAttribute are different: t.Name: {t.Name} ret1: {ret1} ret2: {ret2} ret3: {ret3}"); + Assert.AreEqual (class_ptr, register_class_ptr, "class_ptr and RegisterAttribute are different: " + t.Name); } } diff --git a/tests/introspection/ApiCtorInitTest.cs b/tests/introspection/ApiCtorInitTest.cs index 8014a9ca50d4..4088ae505bea 100644 --- a/tests/introspection/ApiCtorInitTest.cs +++ b/tests/introspection/ApiCtorInitTest.cs @@ -68,6 +68,13 @@ protected virtual bool Skip (Type type) return true; case "NEPacketTunnelProvider": return true; + // On iOS 14 (beta 4) we get: [NISimulator] To simulate Nearby Interaction distance and direction, launch two or more simulators and + // move the simulator windows around the screen. + // The same error occurs when trying to default init NISession in Xcode. + // It seems that it is only possible to create a NISession when there are two devices or sims running, which makes sense given the description of + // NISession from Apple API docs: "An object that identifies a unique connection between two peer devices" + case "NISession": + return true; case "NSUnitDispersion": // -init should never be called on NSUnit! case "NSUnitVolume": // -init should never be called on NSUnit! case "NSUnitDuration": // -init should never be called on NSUnit! diff --git a/tests/xtro-sharpie/iOS-NearbyInteraction.ignore b/tests/xtro-sharpie/iOS-NearbyInteraction.ignore new file mode 100644 index 000000000000..d0c8d6cc801f --- /dev/null +++ b/tests/xtro-sharpie/iOS-NearbyInteraction.ignore @@ -0,0 +1,2 @@ +## TODO: We do not have generator support to trampoline Vector3 -> vector_float3 for Fields +!missing-field! NINearbyObjectDirectionNotAvailable not bound diff --git a/tests/xtro-sharpie/iOS-NearbyInteraction.todo b/tests/xtro-sharpie/iOS-NearbyInteraction.todo deleted file mode 100644 index bba386146ae8..000000000000 --- a/tests/xtro-sharpie/iOS-NearbyInteraction.todo +++ /dev/null @@ -1,26 +0,0 @@ -!missing-enum! NIErrorCode not bound -!missing-enum! NINearbyObjectRemovalReason not bound -!missing-field! NIErrorDomain not bound -!missing-field! NINearbyObjectDirectionNotAvailable not bound -!missing-field! NINearbyObjectDistanceNotAvailable not bound -!missing-protocol! NISessionDelegate not bound -!missing-selector! +NISession::isSupported not bound -!missing-selector! NINearbyObject::direction not bound -!missing-selector! NINearbyObject::discoveryToken not bound -!missing-selector! NINearbyObject::distance not bound -!missing-selector! NINearbyPeerConfiguration::initWithPeerToken: not bound -!missing-selector! NINearbyPeerConfiguration::peerDiscoveryToken not bound -!missing-selector! NISession::configuration not bound -!missing-selector! NISession::delegate not bound -!missing-selector! NISession::delegateQueue not bound -!missing-selector! NISession::discoveryToken not bound -!missing-selector! NISession::invalidate not bound -!missing-selector! NISession::pause not bound -!missing-selector! NISession::runWithConfiguration: not bound -!missing-selector! NISession::setDelegate: not bound -!missing-selector! NISession::setDelegateQueue: not bound -!missing-type! NIConfiguration not bound -!missing-type! NIDiscoveryToken not bound -!missing-type! NINearbyObject not bound -!missing-type! NINearbyPeerConfiguration not bound -!missing-type! NISession not bound diff --git a/tests/xtro-sharpie/macOS-NearbyInteraction.todo b/tests/xtro-sharpie/macOS-NearbyInteraction.ignore similarity index 65% rename from tests/xtro-sharpie/macOS-NearbyInteraction.todo rename to tests/xtro-sharpie/macOS-NearbyInteraction.ignore index be8289de1f3c..39e3525be604 100644 --- a/tests/xtro-sharpie/macOS-NearbyInteraction.todo +++ b/tests/xtro-sharpie/macOS-NearbyInteraction.ignore @@ -1,2 +1,3 @@ +## not available on macOS as of Xcode12 beta 4 !missing-enum! NIErrorCode not bound !missing-enum! NINearbyObjectRemovalReason not bound diff --git a/tools/mtouch/Makefile b/tools/mtouch/Makefile index 37fb65a347ef..d238b8b2c6cf 100644 --- a/tools/mtouch/Makefile +++ b/tools/mtouch/Makefile @@ -165,6 +165,7 @@ SIMLAUNCHER_FRAMEWORKS = \ -weak_framework AppClip \ -weak_framework SensorKit \ -weak_framework UniformTypeIdentifiers \ + -weak_framework NearbyInteraction \ # keep the above list of weak_framework # 1. grouped by iOS versions; From d822bb3a1f27836735838ead40d2fc09a634d0c3 Mon Sep 17 00:00:00 2001 From: Whitney Schmidt Date: Fri, 7 Aug 2020 18:27:23 -0400 Subject: [PATCH 04/11] link to maccore issue --- src/nearbyinteraction.cs | 3 ++- tests/xtro-sharpie/iOS-NearbyInteraction.ignore | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/nearbyinteraction.cs b/src/nearbyinteraction.cs index d37e9c84187b..1c094dff174c 100644 --- a/src/nearbyinteraction.cs +++ b/src/nearbyinteraction.cs @@ -65,7 +65,8 @@ Vector3 Direction { [Field ("NINearbyObjectDistanceNotAvailable")] float DistanceNotAvailable { get; } - // TODO: We do not have generator support to trampoline Vector3 -> vector_float3 for Fields + // TODO: https://github.com/xamarin/maccore/issues/2274 + // We do not have generator support to trampoline Vector3 -> vector_float3 for Fields // There is support for Vector3 -> vector_float3 for properties // error BI1014: bgen: Unsupported type for Fields: global::OpenTK.Vector3 for 'NearbyInteraction.NINearbyObjectDistance DirectionNotAvailable'. // extern simd_float3 NINearbyObjectDirectionNotAvailable __attribute__((availability(ios, introduced=14.0))) __attribute__((availability(macos, unavailable))) __attribute__((availability(watchos, unavailable))) __attribute__((availability(tvos, unavailable))) __attribute__((visibility("default"))) __attribute__((availability(swift, unavailable))); diff --git a/tests/xtro-sharpie/iOS-NearbyInteraction.ignore b/tests/xtro-sharpie/iOS-NearbyInteraction.ignore index d0c8d6cc801f..28d073d4579f 100644 --- a/tests/xtro-sharpie/iOS-NearbyInteraction.ignore +++ b/tests/xtro-sharpie/iOS-NearbyInteraction.ignore @@ -1,2 +1,3 @@ -## TODO: We do not have generator support to trampoline Vector3 -> vector_float3 for Fields +## TODO: https://github.com/xamarin/maccore/issues/2274 +## We do not have generator support to trampoline Vector3 -> vector_float3 for Fields !missing-field! NINearbyObjectDirectionNotAvailable not bound From 0d5b7969527c8dc29de30c91b119ce5226621f34 Mon Sep 17 00:00:00 2001 From: Whitney Schmidt Date: Mon, 10 Aug 2020 17:33:57 -0400 Subject: [PATCH 05/11] updates for nearbyinteraction manual code + fix NIErrorDomain binding --- src/NearbyInteraction/Enums.cs | 1 + src/NearbyInteraction/NINearbyObject.cs | 41 +++++++++++++++++++ src/frameworks.sources | 3 ++ src/nearbyinteraction.cs | 18 -------- .../xtro-sharpie/iOS-NearbyInteraction.ignore | 3 -- 5 files changed, 45 insertions(+), 21 deletions(-) create mode 100644 src/NearbyInteraction/NINearbyObject.cs delete mode 100644 tests/xtro-sharpie/iOS-NearbyInteraction.ignore diff --git a/src/NearbyInteraction/Enums.cs b/src/NearbyInteraction/Enums.cs index a61d4cc904ba..5bd9f7314098 100644 --- a/src/NearbyInteraction/Enums.cs +++ b/src/NearbyInteraction/Enums.cs @@ -14,6 +14,7 @@ namespace NearbyInteraction { [NoWatch, NoTV, NoMac, iOS (14,0)] + [ErrorDomain ("NIErrorDomain")] [Native] public enum NIErrorCode : long { diff --git a/src/NearbyInteraction/NINearbyObject.cs b/src/NearbyInteraction/NINearbyObject.cs new file mode 100644 index 000000000000..822e7df166c2 --- /dev/null +++ b/src/NearbyInteraction/NINearbyObject.cs @@ -0,0 +1,41 @@ +// +// NearbyInteraction manual bindings +// +// Authors: +// Whitney Schmidt +// +// Copyright 2020 Microsoft Inc. +// + +using System; +using System.Runtime.InteropServices; + +using CoreFoundation; +using Foundation; +using ObjCRuntime; +using Vector3 = global::OpenTK.Vector3; + +#if !MONOMAC +namespace NearbyInteraction { + partial class NINearbyObject + { + static Vector3? _NINearbyObjectDirectionNotAvailable; + + // TODO: https://github.com/xamarin/maccore/issues/2274 + // We do not have generator support to trampoline Vector3 -> vector_float3 for Fields + [Field ("NINearbyObjectDirectionNotAvailable", "NearbyInteraction")] + public static Vector3 NINearbyObjectDirectionNotAvailable { + get { + if (_NINearbyObjectDirectionNotAvailable == null) { + unsafe { + Vector3 *pointer = (Vector3 *) Dlfcn.GetIndirect (Libraries.NearbyInteraction.Handle, "NINearbyObjectDirectionNotAvailable"); + _NINearbyObjectDirectionNotAvailable = *pointer; + } + } + return (OpenTK.Vector3)_NINearbyObjectDirectionNotAvailable; + } + } + } + +} +#endif //!MONOMAC diff --git a/src/frameworks.sources b/src/frameworks.sources index 1ac844bba055..7f63ca2703b9 100644 --- a/src/frameworks.sources +++ b/src/frameworks.sources @@ -1202,6 +1202,9 @@ NETWORK_SOURCES = \ NEARBYINTERACTION_API_SOURCES = \ NearbyInteraction/Enums.cs \ +NEARBYINTERACTION_SOURCES = \ + NearbyInteraction/NINearbyObject.cs \ + # NetworkExtension NETWORKEXTENSION_API_SOURCES = \ diff --git a/src/nearbyinteraction.cs b/src/nearbyinteraction.cs index 1c094dff174c..501c3f778ea6 100644 --- a/src/nearbyinteraction.cs +++ b/src/nearbyinteraction.cs @@ -15,14 +15,6 @@ namespace NearbyInteraction { - [NoWatch, NoTV, NoMac, iOS (14, 0)] - [Static] - interface NIErrorDomain - { - [Field ("NIErrorDomain")] - NSString Domain { get; } - } - [NoWatch, NoTV, NoMac, iOS (14,0)] [BaseType (typeof (NSObject))] [DisableDefaultCtor] @@ -64,16 +56,6 @@ Vector3 Direction { [Field ("NINearbyObjectDistanceNotAvailable")] float DistanceNotAvailable { get; } - - // TODO: https://github.com/xamarin/maccore/issues/2274 - // We do not have generator support to trampoline Vector3 -> vector_float3 for Fields - // There is support for Vector3 -> vector_float3 for properties - // error BI1014: bgen: Unsupported type for Fields: global::OpenTK.Vector3 for 'NearbyInteraction.NINearbyObjectDistance DirectionNotAvailable'. - // extern simd_float3 NINearbyObjectDirectionNotAvailable __attribute__((availability(ios, introduced=14.0))) __attribute__((availability(macos, unavailable))) __attribute__((availability(watchos, unavailable))) __attribute__((availability(tvos, unavailable))) __attribute__((visibility("default"))) __attribute__((availability(swift, unavailable))); - // [Unavailable (PlatformName.Swift)] - // [NoWatch, NoTV, NoMac, iOS (14, 0)] - // [Field ("NINearbyObjectDirectionNotAvailable")] - // [unsupported ExtVector: float __attribute__((ext_vector_type(3)))] NINearbyObjectDirectionNotAvailable { get; } } [NoWatch, NoTV, NoMac, iOS (14,0)] diff --git a/tests/xtro-sharpie/iOS-NearbyInteraction.ignore b/tests/xtro-sharpie/iOS-NearbyInteraction.ignore deleted file mode 100644 index 28d073d4579f..000000000000 --- a/tests/xtro-sharpie/iOS-NearbyInteraction.ignore +++ /dev/null @@ -1,3 +0,0 @@ -## TODO: https://github.com/xamarin/maccore/issues/2274 -## We do not have generator support to trampoline Vector3 -> vector_float3 for Fields -!missing-field! NINearbyObjectDirectionNotAvailable not bound From ad09cdd35a0ce77a36bf33fc8cd1f734af6541b6 Mon Sep 17 00:00:00 2001 From: Whitney Schmidt Date: Mon, 10 Aug 2020 18:09:33 -0400 Subject: [PATCH 06/11] remove noise --- src/frameworks.sources | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/frameworks.sources b/src/frameworks.sources index 71d91d78c66c..2e898c75992e 100644 --- a/src/frameworks.sources +++ b/src/frameworks.sources @@ -1,6 +1,6 @@ # # The source files used to build the platform assemblies: -# +# # Xamarin.iOS: monotouch.dll and Xamarin.iOS.dll # Xamarin.Mac: XamMac.dll and Xamarin.Mac.dll # Xamarin.WatchOS: Xamarin.WatchOS.dll @@ -190,7 +190,7 @@ AUDIOTOOLBOX_SOURCES = \ AudioToolbox/MusicPlayer.cs \ AudioToolbox/MusicTrack.cs \ -# AudioUnit +# AudioUnit AUDIOUNIT_CORE_SOURCES = \ AudioUnit/AudioComponent.cs \ @@ -575,7 +575,7 @@ CORESERVICES_SOURCES = \ CORESPOTLIGHT_API_SOURCES = \ CoreSpotlight/CSEnums.cs \ - + CORESPOTLIGHT_SOURCES = \ CoreSpotlight/CSCompat.cs \ CoreSpotlight/CSSearchableIndex.cs \ @@ -1202,8 +1202,8 @@ NETWORK_SOURCES = \ NEARBYINTERACTION_API_SOURCES = \ NearbyInteraction/Enums.cs \ -NEARBYINTERACTION_SOURCES = \ - NearbyInteraction/NINearbyObject.cs \ +NEARBYINTERACTION_SOURCE = \ + NearbyInteaction/NINearbyObject.cs \ # NetworkExtension @@ -1293,7 +1293,7 @@ OPENGLES_SOURCES = \ PASSKIT_API_SOURCES = \ PassKit/PKEnums.cs \ - + PASSKIT_SOURCES = \ PassKit/PKPaymentRequest.cs \ @@ -1334,7 +1334,7 @@ PHOTOSUI_API_SOURCES = \ PRINTCORE_SOURCES = \ PrintCore/Defs.cs \ PrintCore/PrintCore.cs - + # QTKit QTKIT_CORE_SOURCES = \ From 9889c0784f31e83c7629ec4d8590f588c068c258 Mon Sep 17 00:00:00 2001 From: Whitney Schmidt Date: Mon, 10 Aug 2020 18:15:36 -0400 Subject: [PATCH 07/11] remove .ignore --- tests/xtro-sharpie/iOS-NearbyInteraction.ignore | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 tests/xtro-sharpie/iOS-NearbyInteraction.ignore diff --git a/tests/xtro-sharpie/iOS-NearbyInteraction.ignore b/tests/xtro-sharpie/iOS-NearbyInteraction.ignore deleted file mode 100644 index 28d073d4579f..000000000000 --- a/tests/xtro-sharpie/iOS-NearbyInteraction.ignore +++ /dev/null @@ -1,3 +0,0 @@ -## TODO: https://github.com/xamarin/maccore/issues/2274 -## We do not have generator support to trampoline Vector3 -> vector_float3 for Fields -!missing-field! NINearbyObjectDirectionNotAvailable not bound From d523686411d6e0c9a358f0bf544e28f6b4296c91 Mon Sep 17 00:00:00 2001 From: Whitney Schmidt Date: Mon, 10 Aug 2020 19:52:27 -0400 Subject: [PATCH 08/11] fix typos --- src/frameworks.sources | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/frameworks.sources b/src/frameworks.sources index 2e898c75992e..7f63ca2703b9 100644 --- a/src/frameworks.sources +++ b/src/frameworks.sources @@ -1202,8 +1202,8 @@ NETWORK_SOURCES = \ NEARBYINTERACTION_API_SOURCES = \ NearbyInteraction/Enums.cs \ -NEARBYINTERACTION_SOURCE = \ - NearbyInteaction/NINearbyObject.cs \ +NEARBYINTERACTION_SOURCES = \ + NearbyInteraction/NINearbyObject.cs \ # NetworkExtension From 0074fe016df5d1f3852dd65107c4aa26559fc63f Mon Sep 17 00:00:00 2001 From: Whitney Schmidt Date: Tue, 11 Aug 2020 12:40:08 -0400 Subject: [PATCH 09/11] add unit test, fix up seb suggestions --- src/NearbyInteraction/NINearbyObject.cs | 10 ++--- .../NearbyInteraction/NINearbyObjectTest.cs | 37 +++++++++++++++++++ tests/monotouch-test/monotouch-test.csproj | 1 + 3 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 tests/monotouch-test/NearbyInteraction/NINearbyObjectTest.cs diff --git a/src/NearbyInteraction/NINearbyObject.cs b/src/NearbyInteraction/NINearbyObject.cs index 822e7df166c2..fa40c2c94f5f 100644 --- a/src/NearbyInteraction/NINearbyObject.cs +++ b/src/NearbyInteraction/NINearbyObject.cs @@ -19,20 +19,20 @@ namespace NearbyInteraction { partial class NINearbyObject { - static Vector3? _NINearbyObjectDirectionNotAvailable; + static Vector3? _DirectionNotAvailable; // TODO: https://github.com/xamarin/maccore/issues/2274 // We do not have generator support to trampoline Vector3 -> vector_float3 for Fields [Field ("NINearbyObjectDirectionNotAvailable", "NearbyInteraction")] - public static Vector3 NINearbyObjectDirectionNotAvailable { + public static Vector3 DirectionNotAvailable { get { - if (_NINearbyObjectDirectionNotAvailable == null) { + if (_DirectionNotAvailable == null) { unsafe { Vector3 *pointer = (Vector3 *) Dlfcn.GetIndirect (Libraries.NearbyInteraction.Handle, "NINearbyObjectDirectionNotAvailable"); - _NINearbyObjectDirectionNotAvailable = *pointer; + _DirectionNotAvailable = *pointer; } } - return (OpenTK.Vector3)_NINearbyObjectDirectionNotAvailable; + return (Vector3)_DirectionNotAvailable; } } } diff --git a/tests/monotouch-test/NearbyInteraction/NINearbyObjectTest.cs b/tests/monotouch-test/NearbyInteraction/NINearbyObjectTest.cs new file mode 100644 index 000000000000..e32fdd2f408d --- /dev/null +++ b/tests/monotouch-test/NearbyInteraction/NINearbyObjectTest.cs @@ -0,0 +1,37 @@ +// Copyright 2020 Microsoft Inc. + +#if !MONOMAC + +using System; +using Foundation; +using ObjCRuntime; +using NearbyInteraction; +using NUnit.Framework; +using OpenTK; + +namespace MonoTouchFixtures.NearbyInteraction { + + [TestFixture] + [Preserve (AllMembers = true)] + public class NINearbyObjectTest { + + [Test] + public void DirectionNotAvailable () + { + if (!TestRuntime.CheckXcodeVersion (12, 0)) + Assert.Ignore ("Requires iOS 14.0"); + + Vector3 vect = NINearbyObject.DirectionNotAvailable; + + unsafe { + Vector3* v = &vect; + byte* ptr = (byte*) v; + byte zero = 0; + for (var i = 0; i < sizeof (Vector3); i++) + Assert.True (ptr[i] == zero, "Expected {0} but was {1}", zero.ToString(), ptr[i].ToString()); + } + } + } +} + +#endif // !MONOMAC diff --git a/tests/monotouch-test/monotouch-test.csproj b/tests/monotouch-test/monotouch-test.csproj index 505aa130b919..115b8f61f451 100644 --- a/tests/monotouch-test/monotouch-test.csproj +++ b/tests/monotouch-test/monotouch-test.csproj @@ -285,6 +285,7 @@ + From ab47613d218d317945617d37986c6f962c507ca3 Mon Sep 17 00:00:00 2001 From: Whitney Schmidt Date: Tue, 11 Aug 2020 14:03:43 -0400 Subject: [PATCH 10/11] fix Assert to avoid allocating string every time --- tests/monotouch-test/NearbyInteraction/NINearbyObjectTest.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/monotouch-test/NearbyInteraction/NINearbyObjectTest.cs b/tests/monotouch-test/NearbyInteraction/NINearbyObjectTest.cs index e32fdd2f408d..8de18914a63f 100644 --- a/tests/monotouch-test/NearbyInteraction/NINearbyObjectTest.cs +++ b/tests/monotouch-test/NearbyInteraction/NINearbyObjectTest.cs @@ -1,4 +1,4 @@ -// Copyright 2020 Microsoft Inc. +// Copyright 2020 Microsoft Corp. #if !MONOMAC @@ -28,7 +28,7 @@ public void DirectionNotAvailable () byte* ptr = (byte*) v; byte zero = 0; for (var i = 0; i < sizeof (Vector3); i++) - Assert.True (ptr[i] == zero, "Expected {0} but was {1}", zero.ToString(), ptr[i].ToString()); + Assert.That (ptr [i], Is.EqualTo (zero), $"Position {i}"); } } } From 0904e2ac7d482f20d73191095a15b28129cb6f7c Mon Sep 17 00:00:00 2001 From: Whitney Schmidt Date: Wed, 12 Aug 2020 12:43:46 -0400 Subject: [PATCH 11/11] fix test failures by wrapping with __IOS__, clean up version check --- src/NearbyInteraction/NINearbyObject.cs | 4 ++-- .../monotouch-test/NearbyInteraction/NINearbyObjectTest.cs | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/NearbyInteraction/NINearbyObject.cs b/src/NearbyInteraction/NINearbyObject.cs index fa40c2c94f5f..50a1de3d6fb8 100644 --- a/src/NearbyInteraction/NINearbyObject.cs +++ b/src/NearbyInteraction/NINearbyObject.cs @@ -15,7 +15,7 @@ using ObjCRuntime; using Vector3 = global::OpenTK.Vector3; -#if !MONOMAC +#if __IOS__ namespace NearbyInteraction { partial class NINearbyObject { @@ -38,4 +38,4 @@ public static Vector3 DirectionNotAvailable { } } -#endif //!MONOMAC +#endif //__IOS__ diff --git a/tests/monotouch-test/NearbyInteraction/NINearbyObjectTest.cs b/tests/monotouch-test/NearbyInteraction/NINearbyObjectTest.cs index 8de18914a63f..151ad841897a 100644 --- a/tests/monotouch-test/NearbyInteraction/NINearbyObjectTest.cs +++ b/tests/monotouch-test/NearbyInteraction/NINearbyObjectTest.cs @@ -1,6 +1,6 @@ // Copyright 2020 Microsoft Corp. -#if !MONOMAC +#if __IOS__ using System; using Foundation; @@ -18,8 +18,7 @@ public class NINearbyObjectTest { [Test] public void DirectionNotAvailable () { - if (!TestRuntime.CheckXcodeVersion (12, 0)) - Assert.Ignore ("Requires iOS 14.0"); + TestRuntime.AssertXcodeVersion (12, 0); Vector3 vect = NINearbyObject.DirectionNotAvailable; @@ -34,4 +33,4 @@ public void DirectionNotAvailable () } } -#endif // !MONOMAC +#endif // __IOS__