Skip to content

Commit

Permalink
Updated the supported methods of Calculator (#6)
Browse files Browse the repository at this point in the history
1. Updated the supported methods of Calculator
2.1 Updated the `.js` to test it; The `.js` establishes `WS` connection to calculator service; so, it does not have to say `calculator.add`
2.2 Thunder on the otherhand when request was sent as `calculator.add`, it identifies `RustAdapter.so` as plugin library and send the method to be invoked as `add` to it.
3. Updated the calculator.json with other options available for out-of-process execution
  • Loading branch information
karuna2git authored Sep 1, 2022
1 parent 173dae0 commit 7af4d46
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/calculator/calc_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function send_message() {
let req = {};
req.jsonrpc = "2.0"
req.id = 5;
req.method = "calculator.add";
req.method = "add";
req.params = [2, 2]

const s = JSON.stringify(req);
Expand Down
14 changes: 10 additions & 4 deletions examples/calculator/calculator.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"locator":"libWPEFrameworkRustAdapter.so",
"classname":"RustAdapter",
"callsign":"calculator",
"autostart":false
"locator":"libWPEFrameworkRustAdapter.so",
"classname":"RustAdapter",
"callsign":"calculator",
"autostart":false,
"configuration": {
"outofprocess": false,
"address": "127.0.0.1",
"port": 55556,
"autoexec": true
}
}
4 changes: 2 additions & 2 deletions examples/calculator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ impl Calculator {
fn dispatch_request(&mut self, req: json::JsonValue, ctx: thunder_rs::RequestContext) {
if let Some(method) = req["method"].as_str() {
match method {
"calculator.add" => { self.add(req, ctx); }
"calculator.mul" => { self.mul(req, ctx); }
"add" => { self.add(req, ctx); }
"mul" => { self.mul(req, ctx); }
_ => {
println!("method {} not handled here", method);
}
Expand Down

0 comments on commit 7af4d46

Please sign in to comment.