View | Details | Raw Unified | Return to bug 1350
Collapse All | Expand All

(-)a/src/core/bindings/module_helpers.cc (+58 lines)
 Lines 143-148    Link Here 
143
  return NULL;
143
  return NULL;
144
}
144
}
145
145
146
PyObject *
147
_wrap_Simulator_ScheduleWithContext(PyNs3Simulator *PYBINDGEN_UNUSED(dummy), PyObject *args, PyObject *kwargs,
148
                         PyObject **return_exception)
149
{
150
    PyObject *exc_type, *traceback;
151
    PyObject *py_obj_context;        
152
    uint32_t py_context;
153
    PyObject *py_time;
154
    PyObject *py_callback;    
155
    PyObject *user_args;
156
    PythonEventImpl *py_event_impl;
157
158
    if (kwargs && PyObject_Length(kwargs) > 0) {
159
        PyErr_SetString(PyExc_TypeError, "keyword arguments not supported");
160
        goto error;
161
    }
162
163
    if (PyTuple_GET_SIZE(args) < 3 ) {
164
        PyErr_SetString(PyExc_TypeError, "ns3.Simulator.ScheduleWithContext needs at least 3 arguments");
165
        goto error;
166
    }
167
168
    py_obj_context = PyTuple_GET_ITEM(args, 0);
169
    py_time = PyTuple_GET_ITEM(args, 1);
170
    py_callback = PyTuple_GET_ITEM(args, 2);
171
172
    if (!PyLong_Check(py_obj_context)) {
173
        PyErr_SetString(PyExc_TypeError, "Parameter 1 should be uint32_t");
174
        goto error;
175
    }
176
    if (!PyObject_IsInstance(py_time, (PyObject*) &PyNs3Time_Type)) {
177
        PyErr_SetString(PyExc_TypeError, "Parameter 2 should be a ns3.Time instance");
178
        goto error;
179
    }
180
    if (!PyCallable_Check(py_callback)) {
181
        PyErr_SetString(PyExc_TypeError, "Parameter 3 should be callable");
182
        goto error;
183
    }
184
185
    py_context = PyLong_AsUnsignedLong(py_obj_context);
186
187
    user_args = PyTuple_GetSlice(args, 3, PyTuple_GET_SIZE(args));
188
    py_event_impl = new PythonEventImpl (py_callback, user_args);
189
    Py_DECREF(user_args);  
190
191
    ns3::Simulator::ScheduleWithContext(py_context, *((PyNs3Time *) py_time)->obj,py_event_impl);
192
193
    //Python functions always expect a return type. In case of C/C++ void function this return type should be None (a.k.a Py_None)
194
    //It is necesary to increment the reference count to the Py_None object before returning it because it is going to be decremented later on.
195
    Py_INCREF(Py_None);
196
    return Py_None;
197
198
error:
199
    PyErr_Fetch(&exc_type, return_exception, &traceback);
200
    Py_XDECREF(exc_type);
201
    Py_XDECREF(traceback);
202
    return NULL;
203
}
146
204
147
PyObject *
205
PyObject *
148
_wrap_Simulator_ScheduleDestroy (PyNs3Simulator *PYBINDGEN_UNUSED (dummy), PyObject *args, PyObject *kwargs,
206
_wrap_Simulator_ScheduleDestroy (PyNs3Simulator *PYBINDGEN_UNUSED (dummy), PyObject *args, PyObject *kwargs,
(-)a/src/core/bindings/modulegen_customizations.py (-1 / +3 lines)
 Lines 303-313    Link Here 
303
    Simulator.add_custom_method_wrapper("Schedule", "_wrap_Simulator_Schedule",
303
    Simulator.add_custom_method_wrapper("Schedule", "_wrap_Simulator_Schedule",
304
                                        flags=["METH_VARARGS", "METH_KEYWORDS", "METH_STATIC"])
304
                                        flags=["METH_VARARGS", "METH_KEYWORDS", "METH_STATIC"])
305
305
306
307
    ## Simulator::ScheduleNow(callback, ...user..args...)
306
    ## Simulator::ScheduleNow(callback, ...user..args...)
308
    Simulator.add_custom_method_wrapper("ScheduleNow", "_wrap_Simulator_ScheduleNow",
307
    Simulator.add_custom_method_wrapper("ScheduleNow", "_wrap_Simulator_ScheduleNow",
309
                                        flags=["METH_VARARGS", "METH_KEYWORDS", "METH_STATIC"])
308
                                        flags=["METH_VARARGS", "METH_KEYWORDS", "METH_STATIC"])
310
309
310
    ## Simulator::ScheduleWithContext(delay, callback, ...user..args...)
311
    Simulator.add_custom_method_wrapper("ScheduleWithContext", "_wrap_Simulator_ScheduleWithContext",
312
                                        flags=["METH_VARARGS", "METH_KEYWORDS", "METH_STATIC"])
311
313
312
    ## Simulator::ScheduleDestroy(callback, ...user..args...)
314
    ## Simulator::ScheduleDestroy(callback, ...user..args...)
313
    Simulator.add_custom_method_wrapper("ScheduleDestroy", "_wrap_Simulator_ScheduleDestroy",
315
    Simulator.add_custom_method_wrapper("ScheduleDestroy", "_wrap_Simulator_ScheduleDestroy",

Return to bug 1350