var failTimout = 0; var gausCurrentRequest = 0; function gausClient(glci) { // Define object properties this.reqSuccessHandle = 0; this.reqFailedHandle = 0; this.reqHandleScope = 0; this.workMode = 0; // Packets to scan this.packetsToScan = 1; this.packetsScanned = 0; // Client interface window this.clientWindow = glci; }; gausClient.prototype.identify = function(Url) { // Store url to send packet to into object if(Url!=undefined) this.PortalURL = Url; // Default mode this.workMode = 0; // Show window for identify this.clientWindow.showWindow(10); // Set status "Init" this.setStatus(10); // this.setError(-302); // return; // Start request to init new gaus session this.init ( this.PortalURL, function(Code) { // Update needed this.identifyScan(); }, function(Code) { this.setError(Code); // Update needed if(Code==2030) this.identifyUpdate(); }, this ); } gausClient.prototype.register = function(fngNum, Url) { // Store packets count needed to register finger this.packetsToScan = 3; this.packetsScanned = 0; // Register mode this.workMode = 1; // Store regiuster finger number if(fngNum != undefined) this.regFingerNumber = fngNum; // Store url to send packet to into object if(Url!=undefined) this.PortalURL = Url; // Check for init data if( (this.regFingerNumber == undefined)||(this.PortalURL == undefined) ) alert("Wrong arguments in register(...)"); // Show window for register this.clientWindow.showWindow(20); // Set status "Init" this.setStatus(10); // Start request to init new gaus session this.init ( this.PortalURL, function(Code) { // Scan first finger this.registerScan(); }, function(Code) { this.setError(Code); if(Code==2030) this.identifyUpdate(); }, this ); } gausClient.prototype.registerUpdate = function() { // Set status "updating" this.setStatus(15); // Update application this.update ( function(Code) { // Update client now this.updateNow(); // Scan first finger setTimeout("gausCurrentRequest.register();", 10000); }, function(Code) { this.setError(Code); }, this ); } gausClient.prototype.identifyUpdate = function() { // Set status "updating" this.setStatus(15); // Update application this.update ( function(Code) { // Update client now this.updateNow(); // Scan first finger setTimeout("gausCurrentRequest.identify();", 5000); }, function(Code) { this.setError(Code); }, this ); } gausClient.prototype.registerScan = function() { // Set status "Scanning" for register process this.setStatus(27, this.packetsScanned+1, this.packetsToScan); // Start request to scan a finger this.scan ( // Does not matter finger number here this.regFingerNumber, // Success handler function(Code) { // Send packet to the server this.registerProcess(); }, // Failed handler function(Code) { switch(Code) { default: { // Set scan error this.setError(Code); } } }, this ); } gausClient.prototype.registerProcess = function() { // Set status "Start processing" this.setStatus(30); // Start request to scan a finger this.process ( // Success handler function(Code) { // Increase scanned fingers count this.packetsScanned++; // Send packet to the server if(this.packetsScanned < this.packetsToScan) this.registerScan(); else this.registerSend(); }, // Failed handler function(Code) { // Set error status this.setError(Code); }, this ); } gausClient.prototype.registerSend = function() { // Set status this.setStatus(40); // Send request to the portal this.send ( // Success handler function(Code, Data) { // Set success status this.setStatus(50); // Send packet to the server switch(Code) { // User exists, finger exists, templates are diffenet case -302: case -304: case -588: this.setError(Code); //setTimeout("gausCurrentRequest.register()", 3000); break; case 8040: eval(Data); break; case 8030: location.href=Data; break; default: alert("Unknown answer: "+Code); break; } }, // Failed handler function(Code) { // Scan first finger this.setError(Code); }, this ); } gausClient.prototype.identifyScan = function() { // Set status "Start scanning" if( this.packetsToScan == 1 ) { this.setStatus(20); } else { this.setStatus(25, this.packetsScanned+1, this.packetsToScan); } // Start request to scan a finger this.scan ( // Does not matter finger number here 0, // Success handler function(Code) { // Send packet to the server this.identifyProcess(); }, // Failed handler function(Code) { switch(Code) { default: { // Set scan error this.setError(Code); } } }, this ); } gausClient.prototype.identifyScheme = function(fngNum) { // Check for fingers number if( fngNum == undefined ) { this.packetsToScan = 1; } else { this.packetsToScan = fngNum; } // Reset current figners buffer this.reset ( // Success handler function(Code) { // reset fingers count this.packetsScanned = 1; // Send packet to the server this.identifyScan(); }, // Failed handler function(Code) { // Set scan error this.setError(Code); }, this ); } gausClient.prototype.identifyProcess = function() { // Set status "Start processing" this.setStatus(30); // Start request to scan a finger this.process ( // Success handler function(Code) { // Send packet to the server this.identifySend(); }, // Failed handler function(Code) { // Set error status this.setError(Code); }, this ); } gausClient.prototype.identifySend = function() { // Increase scanned fingers count this.packetsScanned++; // Check for fungers count to send equal to scanned fingers count if( this.packetsScanned < this.packetsToScan ) { this.identifyScan(); return; } // Set status this.setStatus(40); // Send request to the portal this.send ( // Success handler function(Code, Data) { // Check for code if( (Code > 250)&&(Code < 260) ) { this.identifyScheme(Code-250); return; } // Set success status this.setStatus(50); // Send packet to the server switch(Code) { case 8040: eval(Data); break; case 8030: location.href=Data; break; default: alert("Unknown answer"); break; } }, // Failed handler function(Code) { // Scan first finger this.setError(Code); }, this ); } gausClient.prototype.stop = function() { // Reset timeout clearTimeout(failTimout);failTimout = 0; // Hide window if(this.clientWindow!=undefined) this.clientWindow.hideWindow(); // Destroy client this.destroy(); this.packetsToScan = 1; this.packetsScanned = 0; } gausClient.prototype.quit = function() { // Reset timeout clearTimeout(failTimout);failTimout = 0; // Hide window if(this.clientWindow!=undefined) this.clientWindow.hideWindow(); // Start request to init new gaus session this.makeRequest(0, 0, this, "Quit"); } gausClient.prototype.init = function(Url, hndlSuccess, hndlFail, scope) { // Start request to init new gaus session this.makeRequest(hndlSuccess, hndlFail, scope, "Init", Url); // Start fail timer failTimout = setTimeout("gausRequestFailed(0)", 10000); } gausClient.prototype.scan = function(fngNum, hndlSuccess, hndlFail, scope) { // Start request to init new gaus session this.makeRequest(hndlSuccess, hndlFail, scope, "Scan", fngNum); } gausClient.prototype.send = function(hndlSuccess, hndlFail, scope) { // Start request to init new gaus session this.makeRequest(hndlSuccess, hndlFail, scope, "Send"); } gausClient.prototype.process = function(hndlSuccess, hndlFail, scope) { // Start request to init new gaus session this.makeRequest(hndlSuccess, hndlFail, scope, "Process"); } gausClient.prototype.reset = function(hndlSuccess, hndlFail, scope) { // Start request to init new gaus session this.makeRequest(hndlSuccess, hndlFail, scope, "Reset"); // reset fingers count this.packetsScanned = 0; } gausClient.prototype.destroy = function(hndlSuccess, hndlFail, scope) { // Start request to init new gaus session this.makeRequest(hndlSuccess, hndlFail, scope, "Destroy"); } gausClient.prototype.update = function(hndlSuccess, hndlFail, scope) { // Start request to init new gaus session this.makeRequest(hndlSuccess, hndlFail, scope, "Update"); } gausClient.prototype.updateNow = function(hndlSuccess, hndlFail, scope) { // Start request to init new gaus session this.makeRequest(hndlSuccess, hndlFail, scope, "UpdateNow"); } gausClient.prototype.makeRequest = function(hndlSuccess, hndlFail, scope, Command, Param) { // Check is any query already runned if(failTimout != 0) return(false); // Store handle properties // Store current request gausCurrentRequest = this; gausCurrentRequest.reqSuccessHandle = hndlSuccess; gausCurrentRequest.reqFailedHandle = hndlFail; gausCurrentRequest.reqHandleScope = scope; // Send request gausSendRequest("http://127.0.0.1:4424/" + Command + "?" + (Param!=undefined?Param:"")); // All ok return(true); } gausClient.prototype.setStatus = function(Code, a1, a2, a3) { // Status handler if(this.clientWindow != undefined) this.clientWindow.handleStatus(Code, a1, a2, a3); } gausClient.prototype.setError = function(Code) { // Status handler if(this.clientWindow != undefined) this.clientWindow.handleError(Code); } function gausRequestFailed(Code) { // Reset timeout to do possible to start new requests clearTimeout(failTimout);failTimout = 0; // Show status if(gausCurrentRequest.reqFailedHandle != undefined) { gausCurrentRequest.reqFailedHandle.call(gausCurrentRequest.reqHandleScope!=undefined?gausCurrentRequest.reqHandleScope:this,Code); } } function gausRequestSuccessfull(Code, Data) { // Reset timeout to do possible to start new requests clearTimeout(failTimout);failTimout = 0; // Store current request var lReq = gausCurrentRequest; // Show status if(lReq.reqSuccessHandle != undefined) { gausCurrentRequest.reqSuccessHandle.call(gausCurrentRequest.reqHandleScope!=undefined?gausCurrentRequest.reqHandleScope:this,Code, Data); } } function gausSendRequest(src) { // Generate element name var elName = 'gausTransfer'; // Create transfer tag var s = document.getElementById(elName); if (s) s.parentNode.removeChild(s); s = document.createElement('script'); s.setAttribute('type', 'text/javascript'); s.src = src + "&rand="+Math.random(); s.id = elName; document.getElementsByTagName('head')[0].appendChild(s); } function gausDestroyClient() { if(gausCurrentRequest) { // Packets to scan gausCurrentRequest.stop(); } }