gjc@3408: gjc@3408: LOCAL_MODULES = [ gjc@3408: #'my_extra_api_definitions', gjc@3408: ] gjc@3408: gjc@3408: gjc@3408: gjc@3408: import sys gjc@3408: import os gjc@3408: gjc@3408: from pybindgen import FileCodeSink, write_preamble gjc@3408: from pybindgen.module import MultiSectionFactory gjc@3408: import pybindgen.settings gjc@3408: gjc@3473: from ns3modulegen_generated import module_init, register_types, register_methods, register_functions gjc@3408: import ns3modulegen_core_customizations gjc@3408: import callbacks_list gjc@3408: gjc@3408: this_script_dir = os.path.dirname(os.path.abspath(sys.argv[0])) gjc@3408: gjc@3408: class ErrorHandler(pybindgen.settings.ErrorHandler): gjc@3408: def handle_error(self, wrapper, exception, traceback_): gjc@3408: try: gjc@3408: stack = wrapper.stack_where_defined gjc@3408: except AttributeError: gjc@3408: print >> sys.stderr, "??:??: %s / %r" % (wrapper, exception) gjc@3408: else: gjc@3408: stack = list(stack) gjc@3408: stack.reverse() gjc@3408: for (filename, line_number, function_name, text) in stack: gjc@3408: file_dir = os.path.dirname(os.path.abspath(filename)) gjc@3408: if file_dir == this_script_dir: gjc@3408: print >> sys.stderr, "%s:%i: %r" % (os.path.join("..", "bindings", "python", os.path.basename(filename)), gjc@3408: line_number, exception) gjc@3408: break gjc@3408: return True gjc@3408: pybindgen.settings.error_handler = ErrorHandler() gjc@3408: gjc@3546: pybindgen.settings.wrapper_registry = pybindgen.settings.StdMapWrapperRegistry gjc@3546: gjc@3408: gjc@3408: class MyMultiSectionFactory(MultiSectionFactory): gjc@3408: gjc@3408: def __init__(self, main_file_name, modules): gjc@3408: super(MyMultiSectionFactory, self).__init__() gjc@3408: self.main_file_name = main_file_name gjc@3408: self.main_sink = FileCodeSink(open(main_file_name, "wt")) gjc@3408: self.header_name = "ns3module.h" gjc@3408: header_file_name = os.path.join(os.path.dirname(self.main_file_name), self.header_name) gjc@3408: self.header_sink = FileCodeSink(open(header_file_name, "wt")) gjc@3538: self.section_sinks = {'__main__': self.main_sink} gjc@3408: gjc@3408: for module in modules: gjc@3408: section_name = 'ns3_module_%s' % module.replace('-', '_') gjc@3408: file_name = os.path.join(os.path.dirname(self.main_file_name), "%s.cc" % section_name) gjc@3408: sink = FileCodeSink(open(file_name, "wt")) gjc@3408: self.section_sinks[section_name] = sink gjc@3408: gjc@3408: def get_section_code_sink(self, section_name): gjc@3408: return self.section_sinks[section_name] gjc@3408: gjc@3408: def get_main_code_sink(self): gjc@3408: return self.main_sink gjc@3408: gjc@3408: def get_common_header_code_sink(self): gjc@3408: return self.header_sink gjc@3408: gjc@3408: def get_common_header_include(self): gjc@3408: return '"%s"' % self.header_name gjc@3408: gjc@3408: def close(self): gjc@3408: self.header_sink.file.close() gjc@3408: self.main_sink.file.close() gjc@3408: for sink in self.section_sinks.itervalues(): gjc@3408: sink.file.close() gjc@3408: gjc@3408: gjc@3408: gjc@3408: def main(): gjc@3408: out = MyMultiSectionFactory(sys.argv[1], sys.argv[2:]) gjc@3408: root_module = module_init() gjc@3409: root_module.add_include('"everything.h"') gjc@3408: gjc@3408: register_types(root_module) gjc@3408: gjc@3408: ns3modulegen_core_customizations.Simulator_customizations(root_module) gjc@3408: ns3modulegen_core_customizations.CommandLine_customizations(root_module) gjc@3408: gjc@3408: gjc@3408: for local_module in LOCAL_MODULES: gjc@3408: mod = __import__(local_module) gjc@3408: mod.register_types(root_module) gjc@3408: gjc@3408: ns3modulegen_core_customizations.generate_callback_classes(root_module.after_forward_declarations, gjc@3408: callbacks_list.callback_classes) gjc@3408: gjc@3408: gjc@3408: register_methods(root_module) gjc@3408: gjc@3408: for local_module in LOCAL_MODULES: gjc@3408: mod = __import__(local_module) gjc@3408: mod.register_methods(root_module) gjc@3408: gjc@3408: ns3modulegen_core_customizations.Object_customizations(root_module) gjc@3421: ns3modulegen_core_customizations.Attribute_customizations(root_module) gjc@3408: gjc@3408: register_functions(root_module) gjc@3408: gjc@3408: for local_module in LOCAL_MODULES: gjc@3408: mod = __import__(local_module) gjc@3408: mod.register_functions(root_module) gjc@3408: gjc@3639: enabled_features = os.environ['NS3_ENABLED_FEATURES'].split(',') gjc@3420: gjc@3420: # if GtkConfigStore support is disabled, disable the class wrapper gjc@3639: if 'GtkConfigStore' not in enabled_features: mathieu@3582: try: mathieu@3582: root_module.classes.remove(root_module['ns3::GtkConfigStore']) mathieu@3582: except KeyError: mathieu@3582: pass gjc@3420: gjc@3575: # if no sqlite, the class SqliteDataOutput is disabled gjc@3639: if 'SqliteDataOutput' not in enabled_features: mathieu@3582: try: mathieu@3582: root_module.classes.remove(root_module['ns3::SqliteDataOutput']) mathieu@3582: except KeyError: mathieu@3582: pass gjc@3575: gjc@3648: if 'Threading' not in enabled_features: gjc@3648: for clsname in ['SystemThread', 'SystemMutex', 'SystemCondition', 'CriticalSection']: gjc@3648: root_module.classes.remove(root_module['ns3::%s' % clsname]) gjc@3648: gjc@3648: if 'RealTime' not in enabled_features: gjc@3648: for clsname in ['WallClockSynchronizer', 'RealtimeSimulatorImpl', 'RealtimeEventLock']: gjc@3648: root_module.classes.remove(root_module['ns3::%s' % clsname]) gjc@3648: root_module.enums.remove(root_module['ns3::RealtimeSimulatorImpl::SynchronizationMode']) gjc@3648: gjc@3408: root_module.generate(out, '_ns3') gjc@3408: gjc@3408: out.close() gjc@3408: gjc@3408: if __name__ == '__main__': gjc@3408: main() gjc@3408: