Skip to content

Commit

Permalink
feat(http): expose registeredHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Nov 2, 2019
1 parent a28a460 commit e4ed2bc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
5 changes: 5 additions & 0 deletions lib/ag-solo/vats/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export default function setup(syscall, state, helpers) {
moolaMint: await E(vats.mints).getMint('moola'),
simoleanMint: await E(vats.mints).getMint('simolean'),
spawner,
http: {
registerCommandHandler(handler) {
return E(vats.http).registerCommandHandler(handler);
},
},
wallet: await E(vats.wallet).getWallet(),
});
}
Expand Down
18 changes: 12 additions & 6 deletions lib/ag-solo/vats/vat-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ function build(E, D) {
const registeredHandlers = [];
let canvasState;

// TODO: Don't leak memory.
async function registerCommandHandler(newHandler) {
const commandHandler = await E(newHandler).getCommandHandler();
registeredHandlers.push(commandHandler);
}

return {
setCommandDevice(d, ROLES) {
commandDevice = d;
Expand Down Expand Up @@ -118,10 +124,7 @@ function build(E, D) {
}
},

async registerCommandHandler(newHandler) {
const commandHandler = await E(newHandler).getCommandHandler();
registeredHandlers.push(commandHandler);
},
registerCommandHandler,

setProvisioner(p) {
provisioner = p;
Expand Down Expand Up @@ -171,8 +174,11 @@ function build(E, D) {
res = await handler[type](obj);
} else {
// todo fixme avoid the loop
for (let i = 0; i < registeredHandlers.length; i++) {
res = await E(registeredHandlers[i]).processInbound(obj);
// For now, go from the end to beginning so that handlers
// override.
const hardObjects = harden({...homeObjects});
for (let i = registeredHandlers.length - 1; i >= 0; i++) {
res = await E(registeredHandlers[i]).processInbound(obj, hardObjects);
if (res) {
break;
}
Expand Down

0 comments on commit e4ed2bc

Please sign in to comment.