/* 10 - Identify user 20 - Register finger */ /* Statuses list 10 - Start client init 20 - Start scanning 30 - Start processing 40 - Start sending 50 - Process successfully finished /**/ // Failed request timeout var failTimout = 0; // Current gaus request var gausCurrentRequest = 0; // ---------------------------------- // Gaus Client class // ---------------------------------- function gausClient(glci) { // Define object properties this.reqSuccessHandle = 0; this.reqFailedHandle = 0; this.reqHandleScope = 0; // Packets to scan this.packetsToScan = 1; this.packetsScanned = 0; // Client interface window this.clientWindow = glci; }; // ---------------------------------- // Gaus identify fnction // ---------------------------------- gausClient.prototype.identify = function(Url) { // Store url to send packet to into object if(Url!=undefined) this.PortalURL = Url; // Show window for identify this.clientWindow.showWindow(10); // Set status "Init" this.setStatus(10); // 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 ); } // ---------------------------------- // Gaus register fnction // ---------------------------------- gausClient.prototype.register = function(fngNum, Url) { // Store packets count needed to register finger this.packetsToScan = 3; this.packetsScanned = 0; // 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 ); } // ---------------------------------- // Register update // ---------------------------------- 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 ); } // ---------------------------------- // Identify update // ---------------------------------- 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 ); } // ---------------------------------- // Register scan finger // ---------------------------------- 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 ); } // ---------------------------------- // Process finger for register // ---------------------------------- 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 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 ); } // ---------------------------------- // Core gaus functions // ---------------------------------- // ---------------------------------- // Stop gaus process // ---------------------------------- 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; } // ---------------------------------- // Stop vlient execution // ---------------------------------- 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"); } // ---------------------------------- // Init gaus client // ---------------------------------- 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); } // ---------------------------------- // Scan function // ---------------------------------- gausClient.prototype.scan = function(fngNum, hndlSuccess, hndlFail, scope) { // Start request to init new gaus session this.makeRequest(hndlSuccess, hndlFail, scope, "Scan", fngNum); } // ---------------------------------- // Send packet function // ---------------------------------- gausClient.prototype.send = function(hndlSuccess, hndlFail, scope) { // Start request to init new gaus session this.makeRequest(hndlSuccess, hndlFail, scope, "Send"); } // ---------------------------------- // Process pacjet // ---------------------------------- gausClient.prototype.process = function(hndlSuccess, hndlFail, scope) { // Start request to init new gaus session this.makeRequest(hndlSuccess, hndlFail, scope, "Process"); } // ---------------------------------- // Reset gaus fingers list // ---------------------------------- 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; } // ---------------------------------- // Destroy gaus client // ---------------------------------- gausClient.prototype.destroy = function(hndlSuccess, hndlFail, scope) { // Start request to init new gaus session this.makeRequest(hndlSuccess, hndlFail, scope, "Destroy"); } // ---------------------------------- // Update client // ---------------------------------- gausClient.prototype.update = function(hndlSuccess, hndlFail, scope) { // Start request to init new gaus session this.makeRequest(hndlSuccess, hndlFail, scope, "Update"); } // ---------------------------------- // Update client now // ---------------------------------- gausClient.prototype.updateNow = function(hndlSuccess, hndlFail, scope) { // Start request to init new gaus session this.makeRequest(hndlSuccess, hndlFail, scope, "UpdateNow"); } // ---------------------------------- // Make a gaus request // ---------------------------------- 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); } // ---------------------------------- // Set gaus status // ---------------------------------- gausClient.prototype.setStatus = function(Code, a1, a2, a3) { // Status handler if(this.clientWindow != undefined) this.clientWindow.handleStatus(Code, a1, a2, a3); } // ---------------------------------- // Set gaus error // ---------------------------------- gausClient.prototype.setError = function(Code) { // Status handler if(this.clientWindow != undefined) this.clientWindow.handleError(Code); } // ---------------------------------- // Gaus request was failed, call to fail function // ---------------------------------- 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); } } // ---------------------------------- // Gaus request successfull // ---------------------------------- 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); } } // ---------------------------------- // Gaus send request // ---------------------------------- 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); } // ---------------------------------- // Destroy client // ---------------------------------- function gausDestroyClient() { if(gausCurrentRequest) { // Packets to scan gausCurrentRequest.stop(); } }