/**
 *  ---------
 * |.##> <##.|  SmartCard-HSM Support Scripts
 * |#       #|
 * |#       #|  Copyright (c) 2011-2012 CardContact Software & System Consulting
 * |'##> <##'|  Andreas Schwier, 32429 Minden, Germany (www.cardcontact.de)
 *  ---------
 *
 * Consult your license package for usage terms and conditions.
 *
 * @fileoverview SmartCard-HSM Personalization Service
 */



function PersoService(cfg) {
	this.type = "PersoServer";
	this.name = "PersoServer";
	this.joblist = [];
	this.jobmap = {};
}



PersoService.prototype.addJob = function(job) {
	this.joblist.push(job.id);
	this.jobmap[job.id] = job;
}



PersoService.prototype.getJobs = function() {
	var list = [];
	for each (var id in this.joblist) {
		var job = this.jobmap[id];
		list.push(job);
	}
	return list;
}



PersoService.prototype.getJob = function(jobid) {
	return this.jobmap[jobid];
}



PersoService.prototype.handleJob = function(reader, jobid) {
	var job = this.getJob(jobid);
	job.handler.handleCard(reader, job);
}



PersoService.prototype.getServicePort = function() {
	return new Object();
}



PersoService.prototype.newUI = function() {
	return new PersoServiceGUI(this);
}



PersoService.prototype.handleCard = function(session, pathInfo) {
	GPSystem.trace(pathInfo);
	var l = pathInfo.split("/");
	var jobid = l[l.length - 1];
	GPSystem.trace(session.id + ":" + jobid);
	this.handleJob(session.id, jobid);
}
