Initial lock support

This commit is contained in:
Dan Ballard 2011-01-14 11:49:41 -08:00
parent fa74d77158
commit 27c3dfc692
3 changed files with 79 additions and 49 deletions

View File

@ -38,8 +38,7 @@
var tests = new Array();
var testLocks = new Array();
var lockTrys = new Array();
var myLocks = new Array();
var runningTests = new Array();
var rangeLocks = new Array();
@ -52,53 +51,7 @@ var runTry = null;
var logCheckElem = null;
function log(str) {
if (logCheckElem == null)
logCheckElem = document.getElementById("logCheck");
if (logCheckElem.checked == true) {
str = getTime() + ": " + str+"\n";
var log = document.getElementById('log');
log.value = str + log.value;
}
}
/*
function log2(str) {
str = getTime() + ": " + str+"\n";
var log = document.getElementById('log');
log.value = str + log.value;
}
*/
function sendReqs(addr) {
for(i in lockTrys) {
var lock = lockTrys[i];
if (lock == null)
continue;
var m = new Object();
m["query"] = "getLock";
m["type"] = i;
m["name"] = lock["name"];
m["time"] = lock.time;
m["addr"] = localNodeAddr;
if (i == "range") {
m["start"] = lock.start;
m["end"] = lock.end;
}
sendMsg(m, addr);
}
}
function sendLocks(addr) {
for (var i in testLocks) {
@ -143,7 +96,7 @@ function sendLocks(addr) {
r = r.next;
}
}
}
} */
function sendTests(addr) {
for(var i in tests) {
@ -152,6 +105,7 @@ function sendTests(addr) {
}
}
/*
function handleAddLock(resp) {
if(resp['locked'] == null)
resp['locked'] = false;
@ -177,6 +131,7 @@ function handleAddLock(resp) {
lock.name = resp['name'];
}
}
*/
function packArray(arr) {
if (arr instanceof Object) {

View File

@ -1,4 +1,5 @@
/* cortex.js
* PURPOSE
* AUTHOR
* LICENSE
*

74
cortexLocks.js Normal file
View File

@ -0,0 +1,74 @@
/* cortexLocks.js
* PURPOSE
* AUTHOR
* LICENSE
*
* NOTES
*/
var locks = new Array();
var lockTrys = new Array();
var myLocks = new Array();
function copyobj(arr) {
c = new Object();
for (i in arr) {
c[i] = arr[i];
}
}
function sendReqs(addr) {
for(ltype in lockTrys) {
for (i in lockTrys[ltype]) {
var lock = lockTrys[ltype][i];
if (lock == null)
continue;
var m = copyobj(lock);
m["query"] = "getLock";
m["type"] = ltype;
sendMsg(m, addr);
}
}
function sendLocks(addr) {
for (ltype in locks) {
for (var i in locks[ltype]) {
log ("testLog[" + i + "]");
var l = testLocks[ltype][i];
var m = copyobj(l);
m["query"] = "addLock";
m["type"] = ltype;
sendMsg(m, addr);
}
}
}
function handleAddLock(resp) {
if(resp['locked'] == null)
resp['locked'] = false;
// dont add/overwrite if exists?
var lock = retrieveLock(resp);
if (resp['type'] == "test" ) {//&& (lock == null || lock.addr == null)) {
var locks = getLockType(resp['type']);
locks[resp['name']] = resp
if(resp['running'] == true) {
runningTests.push(resp['name']);
}
} else if(resp['type'] == "range" && lock.addr == null) {
log("Add range lock: " + resp['name'] + " (" + resp['start'] + " to " + resp['end'] + ") : ");
var lock = getRangeLock(resp['name'], resp['start'], resp['end']);
lock.addr = resp['addr'];
lock.locked = resp['locked'];
lock.done = resp['done'];
lock.results = resp['results'];
lock.name = resp['name'];
}
}