Skip to content

Commit d620329

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

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

src/dispatcher.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,27 @@ impl Dispatcher {
554554
}
555555
}
556556
}
557+
558+
fn on_foreign_function(
559+
&self,
560+
context_id: u32,
561+
function_id: u32,
562+
arugments_size: usize,
563+
) {
564+
if let Some(http_stream) = self.http_streams.borrow_mut().get_mut(&context_id) {
565+
self.active_id.set(context_id);
566+
hostcalls::set_effective_context(context_id).unwrap();
567+
http_stream.on_foreign_function(function_id, arugments_size)
568+
} else if let Some(stream) = self.streams.borrow_mut().get_mut(&context_id) {
569+
self.active_id.set(context_id);
570+
hostcalls::set_effective_context(context_id).unwrap();
571+
stream.on_foreign_function(function_id, arugments_size)
572+
} else if let Some(root) = self.roots.borrow_mut().get_mut(&context_id) {
573+
self.active_id.set(context_id);
574+
hostcalls::set_effective_context(context_id).unwrap();
575+
root.on_foreign_function(function_id, arugments_size)
576+
}
577+
}
557578
}
558579

559580
#[no_mangle]
@@ -722,3 +743,14 @@ pub extern "C" fn proxy_on_grpc_receive_trailing_metadata(
722743
pub extern "C" fn proxy_on_grpc_close(_context_id: u32, token_id: u32, status_code: u32) {
723744
DISPATCHER.with(|dispatcher| dispatcher.on_grpc_close(token_id, status_code))
724745
}
746+
747+
#[no_mangle]
748+
pub extern "C" fn proxy_on_foreign_function(
749+
context_id: u32,
750+
function_id: u32,
751+
arguments_size: usize,
752+
) {
753+
DISPATCHER.with(|dispatcher| {
754+
dispatcher.on_foreign_function(context_id, function_id, arguments_size)
755+
})
756+
}

src/traits.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,13 @@ pub trait Context {
197197
hostcalls::get_grpc_status().unwrap()
198198
}
199199

200+
fn on_foreign_function(
201+
&mut self,
202+
_function_id: u32,
203+
_arguments_size: usize,
204+
) {
205+
}
206+
200207
fn call_foreign_function(
201208
&self,
202209
function_name: &str,

src/types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ pub enum BufferType {
8181
GrpcReceiveBuffer = 5,
8282
VmConfiguration = 6,
8383
PluginConfiguration = 7,
84+
CallData = 8,
8485
}
8586

8687
#[repr(u32)]

0 commit comments

Comments
 (0)