mirror of
https://github.com/cccb/servicepoint.git
synced 2025-01-18 18:10:14 +01:00
add fake connection to C API
This commit is contained in:
parent
240766dc11
commit
05aff8b2dd
|
@ -46,6 +46,22 @@ pub unsafe extern "C" fn sp_connection_open(
|
|||
Box::into_raw(Box::new(SPConnection(connection)))
|
||||
}
|
||||
|
||||
/// Creates a new instance of [SPConnection] for testing that does not actually send anything.
|
||||
///
|
||||
/// returns: a new instance. Will never return NULL.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - the returned instance is freed in some way, either by using a consuming function or
|
||||
/// by explicitly calling `sp_connection_free`.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_connection_fake() -> NonNull<SPConnection> {
|
||||
let result = Box::new(SPConnection(servicepoint::Connection::Fake));
|
||||
NonNull::from(Box::leak(result))
|
||||
}
|
||||
|
||||
/// Sends a [SPPacket] to the display using the [SPConnection].
|
||||
///
|
||||
/// The passed `packet` gets consumed.
|
||||
|
|
|
@ -37,6 +37,24 @@ namespace ServicePoint
|
|||
return native == null ? null : new Connection(native);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of [SPConnection] for testing that does not actually send anything.
|
||||
///
|
||||
/// returns: a new instance. Will never return NULL.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - the returned instance is freed in some way, either by using a consuming function or
|
||||
/// by explicitly calling `sp_connection_free`.
|
||||
/// </summary>
|
||||
[System.Runtime.CompilerServices.MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
|
||||
public static Connection Fake()
|
||||
{
|
||||
return new Connection(Connection.sp_connection_fake());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a [SPPacket] to the display using the [SPConnection].
|
||||
///
|
||||
|
@ -141,6 +159,9 @@ namespace ServicePoint
|
|||
[DllImport(__DllName, EntryPoint = "sp_connection_open", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
private static extern SPConnection* sp_connection_open(byte* host);
|
||||
|
||||
[DllImport(__DllName, EntryPoint = "sp_connection_fake", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
private static extern SPConnection* sp_connection_fake();
|
||||
|
||||
[DllImport(__DllName, EntryPoint = "sp_connection_send_packet", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
[return: MarshalAs(UnmanagedType.U1)]
|
||||
private static extern bool sp_connection_send_packet(SPConnection* connection, SPPacket* packet);
|
||||
|
|
Loading…
Reference in a new issue