[Network] NWContentContext binding, progress on NWConnection
This commit is contained in:
Родитель
e2d1190423
Коммит
c7aee0355d
|
@ -199,5 +199,88 @@ namespace Network {
|
|||
block_ptr_handler->CleanupBlock ();
|
||||
}
|
||||
}
|
||||
|
||||
delegate void nw_connection_path_event_handler_t (IntPtr block, IntPtr path);
|
||||
static nw_connection_path_event_handler_t static_PathChanged = TrampolinePathChanged;
|
||||
|
||||
[MonoPInvokeCallback (typeof (nw_connection_path_event_handler_t))]
|
||||
static unsafe void TrampolinePathChanged (IntPtr block, IntPtr path)
|
||||
{
|
||||
var descriptor = (BlockLiteral *) block;
|
||||
var del = (Action<NWPath>) (descriptor->Target);
|
||||
if (del != null){
|
||||
var x = new NWPath (path, owns: false);
|
||||
del (x);
|
||||
x.Dispose ();
|
||||
}
|
||||
}
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
[DllImport (Constants.NetworkLibrary)]
|
||||
static extern unsafe void nw_connection_set_path_changed_handler (IntPtr handle, void *callback);
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
public void SetPathChangedHandler (Action<NWPath> callback)
|
||||
{
|
||||
unsafe {
|
||||
BlockLiteral *block_ptr_handler;
|
||||
BlockLiteral block_handler;
|
||||
block_handler = new BlockLiteral ();
|
||||
block_ptr_handler = &block_handler;
|
||||
block_handler.SetupBlockUnsafe (static_PathChanged, callback);
|
||||
|
||||
nw_connection_set_path_changed_handler (handle, (void*) block_ptr_handler);
|
||||
block_ptr_handler->CleanupBlock ();
|
||||
}
|
||||
}
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
[DllImport (Constants.NetworkLibrary)]
|
||||
static extern void nw_connection_set_queue (IntPtr handle, IntPtr queue);
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
public void SetQueue (DispatchQueue queue)
|
||||
{
|
||||
if (queue == null)
|
||||
throw new ArgumentNullException (nameof (queue));
|
||||
nw_connection_set_queue (handle, queue.handle);
|
||||
}
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
[DllImport (Constants.NetworkLibrary)]
|
||||
static extern void nw_connection_start (IntPtr handle);
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
public void Start () => nw_connection_start (handle);
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
[DllImport (Constants.NetworkLibrary)]
|
||||
static extern void nw_connection_restart (IntPtr handle);
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
public void Restart () => nw_connection_restart (handle);
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
[DllImport (Constants.NetworkLibrary)]
|
||||
static extern void nw_connection_cancel (IntPtr handle);
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
public void Cancel () => nw_connection_cancel (handle);
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
[DllImport (Constants.NetworkLibrary)]
|
||||
static extern void nw_connection_force_cancel (IntPtr handle);
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
public void ForceCancel () => nw_connection_force_cancel (handle);
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
[DllImport (Constants.NetworkLibrary)]
|
||||
static extern void nw_connection_cancel_current_endpoint (IntPtr handle);
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
public void CancelCurrentEndpoint () => nw_connection_cancel_current_endpoint (handle);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,202 @@
|
|||
//
|
||||
// NWContentContext.cs: Bindings the Netowrk nw_content_context_t API
|
||||
//
|
||||
// Authors:
|
||||
// Miguel de Icaza (miguel@microsoft.com)
|
||||
//
|
||||
// Copyrigh 2018 Microsoft Inc
|
||||
//
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using ObjCRuntime;
|
||||
using Foundation;
|
||||
using CoreFoundation;
|
||||
|
||||
namespace Network {
|
||||
|
||||
public class NWContentContext : INativeObject, IDisposable {
|
||||
IntPtr handle;
|
||||
public IntPtr Handle {
|
||||
get { return handle; }
|
||||
}
|
||||
|
||||
public NWContentContext (IntPtr handle, bool owns)
|
||||
{
|
||||
this.handle = handle;
|
||||
if (owns == false)
|
||||
CFObject.CFRetain (handle);
|
||||
}
|
||||
|
||||
public NWContentContext (IntPtr handle) : this (handle, false)
|
||||
{
|
||||
}
|
||||
|
||||
~NWContentContext ()
|
||||
{
|
||||
Dispose (false);
|
||||
}
|
||||
|
||||
public void Dispose ()
|
||||
{
|
||||
Dispose (true);
|
||||
GC.SuppressFinalize (this);
|
||||
}
|
||||
|
||||
public virtual void Dispose (bool disposing)
|
||||
{
|
||||
if (handle != IntPtr.Zero) {
|
||||
CFObject.CFRelease (handle);
|
||||
handle = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
[DllImport (Constants.NetworkLibrary)]
|
||||
extern static IntPtr nw_content_context_create (string contextIdentifier);
|
||||
|
||||
public NWContentContext (string contextIdentifier)
|
||||
{
|
||||
if (contextIdentifier == null)
|
||||
throw new ArgumentNullException (nameof (contextIdentifier));
|
||||
handle = nw_content_context_create (contextIdentifier);
|
||||
}
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
[DllImport (Constants.NetworkLibrary)]
|
||||
extern static IntPtr nw_content_context_get_identifier (IntPtr handle);
|
||||
|
||||
public string Identifier => Marshal.PtrToStringAnsi (nw_content_context_get_identifier (handle));
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
[DllImport (Constants.NetworkLibrary)]
|
||||
[return: MarshalAs (UnmanagedType.I1)]
|
||||
extern static bool nw_content_context_get_is_final (IntPtr handle);
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
[DllImport (Constants.NetworkLibrary)]
|
||||
extern static void nw_content_context_set_is_final (IntPtr handle, [MarshalAs (UnmanagedType.I1)] bool is_final);
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
public bool IsFinal {
|
||||
get => nw_content_context_get_is_final (handle);
|
||||
set => nw_content_context_set_is_final (handle, value);
|
||||
}
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
[DllImport (Constants.NetworkLibrary)]
|
||||
extern static ulong nw_content_context_get_expiration_milliseconds (IntPtr handle);
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
[DllImport (Constants.NetworkLibrary)]
|
||||
extern static void nw_content_context_set_expiration_milliseconds (IntPtr handle, ulong value);
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
public ulong ExpirationMilliseconds {
|
||||
get => nw_content_context_get_expiration_milliseconds (handle);
|
||||
set => nw_content_context_set_expiration_milliseconds (handle, value);
|
||||
}
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
[DllImport (Constants.NetworkLibrary)]
|
||||
extern static double nw_content_context_get_relative_priority (IntPtr handle);
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
[DllImport (Constants.NetworkLibrary)]
|
||||
extern static void nw_content_context_set_relative_priority (IntPtr handle, double value);
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
public double RelativePriority {
|
||||
get => nw_content_context_get_relative_priority (handle);
|
||||
set => nw_content_context_set_relative_priority (handle, value);
|
||||
}
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
[DllImport (Constants.NetworkLibrary)]
|
||||
extern static IntPtr nw_content_context_copy_antecedent (IntPtr handle);
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
[DllImport (Constants.NetworkLibrary)]
|
||||
extern static void nw_content_context_set_antecedent (IntPtr handle, IntPtr value);
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
public NWContentContext Antecedent {
|
||||
get {
|
||||
var h = nw_content_context_copy_antecedent (handle);
|
||||
if (h == IntPtr.Zero)
|
||||
return null;
|
||||
return new NWContentContext (h, owns: true);
|
||||
}
|
||||
set {
|
||||
nw_content_context_set_antecedent (handle, value == null ? IntPtr.Zero : value.Handle);
|
||||
}
|
||||
}
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
[DllImport (Constants.NetworkLibrary)]
|
||||
extern static IntPtr nw_content_context_copy_protocol_metadata (IntPtr handle, IntPtr protocol);
|
||||
|
||||
public NWProtocolMetadata GetProtocolMetadata (NWProtocolDefinition protocolDefinition)
|
||||
{
|
||||
if (protocolDefinition == null)
|
||||
throw new ArgumentNullException (nameof (protocolDefinition));
|
||||
var x = nw_content_context_copy_protocol_metadata (handle, protocolDefinition.handle);
|
||||
if (x == IntPtr.Zero)
|
||||
return null;
|
||||
return new NWProtocolMetadata (x, owns: true);
|
||||
}
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
[DllImport (Constants.NetworkLibrary)]
|
||||
extern static void nw_content_context_set_metadata_for_protocol (IntPtr handle, IntPtr protocolMetadata);
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
public void SetMetadata (NWProtocolMetadata protocolMetadata)
|
||||
{
|
||||
if (protocolMetadata == null)
|
||||
throw new ArgumentNullException (nameof (protocolMetadata));
|
||||
nw_content_context_set_metadata_for_protocol (handle, protocolMetadata.Handle);
|
||||
}
|
||||
|
||||
delegate void ProtocolIterator (IntPtr block, IntPtr definition, IntPtr metadata);
|
||||
static ProtocolIterator static_ProtocolIterator = TrampolineProtocolIterator;
|
||||
|
||||
[MonoPInvokeCallback (typeof (ProtocolIterator))]
|
||||
static unsafe void TrampolineProtocolIterator (IntPtr block, IntPtr definition, IntPtr metadata)
|
||||
{
|
||||
var descriptor = (BlockLiteral *) block;
|
||||
var del = (Action<NWProtocolDefinition,NWProtocolMetadata>) (descriptor->Target);
|
||||
if (del != null){
|
||||
var pdef = definition == IntPtr.Zero ? null : new NWProtocolDefinition (definition, owns: true);
|
||||
var meta = metadata == IntPtr.Zero ? null : new NWProtocolMetadata (metadata, owns: true);
|
||||
|
||||
del (pdef, meta);
|
||||
|
||||
pdef?.Dispose ();
|
||||
meta?.Dispose ();
|
||||
if (pdef != null)
|
||||
pdef.Dispose ();
|
||||
if (meta != null)
|
||||
meta.Dispose ();
|
||||
}
|
||||
}
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
[DllImport (Constants.NetworkLibrary)]
|
||||
static extern unsafe void nw_content_context_foreach_protocol_metadata (IntPtr handle, void *callback);
|
||||
|
||||
[TV (12,0), Mac (10,14), iOS (12,0)]
|
||||
public void ItereateProtocolMetadata (Action<NWProtocolDefinition,NWProtocolMetadata> callback)
|
||||
{
|
||||
unsafe {
|
||||
BlockLiteral *block_ptr_handler;
|
||||
BlockLiteral block_handler;
|
||||
block_handler = new BlockLiteral ();
|
||||
block_ptr_handler = &block_handler;
|
||||
block_handler.SetupBlockUnsafe (static_ProtocolIterator, callback);
|
||||
|
||||
nw_content_context_foreach_protocol_metadata (handle, (void*) block_ptr_handler);
|
||||
block_ptr_handler->CleanupBlock ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -24,7 +24,7 @@ namespace Network {
|
|||
}
|
||||
|
||||
public class NWProtocolDefinition : INativeObject, IDisposable {
|
||||
IntPtr handle;
|
||||
internal IntPtr handle;
|
||||
public IntPtr Handle {
|
||||
get { return handle; }
|
||||
}
|
||||
|
|
|
@ -1078,6 +1078,7 @@ MULTIPEERCONNECTIVITY_SOURCES = \
|
|||
NETWORK_SOURCES = \
|
||||
Network/NWAdvertiseDescriptor.cs \
|
||||
Network/NWConnection.cs \
|
||||
Network/NWContentContext.cs \
|
||||
Network/NWEndpoint.cs \
|
||||
Network/NWError.cs \
|
||||
Network/NWInterface.cs \
|
||||
|
|
Загрузка…
Ссылка в новой задаче