Skip to content

Commit

Permalink
[DeviceDiscoveryExtension] Added bindings for DeviceDiscoveryExtensio…
Browse files Browse the repository at this point in the history
…n. (#20272)

---------

Co-authored-by: Israel Soto <issoto@microsoft.com>
  • Loading branch information
rolfbjarne and Israel Soto committed Mar 14, 2024
1 parent d1f387c commit 2348736
Show file tree
Hide file tree
Showing 17 changed files with 396 additions and 100 deletions.
27 changes: 27 additions & 0 deletions src/DeviceDiscoveryExtension/DDDevice.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Custom methods for DDDevice
//
// Authors:
// Israel Soto (issoto@microsoft.com)
// Rolf Bjarne Kvinge (rolf@xamarin.com)
//
// Copyright 2022, 2024 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 ();
}
}
}
77 changes: 77 additions & 0 deletions src/DeviceDiscoveryExtension/Enums.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//
// Enums.cs
//
// Authors:
// Israel Soto (issoto@microsoft.com)
// Rolf Bjarne Kvinge (rolf@xamarin.com)
//
// Copyright 2022, 2024 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, // don't bind 'Next', it's not static and we'd have to break compat if it were ever to change
}

[NoMac, iOS (16, 0), NoMacCatalyst, NoWatch, NoTV]
[Native]
public enum DDEventType : long {
Unknown = 0,
DeviceFound = 40,
DeviceLost = 41,
DeviceChanged = 42,
}
}
3 changes: 3 additions & 0 deletions src/build/generator-frameworks.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ partial class Frameworks {
"CoreText",
"CoreVideo",
"DeviceCheck",
"DeviceDiscoveryExtension",
"EventKit",
"EventKitUI",
"ExternalAccessory",
Expand Down Expand Up @@ -604,6 +605,7 @@ partial class Frameworks {
bool? _CoreVideo;
bool? _CoreWlan;
bool? _DeviceCheck;
bool? _DeviceDiscoveryExtension;
bool? _DeviceDiscoveryUI;
bool? _EventKit;
bool? _EventKitUI;
Expand Down Expand Up @@ -770,6 +772,7 @@ partial class Frameworks {
public bool HaveCoreVideo { get { if (!_CoreVideo.HasValue) _CoreVideo = GetValue ("CoreVideo"); return _CoreVideo.Value; } }
public bool HaveCoreWlan { get { if (!_CoreWlan.HasValue) _CoreWlan = GetValue ("CoreWlan"); return _CoreWlan.Value; } }
public bool HaveDeviceCheck { get { if (!_DeviceCheck.HasValue) _DeviceCheck = GetValue ("DeviceCheck"); return _DeviceCheck.Value; } }
public bool HaveDeviceDiscoveryExtension { get { if (!_DeviceDiscoveryExtension.HasValue) _DeviceDiscoveryExtension = GetValue ("DeviceDiscoveryExtension"); return _DeviceDiscoveryExtension.Value; } }
public bool HaveDeviceDiscoveryUI { get { if (!_DeviceDiscoveryUI.HasValue) _DeviceDiscoveryUI = GetValue ("DeviceDiscoveryUI"); return _DeviceDiscoveryUI.Value; } }
public bool HaveEventKit { get { if (!_EventKit.HasValue) _EventKit = GetValue ("EventKit"); return _EventKit.Value; } }
public bool HaveEventKitUI { get { if (!_EventKitUI.HasValue) _EventKitUI = GetValue ("EventKitUI"); return _EventKitUI.Value; } }
Expand Down
107 changes: 107 additions & 0 deletions src/devicediscoveryextension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
//
// DeviceDiscoveryExtension C# bindings
//
// Authors:
// Israel Soto (issoto@microsoft.com)
// Rolf Bjarne Kvinge (rolf@xamarin.com)
//
// Copyright 2022, 2024 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 {
[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; }

[iOS (17, 0)]
[Export ("supportsGrouping")]
bool SupportsGrouping { get; set; }
}

[NoMac, iOS (16, 0), NoMacCatalyst, NoWatch, NoTV]
[BaseType (typeof (NSObject))]
[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 {
[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 @@ -726,6 +726,14 @@ COREWLAN_SOURCES = \
CoreWlan/CWInterface.cs \
CoreWlan/CWKeychain.cs \

# DeviceDiscoveryExtension

DEVICEDISCOVERYEXTENSION_API_SOURCES = \
DeviceDiscoveryExtension/Enums.cs \

DEVICEDISCOVERYEXTENSION_SOURCES = \
DeviceDiscoveryExtension/DDDevice.cs \

# DeviceDiscoveryUI

DEVICEDISCOVERYUI_SOURCES = \
Expand Down Expand Up @@ -2198,6 +2206,7 @@ IOS_FRAMEWORKS = \
CoreSpotlight \
CoreTelephony \
CoreText \
DeviceDiscoveryExtension \
EventKit \
EventKitUI \
ExternalAccessory \
Expand Down
1 change: 1 addition & 0 deletions src/rsp/dotnet/ios-defines-dotnet.rsp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
-d:HAS_CORETEXT
-d:HAS_COREVIDEO
-d:HAS_DEVICECHECK
-d:HAS_DEVICEDISCOVERYEXTENSION
-d:HAS_EVENTKIT
-d:HAS_EVENTKITUI
-d:HAS_EXTERNALACCESSORY
Expand Down
1 change: 1 addition & 0 deletions src/rsp/ios-defines.rsp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
-d:HAS_CORETEXT
-d:HAS_COREVIDEO
-d:HAS_DEVICECHECK
-d:HAS_DEVICEDISCOVERYEXTENSION
-d:HAS_EVENTKIT
-d:HAS_EVENTKITUI
-d:HAS_EXTERNALACCESSORY
Expand Down
Loading

8 comments on commit 2348736

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.