123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- /*
- * state.c
- *
- * Copyright (c) 2023 Thomas Buck (thomas@xythobuz.de)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * See <http://www.gnu.org/licenses/>.
- */
-
- #include "config.h"
- #include "log.h"
- #include "state_scan.h"
- #include "state_volcano_workflow.h"
- #include "state_volcano_run.h"
- #include "state_crafty.h"
- #include "state.h"
-
- static enum system_state state = STATE_INIT;
-
- void state_switch(enum system_state next) {
- if (state == next) {
- return;
- }
-
- // clean up old state when leaving it
- switch (state) {
- case STATE_SCAN:
- debug("leaving STATE_SCAN");
- state_scan_exit();
- break;
-
- case STATE_VOLCANO_WORKFLOW:
- debug("leaving STATE_VOLCANO_WORKFLOW");
- state_volcano_wf_exit();
- break;
-
- case STATE_VOLCANO_RUN:
- debug("leaving STATE_VOLCANO_RUN");
- state_volcano_run_exit();
- break;
-
- case STATE_CRAFTY:
- debug("leaving STATE_CRAFTY");
- state_crafty_exit();
- break;
-
- default:
- break;
- }
-
- // prepare new state on entering
- switch (next) {
- case STATE_SCAN:
- debug("entering STATE_SCAN");
- state_scan_enter();
- break;
-
- case STATE_VOLCANO_WORKFLOW:
- debug("entering STATE_VOLCANO_WORKFLOW");
- state_volcano_wf_enter();
- break;
-
- case STATE_VOLCANO_RUN:
- debug("entering STATE_VOLCANO_RUN");
- state_volcano_run_enter();
- break;
-
- case STATE_CRAFTY:
- debug("entering STATE_CRAFTY");
- state_crafty_enter();
- break;
-
- default:
- break;
- }
-
- state = next;
- }
-
- void state_run(void) {
- switch (state) {
- case STATE_INIT:
- break;
-
- case STATE_SCAN:
- state_scan_run();
- break;
-
- case STATE_VOLCANO_WORKFLOW:
- state_volcano_wf_run();
- break;
-
- case STATE_VOLCANO_RUN:
- state_volcano_run_run();
- break;
-
- case STATE_CRAFTY:
- state_crafty_run();
- break;
-
- default:
- debug("invalid main state %d", state);
- state_switch(STATE_SCAN);
- break;
- }
- }
|