Skip to content

Commit a7cb38f

Browse files
committed
Add support for foreign function callback.
Signed-off-by: Caio Ramos Casimiro <caiorcasimiro@gmail.com>
1 parent 6d88ed5 commit a7cb38f

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/dispatcher.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,27 @@ impl Dispatcher {
427427
}
428428
}
429429

430+
fn on_foreign_function(
431+
&self,
432+
context_id: u32,
433+
function_id: u32,
434+
arugments_size: usize,
435+
) {
436+
if let Some(http_stream) = self.http_streams.borrow_mut().get_mut(&context_id) {
437+
self.active_id.set(context_id);
438+
hostcalls::set_effective_context(context_id).unwrap();
439+
http_stream.on_foreign_function(function_id, arugments_size)
440+
} else if let Some(stream) = self.streams.borrow_mut().get_mut(&context_id) {
441+
self.active_id.set(context_id);
442+
hostcalls::set_effective_context(context_id).unwrap();
443+
stream.on_foreign_function(function_id, arugments_size)
444+
} else if let Some(root) = self.roots.borrow_mut().get_mut(&context_id) {
445+
self.active_id.set(context_id);
446+
hostcalls::set_effective_context(context_id).unwrap();
447+
root.on_foreign_function(function_id, arugments_size)
448+
}
449+
}
450+
430451
fn on_grpc_receive_initial_metadata(&self, token_id: u32, headers: u32) {
431452
let context_id = match self.grpc_streams.borrow_mut().get(&token_id) {
432453
Some(id) => *id,
@@ -695,6 +716,17 @@ pub extern "C" fn proxy_on_http_call_response(
695716
})
696717
}
697718

719+
#[no_mangle]
720+
pub extern "C" fn proxy_on_foreign_function(
721+
context_id: u32,
722+
function_id: u32,
723+
arguments_size: usize,
724+
) {
725+
DISPATCHER.with(|dispatcher| {
726+
dispatcher.on_foreign_function(context_id, function_id, arguments_size)
727+
})
728+
}
729+
698730
#[no_mangle]
699731
pub extern "C" fn proxy_on_grpc_receive_initial_metadata(
700732
_context_id: u32,

src/traits.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ pub trait Context {
7878
) {
7979
}
8080

81+
fn on_foreign_function(
82+
&mut self,
83+
_function_id: u32,
84+
_arguments_size: usize,
85+
) {
86+
}
87+
8188
fn get_http_call_response_headers(&self) -> Vec<(String, String)> {
8289
hostcalls::get_map(MapType::HttpCallResponseHeaders).unwrap()
8390
}

0 commit comments

Comments
 (0)