MCPcopy Create free account
hub / github.com/astonbitecode/j4rs / init_callback_channel

Method init_callback_channel

rust/src/api/mod.rs:1043–1066  ·  view source on GitHub ↗

Initializes a callback channel via a Java Instance that is a `NativeCallbackToRustChannelSupport`. It returns a Result of `InstanceReceiver` that may be used to get an underlying `Receiver `. The `NativeCallbackToRustChannelSupport` Instance which is passed as argument, will be sending `Instance`s via this Receiver.

(&self, instance: &Instance)

Source from the content-addressed store, hash-verified

1041 /// It returns a Result of `InstanceReceiver` that may be used to get an underlying `Receiver<Instance>`.
1042 /// The `NativeCallbackToRustChannelSupport` Instance which is passed as argument, will be sending `Instance`s via this Receiver.
1043 pub fn init_callback_channel(&self, instance: &Instance) -> errors::Result<InstanceReceiver> {
1044 debug("Initializing callback channel");
1045 unsafe {
1046 // Create the channel
1047 let (sender, rx) = channel();
1048 let tx = Box::new(sender);
1049 // First argument: the address of the channel Sender
1050 let raw_ptr = Box::into_raw(tx);
1051 // Find the address of tx
1052 let address_string = format!("{:p}", raw_ptr);
1053 let address = u64::from_str_radix(&address_string[2..], 16).unwrap();
1054
1055 // Call the method of the instance
1056 (opt_to_res(cache::get_jni_call_void_method())?)(
1057 self.jni_env,
1058 instance.jinstance,
1059 cache::get_init_callback_channel_method()?,
1060 address,
1061 );
1062
1063 // Create and return the Instance
1064 Self::do_return(self.jni_env, InstanceReceiver::new(rx, address))
1065 }
1066 }
1067
1068 /// Invokes the static method `method_name` of the class `class_name`, passing an array of `InvocationArg`s. It returns an `Instance` as the result of the invocation.
1069 pub fn invoke_static(

Callers 5

init_callback_channelFunction · 0.80

Calls 5

debugFunction · 0.85
opt_to_resFunction · 0.85
get_jni_call_void_methodFunction · 0.85
do_returnFunction · 0.85

Tested by 1

init_callback_channelFunction · 0.64