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 bindings for DeviceDiscoveryExtension. #20272

Merged
merged 16 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 15 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 ([email protected])
//
// Copyright 2022 Microsoft Corporation.
//
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is from a past PR, but should the copyright headers be updated?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed now.


#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 ();
}
}
}
76 changes: 76 additions & 0 deletions src/DeviceDiscoveryExtension/Enums.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//
// Enums.cs
//
// Authors:
// Israel Soto ([email protected])
//
// 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, // 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
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 <[email protected]>
//
// 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 {
[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
Loading