fix rust flutter

This commit is contained in:
John Smith 2022-02-01 13:07:39 -05:00
parent 65dabd09c7
commit 4bfa72f2db
4 changed files with 65 additions and 29 deletions

View File

@ -15,6 +15,7 @@ typedef struct wire_StringList {
typedef struct wire_VeilidConfig { typedef struct wire_VeilidConfig {
struct wire_uint_8_list *program_name; struct wire_uint_8_list *program_name;
struct wire_uint_8_list *veilid_namespace; struct wire_uint_8_list *veilid_namespace;
int32_t api_log_level;
bool capabilities__protocol_udp; bool capabilities__protocol_udp;
bool capabilities__protocol_connect_tcp; bool capabilities__protocol_connect_tcp;
bool capabilities__protocol_accept_tcp; bool capabilities__protocol_accept_tcp;
@ -95,6 +96,8 @@ void wire_startup_veilid_core(int64_t port_, struct wire_VeilidConfig *config);
void wire_get_veilid_state(int64_t port_); void wire_get_veilid_state(int64_t port_);
void wire_change_api_log_level(int64_t port_, int32_t log_level);
void wire_shutdown_veilid_core(int64_t port_); void wire_shutdown_veilid_core(int64_t port_);
void wire_veilid_version_string(int64_t port_); void wire_veilid_version_string(int64_t port_);
@ -117,6 +120,7 @@ static int64_t dummy_method_to_enforce_bundling(void) {
int64_t dummy_var = 0; int64_t dummy_var = 0;
dummy_var ^= ((int64_t) (void*) wire_startup_veilid_core); dummy_var ^= ((int64_t) (void*) wire_startup_veilid_core);
dummy_var ^= ((int64_t) (void*) wire_get_veilid_state); dummy_var ^= ((int64_t) (void*) wire_get_veilid_state);
dummy_var ^= ((int64_t) (void*) wire_change_api_log_level);
dummy_var ^= ((int64_t) (void*) wire_shutdown_veilid_core); dummy_var ^= ((int64_t) (void*) wire_shutdown_veilid_core);
dummy_var ^= ((int64_t) (void*) wire_veilid_version_string); dummy_var ^= ((int64_t) (void*) wire_veilid_version_string);
dummy_var ^= ((int64_t) (void*) wire_veilid_version); dummy_var ^= ((int64_t) (void*) wire_veilid_version);

View File

@ -26,6 +26,8 @@ abstract class VeilidFlutter {
Future<VeilidState> getVeilidState({ dynamic hint }); Future<VeilidState> getVeilidState({ dynamic hint });
Future<void> changeApiLogLevel({ required VeilidLogLevel logLevel,dynamic hint });
Future<void> shutdownVeilidCore({ dynamic hint }); Future<void> shutdownVeilidCore({ dynamic hint });
Future<String> veilidVersionString({ dynamic hint }); Future<String> veilidVersionString({ dynamic hint });
@ -47,6 +49,7 @@ Detaching,
class VeilidConfig { class VeilidConfig {
final String programName; final String programName;
final String veilidNamespace; final String veilidNamespace;
final VeilidLogLevel apiLogLevel;
final bool capabilitiesProtocolUdp; final bool capabilitiesProtocolUdp;
final bool capabilitiesProtocolConnectTcp; final bool capabilitiesProtocolConnectTcp;
final bool capabilitiesProtocolAcceptTcp; final bool capabilitiesProtocolAcceptTcp;
@ -112,7 +115,7 @@ final int networkLeasesMaxServerRelayLeases;
final int networkLeasesMaxClientSignalLeases; final int networkLeasesMaxClientSignalLeases;
final int networkLeasesMaxClientRelayLeases; final int networkLeasesMaxClientRelayLeases;
VeilidConfig({required this.programName,required this.veilidNamespace,required this.capabilitiesProtocolUdp,required this.capabilitiesProtocolConnectTcp,required this.capabilitiesProtocolAcceptTcp,required this.capabilitiesProtocolConnectWs,required this.capabilitiesProtocolAcceptWs,required this.capabilitiesProtocolConnectWss,required this.capabilitiesProtocolAcceptWss,required this.protectedStoreAllowInsecureFallback,required this.protectedStoreAlwaysUseInsecureStorage,required this.protectedStoreInsecureFallbackDirectory,required this.protectedStoreDelete,required this.tableStoreDirectory,required this.tableStoreDelete,required this.blockStoreDirectory,required this.blockStoreDelete,required this.networkMaxConnections,required this.networkConnectionInitialTimeoutMs,required this.networkNodeId,required this.networkNodeIdSecret,required this.networkBootstrap,required this.networkUpnp,required this.networkNatpmp,required this.networkEnableLocalPeerScope,required this.networkRestrictedNatRetries,required this.networkRpcConcurrency,required this.networkRpcQueueSize,this.networkRpcMaxTimestampBehindMs,this.networkRpcMaxTimestampAheadMs,required this.networkRpcTimeoutMs,required this.networkRpcMaxRouteHopCount,this.networkDhtResolveNodeTimeoutMs,required this.networkDhtResolveNodeCount,required this.networkDhtResolveNodeFanout,required this.networkDhtMaxFindNodeCount,this.networkDhtGetValueTimeoutMs,required this.networkDhtGetValueCount,required this.networkDhtGetValueFanout,this.networkDhtSetValueTimeoutMs,required this.networkDhtSetValueCount,required this.networkDhtSetValueFanout,required this.networkDhtMinPeerCount,required this.networkDhtMinPeerRefreshTimeMs,required this.networkDhtValidateDialInfoReceiptTimeMs,required this.networkProtocolUdpEnabled,required this.networkProtocolUdpSocketPoolSize,required this.networkProtocolUdpListenAddress,this.networkProtocolUdpPublicAddress,required this.networkProtocolTcpConnect,required this.networkProtocolTcpListen,required this.networkProtocolTcpMaxConnections,required this.networkProtocolTcpListenAddress,this.networkProtocolTcpPublicAddress,required this.networkProtocolWsConnect,required this.networkProtocolWsListen,required this.networkProtocolWsMaxConnections,required this.networkProtocolWsListenAddress,required this.networkProtocolWsPath,this.networkProtocolWsUrl,required this.networkProtocolWssConnect,required this.networkProtocolWssMaxConnections,required this.networkLeasesMaxServerSignalLeases,required this.networkLeasesMaxServerRelayLeases,required this.networkLeasesMaxClientSignalLeases,required this.networkLeasesMaxClientRelayLeases,}); VeilidConfig({required this.programName,required this.veilidNamespace,required this.apiLogLevel,required this.capabilitiesProtocolUdp,required this.capabilitiesProtocolConnectTcp,required this.capabilitiesProtocolAcceptTcp,required this.capabilitiesProtocolConnectWs,required this.capabilitiesProtocolAcceptWs,required this.capabilitiesProtocolConnectWss,required this.capabilitiesProtocolAcceptWss,required this.protectedStoreAllowInsecureFallback,required this.protectedStoreAlwaysUseInsecureStorage,required this.protectedStoreInsecureFallbackDirectory,required this.protectedStoreDelete,required this.tableStoreDirectory,required this.tableStoreDelete,required this.blockStoreDirectory,required this.blockStoreDelete,required this.networkMaxConnections,required this.networkConnectionInitialTimeoutMs,required this.networkNodeId,required this.networkNodeIdSecret,required this.networkBootstrap,required this.networkUpnp,required this.networkNatpmp,required this.networkEnableLocalPeerScope,required this.networkRestrictedNatRetries,required this.networkRpcConcurrency,required this.networkRpcQueueSize,this.networkRpcMaxTimestampBehindMs,this.networkRpcMaxTimestampAheadMs,required this.networkRpcTimeoutMs,required this.networkRpcMaxRouteHopCount,this.networkDhtResolveNodeTimeoutMs,required this.networkDhtResolveNodeCount,required this.networkDhtResolveNodeFanout,required this.networkDhtMaxFindNodeCount,this.networkDhtGetValueTimeoutMs,required this.networkDhtGetValueCount,required this.networkDhtGetValueFanout,this.networkDhtSetValueTimeoutMs,required this.networkDhtSetValueCount,required this.networkDhtSetValueFanout,required this.networkDhtMinPeerCount,required this.networkDhtMinPeerRefreshTimeMs,required this.networkDhtValidateDialInfoReceiptTimeMs,required this.networkProtocolUdpEnabled,required this.networkProtocolUdpSocketPoolSize,required this.networkProtocolUdpListenAddress,this.networkProtocolUdpPublicAddress,required this.networkProtocolTcpConnect,required this.networkProtocolTcpListen,required this.networkProtocolTcpMaxConnections,required this.networkProtocolTcpListenAddress,this.networkProtocolTcpPublicAddress,required this.networkProtocolWsConnect,required this.networkProtocolWsListen,required this.networkProtocolWsMaxConnections,required this.networkProtocolWsListenAddress,required this.networkProtocolWsPath,this.networkProtocolWsUrl,required this.networkProtocolWssConnect,required this.networkProtocolWssMaxConnections,required this.networkLeasesMaxServerSignalLeases,required this.networkLeasesMaxServerRelayLeases,required this.networkLeasesMaxClientSignalLeases,required this.networkLeasesMaxClientRelayLeases,});
} }
enum VeilidLogLevel { enum VeilidLogLevel {
@ -175,6 +178,19 @@ Future<VeilidState> getVeilidState({ dynamic hint }) => executeNormal(FlutterRus
)); ));
Future<void> changeApiLogLevel({ required VeilidLogLevel logLevel,dynamic hint }) => executeNormal(FlutterRustBridgeTask(
callFfi: (port_) => inner.wire_change_api_log_level(port_, _api2wire_veilid_log_level(logLevel)),
parseSuccessData: _wire2api_unit,
constMeta: const FlutterRustBridgeTaskConstMeta(
debugName: "change_api_log_level",
argNames: ["logLevel"],
),
argValues: [logLevel],
hint: hint,
));
Future<void> shutdownVeilidCore({ dynamic hint }) => executeNormal(FlutterRustBridgeTask( Future<void> shutdownVeilidCore({ dynamic hint }) => executeNormal(FlutterRustBridgeTask(
callFfi: (port_) => inner.wire_shutdown_veilid_core(port_), callFfi: (port_) => inner.wire_shutdown_veilid_core(port_),
parseSuccessData: _wire2api_unit, parseSuccessData: _wire2api_unit,
@ -275,6 +291,11 @@ ffi.Pointer<wire_uint_8_list> _api2wire_uint_8_list(Uint8List raw) {
int _api2wire_veilid_log_level(VeilidLogLevel raw) {
return raw.index;
}
// Section: api_fill_to_wire // Section: api_fill_to_wire
@ -301,6 +322,7 @@ void _api_fill_to_wire_box_autoadd_veilid_config(VeilidConfig apiObj, ffi.Pointe
void _api_fill_to_wire_veilid_config(VeilidConfig apiObj, wire_VeilidConfig wireObj) { void _api_fill_to_wire_veilid_config(VeilidConfig apiObj, wire_VeilidConfig wireObj) {
wireObj.program_name = _api2wire_String(apiObj.programName); wireObj.program_name = _api2wire_String(apiObj.programName);
wireObj.veilid_namespace = _api2wire_String(apiObj.veilidNamespace); wireObj.veilid_namespace = _api2wire_String(apiObj.veilidNamespace);
wireObj.api_log_level = _api2wire_veilid_log_level(apiObj.apiLogLevel);
wireObj.capabilities__protocol_udp = _api2wire_bool(apiObj.capabilitiesProtocolUdp); wireObj.capabilities__protocol_udp = _api2wire_bool(apiObj.capabilitiesProtocolUdp);
wireObj.capabilities__protocol_connect_tcp = _api2wire_bool(apiObj.capabilitiesProtocolConnectTcp); wireObj.capabilities__protocol_connect_tcp = _api2wire_bool(apiObj.capabilitiesProtocolConnectTcp);
wireObj.capabilities__protocol_accept_tcp = _api2wire_bool(apiObj.capabilitiesProtocolAcceptTcp); wireObj.capabilities__protocol_accept_tcp = _api2wire_bool(apiObj.capabilitiesProtocolAcceptTcp);
@ -366,6 +388,8 @@ wireObj.network__leases__max_server_relay_leases = _api2wire_u32(apiObj.networkL
wireObj.network__leases__max_client_signal_leases = _api2wire_u32(apiObj.networkLeasesMaxClientSignalLeases); wireObj.network__leases__max_client_signal_leases = _api2wire_u32(apiObj.networkLeasesMaxClientSignalLeases);
wireObj.network__leases__max_client_relay_leases = _api2wire_u32(apiObj.networkLeasesMaxClientRelayLeases); wireObj.network__leases__max_client_relay_leases = _api2wire_u32(apiObj.networkLeasesMaxClientRelayLeases);
} }
} }
// Section: wire2api // Section: wire2api
@ -482,6 +506,22 @@ class VeilidFlutterWire implements FlutterRustBridgeWireBase {
late final _wire_get_veilid_state = late final _wire_get_veilid_state =
_wire_get_veilid_statePtr.asFunction<void Function(int)>(); _wire_get_veilid_statePtr.asFunction<void Function(int)>();
void wire_change_api_log_level(
int port_,
int log_level,
) {
return _wire_change_api_log_level(
port_,
log_level,
);
}
late final _wire_change_api_log_levelPtr =
_lookup<ffi.NativeFunction<ffi.Void Function(ffi.Int64, ffi.Int32)>>(
'wire_change_api_log_level');
late final _wire_change_api_log_level =
_wire_change_api_log_levelPtr.asFunction<void Function(int, int)>();
void wire_shutdown_veilid_core( void wire_shutdown_veilid_core(
int port_, int port_,
) { ) {
@ -625,6 +665,9 @@ class wire_VeilidConfig extends ffi.Struct {
external ffi.Pointer<wire_uint_8_list> veilid_namespace; external ffi.Pointer<wire_uint_8_list> veilid_namespace;
@ffi.Int32()
external int api_log_level;
@ffi.Uint8() @ffi.Uint8()
external int capabilities__protocol_udp; external int capabilities__protocol_udp;

View File

@ -437,6 +437,13 @@ pub enum VeilidLogLevel {
Debug, Debug,
Trace, Trace,
} }
impl Default for VeilidLogLevel {
fn default() -> Self {
Self::Info
}
}
impl VeilidLogLevel { impl VeilidLogLevel {
fn from_core(level: veilid_core::VeilidLogLevel) -> Self { fn from_core(level: veilid_core::VeilidLogLevel) -> Self {
match level { match level {
@ -448,13 +455,13 @@ impl VeilidLogLevel {
} }
} }
fn to_config_log_level(&self) -> VeilidConfigLogLevel { fn to_config_log_level(&self) -> veilid_core::VeilidConfigLogLevel {
match self { match self {
Self::Error => VeilidConfigLogLevel::Error, Self::Error => veilid_core::VeilidConfigLogLevel::Error,
Self::Warn => VeilidConfigLogLevel::Warn, Self::Warn => veilid_core::VeilidConfigLogLevel::Warn,
Self::Info => VeilidConfigLogLevel::Info, Self::Info => veilid_core::VeilidConfigLogLevel::Info,
Self::Debug => VeilidConfigLogLevel::Debug, Self::Debug => veilid_core::VeilidConfigLogLevel::Debug,
Self::Trace => VeilidConfigLogLevel::Trace, Self::Trace => veilid_core::VeilidConfigLogLevel::Trace,
} }
} }
} }
@ -543,7 +550,7 @@ pub fn get_veilid_state() -> Result<VeilidState> {
// xxx api functions // xxx api functions
pub fn change_api_log_level(level: VeilidLogLevel) -> Result<()> { pub fn change_api_log_level(log_level: VeilidLogLevel) -> Result<()> {
async_std::task::block_on(async { async_std::task::block_on(async {
let veilid_api = get_veilid_api().await?; let veilid_api = get_veilid_api().await?;
veilid_api veilid_api

View File

@ -41,7 +41,7 @@ pub extern "C" fn wire_get_veilid_state(port_: i64) {
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn wire_change_api_log_level(port_: i64, level: i32) { pub extern "C" fn wire_change_api_log_level(port_: i64, log_level: i32) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap( FLUTTER_RUST_BRIDGE_HANDLER.wrap(
WrapInfo { WrapInfo {
debug_name: "change_api_log_level", debug_name: "change_api_log_level",
@ -49,8 +49,8 @@ pub extern "C" fn wire_change_api_log_level(port_: i64, level: i32) {
mode: FfiCallMode::Normal, mode: FfiCallMode::Normal,
}, },
move || { move || {
let api_level = level.wire2api(); let api_log_level = log_level.wire2api();
move |task_callback| change_api_log_level(api_level) move |task_callback| change_api_log_level(api_log_level)
}, },
) )
} }
@ -579,21 +579,3 @@ pub extern "C" fn free_WireSyncReturnStruct(val: support::WireSyncReturnStruct)
let _ = support::vec_from_leak_ptr(val.ptr, val.len); let _ = support::vec_from_leak_ptr(val.ptr, val.len);
} }
} }
// ----------- DUMMY CODE FOR BINDGEN ----------
// copied from: allo-isolate
pub type DartPort = i64;
pub type DartPostCObjectFnType = unsafe extern "C" fn(port_id: DartPort, message: *mut std::ffi::c_void) -> bool;
#[no_mangle] pub unsafe extern "C" fn store_dart_post_cobject(ptr: DartPostCObjectFnType) { panic!("dummy code") }
// copied from: frb_rust::support.rs
#[repr(C)]
pub struct WireSyncReturnStruct {
pub ptr: *mut u8,
pub len: i32,
pub success: bool,
}
// ---------------------------------------------