Commit c9532b89 authored by Georg Martin Reinke's avatar Georg Martin Reinke
Browse files

add another "done" simulation state


Former-commit-id: 50c7da4e
parent cac0c80e
...@@ -43,7 +43,8 @@ std::vector<BaseComponent*> components; ...@@ -43,7 +43,8 @@ std::vector<BaseComponent*> components;
enum SimState { enum SimState {
StateStopped = 0, StateStopped = 0,
StateRunning, StateRunning,
StatePaused StatePaused,
StateDone
}; };
static std::thread *simThread; static std::thread *simThread;
...@@ -87,7 +88,7 @@ static void simThreadFunction(SimContext* ctx) { ...@@ -87,7 +88,7 @@ static void simThreadFunction(SimContext* ctx) {
} }
} }
lk.lock(); lk.lock();
ctx->state = StateStopped; ctx->state = StateDone;
ctx->cond.notify_one(); ctx->cond.notify_one();
} }
...@@ -96,6 +97,9 @@ static PyObject* pythonStart(PyObject *self, PyObject *args) { ...@@ -96,6 +97,9 @@ static PyObject* pythonStart(PyObject *self, PyObject *args) {
if (globalCtx->state == StateRunning) { if (globalCtx->state == StateRunning) {
PyErr_SetString(PyExc_SystemError, "Simulation already started"); PyErr_SetString(PyExc_SystemError, "Simulation already started");
return nullptr; return nullptr;
} else if (globalCtx->state == StateDone) {
PyErr_SetString(PyExc_SystemError, "Simulation already finished");
return nullptr;
} else if (globalCtx->state == StatePaused) { } else if (globalCtx->state == StatePaused) {
globalCtx->stop = 0; globalCtx->stop = 0;
globalCtx->cond.notify_one(); globalCtx->cond.notify_one();
...@@ -118,6 +122,9 @@ static PyObject* pythonStep(PyObject *self, PyObject *args) { ...@@ -118,6 +122,9 @@ static PyObject* pythonStep(PyObject *self, PyObject *args) {
} else if (globalCtx->state == StatePaused) { } else if (globalCtx->state == StatePaused) {
globalCtx->stop = 1; globalCtx->stop = 1;
globalCtx->cond.notify_one(); globalCtx->cond.notify_one();
} else if (globalCtx->state == StateDone) {
PyErr_SetString(PyExc_SystemError, "Simulation already finished");
return nullptr;
} else { } else {
PyErr_SetString(PyExc_SystemError, "Simulation currently running"); PyErr_SetString(PyExc_SystemError, "Simulation currently running");
return nullptr; return nullptr;
...@@ -144,9 +151,12 @@ static PyObject* pythonPause(PyObject *self, PyObject *args) { ...@@ -144,9 +151,12 @@ static PyObject* pythonPause(PyObject *self, PyObject *args) {
static PyObject* pythonWait(PyObject *self, PyObject *args) { static PyObject* pythonWait(PyObject *self, PyObject *args) {
std::unique_lock<std::mutex> lk(globalCtx->mut); std::unique_lock<std::mutex> lk(globalCtx->mut);
if (globalCtx->state == StateStopped) { if (globalCtx->state == StateDone) {
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} else if (globalCtx->state == StateStopped) {
PyErr_SetString(PyExc_SystemError, "Simulation not currently running");
return nullptr;
} else if (globalCtx->state == StatePaused) { } else if (globalCtx->state == StatePaused) {
PyErr_SetString(PyExc_SystemError, "Simulation currently paused"); PyErr_SetString(PyExc_SystemError, "Simulation currently paused");
return nullptr; return nullptr;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment