Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DeviceDiscoveryExtension] Added support for Xcode 14 beta 1-4 #15741

Closed
Closed
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
26 changes: 26 additions & 0 deletions src/DeviceDiscoveryExtension/DDDevice.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// Custom methods for DDDevice
//
// Authors:
// Israel Soto (issoto@microsoft.com)
//
// Copyright 2022 Microsoft Corporation.
//

#nullable enable

using ObjCRuntime;
using Foundation;
using Network;
using System;

using nw_endpoint_t = System.IntPtr;

namespace DeviceDiscoveryExtension {
public partial class DDDevice {
public NWEndpoint? NetworkEndpoint {
get => _NetworkEndpoint != nw_endpoint_t.Zero ? new NWEndpoint (_NetworkEndpoint, false) : null;
set => _NetworkEndpoint = value.GetHandle();
}
}
}
82 changes: 82 additions & 0 deletions src/DeviceDiscoveryExtension/Enums.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//
// Enums.cs
//
// Authors:
// Israel Soto (issoto@microsoft.com)
//
// Copyright 2022 Microsoft Corporation
//

using System;

using ObjCRuntime;
using Foundation;

namespace DeviceDiscoveryExtension {

[NoMac, iOS (16,0), NoMacCatalyst, NoWatch, NoTV]
[Native]
public enum DDDeviceProtocol : long
{
Invalid = 0,
Dial = 1,
}

[NoMac, iOS (16,0), NoMacCatalyst, NoWatch, NoTV]
[Native]
public enum DDDeviceCategory : long
{
HiFiSpeaker = 0,
HiFiSpeakerMultiple = 1,
TvWithMediaBox = 2,
Tv = 3,
LaptopComputer = 4,
DesktopComputer = 5,
}

[NoMac, iOS (16,0), NoMacCatalyst, NoWatch, NoTV]
[Native]
public enum DDDeviceState : long
{
Invalid = 0,
Activating = 10,
Activated = 20,
Authorized = 25,
Invalidating = 30,
}

[NoMac, iOS (16,0), NoMacCatalyst, NoWatch, NoTV]
[Native]
public enum DDDeviceMediaPlaybackState : long
{
NoContent = 0,
Paused = 1,
Playing = 2,
}

[NoMac, iOS (16,0), NoMacCatalyst, NoWatch, NoTV]
[ErrorDomain ("DDErrorDomain")]
[Native]
public enum DDErrorCode : long
{
Success = 0,
Unknown = 350000,
BadParameter = 350001,
Unsupported = 350002,
Timeout = 350003,
Internal = 350004,
MissingEntitlement = 350005,
Permission = 350006,
Next,
}

[NoMac, iOS (16,0), NoMacCatalyst, NoWatch, NoTV]
[Native]
public enum DDEventType : long
SotoiGhost marked this conversation as resolved.
Show resolved Hide resolved
{
Unknown = 0,
DeviceFound = 40,
DeviceLost = 41,
DeviceChanged = 42,
}
}
106 changes: 106 additions & 0 deletions src/devicediscoveryextension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
//
// DeviceDiscoveryExtension C# bindings
//
// Authors:
// Israel Soto <issoto@microsoft.com>
//
// Copyright 2022 Microsoft Corporation.
//

using System;
using ObjCRuntime;
using Foundation;
using UniformTypeIdentifiers;

using nw_endpoint_t = System.IntPtr;

#if !NET
using NativeHandle = System.IntPtr;
#endif

namespace DeviceDiscoveryExtension {

[Static]
[NoMac, iOS (16,0), NoMacCatalyst, NoWatch, NoTV]
interface DDDeviceProtocolStrings
SotoiGhost marked this conversation as resolved.
Show resolved Hide resolved
{
[Field ("DDDeviceProtocolStringInvalid")]
NSString Invalid { get; }

[Field ("DDDeviceProtocolStringDIAL")]
NSString Dial { get; }
}

[NoMac, iOS (16,0), NoMacCatalyst, NoWatch, NoTV]
[BaseType (typeof (NSObject))]
[DisableDefaultCtor]
interface DDDevice
{
[Export ("initWithDisplayName:category:protocolType:identifier:")]
[DesignatedInitializer]
NativeHandle Constructor (string displayName, DDDeviceCategory category, UTType protocolType, string identifier);

[NullAllowed, Export ("bluetoothIdentifier", ArgumentSemantic.Strong)]
NSUuid BluetoothIdentifier { get; set; }

[Export ("category", ArgumentSemantic.Assign)]
DDDeviceCategory Category { get; set; }

[Export ("displayName")]
string DisplayName { get; set; }

[Export ("identifier")]
string Identifier { get; set; }

[Internal]
[Export ("networkEndpoint", ArgumentSemantic.Strong)]
nw_endpoint_t _NetworkEndpoint { get; set; }

[Export ("protocol", ArgumentSemantic.Assign)]
DDDeviceProtocol Protocol { get; set; }

[Export ("protocolType", ArgumentSemantic.Strong)]
UTType ProtocolType { get; set; }

[Export ("state", ArgumentSemantic.Assign)]
DDDeviceState State { get; set; }

[NullAllowed, Export ("txtRecordData", ArgumentSemantic.Copy)]
NSData TxtRecordData { get; set; }

[Export ("url", ArgumentSemantic.Copy)]
NSUrl Url { get; set; }

[Export ("mediaPlaybackState", ArgumentSemantic.Assign)]
DDDeviceMediaPlaybackState MediaPlaybackState { get; set; }

[NullAllowed, Export ("mediaContentTitle")]
string MediaContentTitle { get; set; }

[NullAllowed, Export ("mediaContentSubtitle")]
string MediaContentSubtitle { get; set; }
}

[NoMac, iOS (16,0), NoMacCatalyst, NoWatch, NoTV]
[BaseType (typeof (NSObject))]
SotoiGhost marked this conversation as resolved.
Show resolved Hide resolved
[DisableDefaultCtor]
interface DDDeviceEvent
{
[Export ("initWithEventType:device:")]
NativeHandle Constructor (DDEventType type, DDDevice device);

[Export ("device", ArgumentSemantic.Strong)]
DDDevice Device { get; }

[Export ("eventType", ArgumentSemantic.Assign)]
DDEventType EventType { get; }
}

[NoMac, iOS (16,0), NoMacCatalyst, NoWatch, NoTV]
[BaseType (typeof (NSObject))]
interface DDDiscoverySession
SotoiGhost marked this conversation as resolved.
Show resolved Hide resolved
{
[Export ("reportEvent:")]
void ReportEvent (DDDeviceEvent inEvent);
}
}
9 changes: 9 additions & 0 deletions src/frameworks.sources
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,14 @@ COREWLAN_SOURCES = \
CoreWlan/CWInterface.cs \
CoreWlan/CWKeychain.cs \

# DeviceDiscoveryExtension

DEVICEDISCOVERYEXTENSION_API_SOURCES = \
DeviceDiscoveryExtension/Enums.cs \

DEVICEDISCOVERYEXTENSION_SOURCES = \
DeviceDiscoveryExtension/DDDevice.cs \

# EventKit

EVENTKIT_API_SOURCES = \
Expand Down Expand Up @@ -2130,6 +2138,7 @@ IOS_FRAMEWORKS = \
CoreSpotlight \
CoreTelephony \
CoreText \
DeviceDiscoveryExtension \
EventKit \
EventKitUI \
ExternalAccessory \
Expand Down
11 changes: 11 additions & 0 deletions tests/introspection/iOS/iOSApiProtocolTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,10 @@ protected override bool Skip (Type type, string protocolName)
case "OSLogEntryLog":
case "OSLogEntrySignpost":
return true;
// iOS 16
case "DDDevice":
SotoiGhost marked this conversation as resolved.
Show resolved Hide resolved
case "DDDeviceEvent":
return true;
#if __WATCHOS__
case "CLKComplicationTemplate":
case "CLKComplicationTemplateCircularSmallRingImage":
Expand Down Expand Up @@ -611,6 +615,10 @@ protected override bool Skip (Type type, string protocolName)
case "OSLogEntryLog":
case "OSLogEntrySignpost":
return true;
// iOS 16
case "DDDevice":
case "DDDeviceEvent":
return true;
#if __WATCHOS__
case "CLKComplicationTemplate":
case "CLKComplicationTemplateCircularSmallRingImage":
Expand Down Expand Up @@ -767,6 +775,9 @@ protected override bool Skip (Type type, string protocolName)
case "WKPreferences": // Conformance not in headers
case "QLPreviewSceneActivationConfiguration":
return true;
// iOS 16
case "DDDevice":
return true;
#if __WATCHOS__
case "CLKComplicationTimelineEntry":
return true;
Expand Down
45 changes: 45 additions & 0 deletions tests/monotouch-test/DeviceDiscoveryExtension/DDDeviceTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// Unit tests for DDDevice
//
// Authors:
// Israel Soto <issoto@microsoft.com>
//
// Copyright 2022 Microsoft Corporation.
//

#nullable enable

#if __IOS__

using System;
using DeviceDiscoveryExtension;
using Foundation;
using Network;
using ObjCRuntime;
using UniformTypeIdentifiers;
using NUnit.Framework;

namespace MonoTouchFixtures.DeviceDiscoveryExtension {

[TestFixture]
[Preserve (AllMembers = true)]
public class DDDeviceTest {

[Test]
public void NetworkEndpointTest ()
{
TestRuntime.AssertXcodeVersion (14,0);

var uuid = Guid.NewGuid ();
var endpoint = NWEndpoint.Create ("www.microsoft.com", "https");
var device = new DDDevice ("MyDevice", DDDeviceCategory.LaptopComputer, UTType.CreateFromIdentifier ("com.adobe.pdf"), uuid.ToString ());

device.NetworkEndpoint = endpoint;
var tmpEndpoint = device.NetworkEndpoint;

Assert.True (endpoint.GetHandle () == tmpEndpoint.GetHandle (), "NetworkEndpoint");
}
}
}

#endif // __IOS__
1 change: 1 addition & 0 deletions tests/monotouch-test/monotouch-test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@
<Folder Include="WebKit\" />
<Folder Include="NearbyInteraction\" />
<Folder Include="MetricKit\" />
<Folder Include="DeviceDiscoveryExtension\" />
</ItemGroup>
<ItemGroup>
<Content Include="AudioToolbox\1.caf" />
Expand Down
1 change: 1 addition & 0 deletions tests/mtouch/RegistrarTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ public void MT4134 ()
new { Framework = "Chip", Version = "15.0" },
new { Framework = "ThreadNetwork", Version = "15.0" },
new { Framework = "BackgroundAssets", Version = "16.0" },
new { Framework = "DeviceDiscoveryExtension", Version = "16.0" },
new { Framework = "PushToTalk", Version = "16.0" },
new { Framework = "SharedWithYou", Version = "16.0" },
new { Framework = "SharedWithYouCore", Version = "16.0" },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## These C methods are helpers to cast an enum value to string, but the string value is not used anywhere. Ignored them for now.
!missing-pinvoke! DDDeviceCategoryToString is not bound
SotoiGhost marked this conversation as resolved.
Show resolved Hide resolved
!missing-pinvoke! DDDeviceMediaPlaybackStateToString is not bound
!missing-pinvoke! DDDeviceProtocolToString is not bound
!missing-pinvoke! DDDeviceStateToString is not bound
!missing-pinvoke! DDEventTypeToString is not bound

This file was deleted.

6 changes: 6 additions & 0 deletions tests/xtro-sharpie/iOS-DeviceDiscoveryExtension.ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## These C methods are helpers to cast an enum value to string, but the string value is not used anywhere. Ignored them for now.
!missing-pinvoke! DDDeviceCategoryToString is not bound
!missing-pinvoke! DDDeviceMediaPlaybackStateToString is not bound
!missing-pinvoke! DDDeviceProtocolToString is not bound
!missing-pinvoke! DDDeviceStateToString is not bound
!missing-pinvoke! DDEventTypeToString is not bound
Loading