Skip to content

Commit ae38c0f

Browse files
authored
Add support for foreign function callbacks. (#290)
Signed-off-by: Caio Ramos Casimiro <[email protected]>
1 parent 8604c64 commit ae38c0f

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

Diff for: src/dispatcher.rs

+26
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,22 @@ impl Dispatcher {
554554
}
555555
}
556556
}
557+
558+
fn on_foreign_function(&self, context_id: u32, function_id: u32, arugments_size: usize) {
559+
if let Some(http_stream) = self.http_streams.borrow_mut().get_mut(&context_id) {
560+
self.active_id.set(context_id);
561+
hostcalls::set_effective_context(context_id).unwrap();
562+
http_stream.on_foreign_function(function_id, arugments_size)
563+
} else if let Some(stream) = self.streams.borrow_mut().get_mut(&context_id) {
564+
self.active_id.set(context_id);
565+
hostcalls::set_effective_context(context_id).unwrap();
566+
stream.on_foreign_function(function_id, arugments_size)
567+
} else if let Some(root) = self.roots.borrow_mut().get_mut(&context_id) {
568+
self.active_id.set(context_id);
569+
hostcalls::set_effective_context(context_id).unwrap();
570+
root.on_foreign_function(function_id, arugments_size)
571+
}
572+
}
557573
}
558574

559575
#[no_mangle]
@@ -722,3 +738,13 @@ pub extern "C" fn proxy_on_grpc_receive_trailing_metadata(
722738
pub extern "C" fn proxy_on_grpc_close(_context_id: u32, token_id: u32, status_code: u32) {
723739
DISPATCHER.with(|dispatcher| dispatcher.on_grpc_close(token_id, status_code))
724740
}
741+
742+
#[no_mangle]
743+
pub extern "C" fn proxy_on_foreign_function(
744+
context_id: u32,
745+
function_id: u32,
746+
arguments_size: usize,
747+
) {
748+
DISPATCHER
749+
.with(|dispatcher| dispatcher.on_foreign_function(context_id, function_id, arguments_size))
750+
}

Diff for: src/traits.rs

+2
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ pub trait Context {
197197
hostcalls::get_grpc_status().unwrap()
198198
}
199199

200+
fn on_foreign_function(&mut self, _function_id: u32, _arguments_size: usize) {}
201+
200202
fn call_foreign_function(
201203
&self,
202204
function_name: &str,

Diff for: src/types.rs

+1
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)