/* Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)

Date:   Mon Aug 08 09:49:18 2016

Model author: Herr Joeri Exelmans
Model name:   no_statechart
Model description:
Test to see what happens when a class with no statechart is defined.*/


// package "no_statechart"
var no_statechart = {};
(function() {

var my_struct = function(x, y) {
    
    // user defined attributes
    this.x = null;
    this.y = null;
    
    // call user defined constructor
    my_struct.prototype.user_defined_constructor.call(this, x, y);
};

my_struct.prototype.user_defined_constructor = function(x, y) {
    this.x = x;
    this.y = y;
};

my_struct.prototype.user_defined_destructor = function() {
};

// add symbol 'my_struct' to package 'no_statechart'
no_statechart.my_struct = my_struct;

var my_class = function(controller) {
    RuntimeClassBase.call(this, controller);
    
    this.semantics.big_step_maximality = StatechartSemantics.TakeMany;
    this.semantics.internal_event_lifeline = StatechartSemantics.Queue;
    this.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep;
    this.semantics.priority = StatechartSemantics.SourceParent;
    this.semantics.concurrency = StatechartSemantics.Single;
    
    // build Statechart structure
    this.build_statechart_structure();
    
    // call user defined constructor
    my_class.prototype.user_defined_constructor.call(this);
};
my_class.prototype = new Object();
(function() {
    var proto = new RuntimeClassBase();
    for (prop in proto) {
        my_class.prototype[prop] = proto[prop];
    }
})();

my_class.prototype.user_defined_constructor = function() {
    this.data = new my_struct(0, 0);
};

my_class.prototype.user_defined_destructor = function() {
};


// builds Statechart structure
my_class.prototype.build_statechart_structure = function() {
    
    // state <root>
    this.states[""] = new State(0, this);
    
    // state /a
    this.states["/a"] = new State(1, this);
    this.states["/a"].setEnter(this._a_enter);
    this.states["/a"].setExit(this._a_exit);
    
    // state /b
    this.states["/b"] = new State(2, this);
    this.states["/b"].setEnter(this._b_enter);
    this.states["/b"].setExit(this._b_exit);
    
    // add children
    this.states[""].addChild(this.states["/a"]);
    this.states[""].addChild(this.states["/b"]);
    this.states[""].fixTree();
    this.states[""].default_state = this.states["/a"];
    
    // transition /a
    var _a_0 = new Transition(this, this.states["/a"], [this.states["/b"]]);
    _a_0.setAction(this._a_0_exec);
    _a_0.setTrigger(new Event("_0after"));
    _a_0.setGuard(this._a_0_guard);
    this.states["/a"].addTransition(_a_0);
    
    // transition /b
    var _b_0 = new Transition(this, this.states["/b"], [this.states["/a"]]);
    _b_0.setAction(this._b_0_exec);
    _b_0.setTrigger(new Event("_1after"));
    _b_0.setGuard(this._b_0_guard);
    this.states["/b"].addTransition(_b_0);
};

my_class.prototype._a_enter = function() {
    this.addTimer(0, 0.1);
};

my_class.prototype._a_exit = function() {
    this.removeTimer(0);
};

my_class.prototype._b_enter = function() {
    this.addTimer(1, 0.1);
};

my_class.prototype._b_exit = function() {
    this.removeTimer(1);
};

my_class.prototype._a_0_exec = function(parameters) {
    this.big_step.outputEvent(new Event("to_b", "out", [this.data.x]));
    this.data.x += 1;
};

my_class.prototype._a_0_guard = function(parameters) {
    return this.data.x < 2;
};

my_class.prototype._b_0_exec = function(parameters) {
    this.data.y += 1;
    this.big_step.outputEvent(new Event("to_a", "out", [this.data.y]));
};

my_class.prototype._b_0_guard = function(parameters) {
    return this.data.y < 2;
};

my_class.prototype.initializeStatechart = function() {
    // enter default state
    var states = this.states["/a"].getEffectiveTargetStates();
    this.updateConfiguration(states);
    for (var state_idx in states) {
        if (!states.hasOwnProperty(state_idx)) continue;
        var state = states[state_idx]
        if (state.enter) {
            state.enter();
        }
    }
};

// add symbol 'my_class' to package 'no_statechart'
no_statechart.my_class = my_class;

var ObjectManager = function(controller) {
    ObjectManagerBase.call(this, controller);
};
ObjectManager.prototype = new Object();
(function() {
    var proto = new ObjectManagerBase();
    for (prop in proto) {
        ObjectManager.prototype[prop] = proto[prop];
    }
})();

ObjectManager.prototype.instantiate = function(class_name, construct_params) {
    if (class_name === "my_struct") {
        var instance = new my_struct(this.controller, construct_params[0], construct_params[1]);
        instance.associations = new Object();
    } else if (class_name === "my_class") {
        var instance = new my_class(this.controller);
        instance.associations = new Object();
    } else  {
        throw new Error("Cannot instantiate class " + class_name);
    }
    return instance;
};

// add symbol 'ObjectManager' to package 'no_statechart'
no_statechart.ObjectManager = ObjectManager;

var Controller = function(event_loop_callbacks, finished_callback, behind_schedule_callback) {
    if (finished_callback === undefined) finished_callback = null;
    if (behind_schedule_callback === undefined) behind_schedule_callback = null;
    EventLoopControllerBase.call(this, new ObjectManager(this), event_loop_callbacks, finished_callback, behind_schedule_callback);
    this.addInputPort("in");
    this.addOutputPort("out");
    this.object_manager.createInstance("my_class", new Array());
};
Controller.prototype = new Object();
(function() {
    var proto = new EventLoopControllerBase();
    for (prop in proto) {
        Controller.prototype[prop] = proto[prop];
    }
})();

// add symbol 'Controller' to package 'no_statechart'
no_statechart.Controller = Controller;

var InputEvent = function(name, port, parameters, time_offset) {
    this.name = name;
    this.port = port;
    this.parameters = parameters;
    this.time_offset = time_offset;
};

// add symbol 'InputEvent' to package 'no_statechart'
no_statechart.InputEvent = InputEvent;

var Test = function() {
};
Test.prototype.input_events = new Array();
Test.prototype.expected_events = [[new Event("to_b", "out", [0])], [new Event("to_a", "out", [1])], [new Event("to_b", "out", [1])], [new Event("to_a", "out", [2])]];

// add symbol 'Test' to package 'no_statechart'
no_statechart.Test = Test;
})();