1 /* |
1 /* |
2 * Modelled Trace API |
2 * Modelled Trace API |
|
3 * |
|
4 * This file is part of ktbs4js. |
|
5 * |
|
6 * ktbs4js is free software: you can redistribute it and/or modify it |
|
7 * under the terms of the GNU Lesser General Public License as |
|
8 * published by the Free Software Foundation, either version 3 of the |
|
9 * License, or (at your option) any later version. |
|
10 * |
|
11 * ktbs4js is distributed in the hope that it will be useful, |
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 * GNU Lesser General Public License for more details. |
|
15 * |
|
16 * You should have received a copy of the GNU Lesser General Public |
|
17 * License along with ktbs4js. If not, see <http://www.gnu.org/licenses/>. |
|
18 * |
3 */ |
19 */ |
4 IriSP.TraceManager = function($) { |
20 /* FIXME: properly use require.js feature. This will do for debugging in the meantime */ |
|
21 window.tracemanager = (function($) { |
5 // If there are more than MAX_FAILURE_COUNT synchronisation |
22 // If there are more than MAX_FAILURE_COUNT synchronisation |
6 // failures, then disable synchronisation |
23 // failures, then disable synchronisation |
7 MAX_FAILURE_COUNT = 20; |
24 MAX_FAILURE_COUNT = 20; |
8 |
25 |
9 // If there are more than MAX_BUFFER_SIZE obsels in the buffer, |
26 // If there are more than MAX_BUFFER_SIZE obsels in the buffer, |
10 // then "compress" them as a single "ktbsFullBuffer" |
27 // then "compress" them as a single "ktbsFullBuffer" |
11 MAX_BUFFER_SIZE = 500; |
28 MAX_BUFFER_SIZE = 500; |
12 |
29 |
13 var BufferedService_prototype = { |
30 var BufferedService_prototype = { |
14 /* |
31 /* |
15 * Buffered service for traces |
32 * Buffered service for traces |
16 */ |
33 */ |
17 // url: "", |
34 // url: "", |
18 // buffer: [], |
35 // buffer: [], |
19 // isReady: false, |
36 // isReady: false, |
20 // timer: null, |
37 // timer: null, |
21 // failureCount: 0, |
38 // failureCount: 0, |
70 } |
87 } |
71 } |
88 } |
72 }, |
89 }, |
73 |
90 |
74 /* Sync mode: delayed, sync (immediate sync), none (no |
91 /* Sync mode: delayed, sync (immediate sync), none (no |
75 * synchronisation with server, the trace has to be explicitly saved |
92 * synchronisation with server, the trace has to be explicitly saved |
76 * if needed */ |
93 * if needed */ |
77 set_sync_mode: function(mode, default_subject) { |
94 set_sync_mode: function(mode, default_subject) { |
78 this.sync_mode = mode; |
95 this.sync_mode = mode; |
79 if (! this.isReady && mode !== "none") |
96 if (! this.isReady && mode !== "none") |
80 this.init(default_subject); |
97 this.init(default_subject); |
81 if (mode == 'delayed') { |
98 if (mode == 'delayed') { |
168 }; |
185 }; |
169 BufferedService.prototype = BufferedService_prototype; |
186 BufferedService.prototype = BufferedService_prototype; |
170 |
187 |
171 var Trace_prototype = { |
188 var Trace_prototype = { |
172 /* FIXME: We could/should use a sorted list such as |
189 /* FIXME: We could/should use a sorted list such as |
173 http://closure-library.googlecode.com/svn/docs/class_goog_structs_AvlTree.html |
190 http://closure-library.googlecode.com/svn/docs/class_goog_structs_AvlTree.html |
174 to speed up queries based on time */ |
191 to speed up queries based on time */ |
175 obsels: [], |
192 obsels: [], |
176 /* Trace URI */ |
193 /* Trace URI */ |
177 uri: "", |
194 uri: "", |
178 default_subject: "", |
195 default_subject: "", |
179 /* baseuri is used as the base URI to resolve relative |
196 /* baseuri is used as the base URI to resolve relative |
180 * attribute-type names in obsels. Strictly speaking, this |
197 * attribute-type names in obsels. Strictly speaking, this |
181 * should rather be expressed as a reference to model, or |
198 * should rather be expressed as a reference to model, or |
182 * more generically, as a qname/URI dict */ |
199 * more generically, as a qname/URI dict */ |
183 baseuri: "", |
200 baseuri: "", |
184 /* Mapping of obsel type or property name to a compact |
201 /* Mapping of obsel type or property name to a compact |
185 * representation (shorthands). |
202 * representation (shorthands). |
186 */ |
203 */ |
187 shorthands: null, |
204 shorthands: null, |
188 syncservice: null, |
205 syncservice: null, |
189 |
206 |
190 /* Define the trace URI */ |
207 /* Define the trace URI */ |
191 set_uri: function(uri) { |
208 set_uri: function(uri) { |
192 this.uri = uri; |
209 this.uri = uri; |
193 }, |
210 }, |
194 |
211 |
195 /* Sync mode: delayed, sync (immediate sync), none (no |
212 /* Sync mode: delayed, sync (immediate sync), none (no |
196 * synchronisation with server, the trace has to be explicitly saved |
213 * synchronisation with server, the trace has to be explicitly saved |
197 * if needed */ |
214 * if needed */ |
198 set_sync_mode: function(mode) { |
215 set_sync_mode: function(mode) { |
199 if (this.syncservice !== null) { |
216 if (this.syncservice !== null) { |
200 this.syncservice.set_sync_mode(mode, this.default_subject); |
217 this.syncservice.set_sync_mode(mode, this.default_subject); |
201 } |
218 } |
202 }, |
219 }, |
203 |
220 |
204 /* |
221 /* |
205 * Return a list of the obsels of this trace matching the parameters |
222 * Return a list of the obsels of this trace matching the parameters |
206 */ |
223 */ |
207 list_obsels: function(_begin, _end, _reverse) { |
224 list_obsels: function(_begin, _end, _reverse) { |
208 var res; |
225 var res; |
209 if (typeof _begin !== 'undefined' || typeof _end !== 'undefined') { |
226 if (typeof _begin !== 'undefined' || typeof _end !== 'undefined') { |
210 /* |
227 /* |
211 * Not optimized yet. |
228 * Not optimized yet. |
212 */ |
229 */ |
213 res = []; |
230 res = []; |
214 var l = this.obsels.length; |
231 var l = this.obsels.length; |
215 for (var i = 0; i < l; i++) { |
232 for (var i = 0; i < l; i++) { |
216 var o = this.obsels[i]; |
233 var o = this.obsels[i]; |
217 if ((typeof _begin !== 'undefined' && o.begin > _begin) && (typeof _end !== 'undefined' && o.end < _end)) { |
234 if ((typeof _begin !== 'undefined' && o.begin > _begin) && (typeof _end !== 'undefined' && o.end < _end)) { |
235 return res; |
252 return res; |
236 |
253 |
237 }, |
254 }, |
238 |
255 |
239 /* |
256 /* |
240 * Return the obsel of this trace identified by the URI, or undefined |
257 * Return the obsel of this trace identified by the URI, or undefined |
241 */ |
258 */ |
242 get_obsel: function(id) { |
259 get_obsel: function(id) { |
243 for (var i = 0; i < this.obsels.length; i++) { |
260 for (var i = 0; i < this.obsels.length; i++) { |
244 /* FIXME: should check against variations of id/uri, take this.baseuri into account */ |
261 /* FIXME: should check against variations of id/uri, take this.baseuri into account */ |
245 if (this.obsels[i].uri === id) { |
262 if (this.obsels[i].uri === id) { |
246 return this.obsels[i]; |
263 return this.obsels[i]; |
483 Obsel.prototype = Obsel_prototype; |
500 Obsel.prototype = Obsel_prototype; |
484 |
501 |
485 var TraceManager_prototype = { |
502 var TraceManager_prototype = { |
486 traces: [], |
503 traces: [], |
487 /* |
504 /* |
488 * Return the trace with id name |
505 * Return the trace with id name |
489 * If it was not registered, return undefined. |
506 * If it was not registered, return undefined. |
490 */ |
507 */ |
491 get_trace: function(name) { |
508 get_trace: function(name) { |
492 return this.traces[name]; |
509 return this.traces[name]; |
493 }, |
510 }, |
494 |
511 |
495 /* |
512 /* |
496 * Explicitly create and initialize a new trace with the given name. |
513 * Explicitly create and initialize a new trace with the given name. |
497 * The optional uri parameter allows to initialize the trace URI. |
514 * The optional uri parameter allows to initialize the trace URI. |
498 * |
515 * |
499 * If another existed with the same name before, then it is replaced by a new one. |
516 * If another existed with the same name before, then it is replaced by a new one. |
500 */ |
517 */ |
501 init_trace: function(name, params) |
518 init_trace: function(name, params) |
502 { |
519 { |
503 if (window.console) window.console.log("init_trace", params); |
520 if (window.console) window.console.log("init_trace", params); |
504 url = params.url ? params.url : ""; |
521 url = params.url ? params.url : ""; |
505 requestmode = params.requestmode ? params.requestmode : "POST"; |
522 requestmode = params.requestmode ? params.requestmode : "POST"; |