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