aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/js
diff options
context:
space:
mode:
authorVincent Brillault2013-12-16 21:49:20 +0100
committerPim van den Berg2014-01-12 14:35:02 +0100
commitb7686445e12175baf1acb298053c10424e616580 (patch)
tree076a58e9d4b46866ca3b29720cdc787f822fc320 /js
parentjsrrdgraph: RrdGraph.js: splitting RrdGraph.prototype.graph_paint into init, ... (diff)
downloadapt-panopticon_cgp-b7686445e12175baf1acb298053c10424e616580.zip
apt-panopticon_cgp-b7686445e12175baf1acb298053c10424e616580.tar.gz
apt-panopticon_cgp-b7686445e12175baf1acb298053c10424e616580.tar.bz2
apt-panopticon_cgp-b7686445e12175baf1acb298053c10424e616580.tar.xz
jsrrdgraph: RrdDataFile.js: Add async function (fetch_async) to RrdDataFile
Diffstat (limited to '')
-rw-r--r--js/RrdDataFile.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/js/RrdDataFile.js b/js/RrdDataFile.js
index e3e74e6..4ebb220 100644
--- a/js/RrdDataFile.js
+++ b/js/RrdDataFile.js
@@ -34,6 +34,8 @@ RrdDataFile.prototype = {
34 init: function() 34 init: function()
35 { 35 {
36 this.rrdfiles = {}; 36 this.rrdfiles = {};
37 this.rrdfiles_fetching = {};
38 this.rrdfiles_wait = {};
37 }, 39 },
38 build: function(gdp, ft_step, rrd) 40 build: function(gdp, ft_step, rrd)
39 { 41 {
@@ -130,5 +132,42 @@ RrdDataFile.prototype = {
130 } 132 }
131 133
132 return this.build(gdp, ft_step, rrd); 134 return this.build(gdp, ft_step, rrd);
135 },
136 fetch_async_callback: function(bf, args)
137 {
138 var rrd;
139
140 rrd = new RRDFile(bf);
141 args.this.rrdfiles[args.gdp.rrd] = rrd;
142 args.callback(args.callback_arg, args.this.build(args.gdp, args.ft_step, rrd));
143
144 for(var vname in args.this.rrdfiles_wait)
145 {
146 var o_args = args.this.rrdfiles_wait[vname];
147 if (args.gdp.rrd == o_args.gdp.rrd)
148 {
149 delete args.this.rrdfiles_wait[vname];
150 o_args.callback(o_args.callback_arg, args.this.build(o_args.gdp, o_args.ft_step, rrd));
151 }
152 }
153 },
154 fetch_async: function(gdp, ft_step, callback, callback_arg)
155 {
156 var rrd;
157 if (gdp.rrd == null) return -1;
158
159 if (gdp.rrd in this.rrdfiles) {
160 callback(callback_arg, this.build(gdp, ft_step, this.rrdfiles[gdp.rrd]));
161 } else if (gdp.rrd in this.rrdfiles_fetching) {
162 this.rrdfiles_wait[gdp.vname] = { this:this, gdp: gdp, ft_step: ft_step, callback: callback, callback_arg: callback_arg };
163 if (gdp.rrd in this.rrdfiles)
164 {
165 delete this.rrdfiles_wait[gdp.vname];
166 callback(callback_arg, this.build(gdp, ft_step, this.rrdfiles[gdp.rrd]));
167 }
168 } else {
169 this.rrdfiles_fetching[gdp.rrd] = FetchBinaryURLAsync(gdp.rrd, this.fetch_async_callback, { this:this, gdp: gdp, ft_step: ft_step, callback: callback, callback_arg: callback_arg });
170 }
171 return 0;
133 } 172 }
134}; 173};