diff options
| author | Tristan Zur <tzur@web.web.ccwn.org> | 2014-03-27 22:27:47 +0100 |
|---|---|---|
| committer | Tristan Zur <tzur@web.web.ccwn.org> | 2014-03-27 22:27:47 +0100 |
| commit | b62676ca5d3d6f6ba3f019ea3f99722e165a98d8 (patch) | |
| tree | 86722cb80f07d4569f90088eeaea2fc2f6e2ef94 /js/dojo-1.6/dojox/timing | |
Diffstat (limited to 'js/dojo-1.6/dojox/timing')
| -rw-r--r-- | js/dojo-1.6/dojox/timing/README | 63 | ||||
| -rw-r--r-- | js/dojo-1.6/dojox/timing/Sequence.js | 158 | ||||
| -rw-r--r-- | js/dojo-1.6/dojox/timing/Sequence.xd.js | 162 | ||||
| -rw-r--r-- | js/dojo-1.6/dojox/timing/Streamer.js | 101 | ||||
| -rw-r--r-- | js/dojo-1.6/dojox/timing/Streamer.xd.js | 106 | ||||
| -rw-r--r-- | js/dojo-1.6/dojox/timing/ThreadPool.js | 164 | ||||
| -rw-r--r-- | js/dojo-1.6/dojox/timing/ThreadPool.xd.js | 169 | ||||
| -rw-r--r-- | js/dojo-1.6/dojox/timing/_base.js | 65 | ||||
| -rw-r--r-- | js/dojo-1.6/dojox/timing/_base.xd.js | 69 | ||||
| -rw-r--r-- | js/dojo-1.6/dojox/timing/doLater.js | 53 | ||||
| -rw-r--r-- | js/dojo-1.6/dojox/timing/doLater.xd.js | 57 |
11 files changed, 1167 insertions, 0 deletions
diff --git a/js/dojo-1.6/dojox/timing/README b/js/dojo-1.6/dojox/timing/README new file mode 100644 index 0000000..6673d19 --- /dev/null +++ b/js/dojo-1.6/dojox/timing/README @@ -0,0 +1,63 @@ +------------------------------------------------------------------------------- +DojoX Timing +------------------------------------------------------------------------------- +Version 0.1.0 +Release date: 08/08/2007 +------------------------------------------------------------------------------- +Project state: +experimental +------------------------------------------------------------------------------- +Credits + Tom Trenka (ttrenka AT gmail.com): original Timer, Streamer, Thread and ThreadPool + Wolfram Kriesing (http://wolfram.kriesing.de/blog/): Sequence + Jonathan Bond-Caron (jbondc AT gmail.com): port of Timer and Streamer + Pete Higgins (phiggins AT gmail.com): port of Sequence + Mike Wilcox (anm8tr AT yahoo.com): dojo.doLater +------------------------------------------------------------------------------- +Project description + +DojoX Timing is a project that deals with any kind of advanced use of timing +constructs. The central object, dojox.timing.Timer (included by default), is +a simple object that fires a callback on each tick of the timer, as well as +when starting or stopping it. The interval of each tick is settable, but the +default is 1 second--useful for driving something such as a clock. + +dojox.timing.Streamer is an object designed to facilitate streaming/buffer-type +scenarios; it takes an input and an output function, will execute the output +function onTick, and run the input function when the internal buffer gets +beneath a certain threshold of items. This can be useful for something timed-- +such as updating a data plot at every N interval, and getting new data from +a source when there's less than X data points in the internal buffer (think +real-time data updating). + +dojox.timing.Sequencer is an object, similar to Streamer, that will allow you +to set up a set of functions to be executed in a specific order, at specific +intervals. + +The DojoX Timing ThreadPool is a port from the original implementation in the +f(m) library. It allows a user to feed a set of callback functions (wrapped +in a Thread constructor) to a pool for background processing. + +dojo.doLater() provides a simple mechanism that checks a conditional before allowing +your function to continue. If the conditional is false, the function is blocked and continually +re-called, with arguments, until the conditional passes. +------------------------------------------------------------------------------- +Dependencies: + +DojoX Timing only relies on the Dojo Base. +------------------------------------------------------------------------------- +Documentation + +TBD. +------------------------------------------------------------------------------- +Installation instructions + +Grab the following from the Dojo SVN Repository: +http://svn.dojotoolkit.org/var/src/dojo/dojox/trunk/timing.js +http://svn.dojotoolkit.org/var/src/dojo/dojox/trunk/timing/* + +Install into the following directory structure: +/dojox/timing.js +/dojox/timing/ + +...which should be at the same level as your Dojo checkout. diff --git a/js/dojo-1.6/dojox/timing/Sequence.js b/js/dojo-1.6/dojox/timing/Sequence.js new file mode 100644 index 0000000..2a101df --- /dev/null +++ b/js/dojo-1.6/dojox/timing/Sequence.js @@ -0,0 +1,158 @@ +/*
+ Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
+ Available via Academic Free License >= 2.1 OR the modified BSD license.
+ see: http://dojotoolkit.org/license for details
+*/
+
+
+if(!dojo._hasResource["dojox.timing.Sequence"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojox.timing.Sequence"] = true;
+dojo.provide("dojox.timing.Sequence");
+dojo.experimental("dojox.timing.Sequence");
+
+dojo.declare("dojox.timing.Sequence", null, {
+ // summary:
+ // This class provides functionality to really sequentialize
+ // function calls. You need to provide a list of functions and
+ // some parameters for each (like: pauseBefore) and they will
+ // be run one after another. This can be very useful for slideshows
+ // or alike things.
+ //
+ // description:
+ // This array will contain the sequence defines resolved, so that
+ // ie. repeat:10 will result in 10 elements in the sequence, so
+ // the repeat handling is easier and we don't need to handle that
+ // many extra cases. Also the doneFunction, if given is added at the
+ // end of the resolved-sequences.
+
+/*=====
+ // _defsResolved: Array
+ // The resolved sequence, for easier handling.
+ _defsResolved: [],
+=====*/
+
+ // This is the time to wait before goOn() calls _go(), which
+ // mostly results from a pauseAfter for a function that returned
+ // false and is later continued by the external goOn() call.
+ // The time to wait needs to be waited in goOn() where the
+ // sequence is continued.
+
+ // _goOnPause: Integer
+ // The pause to wait before really going on.
+ _goOnPause: 0,
+
+ _running: false,
+
+ constructor: function(){
+ this._defsResolved = [];
+ },
+
+ go: function(/* Array */defs, /* Function|Array? */doneFunction){
+ // summary: Run the passed sequence definition
+ //
+ // defs: Array
+ // The sequence of actions
+ // doneFunction: Function|Array?
+ // The function to call when done
+ this._running = true;
+ dojo.forEach(defs, function(cur){
+ if(cur.repeat > 1){
+ var repeat = cur.repeat;
+ for(var j = 0; j < repeat; j++){
+ cur.repeat = 1;
+ this._defsResolved.push(cur);
+ }
+ }else{
+ this._defsResolved.push(cur);
+ }
+ }, this);
+ var last = defs[defs.length - 1];
+ if(doneFunction){
+ this._defsResolved.push({ func: doneFunction });
+ }
+ // stop the sequence, this actually just sets this._running to false
+ this._defsResolved.push({ func: [this.stop, this] });
+ this._curId = 0;
+ this._go();
+ },
+
+ _go: function(){
+ // summary: Execute one task of this._defsResolved.
+
+ // if _running was set to false stop the sequence, this is the
+ // case when i.e. stop() was called.
+ if(!this._running){
+ return;
+ }
+ var cur = this._defsResolved[this._curId];
+ this._curId += 1;
+ // create the function to call, the func property might be an array, which means
+ // [function, context, parameter1, parameter2, ...]
+ function resolveAndCallFunc(func) {
+ var ret = null;
+ if(dojo.isArray(func)){
+ // Two elements might only be given when the function+context
+ // is given, this is nice for using this, ie: [this.func, this]
+ if(func.length>2){
+ ret = func[0].apply(func[1], func.slice(2));
+ }else{
+ ret = func[0].apply(func[1]);
+ }
+ }else{
+ ret = func();
+ }
+ return ret;
+ }
+
+ if(this._curId >= this._defsResolved.length){
+ resolveAndCallFunc(cur.func); // call the last function, since it is the doneFunction we dont need to handle pause stuff
+ // don't go on and call this._go() again, we are done
+ return;
+ }
+
+ if(cur.pauseAfter){
+ if(resolveAndCallFunc(cur.func) !== false){
+ setTimeout(dojo.hitch(this, "_go"), cur.pauseAfter);
+ }else{
+ this._goOnPause = cur.pauseAfter;
+ }
+ }else if(cur.pauseBefore){
+ var x = dojo.hitch(this,function(){
+ if(resolveAndCallFunc(cur.func) !== false){
+ this._go()
+ }
+ });
+ setTimeout(x, cur.pauseBefore);
+ }else{
+ if(resolveAndCallFunc(cur.func) !== false){
+ this._go();
+ }
+ }
+ },
+
+ goOn: function(){
+ // summary: This method just provides a hook from the outside, so that
+ // an interrupted sequence can be continued.
+ if(this._goOnPause){
+ setTimeout(dojo.hitch(this, "_go"), this._goOnPause);
+ this._goOnPause = 0; // reset it, so if the next one doesnt set it we dont use the old pause
+ }else{ this._go(); }
+ },
+
+ stop: function(){
+ // summary: Stop the currently running sequence.
+ //
+ // description:
+ // This can only interrupt the sequence not the last function that
+ // had been started. If the last function was i.e. a slideshow
+ // that is handled inside a function that you have given as
+ // one sequence item it cant be stopped, since it is not controlled
+ // by this object here. In this case it would be smarter to
+ // run the slideshow using a sequence object so you can also stop
+ // it using this method.
+ this._running = false;
+ }
+
+});
+
+}
diff --git a/js/dojo-1.6/dojox/timing/Sequence.xd.js b/js/dojo-1.6/dojox/timing/Sequence.xd.js new file mode 100644 index 0000000..3b270af --- /dev/null +++ b/js/dojo-1.6/dojox/timing/Sequence.xd.js @@ -0,0 +1,162 @@ +/*
+ Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
+ Available via Academic Free License >= 2.1 OR the modified BSD license.
+ see: http://dojotoolkit.org/license for details
+*/
+
+
+dojo._xdResourceLoaded(function(dojo, dijit, dojox){
+return {depends: [["provide", "dojox.timing.Sequence"]],
+defineResource: function(dojo, dijit, dojox){if(!dojo._hasResource["dojox.timing.Sequence"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojox.timing.Sequence"] = true;
+dojo.provide("dojox.timing.Sequence");
+dojo.experimental("dojox.timing.Sequence");
+
+dojo.declare("dojox.timing.Sequence", null, {
+ // summary:
+ // This class provides functionality to really sequentialize
+ // function calls. You need to provide a list of functions and
+ // some parameters for each (like: pauseBefore) and they will
+ // be run one after another. This can be very useful for slideshows
+ // or alike things.
+ //
+ // description:
+ // This array will contain the sequence defines resolved, so that
+ // ie. repeat:10 will result in 10 elements in the sequence, so
+ // the repeat handling is easier and we don't need to handle that
+ // many extra cases. Also the doneFunction, if given is added at the
+ // end of the resolved-sequences.
+
+/*=====
+ // _defsResolved: Array
+ // The resolved sequence, for easier handling.
+ _defsResolved: [],
+=====*/
+
+ // This is the time to wait before goOn() calls _go(), which
+ // mostly results from a pauseAfter for a function that returned
+ // false and is later continued by the external goOn() call.
+ // The time to wait needs to be waited in goOn() where the
+ // sequence is continued.
+
+ // _goOnPause: Integer
+ // The pause to wait before really going on.
+ _goOnPause: 0,
+
+ _running: false,
+
+ constructor: function(){
+ this._defsResolved = [];
+ },
+
+ go: function(/* Array */defs, /* Function|Array? */doneFunction){
+ // summary: Run the passed sequence definition
+ //
+ // defs: Array
+ // The sequence of actions
+ // doneFunction: Function|Array?
+ // The function to call when done
+ this._running = true;
+ dojo.forEach(defs, function(cur){
+ if(cur.repeat > 1){
+ var repeat = cur.repeat;
+ for(var j = 0; j < repeat; j++){
+ cur.repeat = 1;
+ this._defsResolved.push(cur);
+ }
+ }else{
+ this._defsResolved.push(cur);
+ }
+ }, this);
+ var last = defs[defs.length - 1];
+ if(doneFunction){
+ this._defsResolved.push({ func: doneFunction });
+ }
+ // stop the sequence, this actually just sets this._running to false
+ this._defsResolved.push({ func: [this.stop, this] });
+ this._curId = 0;
+ this._go();
+ },
+
+ _go: function(){
+ // summary: Execute one task of this._defsResolved.
+
+ // if _running was set to false stop the sequence, this is the
+ // case when i.e. stop() was called.
+ if(!this._running){
+ return;
+ }
+ var cur = this._defsResolved[this._curId];
+ this._curId += 1;
+ // create the function to call, the func property might be an array, which means
+ // [function, context, parameter1, parameter2, ...]
+ function resolveAndCallFunc(func) {
+ var ret = null;
+ if(dojo.isArray(func)){
+ // Two elements might only be given when the function+context
+ // is given, this is nice for using this, ie: [this.func, this]
+ if(func.length>2){
+ ret = func[0].apply(func[1], func.slice(2));
+ }else{
+ ret = func[0].apply(func[1]);
+ }
+ }else{
+ ret = func();
+ }
+ return ret;
+ }
+
+ if(this._curId >= this._defsResolved.length){
+ resolveAndCallFunc(cur.func); // call the last function, since it is the doneFunction we dont need to handle pause stuff
+ // don't go on and call this._go() again, we are done
+ return;
+ }
+
+ if(cur.pauseAfter){
+ if(resolveAndCallFunc(cur.func) !== false){
+ setTimeout(dojo.hitch(this, "_go"), cur.pauseAfter);
+ }else{
+ this._goOnPause = cur.pauseAfter;
+ }
+ }else if(cur.pauseBefore){
+ var x = dojo.hitch(this,function(){
+ if(resolveAndCallFunc(cur.func) !== false){
+ this._go()
+ }
+ });
+ setTimeout(x, cur.pauseBefore);
+ }else{
+ if(resolveAndCallFunc(cur.func) !== false){
+ this._go();
+ }
+ }
+ },
+
+ goOn: function(){
+ // summary: This method just provides a hook from the outside, so that
+ // an interrupted sequence can be continued.
+ if(this._goOnPause){
+ setTimeout(dojo.hitch(this, "_go"), this._goOnPause);
+ this._goOnPause = 0; // reset it, so if the next one doesnt set it we dont use the old pause
+ }else{ this._go(); }
+ },
+
+ stop: function(){
+ // summary: Stop the currently running sequence.
+ //
+ // description:
+ // This can only interrupt the sequence not the last function that
+ // had been started. If the last function was i.e. a slideshow
+ // that is handled inside a function that you have given as
+ // one sequence item it cant be stopped, since it is not controlled
+ // by this object here. In this case it would be smarter to
+ // run the slideshow using a sequence object so you can also stop
+ // it using this method.
+ this._running = false;
+ }
+
+});
+
+}
+
+}};});
diff --git a/js/dojo-1.6/dojox/timing/Streamer.js b/js/dojo-1.6/dojox/timing/Streamer.js new file mode 100644 index 0000000..07747d8 --- /dev/null +++ b/js/dojo-1.6/dojox/timing/Streamer.js @@ -0,0 +1,101 @@ +/*
+ Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
+ Available via Academic Free License >= 2.1 OR the modified BSD license.
+ see: http://dojotoolkit.org/license for details
+*/
+
+
+if(!dojo._hasResource["dojox.timing.Streamer"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojox.timing.Streamer"] = true;
+dojo.provide("dojox.timing.Streamer");
+
+dojo.require("dojox.timing._base");
+
+dojox.timing.Streamer = function(
+ /* function */input,
+ /* function */output,
+ /* int */interval,
+ /* int */minimum,
+ /* array */initialData
+){
+ // summary
+ // Streamer will take an input function that pushes N datapoints into a
+ // queue, and will pass the next point in that queue out to an
+ // output function at the passed interval; this way you can emulate
+ // a constant buffered stream of data.
+ // input: the function executed when the internal queue reaches minimumSize
+ // output: the function executed on internal tick
+ // interval: the interval in ms at which the output function is fired.
+ // minimum: the minimum number of elements in the internal queue.
+
+ var self = this;
+ var queue = [];
+
+ // public properties
+ this.interval = interval || 1000;
+ this.minimumSize = minimum || 10; // latency usually == interval * minimumSize
+ this.inputFunction = input || function(q){ };
+ this.outputFunction = output || function(point){ };
+
+ // more setup
+ var timer = new dojox.timing.Timer(this.interval);
+ var tick = function(){
+ self.onTick(self);
+
+ if(queue.length < self.minimumSize){
+ self.inputFunction(queue);
+ }
+
+ var obj = queue.shift();
+ while(typeof(obj) == "undefined" && queue.length > 0){
+ obj = queue.shift();
+ }
+
+ // check to see if the input function needs to be fired
+ // stop before firing the output function
+ // TODO: relegate this to the output function?
+ if(typeof(obj) == "undefined"){
+ self.stop();
+ return;
+ }
+
+ // call the output function.
+ self.outputFunction(obj);
+ };
+
+ this.setInterval = function(/* int */ms){
+ // summary
+ // sets the interval in milliseconds of the internal timer
+ this.interval = ms;
+ timer.setInterval(ms);
+ };
+
+ this.onTick = function(/* dojox.timing.Streamer */obj){ };
+ // wrap the timer functions so that we can connect to them if needed.
+ this.start = function(){
+ // summary
+ // starts the Streamer
+ if(typeof(this.inputFunction) == "function" && typeof(this.outputFunction) == "function"){
+ timer.start();
+ return;
+ }
+ throw new Error("You cannot start a Streamer without an input and an output function.");
+ };
+ this.onStart = function(){ };
+ this.stop = function(){
+ // summary
+ // stops the Streamer
+ timer.stop();
+ };
+ this.onStop = function(){ };
+
+ // finish initialization
+ timer.onTick = this.tick;
+ timer.onStart = this.onStart;
+ timer.onStop = this.onStop;
+ if(initialData){
+ queue.concat(initialData);
+ }
+};
+
+}
diff --git a/js/dojo-1.6/dojox/timing/Streamer.xd.js b/js/dojo-1.6/dojox/timing/Streamer.xd.js new file mode 100644 index 0000000..77ba944 --- /dev/null +++ b/js/dojo-1.6/dojox/timing/Streamer.xd.js @@ -0,0 +1,106 @@ +/*
+ Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
+ Available via Academic Free License >= 2.1 OR the modified BSD license.
+ see: http://dojotoolkit.org/license for details
+*/
+
+
+dojo._xdResourceLoaded(function(dojo, dijit, dojox){
+return {depends: [["provide", "dojox.timing.Streamer"],
+["require", "dojox.timing._base"]],
+defineResource: function(dojo, dijit, dojox){if(!dojo._hasResource["dojox.timing.Streamer"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojox.timing.Streamer"] = true;
+dojo.provide("dojox.timing.Streamer");
+
+dojo.require("dojox.timing._base");
+
+dojox.timing.Streamer = function(
+ /* function */input,
+ /* function */output,
+ /* int */interval,
+ /* int */minimum,
+ /* array */initialData
+){
+ // summary
+ // Streamer will take an input function that pushes N datapoints into a
+ // queue, and will pass the next point in that queue out to an
+ // output function at the passed interval; this way you can emulate
+ // a constant buffered stream of data.
+ // input: the function executed when the internal queue reaches minimumSize
+ // output: the function executed on internal tick
+ // interval: the interval in ms at which the output function is fired.
+ // minimum: the minimum number of elements in the internal queue.
+
+ var self = this;
+ var queue = [];
+
+ // public properties
+ this.interval = interval || 1000;
+ this.minimumSize = minimum || 10; // latency usually == interval * minimumSize
+ this.inputFunction = input || function(q){ };
+ this.outputFunction = output || function(point){ };
+
+ // more setup
+ var timer = new dojox.timing.Timer(this.interval);
+ var tick = function(){
+ self.onTick(self);
+
+ if(queue.length < self.minimumSize){
+ self.inputFunction(queue);
+ }
+
+ var obj = queue.shift();
+ while(typeof(obj) == "undefined" && queue.length > 0){
+ obj = queue.shift();
+ }
+
+ // check to see if the input function needs to be fired
+ // stop before firing the output function
+ // TODO: relegate this to the output function?
+ if(typeof(obj) == "undefined"){
+ self.stop();
+ return;
+ }
+
+ // call the output function.
+ self.outputFunction(obj);
+ };
+
+ this.setInterval = function(/* int */ms){
+ // summary
+ // sets the interval in milliseconds of the internal timer
+ this.interval = ms;
+ timer.setInterval(ms);
+ };
+
+ this.onTick = function(/* dojox.timing.Streamer */obj){ };
+ // wrap the timer functions so that we can connect to them if needed.
+ this.start = function(){
+ // summary
+ // starts the Streamer
+ if(typeof(this.inputFunction) == "function" && typeof(this.outputFunction) == "function"){
+ timer.start();
+ return;
+ }
+ throw new Error("You cannot start a Streamer without an input and an output function.");
+ };
+ this.onStart = function(){ };
+ this.stop = function(){
+ // summary
+ // stops the Streamer
+ timer.stop();
+ };
+ this.onStop = function(){ };
+
+ // finish initialization
+ timer.onTick = this.tick;
+ timer.onStart = this.onStart;
+ timer.onStop = this.onStop;
+ if(initialData){
+ queue.concat(initialData);
+ }
+};
+
+}
+
+}};});
diff --git a/js/dojo-1.6/dojox/timing/ThreadPool.js b/js/dojo-1.6/dojox/timing/ThreadPool.js new file mode 100644 index 0000000..17160dd --- /dev/null +++ b/js/dojo-1.6/dojox/timing/ThreadPool.js @@ -0,0 +1,164 @@ +/*
+ Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
+ Available via Academic Free License >= 2.1 OR the modified BSD license.
+ see: http://dojotoolkit.org/license for details
+*/
+
+
+if(!dojo._hasResource["dojox.timing.ThreadPool"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojox.timing.ThreadPool"] = true;
+dojo.provide("dojox.timing.ThreadPool");
+dojo.require("dojox.timing");
+
+dojo.experimental("dojox.timing.ThreadPool");
+
+// dojox.timing.Timer is included as part of _base
+/********************************************************************
+ This is a port of the original System.Threading.ThreadPool from
+ the f(m) class library.
+
+ Donated to the Dojo toolkit by the author :)
+*********************************************************************/
+(function(){
+ var t=dojox.timing;
+ t.threadStates={
+ UNSTARTED:"unstarted",
+ STOPPED:"stopped",
+ PENDING:"pending",
+ RUNNING:"running",
+ SUSPENDED:"suspended",
+ WAITING:"waiting",
+ COMPLETE:"complete",
+ ERROR:"error"
+ };
+
+ // Before rar says a word, we actually *use* these numbers for a purpose :)
+ t.threadPriorities={
+ LOWEST:1,
+ BELOWNORMAL:2,
+ NORMAL:3,
+ ABOVENORMAL:4,
+ HIGHEST:5
+ };
+
+ t.Thread=function(/* Function */fn, /* dojox.timing.threadPriorities? */priority){
+ var self=this;
+ this.state=t.threadStates.UNSTARTED;
+ this.priority=priority||t.threadPriorities.NORMAL;
+ this.lastError=null;
+ this.func=fn; // for lookup purposes.
+ this.invoke=function(){
+ self.state=t.threadStates.RUNNING;
+ try{
+ fn(this);
+ self.state=t.threadStates.COMPLETE;
+ }catch(e){
+ self.lastError=e;
+ self.state=t.threadStates.ERROR;
+ }
+ };
+ };
+
+ // TODO: allow for changing of maxThreads and tick interval
+ t.ThreadPool=new (function(/* Number */mxthrs, /* Number */intvl){
+ var self=this;
+ var maxThreads=mxthrs;
+ var availableThreads=maxThreads;
+ var interval=intvl;
+ var fireInterval=Math.floor((interval/2)/maxThreads);
+ var queue=[];
+ var timers=new Array(maxThreads+1);
+ var timer=new dojox.timing.Timer();
+ var invoke=function(){
+ var tracker=timers[0]={};
+ for(var i=0; i<timers.length; i++){
+ window.clearTimeout(timers[i]);
+ var thread=queue.shift();
+ if(typeof(thread)=="undefined"){ break; }
+ tracker["thread-"+i]=thread;
+ timers[i]=window.setTimeout(thread.invoke,(fireInterval*i));
+ }
+ availableThreads=maxThreads-(i-1);
+ };
+
+ // public methods
+ this.getMaxThreads=function(){ return maxThreads; };
+ this.getAvailableThreads=function(){ return availableThreads; };
+ this.getTickInterval=function(){ return interval; };
+ this.queueUserWorkItem=function(/* Function || dojox.timing.Thread */fn){
+ var item=fn;
+ if(item instanceof Function){
+ item=new t.Thread(item);
+ }
+ var idx=queue.length;
+ for(var i=0; i<queue.length; i++){
+ if(queue[i].priority<item.priority){
+ idx=i;
+ break;
+ }
+ }
+ if(idx<queue.length){
+ queue.splice(idx, 0, item);
+ } else {
+ queue.push(item);
+ }
+ return true;
+ };
+ this.removeQueuedUserWorkItem=function(/* Function || dojox.timing.Thread */item){
+ if(item instanceof Function){
+ var idx=-1;
+ for(var i=0; i<queue.length; i++){
+ if(queue[i].func==item){
+ idx=i;
+ break;
+ }
+ }
+ if(idx>-1){
+ queue.splice(idx,1);
+ return true;
+ }
+ return false;
+ }
+
+ var idx=-1;
+ for(var i=0; i<queue.length; i++){
+ if(queue[i]==item){
+ idx=i;
+ break;
+ }
+ }
+ if(idx>-1){
+ queue.splice(idx,1);
+ return true;
+ }
+ return false;
+ };
+ this.start=function(){ timer.start(); };
+ this.stop=function(){ timer.stop(); };
+ this.abort=function(){
+ this.stop();
+ for(var i=1; i<timers.length; i++){
+ if(timers[i]){
+ window.clearTimeout(timers[i]);
+ }
+ }
+ for(var thread in timers[0]){
+ this.queueUserWorkItem(thread);
+ }
+ timers[0]={};
+ };
+ this.reset=function(){
+ this.abort();
+ queue=[];
+ };
+ this.sleep=function(/* Number */nSleep){
+ timer.stop();
+ window.setTimeout(timer.start, nSleep);
+ };
+
+ // dedicate the timer to us.
+ timer.onTick=self.invoke;
+ })(16, 5000);
+})();
+
+}
diff --git a/js/dojo-1.6/dojox/timing/ThreadPool.xd.js b/js/dojo-1.6/dojox/timing/ThreadPool.xd.js new file mode 100644 index 0000000..d70c39f --- /dev/null +++ b/js/dojo-1.6/dojox/timing/ThreadPool.xd.js @@ -0,0 +1,169 @@ +/*
+ Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
+ Available via Academic Free License >= 2.1 OR the modified BSD license.
+ see: http://dojotoolkit.org/license for details
+*/
+
+
+dojo._xdResourceLoaded(function(dojo, dijit, dojox){
+return {depends: [["provide", "dojox.timing.ThreadPool"],
+["require", "dojox.timing"]],
+defineResource: function(dojo, dijit, dojox){if(!dojo._hasResource["dojox.timing.ThreadPool"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojox.timing.ThreadPool"] = true;
+dojo.provide("dojox.timing.ThreadPool");
+dojo.require("dojox.timing");
+
+dojo.experimental("dojox.timing.ThreadPool");
+
+// dojox.timing.Timer is included as part of _base
+/********************************************************************
+ This is a port of the original System.Threading.ThreadPool from
+ the f(m) class library.
+
+ Donated to the Dojo toolkit by the author :)
+*********************************************************************/
+(function(){
+ var t=dojox.timing;
+ t.threadStates={
+ UNSTARTED:"unstarted",
+ STOPPED:"stopped",
+ PENDING:"pending",
+ RUNNING:"running",
+ SUSPENDED:"suspended",
+ WAITING:"waiting",
+ COMPLETE:"complete",
+ ERROR:"error"
+ };
+
+ // Before rar says a word, we actually *use* these numbers for a purpose :)
+ t.threadPriorities={
+ LOWEST:1,
+ BELOWNORMAL:2,
+ NORMAL:3,
+ ABOVENORMAL:4,
+ HIGHEST:5
+ };
+
+ t.Thread=function(/* Function */fn, /* dojox.timing.threadPriorities? */priority){
+ var self=this;
+ this.state=t.threadStates.UNSTARTED;
+ this.priority=priority||t.threadPriorities.NORMAL;
+ this.lastError=null;
+ this.func=fn; // for lookup purposes.
+ this.invoke=function(){
+ self.state=t.threadStates.RUNNING;
+ try{
+ fn(this);
+ self.state=t.threadStates.COMPLETE;
+ }catch(e){
+ self.lastError=e;
+ self.state=t.threadStates.ERROR;
+ }
+ };
+ };
+
+ // TODO: allow for changing of maxThreads and tick interval
+ t.ThreadPool=new (function(/* Number */mxthrs, /* Number */intvl){
+ var self=this;
+ var maxThreads=mxthrs;
+ var availableThreads=maxThreads;
+ var interval=intvl;
+ var fireInterval=Math.floor((interval/2)/maxThreads);
+ var queue=[];
+ var timers=new Array(maxThreads+1);
+ var timer=new dojox.timing.Timer();
+ var invoke=function(){
+ var tracker=timers[0]={};
+ for(var i=0; i<timers.length; i++){
+ window.clearTimeout(timers[i]);
+ var thread=queue.shift();
+ if(typeof(thread)=="undefined"){ break; }
+ tracker["thread-"+i]=thread;
+ timers[i]=window.setTimeout(thread.invoke,(fireInterval*i));
+ }
+ availableThreads=maxThreads-(i-1);
+ };
+
+ // public methods
+ this.getMaxThreads=function(){ return maxThreads; };
+ this.getAvailableThreads=function(){ return availableThreads; };
+ this.getTickInterval=function(){ return interval; };
+ this.queueUserWorkItem=function(/* Function || dojox.timing.Thread */fn){
+ var item=fn;
+ if(item instanceof Function){
+ item=new t.Thread(item);
+ }
+ var idx=queue.length;
+ for(var i=0; i<queue.length; i++){
+ if(queue[i].priority<item.priority){
+ idx=i;
+ break;
+ }
+ }
+ if(idx<queue.length){
+ queue.splice(idx, 0, item);
+ } else {
+ queue.push(item);
+ }
+ return true;
+ };
+ this.removeQueuedUserWorkItem=function(/* Function || dojox.timing.Thread */item){
+ if(item instanceof Function){
+ var idx=-1;
+ for(var i=0; i<queue.length; i++){
+ if(queue[i].func==item){
+ idx=i;
+ break;
+ }
+ }
+ if(idx>-1){
+ queue.splice(idx,1);
+ return true;
+ }
+ return false;
+ }
+
+ var idx=-1;
+ for(var i=0; i<queue.length; i++){
+ if(queue[i]==item){
+ idx=i;
+ break;
+ }
+ }
+ if(idx>-1){
+ queue.splice(idx,1);
+ return true;
+ }
+ return false;
+ };
+ this.start=function(){ timer.start(); };
+ this.stop=function(){ timer.stop(); };
+ this.abort=function(){
+ this.stop();
+ for(var i=1; i<timers.length; i++){
+ if(timers[i]){
+ window.clearTimeout(timers[i]);
+ }
+ }
+ for(var thread in timers[0]){
+ this.queueUserWorkItem(thread);
+ }
+ timers[0]={};
+ };
+ this.reset=function(){
+ this.abort();
+ queue=[];
+ };
+ this.sleep=function(/* Number */nSleep){
+ timer.stop();
+ window.setTimeout(timer.start, nSleep);
+ };
+
+ // dedicate the timer to us.
+ timer.onTick=self.invoke;
+ })(16, 5000);
+})();
+
+}
+
+}};});
diff --git a/js/dojo-1.6/dojox/timing/_base.js b/js/dojo-1.6/dojox/timing/_base.js new file mode 100644 index 0000000..577d7e5 --- /dev/null +++ b/js/dojo-1.6/dojox/timing/_base.js @@ -0,0 +1,65 @@ +/*
+ Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
+ Available via Academic Free License >= 2.1 OR the modified BSD license.
+ see: http://dojotoolkit.org/license for details
+*/
+
+
+if(!dojo._hasResource["dojox.timing._base"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojox.timing._base"] = true;
+dojo.provide("dojox.timing._base");
+dojo.experimental("dojox.timing");
+
+dojox.timing.Timer = function(/*int*/ interval){
+ // summary: Timer object executes an "onTick()" method repeatedly at a specified interval.
+ // repeatedly at a given interval.
+ // interval: Interval between function calls, in milliseconds.
+ this.timer = null;
+ this.isRunning = false;
+ this.interval = interval;
+
+ this.onStart = null;
+ this.onStop = null;
+};
+
+dojo.extend(dojox.timing.Timer, {
+ onTick : function(){
+ // summary: Method called every time the interval passes. Override to do something useful.
+ },
+
+ setInterval : function(interval){
+ // summary: Reset the interval of a timer, whether running or not.
+ // interval: New interval, in milliseconds.
+ if (this.isRunning){
+ window.clearInterval(this.timer);
+ }
+ this.interval = interval;
+ if (this.isRunning){
+ this.timer = window.setInterval(dojo.hitch(this, "onTick"), this.interval);
+ }
+ },
+
+ start : function(){
+ // summary: Start the timer ticking.
+ // description: Calls the "onStart()" handler, if defined.
+ // Note that the onTick() function is not called right away,
+ // only after first interval passes.
+ if (typeof this.onStart == "function"){
+ this.onStart();
+ }
+ this.isRunning = true;
+ this.timer = window.setInterval(dojo.hitch(this, "onTick"), this.interval);
+ },
+
+ stop : function(){
+ // summary: Stop the timer.
+ // description: Calls the "onStop()" handler, if defined.
+ if (typeof this.onStop == "function"){
+ this.onStop();
+ }
+ this.isRunning = false;
+ window.clearInterval(this.timer);
+ }
+});
+
+}
diff --git a/js/dojo-1.6/dojox/timing/_base.xd.js b/js/dojo-1.6/dojox/timing/_base.xd.js new file mode 100644 index 0000000..7e3ee3e --- /dev/null +++ b/js/dojo-1.6/dojox/timing/_base.xd.js @@ -0,0 +1,69 @@ +/*
+ Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
+ Available via Academic Free License >= 2.1 OR the modified BSD license.
+ see: http://dojotoolkit.org/license for details
+*/
+
+
+dojo._xdResourceLoaded(function(dojo, dijit, dojox){
+return {depends: [["provide", "dojox.timing._base"]],
+defineResource: function(dojo, dijit, dojox){if(!dojo._hasResource["dojox.timing._base"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojox.timing._base"] = true;
+dojo.provide("dojox.timing._base");
+dojo.experimental("dojox.timing");
+
+dojox.timing.Timer = function(/*int*/ interval){
+ // summary: Timer object executes an "onTick()" method repeatedly at a specified interval.
+ // repeatedly at a given interval.
+ // interval: Interval between function calls, in milliseconds.
+ this.timer = null;
+ this.isRunning = false;
+ this.interval = interval;
+
+ this.onStart = null;
+ this.onStop = null;
+};
+
+dojo.extend(dojox.timing.Timer, {
+ onTick : function(){
+ // summary: Method called every time the interval passes. Override to do something useful.
+ },
+
+ setInterval : function(interval){
+ // summary: Reset the interval of a timer, whether running or not.
+ // interval: New interval, in milliseconds.
+ if (this.isRunning){
+ window.clearInterval(this.timer);
+ }
+ this.interval = interval;
+ if (this.isRunning){
+ this.timer = window.setInterval(dojo.hitch(this, "onTick"), this.interval);
+ }
+ },
+
+ start : function(){
+ // summary: Start the timer ticking.
+ // description: Calls the "onStart()" handler, if defined.
+ // Note that the onTick() function is not called right away,
+ // only after first interval passes.
+ if (typeof this.onStart == "function"){
+ this.onStart();
+ }
+ this.isRunning = true;
+ this.timer = window.setInterval(dojo.hitch(this, "onTick"), this.interval);
+ },
+
+ stop : function(){
+ // summary: Stop the timer.
+ // description: Calls the "onStop()" handler, if defined.
+ if (typeof this.onStop == "function"){
+ this.onStop();
+ }
+ this.isRunning = false;
+ window.clearInterval(this.timer);
+ }
+});
+
+}
+
+}};});
diff --git a/js/dojo-1.6/dojox/timing/doLater.js b/js/dojo-1.6/dojox/timing/doLater.js new file mode 100644 index 0000000..868c7ea --- /dev/null +++ b/js/dojo-1.6/dojox/timing/doLater.js @@ -0,0 +1,53 @@ +/*
+ Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
+ Available via Academic Free License >= 2.1 OR the modified BSD license.
+ see: http://dojotoolkit.org/license for details
+*/
+
+
+if(!dojo._hasResource["dojox.timing.doLater"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojox.timing.doLater"] = true;
+dojo.provide("dojox.timing.doLater");
+dojo.experimental("dojox.timing.doLater");
+
+dojox.timing.doLater = function(/*anything*/conditional,/*Object ?*/context, /* Number ? */interval){
+ // summary:
+ // Check if a parameter is ready, and if not,
+ // "do later". doLater will ping the parameter
+ // until it evaluates to something (truthy).
+ // It thens calls the caller with original
+ // arguments, using the supplied context or
+ // window.
+ // description:
+ // dojox.timing.doLater(conditional) is testing if the call
+ // should be done later. So it returns
+ // true if the param is false.
+ // arguments:
+ // conditional: anything
+ // Can be a property that eventually gets set, or
+ // an expression, method... anything that can be
+ // evaluated.
+ // context: Object
+ // The namespace where the call originated.
+ // Defaults to global and anonymous functions
+ // interval: Number
+ // Poll time to check conditional in Milliseconds
+ // example:
+ // | setTimeout(function(){
+ // | if(dojox.timing.doLater(app.ready)){return;}
+ // | console.log("Code is ready! anonymous.function SUCCESS")
+ // | },700);
+ //
+ if(conditional){ return false; } // Boolean
+ var callback = dojox.timing.doLater.caller,
+ args = dojox.timing.doLater.caller.arguments;
+ interval = interval || 100;
+ context = context || dojo.global;
+
+ setTimeout(function(){
+ callback.apply(context, args);
+ },interval);
+ return true; // Boolean
+}
+
+}
diff --git a/js/dojo-1.6/dojox/timing/doLater.xd.js b/js/dojo-1.6/dojox/timing/doLater.xd.js new file mode 100644 index 0000000..8d339aa --- /dev/null +++ b/js/dojo-1.6/dojox/timing/doLater.xd.js @@ -0,0 +1,57 @@ +/*
+ Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
+ Available via Academic Free License >= 2.1 OR the modified BSD license.
+ see: http://dojotoolkit.org/license for details
+*/
+
+
+dojo._xdResourceLoaded(function(dojo, dijit, dojox){
+return {depends: [["provide", "dojox.timing.doLater"]],
+defineResource: function(dojo, dijit, dojox){if(!dojo._hasResource["dojox.timing.doLater"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojox.timing.doLater"] = true;
+dojo.provide("dojox.timing.doLater");
+dojo.experimental("dojox.timing.doLater");
+
+dojox.timing.doLater = function(/*anything*/conditional,/*Object ?*/context, /* Number ? */interval){
+ // summary:
+ // Check if a parameter is ready, and if not,
+ // "do later". doLater will ping the parameter
+ // until it evaluates to something (truthy).
+ // It thens calls the caller with original
+ // arguments, using the supplied context or
+ // window.
+ // description:
+ // dojox.timing.doLater(conditional) is testing if the call
+ // should be done later. So it returns
+ // true if the param is false.
+ // arguments:
+ // conditional: anything
+ // Can be a property that eventually gets set, or
+ // an expression, method... anything that can be
+ // evaluated.
+ // context: Object
+ // The namespace where the call originated.
+ // Defaults to global and anonymous functions
+ // interval: Number
+ // Poll time to check conditional in Milliseconds
+ // example:
+ // | setTimeout(function(){
+ // | if(dojox.timing.doLater(app.ready)){return;}
+ // | console.log("Code is ready! anonymous.function SUCCESS")
+ // | },700);
+ //
+ if(conditional){ return false; } // Boolean
+ var callback = dojox.timing.doLater.caller,
+ args = dojox.timing.doLater.caller.arguments;
+ interval = interval || 100;
+ context = context || dojo.global;
+
+ setTimeout(function(){
+ callback.apply(context, args);
+ },interval);
+ return true; // Boolean
+}
+
+}
+
+}};});
|
