diff options
author | William R. Otte <wotte@dre.vanderbilt.edu> | 2008-11-24 16:08:26 +0000 |
---|---|---|
committer | William R. Otte <wotte@dre.vanderbilt.edu> | 2008-11-24 16:08:26 +0000 |
commit | 137b83b44b5f493f34fbd3c8d8915b24a7d587e3 (patch) | |
tree | fb973a0a1b521e63edb52603ca3089c43a3f4144 | |
parent | afd0edd68315606ee1a4a964a7b720edce7f1734 (diff) | |
download | ATCD-137b83b44b5f493f34fbd3c8d8915b24a7d587e3.tar.gz |
ChangeLogTag: Mon Nov 24 16:06:57 UTC 2008 William R. Otte <wotte@dre.vanderbilt.edu>
-rw-r--r-- | flat/CIAO/ChangeLog | 25 | ||||
-rw-r--r-- | flat/CIAO/DAnCE/NodeApplication/Name_Utilities.cpp | 156 | ||||
-rw-r--r-- | flat/CIAO/DAnCE/NodeApplication/Name_Utilities.h | 42 |
3 files changed, 214 insertions, 9 deletions
diff --git a/flat/CIAO/ChangeLog b/flat/CIAO/ChangeLog index fea1902498c..cbdc8089632 100644 --- a/flat/CIAO/ChangeLog +++ b/flat/CIAO/ChangeLog @@ -1,7 +1,14 @@ +Mon Nov 24 16:06:57 UTC 2008 William R. Otte <wotte@dre.vanderbilt.edu> + + * DAnCE/NodeApplication/Name_Utilities.h: + * DAnCE/NodeApplication/Name_Utilities.cpp: + + Files missing from last commit. + Sun Nov 23 23:59:50 UTC 2008 William R. Otte <wotte@dre.vanderbilt.edu> * DAnCE/Deployment/DAnCE_Properties.idl: - + Rearranged, organized * DAnCE/DomainApplicationManager/Node_Locator.h: @@ -16,20 +23,20 @@ Sun Nov 23 23:59:50 UTC 2008 William R. Otte <wotte@dre.vanderbilt.edu> * DAnCE/Plan_Launcher/Plan_Launcher_Base_Impl.cpp: * DAnCE/Plan_Launcher/Plan_Launcher_Impl.cpp: * DAnCE/Plan_Launcher/Plan_Launcher_Module.cpp: - - Improved NameService support. - + + Improved NameService support. + * examples/Hello/Sender/Sender_exec.cpp: * examples/Hello/descriptors/DeploymentPlan.cdp: * examples/Hello/descriptors/run_test.pl: - - Updates to work with new DAnCE. - + + Updates to work with new DAnCE. + * tools/Config_Handlers/XSCRT/Elements.hpp: * tools/XML/XML_Helper.h: - + Compile fixes. - + * examples/Hello/ReDaC-Usage.html: * examples/Hello/descriptors/Hello.cid: * examples/Hello/descriptors/Hello.cpd: diff --git a/flat/CIAO/DAnCE/NodeApplication/Name_Utilities.cpp b/flat/CIAO/DAnCE/NodeApplication/Name_Utilities.cpp new file mode 100644 index 00000000000..a3b12b6da9b --- /dev/null +++ b/flat/CIAO/DAnCE/NodeApplication/Name_Utilities.cpp @@ -0,0 +1,156 @@ +// $Id$ + +#include "Name_Utilities.h" + +#include "ace/Auto_Ptr.h" +#include "ace/SString.h" +#include "Logger/Log_Macros.h" + +namespace DAnCE +{ + bool + Name_Utilities::write_ior (const ACE_TCHAR *file, + const ACE_TCHAR *ior) + { + FILE* ior_output_file_ = ACE_OS::fopen (file, "w"); + if (ior_output_file_) + { + ACE_OS::fprintf (ior_output_file_, + "%s", + ior); + ACE_OS::fclose (ior_output_file_); + return true; + } + return false; + } + + bool + Name_Utilities::bind_object (const ACE_TCHAR *name, + CORBA::Object_ptr obj, + CosNaming::NamingContext_ptr ctx) + { + DANCE_TRACE ("Name_Utilities::bind_object"); + try + { + CosNaming::Name nm; + + Name_Utilities::build_name (name, nm); + + if (nm.length () == 0) + { + DANCE_ERROR ((LM_WARNING, DLINFO "Name_Utilities::bind_object - " + "build_name resulted in an invalid name for string %C\n", + name)); + return false; + } + + Name_Utilities::bind_context (nm, ctx); + + try + { + ctx->bind (nm, obj); + } + catch (CosNaming::NamingContext::AlreadyBound &ex) + { + DANCE_ERROR ((LM_WARNING, DLINFO "Name_Utilities::bind_object - " + "Name %C already bound, rebinding....\n", + name)); + ctx->rebind (nm, obj); + } + } + catch (CORBA::Exception &ex) + { + DANCE_ERROR ((LM_ERROR, DLINFO "Name_Utilities::bind_object - " + "Caught CORBA exception while attempting to bind name %C: %C\n", + name, ex._info ().c_str ())); + return false; + } + catch (...) + { + DANCE_ERROR ((LM_ERROR, DLINFO "Name_Utilities::bind_object - " + "Caught unknown C++ exception while attemptint to bind name %C\n", + name)); + return false; + } + + return true; + } + + void + Name_Utilities::bind_context (CosNaming::Name &nm, + CosNaming::NamingContext_ptr ctx) + { + DANCE_TRACE ("Name_Utilities::bind_context"); + + CosNaming::Name newname (nm.length ()); + + for (CORBA::ULong i = 0; + i < (nm.length () - 1); ++i) + { + newname.length (i + 1); + newname[i] = nm[i]; + + try + { + ctx->bind_new_context (newname); + DANCE_DEBUG ((LM_TRACE, DLINFO "Name_Utilities::bind_context - " + "Bound new context %C\n", newname[i].id.in ())); + } + catch (CosNaming::NamingContext::AlreadyBound &) + { + DANCE_DEBUG ((LM_TRACE, DLINFO "Name_Utilities::bind_context - " + "Context %C already bound.\n", newname[i].id.in ())); + } + } + } + + bool + Name_Utilities::unbind_object (const ACE_TCHAR *name, + CosNaming::NamingContext_ptr ctx) + { + DANCE_TRACE ("Name_Utilities::unbind_object"); + + CosNaming::Name nm; + Name_Utilities::build_name (name, nm); + + try + { + ctx->unbind (nm); + } + catch (CORBA::Exception &e) + { + DANCE_ERROR ((LM_ERROR, DLINFO "Name_Utilities::unbind_object - " + "Caught CORBA exception whilst unbinding name %C: %C\n", + name, e._info ().c_str ())); + return false; + } + return true; + } + + void + Name_Utilities::build_name (const ACE_TCHAR *name, + CosNaming::Name &nm) + { + DANCE_TRACE ("Name_Utilities::build_name"); + + /*ACE_Auto_Basic_Array_Ptr<ACE_TCHAR>*/ ACE_TCHAR *safe_array (new ACE_TCHAR[ACE_OS::strlen (name)]); + + ACE_Tokenizer parser (ACE_OS::strcpy (safe_array/*.get ()*/, name)); + parser.delimiter ('/'); + + ACE_TCHAR *next (0); + + while ((next = parser.next ()) != 0) + { + CORBA::ULong i = nm.length (); + nm.length (i + 1); + + DANCE_DEBUG ((LM_TRACE, DLINFO "Name_Utilities::build_name - " + "Found name component %C\n", + next)); + + nm[i].id = CORBA::string_dup (next); + } + } + +} diff --git a/flat/CIAO/DAnCE/NodeApplication/Name_Utilities.h b/flat/CIAO/DAnCE/NodeApplication/Name_Utilities.h new file mode 100644 index 00000000000..c6fa11e1c87 --- /dev/null +++ b/flat/CIAO/DAnCE/NodeApplication/Name_Utilities.h @@ -0,0 +1,42 @@ +/** + * @file Name_Utilities.h + * @author William R. Otte <wotte@dre.vanderbilt.edu> + * + * A set of utility methods to manages references. + * + */ + +#ifndef NAME_UTILITIES_H +#define NAME_UTILITIES_H + +#include "orbsvcs/CosNamingC.h" + +namespace DAnCE +{ + class Name_Utilities + { + public: + /// Write IOR to named file. Will overwrite file if present. + static bool write_ior (const ACE_TCHAR *file, const ACE_TCHAR *ior); + + /// Binds object to provided name, which may be formatted with / to indicate + /// naming contexts, e.g. A/B/C. + static bool bind_object (const ACE_TCHAR *name, + CORBA::Object_ptr obj, + CosNaming::NamingContext_ptr); + + /// Will unbind the provided name. + static bool unbind_object (const ACE_TCHAR *name, + CosNaming::NamingContext_ptr); + + private: + static void bind_context (CosNaming::Name &nm, + CosNaming::NamingContext_ptr); + + static void build_name (const ACE_TCHAR *nm, + CosNaming::Name &); + + }; +} + +#endif /* NAME_UTILITIES_H */ |