From 4d17b00ad47120134501c4ff418f7bfae4e0695a Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Thu, 26 Mar 2009 17:39:20 -0700 Subject: [PATCH] Make Names API return void not bool, rescan for Python Bindings --- bindings/python/ns3_module_core.py | 24 +++---- bindings/python/ns3_module_helper.py | 6 ++ bindings/python/ns3_module_tap_bridge.py | 10 +++ src/core/names.cc | 79 ++++++++++++------------ src/core/names.h | 22 ++----- 5 files changed, 75 insertions(+), 66 deletions(-) diff --git a/bindings/python/ns3_module_core.py b/bindings/python/ns3_module_core.py index 155e889e5..71322205c 100644 --- a/bindings/python/ns3_module_core.py +++ b/bindings/python/ns3_module_core.py @@ -479,34 +479,34 @@ def register_Ns3Names_methods(root_module, cls): cls.add_constructor([param('ns3::Names const &', 'arg0')]) ## names.h: ns3::Names::Names() [constructor] cls.add_constructor([]) - ## names.h: static bool ns3::Names::Add(std::string name, ns3::Ptr obj) [member function] + ## names.h: static void ns3::Names::Add(std::string name, ns3::Ptr obj) [member function] cls.add_method('Add', - 'bool', + 'void', [param('std::string', 'name'), param('ns3::Ptr< ns3::Object >', 'obj')], is_static=True) - ## names.h: static bool ns3::Names::Add(std::string path, std::string name, ns3::Ptr object) [member function] + ## names.h: static void ns3::Names::Add(std::string path, std::string name, ns3::Ptr object) [member function] cls.add_method('Add', - 'bool', + 'void', [param('std::string', 'path'), param('std::string', 'name'), param('ns3::Ptr< ns3::Object >', 'object')], is_static=True) - ## names.h: static bool ns3::Names::Add(ns3::Ptr context, std::string name, ns3::Ptr object) [member function] + ## names.h: static void ns3::Names::Add(ns3::Ptr context, std::string name, ns3::Ptr object) [member function] cls.add_method('Add', - 'bool', + 'void', [param('ns3::Ptr< ns3::Object >', 'context'), param('std::string', 'name'), param('ns3::Ptr< ns3::Object >', 'object')], is_static=True) - ## names.h: static bool ns3::Names::Rename(std::string oldpath, std::string newname) [member function] + ## names.h: static void ns3::Names::Rename(std::string oldpath, std::string newname) [member function] cls.add_method('Rename', - 'bool', + 'void', [param('std::string', 'oldpath'), param('std::string', 'newname')], is_static=True) - ## names.h: static bool ns3::Names::Rename(std::string path, std::string oldname, std::string newname) [member function] + ## names.h: static void ns3::Names::Rename(std::string path, std::string oldname, std::string newname) [member function] cls.add_method('Rename', - 'bool', + 'void', [param('std::string', 'path'), param('std::string', 'oldname'), param('std::string', 'newname')], is_static=True) - ## names.h: static bool ns3::Names::Rename(ns3::Ptr context, std::string oldname, std::string newname) [member function] + ## names.h: static void ns3::Names::Rename(ns3::Ptr context, std::string oldname, std::string newname) [member function] cls.add_method('Rename', - 'bool', + 'void', [param('ns3::Ptr< ns3::Object >', 'context'), param('std::string', 'oldname'), param('std::string', 'newname')], is_static=True) ## names.h: static std::string ns3::Names::FindName(ns3::Ptr object) [member function] diff --git a/bindings/python/ns3_module_helper.py b/bindings/python/ns3_module_helper.py index bdcf01d60..583c388bf 100644 --- a/bindings/python/ns3_module_helper.py +++ b/bindings/python/ns3_module_helper.py @@ -946,6 +946,8 @@ def register_Ns3StaticMulticastRouteHelper_methods(root_module, cls): def register_Ns3TapBridgeHelper_methods(root_module, cls): ## tap-bridge-helper.h: ns3::TapBridgeHelper::TapBridgeHelper(ns3::TapBridgeHelper const & arg0) [copy constructor] cls.add_constructor([param('ns3::TapBridgeHelper const &', 'arg0')]) + ## tap-bridge-helper.h: ns3::TapBridgeHelper::TapBridgeHelper() [constructor] + cls.add_constructor([]) ## tap-bridge-helper.h: ns3::TapBridgeHelper::TapBridgeHelper(ns3::Ipv4Address gateway) [constructor] cls.add_constructor([param('ns3::Ipv4Address', 'gateway')]) ## tap-bridge-helper.h: void ns3::TapBridgeHelper::SetAttribute(std::string n1, ns3::AttributeValue const & v1) [member function] @@ -968,6 +970,10 @@ def register_Ns3TapBridgeHelper_methods(root_module, cls): cls.add_method('Install', 'ns3::Ptr< ns3::NetDevice >', [param('std::string', 'nodeName'), param('std::string', 'ndName')]) + ## tap-bridge-helper.h: ns3::Ptr ns3::TapBridgeHelper::Install(ns3::Ptr node, ns3::Ptr nd, ns3::AttributeValue const & v1) [member function] + cls.add_method('Install', + 'ns3::Ptr< ns3::NetDevice >', + [param('ns3::Ptr< ns3::Node >', 'node'), param('ns3::Ptr< ns3::NetDevice >', 'nd'), param('ns3::AttributeValue const &', 'v1')]) return def register_Ns3UdpEchoClientHelper_methods(root_module, cls): diff --git a/bindings/python/ns3_module_tap_bridge.py b/bindings/python/ns3_module_tap_bridge.py index 66185dc52..49b6e651f 100644 --- a/bindings/python/ns3_module_tap_bridge.py +++ b/bindings/python/ns3_module_tap_bridge.py @@ -5,6 +5,8 @@ def register_types(module): ## tap-bridge.h: ns3::TapBridge [class] module.add_class('TapBridge', parent=root_module['ns3::NetDevice']) + ## tap-bridge.h: ns3::TapBridge::Mode [enumeration] + module.add_enum('Mode', ['ILLEGAL', 'CONFIGURE_LOCAL', 'USE_LOCAL', 'USE_BRIDGE'], outer_class=root_module['ns3::TapBridge']) ## Register a nested module for the namespace Config @@ -76,6 +78,14 @@ def register_Ns3TapBridge_methods(root_module, cls): cls.add_method('Stop', 'void', [param('ns3::Time', 'tStop')]) + ## tap-bridge.h: void ns3::TapBridge::SetMode(ns3::TapBridge::Mode mode) [member function] + cls.add_method('SetMode', + 'void', + [param('ns3::TapBridge::Mode', 'mode')]) + ## tap-bridge.h: ns3::TapBridge::Mode ns3::TapBridge::GetMode() [member function] + cls.add_method('GetMode', + 'ns3::TapBridge::Mode', + []) ## tap-bridge.h: void ns3::TapBridge::SetName(std::string const name) [member function] cls.add_method('SetName', 'void', diff --git a/src/core/names.cc b/src/core/names.cc index 2cb1e88b2..b7d6f4464 100644 --- a/src/core/names.cc +++ b/src/core/names.cc @@ -623,40 +623,47 @@ Names::Delete (void) NamesPriv::Delete (); } -bool +void Names::Add (std::string name, Ptr object) { - return NamesPriv::Get ()->Add (name, object); + bool result = NamesPriv::Get ()->Add (name, object); + NS_ABORT_MSG_UNLESS (result, "Names::Add(): Error adding name " << name); } -bool +void Names::Rename (std::string oldpath, std::string newname) { - return NamesPriv::Get ()->Rename (oldpath, newname); + bool result = NamesPriv::Get ()->Rename (oldpath, newname); + NS_ABORT_MSG_UNLESS (result, "Names::Rename(): Error renaming " << oldpath << " to " << newname); } -bool +void Names::Add (std::string path, std::string name, Ptr object) { - return NamesPriv::Get ()->Add (path, name, object); + bool result = NamesPriv::Get ()->Add (path, name, object); + NS_ABORT_MSG_UNLESS (result, "Names::Add(): Error adding " << path << " " << name); } -bool +void Names::Rename (std::string path, std::string oldname, std::string newname) { - return NamesPriv::Get ()->Rename (path, oldname, newname); + bool result = NamesPriv::Get ()->Rename (path, oldname, newname); + NS_ABORT_MSG_UNLESS (result, "Names::Rename (): Error renaming " << path << " " << oldname << " to " << newname); } -bool +void Names::Add (Ptr context, std::string name, Ptr object) { - return NamesPriv::Get ()->Add (context, name, object); + bool result = NamesPriv::Get ()->Add (context, name, object); + NS_ABORT_MSG_UNLESS (result, "Names::Add(): Error adding name " << name << " under context " << &context); } -bool +void Names::Rename (Ptr context, std::string oldname, std::string newname) { - return NamesPriv::Get ()->Rename (context, oldname, newname); + bool result = NamesPriv::Get ()->Rename (context, oldname, newname); + NS_ABORT_MSG_UNLESS (result, "Names::Rename (): Error renaming " << oldname << " to " << newname << " under context " << + &context); } std::string @@ -730,50 +737,53 @@ NamesTest::RunTests (void) { bool result = true; + // + // Names::Add and Names::Rename return void to align with the Config API. + // The private versions of these functions do return error codes so we + // can test to make sure errors are detected. Names::Add and + // Names::Rename check for these error codes and abort if an error was + // detected. So when we expect that an error should be detected, we + // have to call the private routine to avoid a fatal error popping. // // Name a couple of objects at the root level // Ptr client = CreateObject (); - result = Names::Add ("Client", client); - NS_TEST_ASSERT_EQUAL (result, true); + Names::Add ("Client", client); Ptr server = CreateObject (); - result = Names::Add ("Server", server); - NS_TEST_ASSERT_EQUAL (result, true); + Names::Add ("Server", server); // // We shouldn't be able to add another name to a previously named object // - result = Names::Add ("Not Client", client); + result = NamesPriv::Get ()->Add ("Not Client", client); NS_TEST_ASSERT_EQUAL (result, false); // // We shouldn't be able to duplicate a name at the root level. // Ptr secondClient = CreateObject (); - result = Names::Add ("Client", secondClient); + result = NamesPriv::Get ()->Add ("Client", secondClient); NS_TEST_ASSERT_EQUAL (result, false); // // We should be able to add a new name in the first object's context // Ptr clientEth0 = CreateObject (); - result = Names::Add (client, "eth0", clientEth0); - NS_TEST_ASSERT_EQUAL (result, true); + Names::Add (client, "eth0", clientEth0); // // We shouldn't be able to duplicate a name in that context. // Ptr secondClientEth0 = CreateObject (); - result = Names::Add (client, "eth0", secondClientEth0); + result = NamesPriv::Get ()->Add (client, "eth0", secondClientEth0); NS_TEST_ASSERT_EQUAL (result, false); // // We should be able to add the same name in the second object's context // Ptr serverEth0 = CreateObject (); - result = Names::Add (server, "eth0", serverEth0); - NS_TEST_ASSERT_EQUAL (result, true); + Names::Add (server, "eth0", serverEth0); // // We should be able to find the short names for the objects we created @@ -879,32 +889,28 @@ NamesTest::RunTests (void) // in the name. // Ptr router1 = CreateObject (); - result = Names::Add ("/Names/Router1", router1); - NS_TEST_ASSERT_EQUAL (result, true); + Names::Add ("/Names/Router1", router1); // // We should be able to add objects while not including the root of the namespace // in the name. // Ptr router2 = CreateObject (); - result = Names::Add ("Router2", router2); - NS_TEST_ASSERT_EQUAL (result, true); + Names::Add ("Router2", router2); // // We should be able to add sub-objects while including the root of the namespace // in the name. // Ptr router1Eth0 = CreateObject (); - result = Names::Add ("/Names/Router1/eth0", router1Eth0); - NS_TEST_ASSERT_EQUAL (result, true); + Names::Add ("/Names/Router1/eth0", router1Eth0); // // We should be able to add sub-objects while not including the root of the namespace // in the name. // Ptr router2Eth0 = CreateObject (); - result = Names::Add ("Router2/eth0", router2Eth0); - NS_TEST_ASSERT_EQUAL (result, true); + Names::Add ("Router2/eth0", router2Eth0); // // We should be able to find these objects in the same two ways @@ -937,20 +943,17 @@ NamesTest::RunTests (void) // We have a pile of names defined. We should be able to rename them in the // usual ways. // - result = Names::Rename ("/Names/Router1", "RouterX"); - NS_TEST_ASSERT_EQUAL (result, true); + Names::Rename ("/Names/Router1", "RouterX"); foundObject = Names::Find ("/Names/RouterX"); NS_TEST_ASSERT_EQUAL (foundObject, router1); - result = Names::Rename ("Router2", "RouterY"); - NS_TEST_ASSERT_EQUAL (result, true); + Names::Rename ("Router2", "RouterY"); foundObject = Names::Find ("RouterY"); NS_TEST_ASSERT_EQUAL (foundObject, router2); - result = Names::Rename ("/Names/RouterX/eth0", "ath0"); - NS_TEST_ASSERT_EQUAL (result, true); + Names::Rename ("/Names/RouterX/eth0", "ath0"); foundObject = Names::Find ("/Names/RouterX/ath0"); NS_TEST_ASSERT_EQUAL (foundObject, router1Eth0); @@ -963,7 +966,7 @@ NamesTest::RunTests (void) // object. // - result = Names::Rename ("/Names/RouterX", "RouterY"); + result = NamesPriv::Get ()->Rename ("/Names/RouterX", "RouterY"); NS_TEST_ASSERT_EQUAL (result, false); Names::Delete (); diff --git a/src/core/names.h b/src/core/names.h index 7f163e2fb..cbb61bef2 100644 --- a/src/core/names.h +++ b/src/core/names.h @@ -65,7 +65,7 @@ public: * prepended with a path to that object. * \param obj A smart pointer to the object itself. */ - static bool Add (std::string name, Ptr obj); + static void Add (std::string name, Ptr obj); /** * \brief An intermediate form of Names::Add allowing you to provide a path to @@ -96,11 +96,9 @@ public: * \param name The name of the object you want to associate. * \param obj A smart pointer to the object itself. * - * \returns true if the association was successfully completed, false otherwise - * * \see Names::Add (Ptr context, std::string name, Ptr object); */ - static bool Add (std::string path, std::string name, Ptr object); + static void Add (std::string path, std::string name, Ptr object); /** * \brief A low-level form of Names::Add allowing you to specify the path to @@ -148,10 +146,8 @@ public: * under which you want this new name to be defined. * \param name The name of the object you want to associate. * \param obj A smart pointer to the object itself. - * - * \returns true if the association was successfully completed, false otherwise */ - static bool Add (Ptr context, std::string name, Ptr object); + static void Add (Ptr context, std::string name, Ptr object); /** * \brief Rename a previously associated name. @@ -178,11 +174,9 @@ public: * \param oldpath The current path name to the object you want to change. * \param newname The new name of the object you want to change. * - * \returns true if the name change was successfully completed, false otherwise - * * \see Names::Add (std::string name, Ptr obj) */ - static bool Rename (std::string oldpath, std::string newname); + static void Rename (std::string oldpath, std::string newname); /** * \brief An intermediate form of Names::Rename allowing you to provide a path to @@ -203,10 +197,8 @@ public: * you want this name change to occur (cf. directory). * \param oldname The currently defined name of the object. * \param newname The new name you want the object to have. - * - * \returns true if the name change was successfully completed, false otherwise */ - static bool Rename (std::string path, std::string oldname, std::string newname); + static void Rename (std::string path, std::string oldname, std::string newname); /** * \brief A low-level form of Names::Rename allowing you to specify the path to @@ -244,10 +236,8 @@ public: * under which you want this new name to be defined. * \param oldname The current shortname of the object you want to change. * \param newname The new shortname of the object you want to change. - * - * \returns true if the name change was successfully completed, false otherwise */ - static bool Rename (Ptr context, std::string oldname, std::string newname); + static void Rename (Ptr context, std::string oldname, std::string newname); /** * Given a pointer to an object, look to see if that object has a name