@@ -95,7 +95,7 @@ static void PyEngine_dealloc( PyEngine * self )
9595{
9696 CSP_BEGIN_METHOD;
9797 self -> ~PyEngine ();
98- Py_TYPE ( self ) -> tp_free ( self );
98+ Py_TYPE ( self ) -> tp_free ( self );
9999 CSP_RETURN;
100100}
101101
@@ -105,7 +105,7 @@ static PyObject * PyEngine_run( PyEngine * self, PyObject * args )
105105
106106 PyObject * pyStart;
107107 PyObject * pyEnd;
108- if ( !PyArg_ParseTuple ( args, " OO" , &pyStart, &pyEnd ) )
108+ if ( !PyArg_ParseTuple ( args, " OO" , &pyStart, &pyEnd ) )
109109 return nullptr ;
110110
111111 auto start = fromPython<DateTime>( pyStart );
@@ -118,8 +118,94 @@ static PyObject * PyEngine_run( PyEngine * self, PyObject * args )
118118 CSP_RETURN_NONE;
119119}
120120
121+ static PyObject * PyEngine_startStepping ( PyEngine * self, PyObject * args )
122+ {
123+ CSP_BEGIN_METHOD;
124+
125+ PyObject * pyStart;
126+ PyObject * pyEnd;
127+ if ( !PyArg_ParseTuple ( args, " OO" , &pyStart, &pyEnd ) )
128+ return nullptr ;
129+
130+ auto start = fromPython<DateTime>( pyStart );
131+ auto end = fromPython<DateTime>( pyEnd );
132+
133+ CSP_TRUE_OR_THROW_RUNTIME ( self -> engine () -> isRootEngine (), " engine is not root engine" );
134+ self -> rootEngine () -> startStepping ( start, end );
135+
136+ Py_RETURN_NONE;
137+ CSP_RETURN_NONE;
138+ }
139+
140+ static PyObject * PyEngine_step ( PyEngine * self, PyObject * args )
141+ {
142+ CSP_BEGIN_METHOD;
143+
144+ double maxWaitSeconds = 0.0 ;
145+ if ( !PyArg_ParseTuple ( args, " |d" , &maxWaitSeconds ) )
146+ return nullptr ;
147+
148+ CSP_TRUE_OR_THROW_RUNTIME ( self -> engine () -> isRootEngine (), " engine is not root engine" );
149+
150+ TimeDelta maxWait = maxWaitSeconds > 0 ? TimeDelta::fromSeconds ( maxWaitSeconds ) : TimeDelta::ZERO ();
151+ bool hasMore = self -> rootEngine () -> step ( maxWait );
152+
153+ return PyBool_FromLong ( hasMore );
154+ CSP_RETURN_NONE;
155+ }
156+
157+ static PyObject * PyEngine_stopStepping ( PyEngine * self, PyObject * args )
158+ {
159+ CSP_BEGIN_METHOD;
160+
161+ CSP_TRUE_OR_THROW_RUNTIME ( self -> engine () -> isRootEngine (), " engine is not root engine" );
162+ self -> rootEngine () -> stopStepping ();
163+
164+ return self -> collectOutputs ();
165+ CSP_RETURN_NONE;
166+ }
167+
168+ static PyObject * PyEngine_isStepping ( PyEngine * self, PyObject * args )
169+ {
170+ CSP_BEGIN_METHOD;
171+
172+ CSP_TRUE_OR_THROW_RUNTIME ( self -> engine () -> isRootEngine (), " engine is not root engine" );
173+ bool stepping = self -> rootEngine () -> isStepping ();
174+
175+ return PyBool_FromLong ( stepping );
176+ CSP_RETURN_NONE;
177+ }
178+
179+ static PyObject * PyEngine_now ( PyEngine * self, PyObject * args )
180+ {
181+ CSP_BEGIN_METHOD;
182+
183+ CSP_TRUE_OR_THROW_RUNTIME ( self -> engine () -> isRootEngine (), " engine is not root engine" );
184+ DateTime now = self -> rootEngine () -> now ();
185+
186+ return toPython ( now );
187+ CSP_RETURN_NONE;
188+ }
189+
190+ static PyObject * PyEngine_nextScheduledTime ( PyEngine * self, PyObject * args )
191+ {
192+ CSP_BEGIN_METHOD;
193+
194+ CSP_TRUE_OR_THROW_RUNTIME ( self -> engine () -> isRootEngine (), " engine is not root engine" );
195+ DateTime nextTime = self -> rootEngine () -> nextScheduledTime ();
196+
197+ return toPython ( nextTime );
198+ CSP_RETURN_NONE;
199+ }
200+
121201static PyMethodDef PyEngine_methods[] = {
122- { " run" , (PyCFunction) PyEngine_run, METH_VARARGS, " start and run engine" },
202+ { " run" , ( PyCFunction ) PyEngine_run, METH_VARARGS, " start and run engine" },
203+ { " start_stepping" , ( PyCFunction ) PyEngine_startStepping, METH_VARARGS, " start engine in step mode" },
204+ { " step" , ( PyCFunction ) PyEngine_step, METH_VARARGS, " execute one step, returns True if more work pending" },
205+ { " stop_stepping" , ( PyCFunction ) PyEngine_stopStepping, METH_NOARGS, " stop stepping and cleanup" },
206+ { " is_stepping" , ( PyCFunction ) PyEngine_isStepping, METH_NOARGS, " check if in stepping mode" },
207+ { " now" , ( PyCFunction ) PyEngine_now, METH_NOARGS, " get current engine time" },
208+ { " next_scheduled_time" , ( PyCFunction ) PyEngine_nextScheduledTime, METH_NOARGS, " get next scheduled event time" },
123209 { NULL }
124210};
125211
0 commit comments