Commit 50c7da4e authored by Georg Martin Reinke's avatar Georg Martin Reinke
Browse files

add another "done" simulation state

parent 269e8378
......@@ -43,7 +43,8 @@ std::vector<BaseComponent*> components;
enum SimState {
StateStopped = 0,
StateRunning,
StatePaused
StatePaused,
StateDone
};
static std::thread *simThread;
......@@ -87,7 +88,7 @@ static void simThreadFunction(SimContext* ctx) {
}
}
lk.lock();
ctx->state = StateStopped;
ctx->state = StateDone;
ctx->cond.notify_one();
}
......@@ -96,6 +97,9 @@ static PyObject* pythonStart(PyObject *self, PyObject *args) {
if (globalCtx->state == StateRunning) {
PyErr_SetString(PyExc_SystemError, "Simulation already started");
return nullptr;
} else if (globalCtx->state == StateDone) {
PyErr_SetString(PyExc_SystemError, "Simulation already finished");
return nullptr;
} else if (globalCtx->state == StatePaused) {
globalCtx->stop = 0;
globalCtx->cond.notify_one();
......@@ -118,6 +122,9 @@ static PyObject* pythonStep(PyObject *self, PyObject *args) {
} else if (globalCtx->state == StatePaused) {
globalCtx->stop = 1;
globalCtx->cond.notify_one();
} else if (globalCtx->state == StateDone) {
PyErr_SetString(PyExc_SystemError, "Simulation already finished");
return nullptr;
} else {
PyErr_SetString(PyExc_SystemError, "Simulation currently running");
return nullptr;
......@@ -144,9 +151,12 @@ static PyObject* pythonPause(PyObject *self, PyObject *args) {
static PyObject* pythonWait(PyObject *self, PyObject *args) {
std::unique_lock<std::mutex> lk(globalCtx->mut);
if (globalCtx->state == StateStopped) {
if (globalCtx->state == StateDone) {
Py_INCREF(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) {
PyErr_SetString(PyExc_SystemError, "Simulation currently paused");
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