bindings/python/ns3modulegen.py
author Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
Fri, 26 Mar 2010 18:54:11 +0000
changeset 6159 eed3fc8897bc
parent 6137 86045031f03a
child 6785 afe95f44de93
permissions -rwxr-xr-x
Change Python bindings method for overriding virtual methods of C++ classes To override the C++ virtual method 'DoStart', we new define a method in Python called 'DoStart', whilst before we would define '_DoStart'. This change is to align pybindgen generated bindings with the other python bindings tools out there, such as boost.python, swig, and sip. It is also simpler to understand for users.
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
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     2
LOCAL_MODULES = [
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     3
    #'my_extra_api_definitions',
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     4
    ]
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
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     7
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     8
import sys
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     9
import os
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    10
5249
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4299
diff changeset
    11
sys.path.insert(0, sys.argv[2])
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4299
diff changeset
    12
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    13
from pybindgen import FileCodeSink, write_preamble
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    14
from pybindgen.module import MultiSectionFactory
6159
eed3fc8897bc Change Python bindings method for overriding virtual methods of C++ classes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6137
diff changeset
    15
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    16
import pybindgen.settings
6159
eed3fc8897bc Change Python bindings method for overriding virtual methods of C++ classes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6137
diff changeset
    17
pybindgen.settings.deprecated_virtuals = False
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    18
3473
6bce86ea4778 Require new PyBindGen; make it work for Python 2.3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3421
diff changeset
    19
from ns3modulegen_generated import module_init, register_types, register_methods, register_functions
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    20
import ns3modulegen_core_customizations
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    21
import callbacks_list
5878
34459001e1ba python: fix error reporting, make it much more verbose
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5839
diff changeset
    22
import traceback
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    23
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    24
this_script_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    25
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    26
class ErrorHandler(pybindgen.settings.ErrorHandler):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    27
    def handle_error(self, wrapper, exception, traceback_):
5878
34459001e1ba python: fix error reporting, make it much more verbose
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5839
diff changeset
    28
        print >> sys.stderr
34459001e1ba python: fix error reporting, make it much more verbose
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5839
diff changeset
    29
        print >> sys.stderr, "---- location:"
34459001e1ba python: fix error reporting, make it much more verbose
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5839
diff changeset
    30
        traceback.print_stack()
34459001e1ba python: fix error reporting, make it much more verbose
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5839
diff changeset
    31
        print >> sys.stderr, "---- error:"
34459001e1ba python: fix error reporting, make it much more verbose
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5839
diff changeset
    32
        traceback.print_tb(traceback_)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    33
        try:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    34
            stack = wrapper.stack_where_defined
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    35
        except AttributeError:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    36
            print >> sys.stderr, "??:??: %s / %r" % (wrapper, exception)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    37
        else:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    38
            stack = list(stack)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    39
            stack.reverse()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    40
            for (filename, line_number, function_name, text) in stack:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    41
                file_dir = os.path.dirname(os.path.abspath(filename))
5878
34459001e1ba python: fix error reporting, make it much more verbose
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5839
diff changeset
    42
                if file_dir.startswith(this_script_dir):
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    43
                    print >> sys.stderr, "%s:%i: %r" % (os.path.join("..", "bindings", "python", os.path.basename(filename)),
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    44
                                                        line_number, exception)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    45
                    break
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    46
        return True
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    47
pybindgen.settings.error_handler = ErrorHandler()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    48
3546
cecda7126440 New PyBindGen, fixes python wrapper identity issue.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3538
diff changeset
    49
pybindgen.settings.wrapper_registry = pybindgen.settings.StdMapWrapperRegistry
cecda7126440 New PyBindGen, fixes python wrapper identity issue.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3538
diff changeset
    50
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    51
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    52
class MyMultiSectionFactory(MultiSectionFactory):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    53
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    54
    def __init__(self, main_file_name, modules):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    55
        super(MyMultiSectionFactory, self).__init__()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    56
        self.main_file_name = main_file_name
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    57
        self.main_sink = FileCodeSink(open(main_file_name, "wt"))
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    58
        self.header_name = "ns3module.h"
6137
86045031f03a Add option to enable gcc precompiled header for compiling python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5922
diff changeset
    59
        header_file_name = os.path.join(os.path.dirname(self.main_file_name), 'pch', self.header_name)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    60
        self.header_sink = FileCodeSink(open(header_file_name, "wt"))
3538
99f49426595a Python: fix bad parameter passed into pybindgen.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3473
diff changeset
    61
        self.section_sinks = {'__main__': self.main_sink}
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
        for module in modules:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    64
            section_name = 'ns3_module_%s' % module.replace('-', '_')
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    65
            file_name = os.path.join(os.path.dirname(self.main_file_name), "%s.cc" % section_name)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    66
            sink = FileCodeSink(open(file_name, "wt"))
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    67
            self.section_sinks[section_name] = sink            
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
    def get_section_code_sink(self, section_name):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    70
        return self.section_sinks[section_name]
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
    def get_main_code_sink(self):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    73
        return self.main_sink
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
    def get_common_header_code_sink(self):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    76
        return self.header_sink
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
    def get_common_header_include(self):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    79
        return '"%s"' % self.header_name
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
    def close(self):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    82
        self.header_sink.file.close()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    83
        self.main_sink.file.close()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    84
        for sink in self.section_sinks.itervalues():
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    85
            sink.file.close()
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
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    88
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    89
def main():
5249
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4299
diff changeset
    90
    out = MyMultiSectionFactory(sys.argv[1], sys.argv[3:])
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    91
    root_module = module_init()
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
    92
    root_module.add_include('"everything.h"')
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    93
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    94
    register_types(root_module)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    95
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    96
    ns3modulegen_core_customizations.Simulator_customizations(root_module)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    97
    ns3modulegen_core_customizations.CommandLine_customizations(root_module)
3753
a84a48233eb3 A more pythonic wrapper for ns3.TypeId.LookupByNameFailSafe
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3648
diff changeset
    98
    ns3modulegen_core_customizations.TypeId_customizations(root_module)
4196
ed59d07c5373 Python: wrap std::ostream/ofstream, for ascii tracing.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4105
diff changeset
    99
    ns3modulegen_core_customizations.add_std_ofstream(root_module)
5911
993998a62a6a Bug 786 - Make Ipv4Address hashable from Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5878
diff changeset
   100
    ns3modulegen_core_customizations.add_ipv4_address_tp_hash(root_module)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   101
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   102
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   103
    for local_module in LOCAL_MODULES:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   104
        mod = __import__(local_module)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   105
        mod.register_types(root_module)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   106
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   107
    ns3modulegen_core_customizations.generate_callback_classes(root_module.after_forward_declarations,
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   108
                                                               callbacks_list.callback_classes)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   109
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   110
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   111
    register_methods(root_module)
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
    for local_module in LOCAL_MODULES:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   114
        mod = __import__(local_module)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   115
        mod.register_methods(root_module)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   116
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   117
    ns3modulegen_core_customizations.Object_customizations(root_module)
3421
b9424c43753d Python: make helper class methods using attribute optional parameters work.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3420
diff changeset
   118
    ns3modulegen_core_customizations.Attribute_customizations(root_module)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   119
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   120
    register_functions(root_module)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   121
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   122
    for local_module in LOCAL_MODULES:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   123
        mod = __import__(local_module)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   124
        mod.register_functions(root_module)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   125
3639
8e69ebf086f1 Use the information provided by conf.report_optional_feature() to enable/disable python bindings for optional APIs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3582
diff changeset
   126
    enabled_features = os.environ['NS3_ENABLED_FEATURES'].split(',')
3420
390db659644b If GtkConfigStore support is disabled, disable the python bindings for it, or else compilation fails.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3409
diff changeset
   127
390db659644b If GtkConfigStore support is disabled, disable the python bindings for it, or else compilation fails.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3409
diff changeset
   128
    # if GtkConfigStore support is disabled, disable the class wrapper
3639
8e69ebf086f1 Use the information provided by conf.report_optional_feature() to enable/disable python bindings for optional APIs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3582
diff changeset
   129
    if 'GtkConfigStore' not in enabled_features:
3582
96fa2a7b5f88 catch KeyError exception to avoid failing when sqlite or gtk are not installed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3575
diff changeset
   130
        try:
96fa2a7b5f88 catch KeyError exception to avoid failing when sqlite or gtk are not installed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3575
diff changeset
   131
            root_module.classes.remove(root_module['ns3::GtkConfigStore'])
96fa2a7b5f88 catch KeyError exception to avoid failing when sqlite or gtk are not installed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3575
diff changeset
   132
        except KeyError:
96fa2a7b5f88 catch KeyError exception to avoid failing when sqlite or gtk are not installed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3575
diff changeset
   133
            pass
3420
390db659644b If GtkConfigStore support is disabled, disable the python bindings for it, or else compilation fails.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3409
diff changeset
   134
3575
1f5d9b97a1a2 Fix compilation of Python bindings when libsqlite3 is not available (and so the class SqliteDataOutput is omitted).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3546
diff changeset
   135
    # if no sqlite, the class SqliteDataOutput is disabled
3639
8e69ebf086f1 Use the information provided by conf.report_optional_feature() to enable/disable python bindings for optional APIs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3582
diff changeset
   136
    if 'SqliteDataOutput' not in enabled_features:
3582
96fa2a7b5f88 catch KeyError exception to avoid failing when sqlite or gtk are not installed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3575
diff changeset
   137
        try:
96fa2a7b5f88 catch KeyError exception to avoid failing when sqlite or gtk are not installed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3575
diff changeset
   138
            root_module.classes.remove(root_module['ns3::SqliteDataOutput'])
96fa2a7b5f88 catch KeyError exception to avoid failing when sqlite or gtk are not installed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3575
diff changeset
   139
        except KeyError:
96fa2a7b5f88 catch KeyError exception to avoid failing when sqlite or gtk are not installed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3575
diff changeset
   140
            pass
3575
1f5d9b97a1a2 Fix compilation of Python bindings when libsqlite3 is not available (and so the class SqliteDataOutput is omitted).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3546
diff changeset
   141
3648
f912b24ddf2d Detect the pthread.h header file and automatically disable components that cannot build without it.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3639
diff changeset
   142
    if 'Threading' not in enabled_features:
5922
d5527ca873af Fix python bindings build when threading features are disabled (e.g. mingw)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5911
diff changeset
   143
        for clsname in ['SystemThread', 'SystemMutex', 'SystemCondition', 'CriticalSection',
d5527ca873af Fix python bindings build when threading features are disabled (e.g. mingw)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5911
diff changeset
   144
                        'SimpleRefCount< ns3::SystemThread, ns3::empty, ns3::DefaultDeleter<ns3::SystemThread> >']:
3648
f912b24ddf2d Detect the pthread.h header file and automatically disable components that cannot build without it.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3639
diff changeset
   145
            root_module.classes.remove(root_module['ns3::%s' % clsname])
f912b24ddf2d Detect the pthread.h header file and automatically disable components that cannot build without it.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3639
diff changeset
   146
3916
a1e72a0595a6 Disable EmuNetDevice Python bindings if the netdevice is not compiled in (bug #413)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3753
diff changeset
   147
    if 'EmuNetDevice' not in enabled_features:
a1e72a0595a6 Disable EmuNetDevice Python bindings if the netdevice is not compiled in (bug #413)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3753
diff changeset
   148
        for clsname in ['EmuNetDevice', 'EmuHelper']:
a1e72a0595a6 Disable EmuNetDevice Python bindings if the netdevice is not compiled in (bug #413)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3753
diff changeset
   149
            root_module.classes.remove(root_module['ns3::%s' % clsname])
5838
eb5b9d295192 Fixing building with python bindings under MacOS and MingW
fmoatamr
parents: 5249
diff changeset
   150
        root_module.enums.remove(root_module['ns3::EmuNetDevice::EncapsulationMode'])
3916
a1e72a0595a6 Disable EmuNetDevice Python bindings if the netdevice is not compiled in (bug #413)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3753
diff changeset
   151
3648
f912b24ddf2d Detect the pthread.h header file and automatically disable components that cannot build without it.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3639
diff changeset
   152
    if 'RealTime' not in enabled_features:
4090
3dda1049f0d8 RealtimeEventLock is gone
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3916
diff changeset
   153
        for clsname in ['WallClockSynchronizer', 'RealtimeSimulatorImpl']:
3648
f912b24ddf2d Detect the pthread.h header file and automatically disable components that cannot build without it.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3639
diff changeset
   154
            root_module.classes.remove(root_module['ns3::%s' % clsname])
f912b24ddf2d Detect the pthread.h header file and automatically disable components that cannot build without it.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3639
diff changeset
   155
        root_module.enums.remove(root_module['ns3::RealtimeSimulatorImpl::SynchronizationMode'])
f912b24ddf2d Detect the pthread.h header file and automatically disable components that cannot build without it.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3639
diff changeset
   156
4208
ef9ae8962bbb Fix build of Python bindings on systems with no support for TabBridge
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4196
diff changeset
   157
    if 'TapBridge' not in enabled_features:
ef9ae8962bbb Fix build of Python bindings on systems with no support for TabBridge
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4196
diff changeset
   158
        for clsname in ['TapBridge', 'TapBridgeHelper']:
ef9ae8962bbb Fix build of Python bindings on systems with no support for TabBridge
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4196
diff changeset
   159
            root_module.classes.remove(root_module['ns3::%s' % clsname])
4299
834a7ac30481 fix mac osx python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4208
diff changeset
   160
        root_module.enums.remove(root_module['ns3::TapBridge::Mode'])
4208
ef9ae8962bbb Fix build of Python bindings on systems with no support for TabBridge
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4196
diff changeset
   161
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   162
    root_module.generate(out, '_ns3')
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   163
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   164
    out.close()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   165
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   166
if __name__ == '__main__':
4105
ce8be572c4d4 Make it easy to turn on profiling of pybindgen
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4090
diff changeset
   167
    if 0:
ce8be572c4d4 Make it easy to turn on profiling of pybindgen
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4090
diff changeset
   168
        try:
ce8be572c4d4 Make it easy to turn on profiling of pybindgen
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4090
diff changeset
   169
            import cProfile as profile
ce8be572c4d4 Make it easy to turn on profiling of pybindgen
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4090
diff changeset
   170
        except ImportError:
ce8be572c4d4 Make it easy to turn on profiling of pybindgen
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4090
diff changeset
   171
            main()
ce8be572c4d4 Make it easy to turn on profiling of pybindgen
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4090
diff changeset
   172
        else:
ce8be572c4d4 Make it easy to turn on profiling of pybindgen
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4090
diff changeset
   173
            print >> sys.stderr, "** running under profiler"
ce8be572c4d4 Make it easy to turn on profiling of pybindgen
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4090
diff changeset
   174
            profile.run('main()', 'ns3modulegen.pstat')
ce8be572c4d4 Make it easy to turn on profiling of pybindgen
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4090
diff changeset
   175
    else:
ce8be572c4d4 Make it easy to turn on profiling of pybindgen
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4090
diff changeset
   176
        main()
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   177