blob: 9677385fd6681020cd59d2f39c33ede6759c5fa8 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2017, 2018 Dortmund University of Applied Sciences and Arts and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Dortmund University of Applied Sciences and Arts - initial API and implementation
*******************************************************************************/
package org.eclipse.app4mc.multicore.execution.logic.btf.fsm;
public class BtfTaskFSM {
private static final BtfTaskState[][] multi = new BtfTaskState[BtfTaskState.COUNT][BtfTaskEvent.COUNT];
static {
// every non transition is null
/* outgoing transitions for state POLLING */
makeTransition(BtfTaskState.POLLING, BtfTaskEvent.RUN, BtfTaskState.RUNNING);
makeTransition(BtfTaskState.POLLING, BtfTaskEvent.PARK, BtfTaskState.PARKING);
/* outgoing transitions for state RUNNING */
makeTransition(BtfTaskState.RUNNING, BtfTaskEvent.TERMINATE, BtfTaskState.TERMINATED);
makeTransition(BtfTaskState.RUNNING, BtfTaskEvent.PREEMPT, BtfTaskState.READY);
makeTransition(BtfTaskState.RUNNING, BtfTaskEvent.POLL, BtfTaskState.POLLING);
makeTransition(BtfTaskState.RUNNING, BtfTaskEvent.WAIT, BtfTaskState.WAITING);
/* outgoing transitions for state TERMINATED */
// none
/* outgoing transitions for state NOT_INITIALIZED */
makeTransition(BtfTaskState.NOT_INITIALIZED, BtfTaskEvent.ACTIVATE, BtfTaskState.ACTIVE);
/* outgoing transitions for state ACTIVE */
makeTransition(BtfTaskState.ACTIVE, BtfTaskEvent.START, BtfTaskState.RUNNING);
/* outgoing transitions for state READY */
makeTransition(BtfTaskState.READY, BtfTaskEvent.RESUME, BtfTaskState.RUNNING);
/* outgoing transitions for state PARKING */
makeTransition(BtfTaskState.PARKING, BtfTaskEvent.RELEASE_PARKING, BtfTaskState.READY);
makeTransition(BtfTaskState.PARKING, BtfTaskEvent.POLL_PARKING, BtfTaskState.POLLING);
/* outgoing transitions for state WAITING */
makeTransition(BtfTaskState.WAITING, BtfTaskEvent.RELEASE, BtfTaskState.READY);
}
private static void makeTransition(final BtfTaskState oldState, final BtfTaskEvent e, final BtfTaskState newState) {
multi[oldState.val()][e.val()] = newState;
}
private BtfTaskState currentState;
public BtfTaskFSM(final BtfTaskState start) {
this.currentState = start;
}
public void setState(final BtfTaskState state) {
this.currentState = state;
}
public BtfTaskState getState() {
return this.currentState;
}
public boolean dispatchEvent(final BtfTaskEvent event) {
final BtfTaskState newState = multi[this.currentState.val()][event.val()];
if (newState != null) {
this.currentState = newState;
return true;
}
// no state change
return false;
}
}