function registry and msgHandler ported to it

This commit is contained in:
Dan Ballard 2011-01-20 10:20:38 -08:00
parent 872929e730
commit 922ab08c86
1 changed files with 7 additions and 3 deletions

View File

@ -98,7 +98,7 @@ function extractHost(url) {
}
var logging = false
var logging = true
function log(str) {
//if (logCheckElem == null)
@ -236,7 +236,7 @@ var fnreg = new Array;
function registerFn(fnname, fn, preplace) {
path = fnname.split(".");
root = fnreg;
for(i=0; i < path.length()-1; i++) {
for(i=0; i < path.length-1; i++) {
if (root[path[i]] == undefined)
root[path[i]] = new Array();
root = root[path[i]];
@ -260,13 +260,16 @@ function registerFn(fnname, fn, preplace) {
function execFn(name, args) {
root = fnreg;
names = name.split(".");
for (i=0; i< names.length-1; i++) {
for (i=0; i< names.length; i++) {
log("Looking at " + root + " for " + names[i]);
root = root[names[i]];
if (root == undefined)
return false; // ERROR, NO FN
}
i=0;
log("found functions");
while(root[i]) {
log("exec " + i);
root[i](args);
i++;
}
@ -300,6 +303,7 @@ function getMsgHandler(msgName) {
function processMsg(resp) {
log("processMsg: " + resp['query']);
if (!execFn("msgHandler." + resp["query"], resp))
log("Error: Uknnown message '" + resp['query'] + "'");
}