diff -r 7e5174fe9816 -r 5b7d7ab6baff web/res/js/tracemanager.js --- a/web/res/js/tracemanager.js Mon May 21 18:53:02 2012 +0200 +++ b/web/res/js/tracemanager.js Tue May 22 16:47:35 2012 +0200 @@ -1,7 +1,24 @@ /* * Modelled Trace API + * + * This file is part of ktbs4js. + * + * ktbs4js is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * ktbs4js is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with ktbs4js. If not, see . + * */ -IriSP.TraceManager = function($) { +/* FIXME: properly use require.js feature. This will do for debugging in the meantime */ +window.tracemanager = (function($) { // If there are more than MAX_FAILURE_COUNT synchronisation // failures, then disable synchronisation MAX_FAILURE_COUNT = 20; @@ -74,10 +91,10 @@ /* Sync mode: delayed, sync (immediate sync), none (no * synchronisation with server, the trace has to be explicitly saved * if needed */ - set_sync_mode: function(mode) { + set_sync_mode: function(mode, default_subject) { this.sync_mode = mode; if (! this.isReady && mode !== "none") - this.init(); + this.init(default_subject); if (mode == 'delayed') { this.start_timer(); } else { @@ -120,14 +137,16 @@ /* * Initialize the sync service */ - init: function() { + init: function(default_subject) { var self = this; if (this.isReady) /* Already initialized */ return; + if (typeof default_subject === 'undefined') + default_subject = 'anonymous'; if (this.mode == 'GET') { - var request=$('').attr('src', this.url + 'login?userinfo={"name":"ktbs4js"}'); + var request=$('').attr('src', this.url + 'login?userinfo={"default_subject": "' + default_subject + '"}'); // Do not wait for the return, assume it is // initialized. This assumption will not work anymore // if login returns some necessary information @@ -137,7 +156,7 @@ { $.ajax({ url: this.url + 'login', type: 'POST', - data: 'userinfo={"name":"ktbs4js"}', + data: 'userinfo={"default_subject":"' + default_subject + '"}', success: function(data, textStatus, jqXHR) { self.isReady = true; if (self.buffer.length) { @@ -195,7 +214,7 @@ * if needed */ set_sync_mode: function(mode) { if (this.syncservice !== null) { - this.syncservice.set_sync_mode(mode); + this.syncservice.set_sync_mode(mode, this.default_subject); } }, @@ -248,6 +267,9 @@ }, set_default_subject: function(subject) { + // FIXME: if we call this method after the sync_service + // init method, then the default_subject will not be + // consistent anymore. Maybe we should then call init() again? this.default_subject = subject; }, @@ -434,8 +456,11 @@ var r = { "@t": (this.trace.shorthands.hasOwnProperty(this.type) ? this.trace.shorthands[this.type] : this.type), "@b": this.begin, - "@s": this.subject }; + // Transmit subject only if different from default_subject + if (this.subject !== this.trace.default_subject) + r["@s"] = this.subject; + // Store duration (to save some bytes) and only if it is non-null if (this.begin !== this.end) r["@d"] = this.end - this.begin; @@ -498,8 +523,8 @@ syncmode = params.syncmode ? params.syncmode : "none"; default_subject = params.default_subject ? params.default_subject : "default"; var t = new Trace(url, requestmode); + t.set_default_subject(default_subject); t.set_sync_mode(syncmode); - t.set_default_subject(default_subject); this.traces[name] = t; return t; } @@ -512,4 +537,4 @@ var tracemanager = new TraceManager(); return tracemanager; - }; + })(jQuery);