2008-07-08 10:43:58 -07:00
|
|
|
|
|
|
|
|
LOCAL_MODULES = [
|
|
|
|
|
#'my_extra_api_definitions',
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
import os
|
|
|
|
|
|
2009-09-22 16:13:42 +01:00
|
|
|
sys.path.insert(0, sys.argv[2])
|
|
|
|
|
|
2008-07-08 10:43:58 -07:00
|
|
|
from pybindgen import FileCodeSink, write_preamble
|
|
|
|
|
from pybindgen.module import MultiSectionFactory
|
2010-03-26 18:54:11 +00:00
|
|
|
|
2008-07-08 10:43:58 -07:00
|
|
|
import pybindgen.settings
|
2010-03-26 18:54:11 +00:00
|
|
|
pybindgen.settings.deprecated_virtuals = False
|
2008-07-08 10:43:58 -07:00
|
|
|
|
2008-07-22 16:54:24 +01:00
|
|
|
from ns3modulegen_generated import module_init, register_types, register_methods, register_functions
|
2008-07-08 10:43:58 -07:00
|
|
|
import ns3modulegen_core_customizations
|
|
|
|
|
import callbacks_list
|
2009-12-28 17:53:52 +00:00
|
|
|
import traceback
|
2008-07-08 10:43:58 -07:00
|
|
|
|
|
|
|
|
this_script_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
|
|
|
|
|
|
|
|
|
|
class ErrorHandler(pybindgen.settings.ErrorHandler):
|
|
|
|
|
def handle_error(self, wrapper, exception, traceback_):
|
2009-12-28 17:53:52 +00:00
|
|
|
print >> sys.stderr
|
|
|
|
|
print >> sys.stderr, "---- location:"
|
|
|
|
|
traceback.print_stack()
|
|
|
|
|
print >> sys.stderr, "---- error:"
|
|
|
|
|
traceback.print_tb(traceback_)
|
2008-07-08 10:43:58 -07:00
|
|
|
try:
|
|
|
|
|
stack = wrapper.stack_where_defined
|
|
|
|
|
except AttributeError:
|
|
|
|
|
print >> sys.stderr, "??:??: %s / %r" % (wrapper, exception)
|
|
|
|
|
else:
|
|
|
|
|
stack = list(stack)
|
|
|
|
|
stack.reverse()
|
|
|
|
|
for (filename, line_number, function_name, text) in stack:
|
|
|
|
|
file_dir = os.path.dirname(os.path.abspath(filename))
|
2009-12-28 17:53:52 +00:00
|
|
|
if file_dir.startswith(this_script_dir):
|
2008-07-08 10:43:58 -07:00
|
|
|
print >> sys.stderr, "%s:%i: %r" % (os.path.join("..", "bindings", "python", os.path.basename(filename)),
|
|
|
|
|
line_number, exception)
|
|
|
|
|
break
|
|
|
|
|
return True
|
|
|
|
|
pybindgen.settings.error_handler = ErrorHandler()
|
|
|
|
|
|
2008-08-23 22:35:10 +01:00
|
|
|
pybindgen.settings.wrapper_registry = pybindgen.settings.StdMapWrapperRegistry
|
|
|
|
|
|
2008-07-08 10:43:58 -07:00
|
|
|
|
|
|
|
|
class MyMultiSectionFactory(MultiSectionFactory):
|
|
|
|
|
|
|
|
|
|
def __init__(self, main_file_name, modules):
|
|
|
|
|
super(MyMultiSectionFactory, self).__init__()
|
|
|
|
|
self.main_file_name = main_file_name
|
|
|
|
|
self.main_sink = FileCodeSink(open(main_file_name, "wt"))
|
|
|
|
|
self.header_name = "ns3module.h"
|
2010-03-17 12:34:52 +00:00
|
|
|
header_file_name = os.path.join(os.path.dirname(self.main_file_name), 'pch', self.header_name)
|
2008-07-08 10:43:58 -07:00
|
|
|
self.header_sink = FileCodeSink(open(header_file_name, "wt"))
|
2008-08-18 16:00:47 +01:00
|
|
|
self.section_sinks = {'__main__': self.main_sink}
|
2008-07-08 10:43:58 -07:00
|
|
|
|
|
|
|
|
for module in modules:
|
|
|
|
|
section_name = 'ns3_module_%s' % module.replace('-', '_')
|
|
|
|
|
file_name = os.path.join(os.path.dirname(self.main_file_name), "%s.cc" % section_name)
|
|
|
|
|
sink = FileCodeSink(open(file_name, "wt"))
|
|
|
|
|
self.section_sinks[section_name] = sink
|
|
|
|
|
|
|
|
|
|
def get_section_code_sink(self, section_name):
|
|
|
|
|
return self.section_sinks[section_name]
|
|
|
|
|
|
|
|
|
|
def get_main_code_sink(self):
|
|
|
|
|
return self.main_sink
|
|
|
|
|
|
|
|
|
|
def get_common_header_code_sink(self):
|
|
|
|
|
return self.header_sink
|
|
|
|
|
|
|
|
|
|
def get_common_header_include(self):
|
|
|
|
|
return '"%s"' % self.header_name
|
|
|
|
|
|
|
|
|
|
def close(self):
|
|
|
|
|
self.header_sink.file.close()
|
|
|
|
|
self.main_sink.file.close()
|
2019-04-15 12:00:57 -07:00
|
|
|
for sink in self.section_sinks.values():
|
2008-07-08 10:43:58 -07:00
|
|
|
sink.file.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2009-09-22 16:13:42 +01:00
|
|
|
out = MyMultiSectionFactory(sys.argv[1], sys.argv[3:])
|
2008-07-08 10:43:58 -07:00
|
|
|
root_module = module_init()
|
2008-07-09 14:58:02 +01:00
|
|
|
root_module.add_include('"everything.h"')
|
2008-07-08 10:43:58 -07:00
|
|
|
|
|
|
|
|
register_types(root_module)
|
|
|
|
|
|
|
|
|
|
ns3modulegen_core_customizations.Simulator_customizations(root_module)
|
|
|
|
|
ns3modulegen_core_customizations.CommandLine_customizations(root_module)
|
2008-10-15 15:55:09 +01:00
|
|
|
ns3modulegen_core_customizations.TypeId_customizations(root_module)
|
2009-02-18 12:23:08 +00:00
|
|
|
ns3modulegen_core_customizations.add_std_ofstream(root_module)
|
2010-01-14 11:45:04 +00:00
|
|
|
ns3modulegen_core_customizations.add_ipv4_address_tp_hash(root_module)
|
2008-07-08 10:43:58 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
for local_module in LOCAL_MODULES:
|
|
|
|
|
mod = __import__(local_module)
|
|
|
|
|
mod.register_types(root_module)
|
|
|
|
|
|
|
|
|
|
ns3modulegen_core_customizations.generate_callback_classes(root_module.after_forward_declarations,
|
|
|
|
|
callbacks_list.callback_classes)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
register_methods(root_module)
|
|
|
|
|
|
|
|
|
|
for local_module in LOCAL_MODULES:
|
|
|
|
|
mod = __import__(local_module)
|
|
|
|
|
mod.register_methods(root_module)
|
|
|
|
|
|
|
|
|
|
ns3modulegen_core_customizations.Object_customizations(root_module)
|
2008-07-13 17:55:48 +01:00
|
|
|
ns3modulegen_core_customizations.Attribute_customizations(root_module)
|
2008-07-08 10:43:58 -07:00
|
|
|
|
|
|
|
|
register_functions(root_module)
|
|
|
|
|
|
|
|
|
|
for local_module in LOCAL_MODULES:
|
|
|
|
|
mod = __import__(local_module)
|
|
|
|
|
mod.register_functions(root_module)
|
|
|
|
|
|
2008-09-06 19:24:32 +01:00
|
|
|
enabled_features = os.environ['NS3_ENABLED_FEATURES'].split(',')
|
2008-07-12 22:06:15 +01:00
|
|
|
|
|
|
|
|
# if GtkConfigStore support is disabled, disable the class wrapper
|
2008-09-06 19:24:32 +01:00
|
|
|
if 'GtkConfigStore' not in enabled_features:
|
2008-09-02 10:44:28 -07:00
|
|
|
try:
|
|
|
|
|
root_module.classes.remove(root_module['ns3::GtkConfigStore'])
|
|
|
|
|
except KeyError:
|
|
|
|
|
pass
|
2008-07-12 22:06:15 +01:00
|
|
|
|
2008-09-02 17:32:19 +01:00
|
|
|
# if no sqlite, the class SqliteDataOutput is disabled
|
2008-09-06 19:24:32 +01:00
|
|
|
if 'SqliteDataOutput' not in enabled_features:
|
2008-09-02 10:44:28 -07:00
|
|
|
try:
|
|
|
|
|
root_module.classes.remove(root_module['ns3::SqliteDataOutput'])
|
|
|
|
|
except KeyError:
|
|
|
|
|
pass
|
2008-09-02 17:32:19 +01:00
|
|
|
|
2008-09-08 12:19:46 +01:00
|
|
|
if 'Threading' not in enabled_features:
|
2010-01-23 19:06:19 +00:00
|
|
|
for clsname in ['SystemThread', 'SystemMutex', 'SystemCondition', 'CriticalSection',
|
|
|
|
|
'SimpleRefCount< ns3::SystemThread, ns3::empty, ns3::DefaultDeleter<ns3::SystemThread> >']:
|
2008-09-08 12:19:46 +01:00
|
|
|
root_module.classes.remove(root_module['ns3::%s' % clsname])
|
|
|
|
|
|
2008-11-24 12:09:47 +00:00
|
|
|
if 'EmuNetDevice' not in enabled_features:
|
|
|
|
|
for clsname in ['EmuNetDevice', 'EmuHelper']:
|
|
|
|
|
root_module.classes.remove(root_module['ns3::%s' % clsname])
|
2009-12-07 19:16:52 +01:00
|
|
|
root_module.enums.remove(root_module['ns3::EmuNetDevice::EncapsulationMode'])
|
2008-11-24 12:09:47 +00:00
|
|
|
|
2008-09-08 12:19:46 +01:00
|
|
|
if 'RealTime' not in enabled_features:
|
2009-01-14 15:35:42 +00:00
|
|
|
for clsname in ['WallClockSynchronizer', 'RealtimeSimulatorImpl']:
|
2008-09-08 12:19:46 +01:00
|
|
|
root_module.classes.remove(root_module['ns3::%s' % clsname])
|
|
|
|
|
root_module.enums.remove(root_module['ns3::RealtimeSimulatorImpl::SynchronizationMode'])
|
|
|
|
|
|
2009-02-23 16:07:46 +00:00
|
|
|
if 'TapBridge' not in enabled_features:
|
2011-01-26 10:56:33 -08:00
|
|
|
for clsname in ['TapBridge', 'TapBridgeHelper', 'TapBridgeFdReader']:
|
2009-02-23 16:07:46 +00:00
|
|
|
root_module.classes.remove(root_module['ns3::%s' % clsname])
|
2009-03-27 11:18:54 +00:00
|
|
|
root_module.enums.remove(root_module['ns3::TapBridge::Mode'])
|
2009-02-23 16:07:46 +00:00
|
|
|
|
2008-07-08 10:43:58 -07:00
|
|
|
root_module.generate(out, '_ns3')
|
|
|
|
|
|
|
|
|
|
out.close()
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2009-01-17 16:59:45 +00:00
|
|
|
if 0:
|
|
|
|
|
try:
|
|
|
|
|
import cProfile as profile
|
|
|
|
|
except ImportError:
|
|
|
|
|
main()
|
|
|
|
|
else:
|
|
|
|
|
print >> sys.stderr, "** running under profiler"
|
|
|
|
|
profile.run('main()', 'ns3modulegen.pstat')
|
|
|
|
|
else:
|
|
|
|
|
main()
|
2008-07-08 10:43:58 -07:00
|
|
|
|