Adding/removing breakpoints.
This commit is contained in:
@@ -12,6 +12,45 @@
|
||||
var module = angular.module('xe.datasources', []);
|
||||
|
||||
|
||||
module.service('Breakpoint', function() {
|
||||
// http://stackoverflow.com/a/2117523/377392
|
||||
var uuidFormat = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
|
||||
function uuid4() {
|
||||
return uuidFormat.replace(/[xy]/g, function(c) {
|
||||
var r = Math.random()*16|0, v = c === 'x' ? r : (r&0x3|0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
};
|
||||
|
||||
var Breakpoint = function(opt_id) {
|
||||
this.id = opt_id || uuid4();
|
||||
this.type = Breakpoint.Type.TEMP;
|
||||
this.address = 0;
|
||||
this.enabled = true;
|
||||
};
|
||||
Breakpoint.Type = {
|
||||
TEMP: 'temp',
|
||||
CODE: 'code'
|
||||
};
|
||||
Breakpoint.fromJSON = function(json) {
|
||||
var breakpoint = new Breakpoint(json.id);
|
||||
breakpoint.type = json.type;
|
||||
breakpoint.address = json.address;
|
||||
breakpoint.enabled = json.enabled;
|
||||
return breakpoint;
|
||||
};
|
||||
Breakpoint.prototype.toJSON = function() {
|
||||
return {
|
||||
'id': this.id,
|
||||
'type': this.type,
|
||||
'address': this.address,
|
||||
'enabled': this.enabled
|
||||
};
|
||||
};
|
||||
return Breakpoint;
|
||||
});
|
||||
|
||||
|
||||
module.service('DataSource', function($q) {
|
||||
var DataSource = function(source) {
|
||||
this.source = source;
|
||||
|
||||
@@ -13,17 +13,50 @@ var module = angular.module('xe.session', []);
|
||||
|
||||
|
||||
module.service('Session', function(
|
||||
$rootScope, $q, $http, log, FileDataSource, RemoteDataSource) {
|
||||
$rootScope, $q, $http, log,
|
||||
Breakpoint, FileDataSource, RemoteDataSource) {
|
||||
var Session = function(id, opt_dataSource) {
|
||||
this.id = id;
|
||||
|
||||
this.breakpoints = {};
|
||||
|
||||
this.dataSource = opt_dataSource || null;
|
||||
|
||||
this.loadState();
|
||||
};
|
||||
|
||||
Session.prototype.dispose = function() {
|
||||
this.saveState();
|
||||
this.disconnect();
|
||||
};
|
||||
|
||||
Session.prototype.loadState = function() {
|
||||
var json = JSON.parse(window.localStorage[this.id]);
|
||||
if (!json) {
|
||||
return;
|
||||
}
|
||||
|
||||
var breakpointList = json.breakpoints;
|
||||
this.breakpoints = {};
|
||||
for (var n = 0; n < breakpointList.length; n++) {
|
||||
var breakpointJson = breakpointList[n];
|
||||
this.breakpoints[breakpointJson.address] =
|
||||
Breakpoint.fromJSON(breakpointJson);
|
||||
}
|
||||
};
|
||||
|
||||
Session.prototype.saveState = function() {
|
||||
var json = {
|
||||
id: this.id,
|
||||
breakpoints: []
|
||||
};
|
||||
for (var key in this.breakpoints) {
|
||||
var breakpoint = this.breakpoints[key];
|
||||
json.breakpoints.push(breakpoint.toJSON());
|
||||
}
|
||||
window.localStorage[this.id] = JSON.stringify(json);
|
||||
};
|
||||
|
||||
Session.DEFAULT_HOST = '127.0.0.1:6200';
|
||||
|
||||
Session.getHost = function(opt_host) {
|
||||
@@ -67,7 +100,7 @@ module.service('Session', function(
|
||||
p.then((function() {
|
||||
log.info('Connected!');
|
||||
log.clearProgress();
|
||||
this.dataSource = dataSource;
|
||||
this.setDataSource(dataSource);
|
||||
d.resolve(this);
|
||||
}).bind(this), (function(e) {
|
||||
log.error('Unable to connect: ' + e);
|
||||
@@ -82,11 +115,72 @@ module.service('Session', function(
|
||||
};
|
||||
|
||||
Session.prototype.disconnect = function() {
|
||||
this.setDataSource(null);
|
||||
};
|
||||
|
||||
Session.prototype.setDataSource = function(dataSource) {
|
||||
if (this.dataSource) {
|
||||
this.dataSource.dispose();
|
||||
this.dataSource = null;
|
||||
$rootScope.$emit('refresh');
|
||||
}
|
||||
if (!dataSource) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.dataSource = dataSource;
|
||||
|
||||
var breakpointList = [];
|
||||
for (var key in this.breakpoints) {
|
||||
breakpointList.push(this.breakpoints[key]);
|
||||
}
|
||||
this.dataSource.addBreakpoints(breakpointList);
|
||||
};
|
||||
|
||||
Session.prototype.addBreakpoint = function(breakpoint) {
|
||||
this.breakpoints[breakpoint.address] = breakpoint;
|
||||
if (this.dataSource) {
|
||||
this.dataSource.addBreakpoint(breakpoint);
|
||||
}
|
||||
this.saveState();
|
||||
return breakpoint;
|
||||
};
|
||||
|
||||
Session.prototype.addTempBreakpoint = function(address) {
|
||||
var breakpoint = new Breakpoint();
|
||||
breakpoint.type = Breakpoint.Type.TEMP;
|
||||
breakpoint.address = address;
|
||||
breakpoint.enabled = true;
|
||||
return this.addBreakpoint(breakpoint);
|
||||
};
|
||||
|
||||
Session.prototype.addCodeBreakpoint = function(address) {
|
||||
var breakpoint = new Breakpoint();
|
||||
breakpoint.type = Breakpoint.Type.CODE;
|
||||
breakpoint.address = address;
|
||||
breakpoint.enabled = true;
|
||||
return this.addBreakpoint(breakpoint);
|
||||
};
|
||||
|
||||
Session.prototype.removeBreakpoint = function(breakpoint) {
|
||||
delete this.breakpoints[breakpoint.address];
|
||||
if (this.dataSource) {
|
||||
this.dataSource.removeBreakpoint(breakpoint.id);
|
||||
}
|
||||
this.saveState();
|
||||
};
|
||||
|
||||
Session.prototype.toggleBreakpoint = function(breakpoint, enabled) {
|
||||
var oldEnabled = enabled;
|
||||
breakpoint.enabled = enabled;
|
||||
if (this.dataSource) {
|
||||
if (breakpoint.enabled) {
|
||||
this.dataSource.addBreakpoint(breakpoint);
|
||||
} else {
|
||||
this.dataSource.removeBreakpoint(breakpoint.id);
|
||||
}
|
||||
}
|
||||
this.saveState();
|
||||
};
|
||||
|
||||
return Session;
|
||||
|
||||
Reference in New Issue
Block a user