src/core/bindings/modulegen_customizations.py
author Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
Sun, 27 Mar 2011 15:52:15 +0100
changeset 6954 10f280ceea11
parent 6895 9d9939611d71
child 7049 85bd74b8d00c
permissions -rw-r--r--
Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     1
import re
6954
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
     2
import os
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
     3
import sys
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     4
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     5
from pybindgen.typehandlers import base as typehandlers
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     6
from pybindgen import ReturnValue, Parameter
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     7
from pybindgen.cppmethod import CustomCppMethodWrapper, CustomCppConstructorWrapper
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     8
from pybindgen.typehandlers.codesink import MemoryCodeSink
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     9
from pybindgen.typehandlers import ctypeparser
6895
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
    10
from pybindgen import cppclass, param, retval
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    11
import warnings
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    12
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    13
from pybindgen.typehandlers.base import CodeGenerationError
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    14
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    15
6954
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    16
# class SmartPointerTransformation(typehandlers.TypeTransformation):
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    17
#     """
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    18
#     This class provides a "type transformation" that tends to support
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    19
#     NS-3 smart pointers.  Parameters such as "Ptr<Foo> foo" are
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    20
#     transformed into something like Parameter.new("Foo*", "foo",
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    21
#     transfer_ownership=False).  Return values such as Ptr<Foo> are
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    22
#     transformed into ReturnValue.new("Foo*",
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    23
#     caller_owns_return=False).  Since the underlying objects have
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    24
#     reference counting, PyBindGen does the right thing.
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    25
#     """
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    26
#     def __init__(self):
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    27
#         super(SmartPointerTransformation, self).__init__()
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    28
#         self.rx = re.compile(r'(ns3::|::ns3::|)Ptr<([^>]+)>\s*$')
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    29
6954
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    30
#     def _get_untransformed_type_traits(self, name):
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    31
#         m = self.rx.match(name)
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    32
#         is_const = False
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    33
#         if m is None:
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    34
#             return None, False
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    35
#         else:
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    36
#             name1 = m.group(2).strip()
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    37
#             if name1.startswith('const '):
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    38
#                 name1 = name1[len('const '):]
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    39
#                 is_const = True
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    40
#             if name1.endswith(' const'):
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    41
#                 name1 = name1[:-len(' const')]
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    42
#                 is_const = True
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    43
#             new_name = name1+' *'
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    44
6954
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    45
#             if new_name.startswith('::'):
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    46
#                 new_name = new_name[2:]
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    47
#             return new_name, is_const
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    48
6954
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    49
#     def get_untransformed_name(self, name):
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    50
#         new_name, dummy_is_const = self._get_untransformed_type_traits(name)
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    51
#         return new_name
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    52
6954
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    53
#     def create_type_handler(self, type_handler, *args, **kwargs):
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    54
#         if issubclass(type_handler, Parameter):
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    55
#             kwargs['transfer_ownership'] = False
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    56
#         elif issubclass(type_handler, ReturnValue):
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    57
#             kwargs['caller_owns_return'] = False
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    58
#         else:
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    59
#             raise AssertionError
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    60
6954
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    61
#         ## fix the ctype, add ns3:: namespace
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    62
#         orig_ctype, is_const = self._get_untransformed_type_traits(args[0])
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    63
#         if is_const:
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    64
#             correct_ctype = 'ns3::Ptr< %s const >' % orig_ctype[:-2]
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    65
#         else:
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    66
#             correct_ctype = 'ns3::Ptr< %s >' % orig_ctype[:-2]
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    67
#         args = tuple([correct_ctype] + list(args[1:]))
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    68
6954
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    69
#         handler = type_handler(*args, **kwargs)
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    70
#         handler.set_tranformation(self, orig_ctype)
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    71
#         return handler
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    72
6954
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    73
#     def untransform(self, type_handler, declarations, code_block, expression):
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    74
#         return 'const_cast<%s> (ns3::PeekPointer (%s))' % (type_handler.untransformed_ctype, expression)
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    75
6954
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    76
#     def transform(self, type_handler, declarations, code_block, expression):
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    77
#         assert type_handler.untransformed_ctype[-1] == '*'
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    78
#         return 'ns3::Ptr< %s > (%s)' % (type_handler.untransformed_ctype[:-1], expression)
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    79
6954
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    80
# ## register the type transformation
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    81
# transf = SmartPointerTransformation()
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    82
# typehandlers.return_type_matcher.register_transformation(transf)
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    83
# typehandlers.param_type_matcher.register_transformation(transf)
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
    84
# del transf
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    85
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    86
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    87
class ArgvParam(Parameter):
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    88
    """
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    89
    Converts a python list-of-strings argument to a pair of 'int argc,
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    90
    char *argv[]' arguments to pass into C.
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    91
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    92
    One Python argument becomes two C function arguments -> it's a miracle!
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    93
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    94
    Note: this parameter type handler is not registered by any name;
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    95
    must be used explicitly.
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    96
    """
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    97
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    98
    DIRECTIONS = [Parameter.DIRECTION_IN]
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    99
    CTYPES = []
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   100
    
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   101
    def convert_c_to_python(self, wrapper):
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   102
        raise NotImplementedError
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   103
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   104
    def convert_python_to_c(self, wrapper):
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   105
        py_name = wrapper.declarations.declare_variable('PyObject*', 'py_' + self.name)
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   106
        argc_var = wrapper.declarations.declare_variable('int', 'argc')
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   107
        name = wrapper.declarations.declare_variable('char**', self.name)
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   108
        idx = wrapper.declarations.declare_variable('Py_ssize_t', 'idx')
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   109
        wrapper.parse_params.add_parameter('O!', ['&PyList_Type', '&'+py_name], self.name)
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   110
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   111
        #wrapper.before_call.write_error_check('!PyList_Check(%s)' % py_name) # XXX
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   112
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   113
        wrapper.before_call.write_code("%s = (char **) malloc(sizeof(char*)*PyList_Size(%s));"
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   114
                                       % (name, py_name))
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   115
        wrapper.before_call.add_cleanup_code('free(%s);' % name)
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   116
        wrapper.before_call.write_code('''
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   117
for (%(idx)s = 0; %(idx)s < PyList_Size(%(py_name)s); %(idx)s++)
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   118
{
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   119
''' % vars())
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   120
        wrapper.before_call.sink.indent()
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   121
        wrapper.before_call.write_code('''
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   122
PyObject *item = PyList_GET_ITEM(%(py_name)s, %(idx)s);
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   123
''' % vars())
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   124
        #wrapper.before_call.write_error_check('item == NULL')
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   125
        wrapper.before_call.write_error_check(
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   126
            '!PyString_Check(item)',
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   127
            failure_cleanup=('PyErr_SetString(PyExc_TypeError, '
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   128
                             '"argument %s must be a list of strings");') % self.name)
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   129
        wrapper.before_call.write_code(
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   130
            '%s[%s] = PyString_AsString(item);' % (name, idx))
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   131
        wrapper.before_call.sink.unindent()
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   132
        wrapper.before_call.write_code('}')
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   133
        wrapper.before_call.write_code('%s = PyList_Size(%s);' % (argc_var, py_name))
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   134
        
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   135
        wrapper.call_params.append(argc_var)
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   136
        wrapper.call_params.append(name)
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   137
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   138
6954
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   139
# class CallbackImplProxyMethod(typehandlers.ReverseWrapperBase):
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   140
#     """
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   141
#     Class that generates a proxy virtual method that calls a similarly named python method.
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   142
#     """
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   143
6954
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   144
#     def __init__(self, return_value, parameters):
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   145
#         super(CallbackImplProxyMethod, self).__init__(return_value, parameters)
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   146
6954
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   147
#     def generate_python_call(self):
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   148
#         """code to call the python method"""
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   149
#         build_params = self.build_params.get_parameters(force_tuple_creation=True)
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   150
#         if build_params[0][0] == '"':
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   151
#             build_params[0] = '(char *) ' + build_params[0]
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   152
#         args = self.before_call.declare_variable('PyObject*', 'args')
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   153
#         self.before_call.write_code('%s = Py_BuildValue(%s);'
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   154
#                                     % (args, ', '.join(build_params)))
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   155
#         self.before_call.add_cleanup_code('Py_DECREF(%s);' % args)
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   156
#         self.before_call.write_code('py_retval = PyObject_CallObject(m_callback, %s);' % args)
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   157
#         self.before_call.write_error_check('py_retval == NULL')
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   158
#         self.before_call.add_cleanup_code('Py_DECREF(py_retval);')
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   159
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   160
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   161
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   162
6954
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   163
# def generate_callback_classes(out, callbacks):
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   164
#     for callback_impl_num, template_parameters in enumerate(callbacks):
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   165
#         sink = MemoryCodeSink()
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   166
#         cls_name = "ns3::Callback< %s >" % ', '.join(template_parameters)
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   167
#         #print >> sys.stderr, "***** trying to register callback: %r" % cls_name
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   168
#         class_name = "PythonCallbackImpl%i" % callback_impl_num
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   169
#         sink.writeln('''
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   170
# class %s : public ns3::CallbackImpl<%s>
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   171
# {
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   172
# public:
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   173
#     PyObject *m_callback;
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   174
#     %s(PyObject *callback)
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   175
#     {
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   176
#         Py_INCREF(callback);
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   177
#         m_callback = callback;
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   178
#     }
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   179
#     virtual ~%s()
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   180
#     {
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   181
#         Py_DECREF(m_callback);
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   182
#         m_callback = NULL;
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   183
#     }
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   184
6954
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   185
#     virtual bool IsEqual(ns3::Ptr<const ns3::CallbackImplBase> other_base) const
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   186
#     {
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   187
#         const %s *other = dynamic_cast<const %s*> (ns3::PeekPointer (other_base));
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   188
#         if (other != NULL)
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   189
#             return (other->m_callback == m_callback);
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   190
#         else
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   191
#             return false;
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   192
#     }
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   193
6954
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   194
# ''' % (class_name, ', '.join(template_parameters), class_name, class_name, class_name, class_name))
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   195
#         sink.indent()
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   196
#         callback_return = template_parameters[0]
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   197
#         return_ctype = ctypeparser.parse_type(callback_return)
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   198
#         if ('const' in return_ctype.remove_modifiers()):
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   199
#             kwargs = {'is_const': True}
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   200
#         else:
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   201
#             kwargs = {}
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   202
#         try:
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   203
#             return_type = ReturnValue.new(str(return_ctype), **kwargs)
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   204
#         except (typehandlers.TypeLookupError, typehandlers.TypeConfigurationError), ex:
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   205
#             warnings.warn("***** Unable to register callback; Return value '%s' error (used in %s): %r"
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   206
#                           % (callback_return, cls_name, ex),
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   207
#                           Warning)
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   208
#             continue
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   209
6954
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   210
#         arguments = []
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   211
#         ok = True
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   212
#         callback_parameters = [arg for arg in template_parameters[1:] if arg != 'ns3::empty']
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   213
#         for arg_num, arg_type in enumerate(callback_parameters):
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   214
#             arg_name = 'arg%i' % (arg_num+1)
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   215
6954
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   216
#             param_ctype = ctypeparser.parse_type(arg_type)
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   217
#             if ('const' in param_ctype.remove_modifiers()):
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   218
#                 kwargs = {'is_const': True}
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   219
#             else:
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   220
#                 kwargs = {}
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   221
#             try:
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   222
#                 arguments.append(Parameter.new(str(param_ctype), arg_name, **kwargs))
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   223
#             except (typehandlers.TypeLookupError, typehandlers.TypeConfigurationError), ex:
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   224
#                 warnings.warn("***** Unable to register callback; parameter '%s %s' error (used in %s): %r"
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   225
#                               % (arg_type, arg_name, cls_name, ex),
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   226
#                               Warning)
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   227
#                 ok = False
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   228
#         if not ok:
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   229
#             continue
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   230
6954
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   231
#         wrapper = CallbackImplProxyMethod(return_type, arguments)
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   232
#         wrapper.generate(sink, 'operator()', decl_modifiers=[])
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   233
            
6954
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   234
#         sink.unindent()
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   235
#         sink.writeln('};\n')
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   236
#         sink.flush_to(out)
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   237
        
6954
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   238
#         class PythonCallbackParameter(Parameter):
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   239
#             "Class handlers"
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   240
#             CTYPES = [cls_name]
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   241
#             #print >> sys.stderr, "***** registering callback handler: %r" % ctypeparser.normalize_type_string(cls_name)
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   242
#             DIRECTIONS = [Parameter.DIRECTION_IN]
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   243
#             PYTHON_CALLBACK_IMPL_NAME = class_name
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   244
#             TEMPLATE_ARGS = template_parameters
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   245
6954
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   246
#             def convert_python_to_c(self, wrapper):
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   247
#                 "parses python args to get C++ value"
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   248
#                 assert isinstance(wrapper, typehandlers.ForwardWrapperBase)
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   249
6954
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   250
#                 if self.default_value is None:
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   251
#                     py_callback = wrapper.declarations.declare_variable('PyObject*', self.name)
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   252
#                     wrapper.parse_params.add_parameter('O', ['&'+py_callback], self.name)
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   253
#                     wrapper.before_call.write_error_check(
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   254
#                         '!PyCallable_Check(%s)' % py_callback,
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   255
#                         'PyErr_SetString(PyExc_TypeError, "parameter \'%s\' must be callbale");' % self.name)
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   256
#                     callback_impl = wrapper.declarations.declare_variable(
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   257
#                         'ns3::Ptr<%s>' % self.PYTHON_CALLBACK_IMPL_NAME,
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   258
#                         '%s_cb_impl' % self.name)
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   259
#                     wrapper.before_call.write_code("%s = ns3::Create<%s> (%s);"
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   260
#                                                    % (callback_impl, self.PYTHON_CALLBACK_IMPL_NAME, py_callback))
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   261
#                     wrapper.call_params.append(
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   262
#                         'ns3::Callback<%s> (%s)' % (', '.join(self.TEMPLATE_ARGS), callback_impl))
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   263
#                 else:
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   264
#                     py_callback = wrapper.declarations.declare_variable('PyObject*', self.name, 'NULL')
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   265
#                     wrapper.parse_params.add_parameter('O', ['&'+py_callback], self.name, optional=True)
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   266
#                     value = wrapper.declarations.declare_variable(
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   267
#                         'ns3::Callback<%s>' % ', '.join(self.TEMPLATE_ARGS),
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   268
#                         self.name+'_value',
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   269
#                         self.default_value)
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   270
6954
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   271
#                     wrapper.before_call.write_code("if (%s) {" % (py_callback,))
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   272
#                     wrapper.before_call.indent()
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   273
6954
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   274
#                     wrapper.before_call.write_error_check(
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   275
#                         '!PyCallable_Check(%s)' % py_callback,
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   276
#                         'PyErr_SetString(PyExc_TypeError, "parameter \'%s\' must be callbale");' % self.name)
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   277
6954
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   278
#                     wrapper.before_call.write_code("%s = ns3::Callback<%s> (ns3::Create<%s> (%s));"
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   279
#                                                    % (value, ', '.join(self.TEMPLATE_ARGS),
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   280
#                                                       self.PYTHON_CALLBACK_IMPL_NAME, py_callback))
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   281
6954
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   282
#                     wrapper.before_call.unindent()
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   283
#                     wrapper.before_call.write_code("}") # closes: if (py_callback) {
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   284
                                        
6954
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   285
#                     wrapper.call_params.append(value)
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   286
                    
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   287
6954
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   288
#             def convert_c_to_python(self, wrapper):
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   289
#                 raise typehandlers.NotSupportedError("Reverse wrappers for ns3::Callback<...> types "
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   290
#                                                      "(python using callbacks defined in C++) not implemented.")
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   291
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   292
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   293
# def write_preamble(out):
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   294
#     pybindgen.write_preamble(out)
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   295
#     out.writeln("#include \"ns3/everything.h\"")
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   296
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   297
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   298
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   299
def Simulator_customizations(module):
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   300
    Simulator = module['ns3::Simulator']
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   301
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   302
    ## Simulator::Schedule(delay, callback, ...user..args...)
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   303
    Simulator.add_custom_method_wrapper("Schedule", "_wrap_Simulator_Schedule",
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   304
                                        flags=["METH_VARARGS", "METH_KEYWORDS", "METH_STATIC"])
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   305
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   306
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   307
    ## Simulator::ScheduleNow(callback, ...user..args...)
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   308
    Simulator.add_custom_method_wrapper("ScheduleNow", "_wrap_Simulator_ScheduleNow",
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   309
                                        flags=["METH_VARARGS", "METH_KEYWORDS", "METH_STATIC"])
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   310
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   311
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   312
    ## Simulator::ScheduleDestroy(callback, ...user..args...)
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   313
    Simulator.add_custom_method_wrapper("ScheduleDestroy", "_wrap_Simulator_ScheduleDestroy",
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   314
                                        flags=["METH_VARARGS", "METH_KEYWORDS", "METH_STATIC"])
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   315
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   316
    Simulator.add_custom_method_wrapper("Run", "_wrap_Simulator_Run",
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   317
                                        flags=["METH_VARARGS", "METH_KEYWORDS", "METH_STATIC"])
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   318
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   319
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   320
def CommandLine_customizations(module):
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   321
    CommandLine = module['ns3::CommandLine']
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   322
    CommandLine.add_method('Parse', None, [ArgvParam(None, 'argv')],
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   323
                           is_static=False)
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   324
    CommandLine.add_custom_method_wrapper("AddValue", "_wrap_CommandLine_AddValue",
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   325
                                          flags=["METH_VARARGS", "METH_KEYWORDS"])
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   326
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   327
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   328
# def Object_customizations(module):
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   329
#     ## ---------------------------------------------------------------------
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   330
#     ## Here we generate custom constructor code for all classes that
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   331
#     ## derive from ns3::Object.  The custom constructors are needed in
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   332
#     ## order to support kwargs only and to translate kwargs into ns3
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   333
#     ## attributes, etc.
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   334
#     ## ---------------------------------------------------------------------
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   335
#     Object = module['ns3::Object']
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   336
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   337
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   338
#     ## add a GetTypeId method to all generatd helper classes
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   339
#     def helper_class_hook(helper_class):
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   340
#         decl = """
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   341
# static ns3::TypeId GetTypeId (void)
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   342
# {
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   343
#   static ns3::TypeId tid = ns3::TypeId ("%s")
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   344
#     .SetParent< %s > ()
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   345
#     ;
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   346
#   return tid;
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   347
# }"""  % (helper_class.name, helper_class.class_.full_name)
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   348
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   349
#         helper_class.add_custom_method(decl)
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   350
#         helper_class.add_post_generation_code(
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   351
#             "NS_OBJECT_ENSURE_REGISTERED (%s);" % helper_class.name)
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   352
#     Object.add_helper_class_hook(helper_class_hook)
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   353
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   354
#     def ns3_object_instance_creation_function(cpp_class, code_block, lvalue,
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   355
#                                               parameters, construct_type_name):
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   356
#         assert lvalue
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   357
#         assert not lvalue.startswith('None')
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   358
#         if cpp_class.cannot_be_constructed:
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   359
#             raise CodeGenerationError("%s cannot be constructed (%s)"
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   360
#                                       % cpp_class.full_name)
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   361
#         if cpp_class.incomplete_type:
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   362
#             raise CodeGenerationError("%s cannot be constructed (incomplete type)"
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   363
#                                       % cpp_class.full_name)
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   364
#         code_block.write_code("%s = new %s(%s);" % (lvalue, construct_type_name, parameters))
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   365
#         code_block.write_code("%s->Ref ();" % (lvalue))
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   366
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   367
#     def ns3_object_post_instance_creation_function(cpp_class, code_block, lvalue,
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   368
#                                                    parameters, construct_type_name):
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   369
#         code_block.write_code("ns3::CompleteConstruct(%s);" % (lvalue, ))
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   370
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   371
#     Object.set_instance_creation_function(ns3_object_instance_creation_function)
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   372
#     Object.set_post_instance_creation_function(ns3_object_post_instance_creation_function)
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   373
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   374
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   375
# def Attribute_customizations(module):
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   376
#     # Fix up for the "const AttributeValue &v = EmptyAttribute()"
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   377
#     # case, as used extensively by helper classes.
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   378
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   379
#     # Here's why we need to do this: pybindgen.gccxmlscanner, when
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   380
#     # scanning parameter default values, is only provided with the
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   381
#     # value as a simple C expression string.  (py)gccxml does not
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   382
#     # report the type of the default value.
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   383
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   384
#     # As a workaround, here we iterate over all parameters of all
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   385
#     # methods of all classes and tell pybindgen what is the type of
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   386
#     # the default value for attributes.
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   387
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   388
#     for cls in module.classes:
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   389
#         for meth in cls.get_all_methods():
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   390
#             for param in meth.parameters:
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   391
#                 if isinstance(param, cppclass.CppClassRefParameter):
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   392
#                     if param.cpp_class.name == 'AttributeValue' \
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   393
#                             and param.default_value is not None \
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   394
#                             and param.default_value_type is None:
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   395
#                         param.default_value_type = 'ns3::EmptyAttributeValue'
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   396
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   397
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   398
def TypeId_customizations(module):
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   399
    TypeId = module['ns3::TypeId']
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   400
    TypeId.add_custom_method_wrapper("LookupByNameFailSafe", "_wrap_TypeId_LookupByNameFailSafe",
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   401
                                     flags=["METH_VARARGS", "METH_KEYWORDS", "METH_STATIC"])
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   402
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   403
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   404
def add_std_ofstream(module):
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   405
    module.add_include('<fstream>')
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   406
    ostream = module.add_class('ostream', foreign_cpp_namespace='::std')
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   407
    ostream.set_cannot_be_constructed("abstract base class")
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   408
    ofstream = module.add_class('ofstream', foreign_cpp_namespace='::std', parent=ostream)
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   409
    ofstream.add_enum('openmode', [
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   410
            ('app', 'std::ios_base::app'),
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   411
            ('ate', 'std::ios_base::ate'),
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   412
            ('binary', 'std::ios_base::binary'),
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   413
            ('in', 'std::ios_base::in'),
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   414
            ('out', 'std::ios_base::out'),
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   415
            ('trunc', 'std::ios_base::trunc'),
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   416
            ])
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   417
    ofstream.add_constructor([Parameter.new("const char *", 'filename'),
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   418
                              Parameter.new("::std::ofstream::openmode", 'mode', default_value="std::ios_base::out")])
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   419
    ofstream.add_method('close', None, [])
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   420
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   421
    import pybindgen.typehandlers.base
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   422
    for alias in "std::_Ios_Openmode", "std::ios::openmode":
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   423
        pybindgen.typehandlers.base.param_type_matcher.add_type_alias(alias, "int")
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   424
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   425
    for flag in 'in', 'out', 'ate', 'app', 'trunc', 'binary':
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   426
        module.after_init.write_code('PyModule_AddIntConstant(m, (char *) "STD_IOS_%s", std::ios::%s);'
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   427
                                     % (flag.upper(), flag))
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   428
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   429
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   430
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   431
def add_ipv4_address_tp_hash(module):
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   432
    module.body.writeln('''
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   433
long
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   434
_ns3_Ipv4Address_tp_hash (PyObject *obj)
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   435
{
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   436
   PyNs3Ipv4Address *addr = reinterpret_cast<PyNs3Ipv4Address *> (obj);
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   437
   return static_cast<long> (ns3::Ipv4AddressHash () (*addr->obj));
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   438
}
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   439
''')
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   440
    module.header.writeln('long _ns3_Ipv4Address_tp_hash (PyObject *obj);')
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   441
    module['Ipv4Address'].pytype.slots['tp_hash'] = "_ns3_Ipv4Address_tp_hash"
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   442
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   443
6895
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   444
def add_scalar_operators(root_module):
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   445
    # Scalar implicitly converts to Time, but pybindgen gccxml parser
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   446
    # cannot pick up operators supported through implicit conversions,
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   447
    # so we add them manually here.
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   448
    cls = root_module['ns3::Scalar']
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   449
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   450
    cls.add_binary_numeric_operator('*', root_module['ns3::Scalar'], root_module['ns3::Scalar'], param('ns3::Scalar const &', 'right'))
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   451
    cls.add_binary_numeric_operator('+', root_module['ns3::Scalar'], root_module['ns3::Scalar'], param('ns3::Scalar const &', 'right'))
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   452
    cls.add_binary_numeric_operator('-', root_module['ns3::Scalar'], root_module['ns3::Scalar'], param('ns3::Scalar const &', 'right'))
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   453
    cls.add_binary_numeric_operator('/', root_module['ns3::Scalar'], root_module['ns3::Scalar'], param('ns3::Scalar const &', 'right'))
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   454
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   455
    cls.add_binary_numeric_operator('*', root_module['ns3::Time'], root_module['ns3::Scalar'], param('ns3::Time const &', 'right'))
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   456
    cls.add_binary_numeric_operator('-', root_module['ns3::Time'], root_module['ns3::Scalar'], param('ns3::Time const &', 'right'))
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   457
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   458
    root_module['ns3::Time'].add_binary_numeric_operator(
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   459
        '*', root_module['ns3::Time'], root_module['ns3::Time'], param('ns3::Scalar const &', 'right'))
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   460
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   461
    root_module['ns3::Time'].add_binary_numeric_operator(
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   462
        '-', root_module['ns3::Time'], root_module['ns3::Time'], param('ns3::Scalar const &', 'right'))
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   463
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   464
    cls.add_binary_comparison_operator('<')
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   465
    cls.add_binary_comparison_operator('>')
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   466
    cls.add_binary_comparison_operator('!=')
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   467
    cls.add_output_stream_operator()
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   468
    cls.add_binary_comparison_operator('<=')
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   469
    cls.add_binary_comparison_operator('==')
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   470
    cls.add_binary_comparison_operator('>=')
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   471
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   472
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   473
def post_register_types(root_module):
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   474
    Simulator_customizations(root_module)
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   475
    CommandLine_customizations(root_module)
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   476
    TypeId_customizations(root_module)
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   477
    add_std_ofstream(root_module)
6895
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   478
    add_scalar_operators(root_module)
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   479
6954
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   480
    enabled_features = os.environ['NS3_ENABLED_FEATURES'].split(',')    
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   481
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   482
    if 'Threading' not in enabled_features:
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   483
        for clsname in ['SystemThread', 'SystemMutex', 'SystemCondition', 'CriticalSection',
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   484
                        'SimpleRefCount< ns3::SystemThread, ns3::empty, ns3::DefaultDeleter<ns3::SystemThread> >']:
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   485
            root_module.classes.remove(root_module['ns3::%s' % clsname])
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   486
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   487
    if 'RealTime' not in enabled_features:
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   488
        for clsname in ['WallClockSynchronizer', 'RealtimeSimulatorImpl']:
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   489
            root_module.classes.remove(root_module['ns3::%s' % clsname])
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   490
        root_module.enums.remove(root_module['ns3::RealtimeSimulatorImpl::SynchronizationMode'])
10f280ceea11 Modular bindings: disable certain binding classes when certain features are disabled in ns-3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6895
diff changeset
   491
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   492
6895
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   493
# these are already in the main script, so commented out here
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   494
# Object_customizations(root_module)
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   495
# Attribute_customizations(root_module)
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   496
#def post_register_functions(root_module):
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   497
#    pass
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   498
9d9939611d71 Modular bindings: make Scalar operators work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   499