From 8a17db8266dad0325d04762a27c4f61446d26d2e Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Sun, 8 Jul 2018 02:45:16 +0200 Subject: Add 'command id' field to messages This allows for correlating response messages to the command message that caused them. --- src/handlers.h | 4 +++- src/handlers.rs | 7 +++++-- src/main.cc | 17 +++++++++-------- src/msg.fbs | 1 + 4 files changed, 18 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/handlers.h b/src/handlers.h index 921ae62b1..b398eca61 100644 --- a/src/handlers.h +++ b/src/handlers.h @@ -3,7 +3,9 @@ #ifndef HANDLERS_H_ #define HANDLERS_H_ extern "C" { -void handle_code_fetch(const char* module_specifier, +#include + +void handle_code_fetch(uint32_t cmd_id, const char* module_specifier, const char* containing_file); } #endif // HANDLERS_H_ diff --git a/src/handlers.rs b/src/handlers.rs index 405fe29da..2b8e51602 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -17,6 +17,7 @@ fn test_example() { #[no_mangle] pub extern "C" fn handle_code_fetch( + cmd_id: u32, module_specifier: *const c_char, containing_file: *const c_char, ) { @@ -24,8 +25,10 @@ pub extern "C" fn handle_code_fetch( let containing_file = string_from_ptr(containing_file); println!( - "handle_code_fetch. module_specifier = {} containing_file = {}", - module_specifier, containing_file + "handle_code_fetch. cmd_id = {} module_specifier = {} containing_file = {}", + cmd_id, + module_specifier, + containing_file ); unimplemented!(); diff --git a/src/main.cc b/src/main.cc index 78c86ee15..a801bc292 100644 --- a/src/main.cc +++ b/src/main.cc @@ -22,7 +22,7 @@ static char** global_argv; static int global_argc; // Sends StartRes message -void HandleStart(Deno* d) { +void HandleStart(Deno* d, uint32_t cmd_id) { flatbuffers::FlatBufferBuilder builder; char cwdbuf[1024]; @@ -37,20 +37,20 @@ void HandleStart(Deno* d) { auto start_argv = builder.CreateVector(args); auto start_msg = CreateStartRes(builder, start_cwd, start_argv); - auto base = CreateBase(builder, 0, Any_StartRes, start_msg.Union()); + auto base = CreateBase(builder, cmd_id, 0, Any_StartRes, start_msg.Union()); builder.Finish(base); deno_buf bufout{reinterpret_cast(builder.GetBufferPointer()), builder.GetSize()}; deno_set_response(d, bufout); } -void HandleCodeFetch(Deno* d, const CodeFetch* msg) { +void HandleCodeFetch(Deno* d, uint32_t cmd_id, const CodeFetch* msg) { auto module_specifier = msg->module_specifier()->c_str(); auto containing_file = msg->containing_file()->c_str(); printf("HandleCodeFetch module_specifier = %s containing_file = %s\n", module_specifier, containing_file); // Call into rust. - handle_code_fetch(module_specifier, containing_file); + handle_code_fetch(cmd_id, module_specifier, containing_file); } void MessagesFromJS(Deno* d, deno_buf buf) { @@ -59,17 +59,18 @@ void MessagesFromJS(Deno* d, deno_buf buf) { DCHECK(verifier.VerifyBuffer()); auto base = flatbuffers::GetRoot(buf.data); + auto cmd_id = base->cmdId(); auto msg_type = base->msg_type(); const char* msg_type_name = EnumNamesAny()[msg_type]; - printf("MessagesFromJS msg_type = %d, msg_type_name = %s\n", msg_type, - msg_type_name); + printf("MessagesFromJS cmd_id = %d, msg_type = %d, msg_type_name = %s\n", + cmd_id, msg_type, msg_type_name); switch (msg_type) { case Any_Start: - HandleStart(d); + HandleStart(d, base->cmdId()); break; case Any_CodeFetch: - HandleCodeFetch(d, base->msg_as_CodeFetch()); + HandleCodeFetch(d, base->cmdId(), base->msg_as_CodeFetch()); break; case Any_NONE: diff --git a/src/msg.fbs b/src/msg.fbs index bda3d6354..b07da99cf 100644 --- a/src/msg.fbs +++ b/src/msg.fbs @@ -18,6 +18,7 @@ union Any { } table Base { + cmdId: uint32; error: string; msg: Any; } -- cgit v1.2.3