bindings/python/ns3modulescan.py
author Alexander Krotov <ilabdsf@yandex.ru>
Fri, 04 Sep 2015 01:10:29 +0200
changeset 11630 aba589d21bce
parent 7723 dfd109d5caf0
permissions -rw-r--r--
bug 2173: WifiInformationElement::DeserializeIfPresent attempts to read beyond the end of buffer
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     1
#! /usr/bin/env python
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     2
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     3
import sys
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     4
import os.path
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     5
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     6
import pybindgen.settings
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     7
from pybindgen.gccxmlparser import ModuleParser, PygenClassifier, PygenSection, WrapperWarning
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     8
from pybindgen.typehandlers.codesink import FileCodeSink
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     9
from pygccxml.declarations import templates
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    10
from pygccxml.declarations.class_declaration import class_t
5755
4214e2d08941 Patch the bad default_value given by gccxml in the case of MilliSeconds(0)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
    11
from pygccxml.declarations.calldef import free_function_t, member_function_t, constructor_t, calldef_t
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    12
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    13
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    14
## we need the smart pointer type transformation to be active even
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    15
## during gccxml scanning.
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    16
import ns3modulegen_core_customizations
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    17
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    18
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    19
## silence gccxmlparser errors; we only want error handling in the
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    20
## generated python script, not while scanning.
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    21
class ErrorHandler(pybindgen.settings.ErrorHandler):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    22
    def handle_error(self, dummy_wrapper, dummy_exception, dummy_traceback_):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    23
        return True
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    24
pybindgen.settings.error_handler = ErrorHandler()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    25
import warnings
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    26
warnings.filterwarnings(category=WrapperWarning, action='ignore')
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    27
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    28
type_annotations = {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    29
    '::ns3::AttributeChecker': {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    30
        'automatic_type_narrowing': 'true',
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    31
        'allow_subclassing': 'false',
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    32
        },
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    33
    '::ns3::AttributeValue': {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    34
        'automatic_type_narrowing': 'true',
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    35
        'allow_subclassing': 'false',
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    36
        },
3929
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3755
diff changeset
    37
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3755
diff changeset
    38
    '::ns3::CommandLine': {
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3755
diff changeset
    39
        'allow_subclassing': 'true', # needed so that AddValue is able to set attributes on the object
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3755
diff changeset
    40
        },
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3755
diff changeset
    41
4749
af227579ab64 Don't python-bind the class NscTcpL4Protocol, it is implementation detail.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4086
diff changeset
    42
    '::ns3::NscTcpL4Protocol': {
af227579ab64 Don't python-bind the class NscTcpL4Protocol, it is implementation detail.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4086
diff changeset
    43
        'ignore': 'true', # this class is implementation detail
af227579ab64 Don't python-bind the class NscTcpL4Protocol, it is implementation detail.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4086
diff changeset
    44
        },
af227579ab64 Don't python-bind the class NscTcpL4Protocol, it is implementation detail.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4086
diff changeset
    45
af227579ab64 Don't python-bind the class NscTcpL4Protocol, it is implementation detail.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4086
diff changeset
    46
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    47
    'ns3::RandomVariable::RandomVariable(ns3::RandomVariableBase const & variable) [constructor]': {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    48
        'ignore': None,
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    49
        },
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    50
    'ns3::RandomVariableBase * ns3::RandomVariable::Peek() const [member function]': {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    51
        'ignore': None,
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    52
        },
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    53
    'void ns3::RandomVariable::GetSeed(uint32_t * seed) const [member function]': {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    54
        'params': {'seed':{'direction':'out',
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    55
                           'array_length':'6'}}
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    56
        },
7723
dfd109d5caf0 Bug 1349 - TypeId.LookupAttributeByName Python bindings missing
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7052
diff changeset
    57
    'bool ns3::TypeId::LookupAttributeByName(std::string name, ns3::TypeId::AttributeInformation * info) const [member function]': {
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    58
        'params': {'info':{'transfer_ownership': 'false'}}
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    59
        },
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    60
    'static bool ns3::TypeId::LookupByNameFailSafe(std::string name, ns3::TypeId * tid) [member function]': {
3753
a84a48233eb3 A more pythonic wrapper for ns3.TypeId.LookupByNameFailSafe
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3537
diff changeset
    61
        'ignore': None, # manually wrapped in 
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    62
        },
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    63
    'bool ns3::TraceSourceAccessor::ConnectWithoutContext(ns3::ObjectBase * obj, ns3::CallbackBase const & cb) const [member function]': {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    64
        'params': {'obj': {'transfer_ownership':'false'}}
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    65
        },
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    66
    'bool ns3::TraceSourceAccessor::Connect(ns3::ObjectBase * obj, std::string context, ns3::CallbackBase const & cb) const [member function]': {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    67
        'params': {'obj': {'transfer_ownership':'false'}}
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    68
        },
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    69
    'bool ns3::TraceSourceAccessor::DisconnectWithoutContext(ns3::ObjectBase * obj, ns3::CallbackBase const & cb) const [member function]': {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    70
        'params': {'obj': {'transfer_ownership':'false'}}
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    71
        },
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    72
    'bool ns3::TraceSourceAccessor::Disconnect(ns3::ObjectBase * obj, std::string context, ns3::CallbackBase const & cb) const [member function]': {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    73
        'params': {'obj': {'transfer_ownership':'false'}}
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    74
        },
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    75
    'bool ns3::AttributeAccessor::Set(ns3::ObjectBase * object, ns3::AttributeValue const & value) const [member function]': {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    76
        'params': {'object': {'transfer_ownership':'false'}}
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    77
        },
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    78
    'ns3::EmpiricalVariable::EmpiricalVariable(ns3::RandomVariableBase const & variable) [constructor]': {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    79
        'ignore': None
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    80
        },
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    81
    'static ns3::AttributeList * ns3::AttributeList::GetGlobal() [member function]': {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    82
        'caller_owns_return': 'false'
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    83
        },
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    84
    'void ns3::CommandLine::Parse(int argc, char * * argv) const [member function]': {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    85
        'ignore': None # manually wrapped
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    86
        },
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    87
    'extern void ns3::PythonCompleteConstruct(ns3::Ptr<ns3::Object> object, ns3::TypeId typeId, ns3::AttributeList const & attributes) [free function]': {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    88
        'ignore': None # used transparently by, should not be wrapped
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    89
        },
6139
3202621a634c Fix the Python binding for ns3::Ipv4ListRouting::GetRoutingProtocol
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6047
diff changeset
    90
3202621a634c Fix the Python binding for ns3::Ipv4ListRouting::GetRoutingProtocol
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6047
diff changeset
    91
    'ns3::Ptr<ns3::Ipv4RoutingProtocol> ns3::Ipv4ListRouting::GetRoutingProtocol(uint32_t index, int16_t & priority) const [member function]': {
3202621a634c Fix the Python binding for ns3::Ipv4ListRouting::GetRoutingProtocol
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6047
diff changeset
    92
        'params': {'priority':{'direction':'out'}}
3202621a634c Fix the Python binding for ns3::Ipv4ListRouting::GetRoutingProtocol
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6047
diff changeset
    93
        },
5980
7929ba7d13bd Python: add needed annotations to ns3::GlobalRouter::GetInjectedRoute and ns3::Ipv4GlobalRouting::GetRoute. Fixes bug #809.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5879
diff changeset
    94
    'ns3::Ipv4RoutingTableEntry * ns3::GlobalRouter::GetInjectedRoute(uint32_t i) [member function]': {
7929ba7d13bd Python: add needed annotations to ns3::GlobalRouter::GetInjectedRoute and ns3::Ipv4GlobalRouting::GetRoute. Fixes bug #809.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5879
diff changeset
    95
        'params': {'return': { 'caller_owns_return': 'false',}},
7929ba7d13bd Python: add needed annotations to ns3::GlobalRouter::GetInjectedRoute and ns3::Ipv4GlobalRouting::GetRoute. Fixes bug #809.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5879
diff changeset
    96
        },
6816
9e50416beaea Python: Re-add ns3::Ipv4GlobalRouting::GetRoute annotation for return pointer type
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6352
diff changeset
    97
    'ns3::Ipv4RoutingTableEntry * ns3::Ipv4GlobalRouting::GetRoute(uint32_t i) const [member function]': {
5980
7929ba7d13bd Python: add needed annotations to ns3::GlobalRouter::GetInjectedRoute and ns3::Ipv4GlobalRouting::GetRoute. Fixes bug #809.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5879
diff changeset
    98
        'params': {'return': { 'caller_owns_return': 'false',}},
7929ba7d13bd Python: add needed annotations to ns3::GlobalRouter::GetInjectedRoute and ns3::Ipv4GlobalRouting::GetRoute. Fixes bug #809.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5879
diff changeset
    99
        },
6989
651f74728160 Python bindings: don't try to wrap Test* classes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6868
diff changeset
   100
651f74728160 Python bindings: don't try to wrap Test* classes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6868
diff changeset
   101
    '::ns3::TestCase': {
651f74728160 Python bindings: don't try to wrap Test* classes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6868
diff changeset
   102
        'ignore': 'true', # we don't need to write test cases in Python
651f74728160 Python bindings: don't try to wrap Test* classes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6868
diff changeset
   103
        },
651f74728160 Python bindings: don't try to wrap Test* classes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6868
diff changeset
   104
    '::ns3::TestRunner': {
651f74728160 Python bindings: don't try to wrap Test* classes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6868
diff changeset
   105
        'ignore': 'true', # we don't need to write test cases in Python
651f74728160 Python bindings: don't try to wrap Test* classes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6868
diff changeset
   106
        },
651f74728160 Python bindings: don't try to wrap Test* classes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6868
diff changeset
   107
    '::ns3::TestSuite': {
651f74728160 Python bindings: don't try to wrap Test* classes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6868
diff changeset
   108
        'ignore': 'true', # we don't need to write test cases in Python
651f74728160 Python bindings: don't try to wrap Test* classes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6868
diff changeset
   109
        },
6139
3202621a634c Fix the Python binding for ns3::Ipv4ListRouting::GetRoutingProtocol
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6047
diff changeset
   110
    
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   111
    }
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   112
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   113
def get_ns3_relative_path(path):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   114
    l = []
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   115
    head = path
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   116
    while head:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   117
        head, tail = os.path.split(head)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   118
        if tail == 'ns3':
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   119
            return os.path.join(*l)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   120
        l.insert(0, tail)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   121
    raise AssertionError("is the path %r inside ns3?!" % path)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   122
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   123
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   124
def pre_scan_hook(dummy_module_parser,
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   125
                  pygccxml_definition,
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   126
                  global_annotations,
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   127
                  parameter_annotations):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   128
    ns3_header = get_ns3_relative_path(pygccxml_definition.location.file_name)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   129
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   130
    ## Note: we don't include line numbers in the comments because
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   131
    ## those numbers are very likely to change frequently, which would
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   132
    ## cause needless changes, since the generated python files are
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   133
    ## kept under version control.
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   134
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   135
    #global_annotations['pygen_comment'] = "%s:%i: %s" % \
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   136
    #    (ns3_header, pygccxml_definition.location.line, pygccxml_definition)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   137
    global_annotations['pygen_comment'] = "%s: %s" % \
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   138
        (ns3_header, pygccxml_definition)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   139
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   140
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   141
    ## handle ns3::Object::GetObject (left to its own devices,
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   142
    ## pybindgen will generate a mangled name containing the template
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   143
    ## argument type name).
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   144
    if isinstance(pygccxml_definition, member_function_t) \
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   145
            and pygccxml_definition.parent.name == 'Object' \
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   146
            and pygccxml_definition.name == 'GetObject':
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   147
        template_args = templates.args(pygccxml_definition.demangled_name)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   148
        if template_args == ['ns3::Object']:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   149
            global_annotations['template_instance_names'] = 'ns3::Object=>GetObject'
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   150
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   151
    ## Don't wrap Simulator::Schedule* (manually wrapped)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   152
    if isinstance(pygccxml_definition, member_function_t) \
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   153
            and pygccxml_definition.parent.name == 'Simulator' \
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   154
            and pygccxml_definition.name.startswith('Schedule'):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   155
        global_annotations['ignore'] = None
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   156
4086
37dbf76b4c66 Bug 375: Ctrl-C does not always work when running Python simulations
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3929
diff changeset
   157
    # manually wrapped
3511
eb17407147c3 Python: re-scan API; unblock python threads during Simulator::Run; new pybindgen brings improved thread safety for virtual methods.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3484
diff changeset
   158
    if isinstance(pygccxml_definition, member_function_t) \
eb17407147c3 Python: re-scan API; unblock python threads during Simulator::Run; new pybindgen brings improved thread safety for virtual methods.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3484
diff changeset
   159
            and pygccxml_definition.parent.name == 'Simulator' \
eb17407147c3 Python: re-scan API; unblock python threads during Simulator::Run; new pybindgen brings improved thread safety for virtual methods.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3484
diff changeset
   160
            and pygccxml_definition.name == 'Run':
4086
37dbf76b4c66 Bug 375: Ctrl-C does not always work when running Python simulations
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3929
diff changeset
   161
        global_annotations['ignore'] = True
3511
eb17407147c3 Python: re-scan API; unblock python threads during Simulator::Run; new pybindgen brings improved thread safety for virtual methods.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3484
diff changeset
   162
5755
4214e2d08941 Patch the bad default_value given by gccxml in the case of MilliSeconds(0)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   163
    ## http://www.gccxml.org/Bug/view.php?id=9915
4214e2d08941 Patch the bad default_value given by gccxml in the case of MilliSeconds(0)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   164
    if isinstance(pygccxml_definition, calldef_t):
4214e2d08941 Patch the bad default_value given by gccxml in the case of MilliSeconds(0)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   165
        for arg in pygccxml_definition.arguments:
4214e2d08941 Patch the bad default_value given by gccxml in the case of MilliSeconds(0)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   166
            if arg.default_value is None:
4214e2d08941 Patch the bad default_value given by gccxml in the case of MilliSeconds(0)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   167
                continue
4214e2d08941 Patch the bad default_value given by gccxml in the case of MilliSeconds(0)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   168
            if "ns3::MilliSeconds( )" == arg.default_value:
4214e2d08941 Patch the bad default_value given by gccxml in the case of MilliSeconds(0)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   169
                arg.default_value = "ns3::MilliSeconds(0)"
6868
5001084c970a Workaround gccxml bug scanning Seconds(0) as default value
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6816
diff changeset
   170
            if "ns3::Seconds( )" == arg.default_value:
5001084c970a Workaround gccxml bug scanning Seconds(0) as default value
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6816
diff changeset
   171
                arg.default_value = "ns3::Seconds(0)"
3511
eb17407147c3 Python: re-scan API; unblock python threads during Simulator::Run; new pybindgen brings improved thread safety for virtual methods.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3484
diff changeset
   172
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   173
    ## classes
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   174
    if isinstance(pygccxml_definition, class_t):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   175
        # no need for helper classes to allow subclassing in Python, I think...
6029
096af1414c37 tell pybindgen not to disable inheritance on classes that end with Helper, and rescan
Craig Dowell <craigdo@ee.washington.edu>
parents: 5879
diff changeset
   176
        #if pygccxml_definition.name.endswith('Helper'):
096af1414c37 tell pybindgen not to disable inheritance on classes that end with Helper, and rescan
Craig Dowell <craigdo@ee.washington.edu>
parents: 5879
diff changeset
   177
        #    global_annotations['allow_subclassing'] = 'false'
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   178
5879
12a17646ad8e python: fix scanning to correctly look for the new SimpleRefCount templated class and declare it is reference counted
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5778
diff changeset
   179
        if pygccxml_definition.decl_string.startswith('::ns3::SimpleRefCount<'):
12a17646ad8e python: fix scanning to correctly look for the new SimpleRefCount templated class and declare it is reference counted
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5778
diff changeset
   180
            global_annotations['incref_method'] = 'Ref'
12a17646ad8e python: fix scanning to correctly look for the new SimpleRefCount templated class and declare it is reference counted
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5778
diff changeset
   181
            global_annotations['decref_method'] = 'Unref'
12a17646ad8e python: fix scanning to correctly look for the new SimpleRefCount templated class and declare it is reference counted
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5778
diff changeset
   182
            global_annotations['peekref_method'] = 'GetReferenceCount'
12a17646ad8e python: fix scanning to correctly look for the new SimpleRefCount templated class and declare it is reference counted
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5778
diff changeset
   183
            global_annotations['automatic_type_narrowing'] = 'true'
12a17646ad8e python: fix scanning to correctly look for the new SimpleRefCount templated class and declare it is reference counted
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5778
diff changeset
   184
            return
12a17646ad8e python: fix scanning to correctly look for the new SimpleRefCount templated class and declare it is reference counted
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5778
diff changeset
   185
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   186
        if pygccxml_definition.decl_string.startswith('::ns3::Callback<'):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   187
            # manually handled in ns3modulegen_core_customizations.py
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   188
            global_annotations['ignore'] = None
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   189
            return
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   190
3537
ab1673dcdf58 Python: ignore TracedCallback classes for the time being: they were never usable and were triggering pybindgen generate code compilation problems.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3511
diff changeset
   191
        if pygccxml_definition.decl_string.startswith('::ns3::TracedCallback<'):
ab1673dcdf58 Python: ignore TracedCallback classes for the time being: they were never usable and were triggering pybindgen generate code compilation problems.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3511
diff changeset
   192
            global_annotations['ignore'] = None
ab1673dcdf58 Python: ignore TracedCallback classes for the time being: they were never usable and were triggering pybindgen generate code compilation problems.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3511
diff changeset
   193
            return
ab1673dcdf58 Python: ignore TracedCallback classes for the time being: they were never usable and were triggering pybindgen generate code compilation problems.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3511
diff changeset
   194
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   195
        if pygccxml_definition.decl_string.startswith('::ns3::Ptr<'):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   196
            # handled by pybindgen "type transformation"
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   197
            global_annotations['ignore'] = None
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   198
            return
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   199
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   200
        # table driven class customization
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   201
        try:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   202
            annotations = type_annotations[pygccxml_definition.decl_string]
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   203
        except KeyError:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   204
            pass
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   205
        else:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   206
            global_annotations.update(annotations)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   207
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   208
    ## free functions
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   209
    if isinstance(pygccxml_definition, free_function_t):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   210
        if pygccxml_definition.name == 'PeekPointer':
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   211
            global_annotations['ignore'] = None
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   212
            return
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   213
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   214
    ## table driven methods/constructors/functions customization
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   215
    if isinstance(pygccxml_definition, (free_function_t, member_function_t, constructor_t)):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   216
        try:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   217
            annotations = type_annotations[str(pygccxml_definition)]
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   218
        except KeyError:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   219
            pass
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   220
        else:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   221
            for key,value in annotations.items():
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   222
                if key == 'params':
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   223
                    parameter_annotations.update (value)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   224
                    del annotations['params']
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   225
            global_annotations.update(annotations)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   226
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   227
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   228
# def post_scan_hook(dummy_module_parser, dummy_pygccxml_definition, pybindgen_wrapper):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   229
#     ## classes
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   230
#     if isinstance(pybindgen_wrapper, CppClass):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   231
#         if pybindgen_wrapper.name.endswith('Checker'):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   232
#             print >> sys.stderr, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", pybindgen_wrapper
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   233
#             #pybindgen_wrapper.set_instance_creation_function(AttributeChecker_instance_creation_function)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   234
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   235
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   236
def scan_callback_classes(module_parser, callback_classes_file):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   237
    callback_classes_file.write("callback_classes = [\n")
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   238
    for cls in module_parser.module_namespace.classes(function=module_parser.location_filter,
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   239
                                                      recursive=False):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   240
        if not cls.name.startswith("Callback<"):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   241
            continue
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   242
        assert templates.is_instantiation(cls.decl_string), "%s is not a template instantiation" % cls
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   243
        dummy_cls_name, template_parameters = templates.split(cls.decl_string)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   244
        callback_classes_file.write("    %r,\n" % template_parameters)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   245
    callback_classes_file.write("]\n")
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   246
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   247
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   248
class MyPygenClassifier(PygenClassifier):
5753
8c105b521d1b Python: rescan; need new 'section precedence' API from PyBindGen; other PBG bug fixes pulled from new version.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5249
diff changeset
   249
    def __init__(self, headers_map, section_precendences):
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   250
        self.headers_map = headers_map
5753
8c105b521d1b Python: rescan; need new 'section precedence' API from PyBindGen; other PBG bug fixes pulled from new version.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5249
diff changeset
   251
        self.section_precendences = section_precendences
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   252
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   253
    def classify(self, pygccxml_definition):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   254
        name = os.path.basename(pygccxml_definition.location.file_name)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   255
        try:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   256
            return self.headers_map[name]
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   257
        except KeyError:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   258
            return '__main__'
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   259
5753
8c105b521d1b Python: rescan; need new 'section precedence' API from PyBindGen; other PBG bug fixes pulled from new version.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5249
diff changeset
   260
    def get_section_precedence(self, section_name):
8c105b521d1b Python: rescan; need new 'section precedence' API from PyBindGen; other PBG bug fixes pulled from new version.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5249
diff changeset
   261
        if section_name == '__main__':
8c105b521d1b Python: rescan; need new 'section precedence' API from PyBindGen; other PBG bug fixes pulled from new version.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5249
diff changeset
   262
            return -1
8c105b521d1b Python: rescan; need new 'section precedence' API from PyBindGen; other PBG bug fixes pulled from new version.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5249
diff changeset
   263
        return self.section_precendences[section_name]
8c105b521d1b Python: rescan; need new 'section precedence' API from PyBindGen; other PBG bug fixes pulled from new version.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5249
diff changeset
   264
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   265
5249
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4749
diff changeset
   266
def ns3_module_scan(top_builddir, pygen_file_name, everything_h, cflags):
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   267
6352
378abdf67899 python-scan: avoid possible deadlock passing list of modules to the api scanner process
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6139
diff changeset
   268
    ns3_modules = eval(sys.stdin.readline())
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   269
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   270
    ## do a topological sort on the modules graph
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   271
    from topsort import topsort
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   272
    graph = []
5778
bb28b3985514 python scanning: order from chaos: pre-sort the ns3 module dependency graph to improve stability of the result
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5755
diff changeset
   273
    module_names = ns3_modules.keys()
bb28b3985514 python scanning: order from chaos: pre-sort the ns3 module dependency graph to improve stability of the result
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5755
diff changeset
   274
    module_names.sort()
bb28b3985514 python scanning: order from chaos: pre-sort the ns3 module dependency graph to improve stability of the result
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5755
diff changeset
   275
    for ns3_module_name in module_names:
bb28b3985514 python scanning: order from chaos: pre-sort the ns3 module dependency graph to improve stability of the result
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5755
diff changeset
   276
        ns3_module_deps = list(ns3_modules[ns3_module_name][0])
bb28b3985514 python scanning: order from chaos: pre-sort the ns3 module dependency graph to improve stability of the result
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5755
diff changeset
   277
        ns3_module_deps.sort()
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   278
        for dep in ns3_module_deps:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   279
            graph.append((dep, ns3_module_name))
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   280
    sorted_ns3_modules = topsort(graph)
3409
94ac3e381075 The 'everything.h' header file is only used for Python bindings and should be generated into bindings/python/, not ns3/.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3408
diff changeset
   281
    #print >> sys.stderr, "******* topological sort: ", sorted_ns3_modules
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   282
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   283
    sections = [PygenSection('__main__', FileCodeSink(open(pygen_file_name, "wt")))]
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   284
    headers_map = {} # header_name -> section_name
5753
8c105b521d1b Python: rescan; need new 'section precedence' API from PyBindGen; other PBG bug fixes pulled from new version.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5249
diff changeset
   285
    section_precendences = {} # section_name -> precedence
8c105b521d1b Python: rescan; need new 'section precedence' API from PyBindGen; other PBG bug fixes pulled from new version.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5249
diff changeset
   286
    for prec, ns3_module in enumerate(sorted_ns3_modules):
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   287
        section_name = "ns3_module_%s" % ns3_module.replace('-', '_')
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   288
        file_name = os.path.join(os.path.dirname(pygen_file_name), "%s.py" % section_name)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   289
        sections.append(PygenSection(section_name, FileCodeSink(open(file_name, "wt")),
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   290
                                     section_name + "__local"))
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   291
        for header in ns3_modules[ns3_module][1]:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   292
            headers_map[header] = section_name
5753
8c105b521d1b Python: rescan; need new 'section precedence' API from PyBindGen; other PBG bug fixes pulled from new version.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5249
diff changeset
   293
        section_precendences[section_name] = prec
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   294
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   295
    module_parser = ModuleParser('ns3', 'ns3')
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   296
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   297
    module_parser.add_pre_scan_hook(pre_scan_hook)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   298
    #module_parser.add_post_scan_hook(post_scan_hook)
3474
dac9146297c8 Define NS3_ASSERT_ENABLE and NS3_LOG_ENABLE, to make sure we pick up all definitions (such as the logging APIs)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3467
diff changeset
   299
dac9146297c8 Define NS3_ASSERT_ENABLE and NS3_LOG_ENABLE, to make sure we pick up all definitions (such as the logging APIs)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3467
diff changeset
   300
    gccxml_options = dict(
dac9146297c8 Define NS3_ASSERT_ENABLE and NS3_LOG_ENABLE, to make sure we pick up all definitions (such as the logging APIs)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3467
diff changeset
   301
        include_paths=[top_builddir],
dac9146297c8 Define NS3_ASSERT_ENABLE and NS3_LOG_ENABLE, to make sure we pick up all definitions (such as the logging APIs)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3467
diff changeset
   302
         define_symbols={
3484
ebdeeb7cd463 When python scanning API, remove again the NS3_LOG_ENABLE define; it is no longer needed.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3474
diff changeset
   303
            #'NS3_ASSERT_ENABLE': None,
ebdeeb7cd463 When python scanning API, remove again the NS3_LOG_ENABLE define; it is no longer needed.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3474
diff changeset
   304
            #'NS3_LOG_ENABLE': None,
5249
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4749
diff changeset
   305
            },
7052
1ed66ad04ef6 define PYTHON_SCAN
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7048
diff changeset
   306
        cflags=('--gccxml-cxxflags "%s -DPYTHON_SCAN"' % cflags)
3474
dac9146297c8 Define NS3_ASSERT_ENABLE and NS3_LOG_ENABLE, to make sure we pick up all definitions (such as the logging APIs)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3467
diff changeset
   307
        )
dac9146297c8 Define NS3_ASSERT_ENABLE and NS3_LOG_ENABLE, to make sure we pick up all definitions (such as the logging APIs)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3467
diff changeset
   308
3409
94ac3e381075 The 'everything.h' header file is only used for Python bindings and should be generated into bindings/python/, not ns3/.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3408
diff changeset
   309
    module_parser.parse_init([everything_h],
3474
dac9146297c8 Define NS3_ASSERT_ENABLE and NS3_LOG_ENABLE, to make sure we pick up all definitions (such as the logging APIs)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3467
diff changeset
   310
                             None, whitelist_paths=[top_builddir, os.path.dirname(everything_h)],
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   311
                             #includes=['"ns3/everything.h"'],
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   312
                             pygen_sink=sections,
5753
8c105b521d1b Python: rescan; need new 'section precedence' API from PyBindGen; other PBG bug fixes pulled from new version.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5249
diff changeset
   313
                             pygen_classifier=MyPygenClassifier(headers_map, section_precendences),
3474
dac9146297c8 Define NS3_ASSERT_ENABLE and NS3_LOG_ENABLE, to make sure we pick up all definitions (such as the logging APIs)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3467
diff changeset
   314
                             gccxml_options=gccxml_options)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   315
    module_parser.scan_types()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   316
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   317
    callback_classes_file = open(os.path.join(os.path.dirname(pygen_file_name), "callbacks_list.py"), "wt")
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   318
    scan_callback_classes(module_parser, callback_classes_file)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   319
    callback_classes_file.close()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   320
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   321
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   322
    module_parser.scan_methods()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   323
    module_parser.scan_functions()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   324
    module_parser.parse_finalize()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   325
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   326
    for section in sections:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   327
        section.code_sink.file.close()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   328
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   329
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   330
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   331
if __name__ == '__main__':
5249
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4749
diff changeset
   332
    ns3_module_scan(sys.argv[1], sys.argv[3], sys.argv[2], sys.argv[4])
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   333