bindings/python/ns3module_helpers.cc
author Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
Fri, 29 Aug 2008 14:56:24 +0100
changeset 3567 728eb3f583b3
parent 3408 2cc40b3e4fa5
child 3702 db14e253e614
permissions -rw-r--r--
Require new PyBindGen (now ignores the badly scanned anonymous containers that cause problems on cygwin) and rescan API.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     1
#include "ns3module.h"
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     2
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     3
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     4
namespace ns3{
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     5
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     6
void PythonCompleteConstruct (Ptr<Object> object, TypeId typeId, const AttributeList &attributes)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     7
{
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     8
  object->SetTypeId (typeId);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     9
  object->Object::Construct (attributes);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    10
}
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    11
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    12
}
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    13
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    14
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    15
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    16
class PythonEventImpl : public ns3::EventImpl
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    17
{
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    18
private:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    19
    PyObject *m_callback;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    20
    PyObject *m_args;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    21
public:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    22
    PythonEventImpl (PyObject *callback, PyObject *args)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    23
    {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    24
        m_callback = callback;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    25
        Py_INCREF(m_callback);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    26
        m_args = args;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    27
        Py_INCREF(m_args);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    28
    }
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    29
    virtual ~PythonEventImpl ()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    30
    {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    31
        Py_DECREF(m_callback);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    32
        Py_DECREF(m_args);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    33
    }
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    34
    virtual void Notify ()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    35
    {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    36
        PyObject *retval = PyObject_CallObject(m_callback, m_args);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    37
        if (retval) {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    38
            if (retval != Py_None) {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    39
                PyErr_SetString(PyExc_TypeError, "event callback should return None");
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    40
                PyErr_Print();
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    41
            }
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    42
            Py_DECREF(retval);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    43
        } else {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    44
             PyErr_Print();
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    45
        }
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    46
    }
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    47
};
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    48
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    49
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    50
PyObject *
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    51
_wrap_Simulator_Schedule(PyNs3Simulator *PYBINDGEN_UNUSED(dummy), PyObject *args, PyObject *kwargs,
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    52
                         PyObject **return_exception)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    53
{
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    54
    PyObject *exc_type, *traceback;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    55
    PyObject *py_time;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    56
    PyObject *py_callback;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    57
    PyObject *user_args;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    58
    ns3::Ptr<PythonEventImpl> py_event_impl;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    59
    PyNs3EventId *py_EventId;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    60
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    61
    if (kwargs && PyObject_Length(kwargs) > 0) {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    62
        PyErr_SetString(PyExc_TypeError, "keyword arguments not supported");
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    63
        goto error;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    64
    }
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    65
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    66
    if (PyTuple_GET_SIZE(args) < 2) {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    67
        PyErr_SetString(PyExc_TypeError, "ns3.Simulator.Schedule needs at least 2 arguments");
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    68
        goto error;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    69
    }
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    70
    py_time = PyTuple_GET_ITEM(args, 0);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    71
    py_callback = PyTuple_GET_ITEM(args, 1);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    72
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    73
    if (!PyObject_IsInstance(py_time, (PyObject*) &PyNs3Time_Type)) {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    74
        PyErr_SetString(PyExc_TypeError, "Parameter 1 should be a ns3.Time instance");
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    75
        goto error;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    76
    }
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    77
    if (!PyCallable_Check(py_callback)) {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    78
        PyErr_SetString(PyExc_TypeError, "Parameter 2 should be callable");
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    79
        goto error;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    80
    }
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    81
    user_args = PyTuple_GetSlice(args, 2, PyTuple_GET_SIZE(args));
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    82
    py_event_impl = ns3::Create<PythonEventImpl>(py_callback, user_args);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    83
    Py_DECREF(user_args);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    84
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    85
    py_EventId = PyObject_New(PyNs3EventId, &PyNs3EventId_Type);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    86
    py_EventId->obj = new ns3::EventId(
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    87
       ns3::Simulator::Schedule(*((PyNs3Time *) py_time)->obj, py_event_impl));
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    88
    return (PyObject *) py_EventId;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    89
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    90
error:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    91
    PyErr_Fetch(&exc_type, return_exception, &traceback);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    92
    Py_XDECREF(exc_type);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    93
    Py_XDECREF(traceback);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    94
    return NULL;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    95
}
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    96
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    97
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    98
PyObject *
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    99
_wrap_Simulator_ScheduleNow(PyNs3Simulator *PYBINDGEN_UNUSED(dummy), PyObject *args, PyObject *kwargs,
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   100
                            PyObject **return_exception)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   101
{
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   102
    PyObject *exc_type, *traceback;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   103
    PyObject *py_callback;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   104
    PyObject *user_args;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   105
    ns3::Ptr<PythonEventImpl> py_event_impl;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   106
    PyNs3EventId *py_EventId;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   107
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   108
    if (kwargs && PyObject_Length(kwargs) > 0) {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   109
        PyErr_SetString(PyExc_TypeError, "keyword arguments not supported");
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   110
        goto error;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   111
    }
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   112
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   113
    if (PyTuple_GET_SIZE(args) < 1) {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   114
        PyErr_SetString(PyExc_TypeError, "ns3.Simulator.Schedule needs at least 1 argument");
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   115
        goto error;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   116
    }
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   117
    py_callback = PyTuple_GET_ITEM(args, 0);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   118
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   119
    if (!PyCallable_Check(py_callback)) {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   120
        PyErr_SetString(PyExc_TypeError, "Parameter 2 should be callable");
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   121
        goto error;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   122
    }
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   123
    user_args = PyTuple_GetSlice(args, 1, PyTuple_GET_SIZE(args));
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   124
    py_event_impl = ns3::Create<PythonEventImpl>(py_callback, user_args);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   125
    Py_DECREF(user_args);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   126
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   127
    py_EventId = PyObject_New(PyNs3EventId, &PyNs3EventId_Type);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   128
    py_EventId->obj = new ns3::EventId(ns3::Simulator::ScheduleNow(py_event_impl));
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   129
    return (PyObject *) py_EventId;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   130
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   131
error:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   132
    PyErr_Fetch(&exc_type, return_exception, &traceback);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   133
    Py_XDECREF(exc_type);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   134
    Py_XDECREF(traceback);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   135
    return NULL;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   136
}
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   137
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   138
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   139
PyObject *
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   140
_wrap_Simulator_ScheduleDestroy(PyNs3Simulator *PYBINDGEN_UNUSED(dummy), PyObject *args, PyObject *kwargs,
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   141
                                PyObject **return_exception)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   142
{
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   143
    PyObject *exc_type, *traceback;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   144
    PyObject *py_callback;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   145
    PyObject *user_args;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   146
    ns3::Ptr<PythonEventImpl> py_event_impl;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   147
    PyNs3EventId *py_EventId;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   148
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   149
    if (kwargs && PyObject_Length(kwargs) > 0) {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   150
        PyErr_SetString(PyExc_TypeError, "keyword arguments not supported");
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   151
        goto error;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   152
    }
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   153
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   154
    if (PyTuple_GET_SIZE(args) < 1) {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   155
        PyErr_SetString(PyExc_TypeError, "ns3.Simulator.Schedule needs at least 1 argument");
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   156
        goto error;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   157
    }
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   158
    py_callback = PyTuple_GET_ITEM(args, 0);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   159
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   160
    if (!PyCallable_Check(py_callback)) {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   161
        PyErr_SetString(PyExc_TypeError, "Parameter 2 should be callable");
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   162
        goto error;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   163
    }
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   164
    user_args = PyTuple_GetSlice(args, 1, PyTuple_GET_SIZE(args));
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   165
    py_event_impl = ns3::Create<PythonEventImpl>(py_callback, user_args);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   166
    Py_DECREF(user_args);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   167
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   168
    py_EventId = PyObject_New(PyNs3EventId, &PyNs3EventId_Type);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   169
    py_EventId->obj = new ns3::EventId(ns3::Simulator::ScheduleDestroy(py_event_impl));
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   170
    return (PyObject *) py_EventId;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   171
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   172
error:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   173
    PyErr_Fetch(&exc_type, return_exception, &traceback);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   174
    Py_XDECREF(exc_type);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   175
    Py_XDECREF(traceback);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   176
    return NULL;
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   177
}
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   178