'use strict'; if (!("Handler_Function_class" in this)){ var Handler_Function_class = { Handler : function(name){ this.name = name; this.handler_function_list = []; }, Handler_Function: function(server_name){ this.name = server_name; this.definition = { final_states: new Set([]), just_wait_states: new Set([]), reset_wait_states: new Set([]), action_states: {}, }; this.wait_state = undefined; this.done = false; this.current_state = undefined; this.last_state = undefined; }, send_command_expect_state: function(command, expectation){ return function(){ console.out(this.name+'in '+this.current_state.name +"..."+command+"."); dim.send(command); this.wait_state = expectation; } }, throw_string_exception: function(message){ return function(){ throw message; } }, throw_error: function(){ throw new Error(this.name+':' +state.name+"["+state.index+"] in error state."); }, }; } else{ console.out("multiple include of 'Handler_Function_class.js'"); } /* add a handler_function to the internal handler_function_list. A handler_function tries every time it is invoked, to get a certain subsystem into a certain *fixed* state. When it succeeded, it return an empty string "". if it not (yet) acomplished its goal it will return: * The name of the state it waits for. * undefined, when it does not know, what state to wait for. It is important to feed it back, the wait_state_name it returned last time, so it knows, it should not do any action, while waiting for a certain state. */ Handler_Function_class.Handler.prototype.add = function(func) { this.handler_function_list.push(func); } /* run each handler_function in the handler_function_list until either all of them return the empty string "" or the timeout occured. */ Handler_Function_class.Handler.prototype.run = function(timeout) { console.out(this.name+":start"); var rc = []; var start_date = new Date(); while (!timeout || (new Date()-start_date)