-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
285 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,34 @@ | ||
use ixc_core::Context; | ||
use ixc_message_api::handler::Handler; | ||
use std::collections::HashMap; | ||
use ixc_message_api::code::{Code, SystemErrorCode}; | ||
use ixc_message_api::handler::{Handler, HandlerCode, HostBackend}; | ||
use ixc_message_api::packet::MessagePacket; | ||
use ixc_vm_api::{VMHandlerID, VM}; | ||
|
||
pub struct HandlerID { | ||
vm: u32, | ||
vm_handler_id: VMHandlerID, | ||
struct NativeVM { | ||
next_handler_id: u64, | ||
handlers: HashMap<u64, Box<dyn Handler>>, | ||
handler_names: HashMap<u64, &'static str>, | ||
} | ||
|
||
pub struct VMHandlerID { | ||
package: u64, | ||
handler: u32, | ||
impl NativeVM { | ||
fn register_handler<H: Handler>(&mut self, handler: H) { | ||
let id = self.next_handler_id; | ||
self.next_handler_id += 1; | ||
self.handler_names.insert(id, handler.name()); | ||
self.handlers.insert(id, Box::new(handler)); | ||
} | ||
} | ||
|
||
pub trait VM { | ||
fn get_handler(&self, ctx: &Context, vm_handler_id: VMHandlerID) -> &dyn Handler; | ||
impl VM for NativeVM { | ||
fn run_handler(&self, vm_handler_id: VMHandlerID, message_packet: &mut MessagePacket, callbacks: &dyn HostBackend) -> Code { | ||
if let Some(handler) = self.handlers.get(&vm_handler_id.package) { | ||
let code = handler.handle(message_packet, callbacks); | ||
match code { | ||
HandlerCode::Ok => Code::Ok, | ||
HandlerCode::HandlerError(code) => Code::HandlerError(code), | ||
} | ||
} else { | ||
Code::SystemError(SystemErrorCode::HandlerNotFound) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.