summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordengg <dengg@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2006-02-10 04:54:09 +0000
committerdengg <dengg@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2006-02-10 04:54:09 +0000
commita7f49788d686459b6b10ea9cc31807479b2051d9 (patch)
tree6af5015d4b28053fbfeabecea0a64b24cbb8a03d
parent254ab7baf378e655f5734a2a70a15a84f2b53ca9 (diff)
downloadATCD-CIAO_Events_01.tar.gz
*** empty log message ***CIAO_Events_01
-rw-r--r--TAO/CIAO/DAnCE/NodeApplication/Container_Impl.cpp62
-rw-r--r--TAO/CIAO/DAnCE/NodeApplication/Container_Impl.h4
-rw-r--r--TAO/CIAO/ciao/Server_init.cpp271
-rw-r--r--TAO/CIAO/ciao/Server_init.h38
4 files changed, 301 insertions, 74 deletions
diff --git a/TAO/CIAO/DAnCE/NodeApplication/Container_Impl.cpp b/TAO/CIAO/DAnCE/NodeApplication/Container_Impl.cpp
index 14c18fb79ae..29d42eea342 100644
--- a/TAO/CIAO/DAnCE/NodeApplication/Container_Impl.cpp
+++ b/TAO/CIAO/DAnCE/NodeApplication/Container_Impl.cpp
@@ -111,19 +111,6 @@ CIAO::Container_Impl::install (
if (CORBA::is_nil (comp.in ()))
ACE_TRY_THROW (Deployment::InstallationFailure ());
- ACE_DEBUG((LM_DEBUG, "Narrowing to SessionComponent ...\n"));
-
- ::Components::SessionComponent_var session_comp
- = ::Components::SessionComponent::_narrow(comp.in ());
-
- if (CORBA::is_nil(session_comp))
- {
- ACE_DEBUG((LM_DEBUG, "session_comp is null\n"));
- ACE_THROW (CORBA::INTERNAL ());
- }
- else
- ACE_DEBUG((LM_DEBUG, "session_comp is good\n"));
-
if (this->component_map_.bind
(impl_infos[i].component_instance_name.in (),
Components::CCMObject::_duplicate (comp.in ())))
@@ -485,7 +472,7 @@ CIAO::Container_Impl::remove_component (const char * comp_ins_name
}
bool
-CIAO::Container_Impl::register_with_ns (const char * obj_name,
+CIAO::Container_Impl::register_with_ns (const char * s,
CORBA::ORB_ptr orb,
Components::CCMObject_ptr obj
ACE_ENV_ARG_DECL)
@@ -500,23 +487,43 @@ CIAO::Container_Impl::register_with_ns (const char * obj_name,
if (CORBA::is_nil (naming_obj.in ()))
ACE_ERROR_RETURN ((LM_ERROR,
- " (%P|%t) Unable to get the Naming Service.\n"),
- false);
+ "DAnCE: (%P|%t) Unable to get the Naming Service.\n"),
+ false);
- CosNaming::NamingContext_var naming_context =
- CosNaming::NamingContext::_narrow (naming_obj.in ()
- ACE_ENV_ARG_PARAMETER);
+ CosNaming::NamingContextExt_var root =
+ CosNaming::NamingContextExt::_narrow (naming_obj.in ()
+ ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
- // Create a Naming Sequence
- CosNaming::Name name (1);
- name.length (1);
- name[0].id = CORBA::string_dup (obj_name);
- name[0].kind = CORBA::string_dup ("");
+ CosNaming::Name name (0);
+ name.length (0);
- // Register with the Name Server
- naming_context->bind (name, obj ACE_ENV_ARG_PARAMETER);
- ACE_TRY_CHECK;
+ // Get the multicomponent naming context from the <naming_context>.
+ // The convention of this <naming_context> input string is that
+ // different naming context is separated by character '/', such as
+ // "create a naming context A/B/C/D".
+ ACE_CString tmp (s);
+ char * naming_string = tmp.rep ();
+ char seps[] = "/:";
+
+ char *token;
+ token = ACE_OS::strtok (naming_string, seps);
+
+ for (CORBA::ULong i = 0; token != NULL; ++i)
+ {
+ // While there still are tokens in the "naming_string"
+ name.length (name.length () + 1);
+ name[i].id = CORBA::string_dup (token);
+
+ // Get next naming context
+ token = ACE_OS::strtok ( NULL, seps );
+ }
+
+ // Let's create the context path first
+ Utility::NameUtility::CreateContextPath (root.in (), name);
+
+ // Bind the actual object
+ Utility::NameUtility::BindObjectPath (root.in (), name, obj);
return true;
}
@@ -583,4 +590,3 @@ CIAO::Container_Impl::unregister_with_ns (const char * obj_name,
ACE_ENDTRY;
return true;
}
-
diff --git a/TAO/CIAO/DAnCE/NodeApplication/Container_Impl.h b/TAO/CIAO/DAnCE/NodeApplication/Container_Impl.h
index 3f3bb550cf0..2458c3b633d 100644
--- a/TAO/CIAO/DAnCE/NodeApplication/Container_Impl.h
+++ b/TAO/CIAO/DAnCE/NodeApplication/Container_Impl.h
@@ -29,7 +29,7 @@
#include "ciao/Container_Base.h"
//#include "ciao/Swapping_Container.h"
#include "ace/SString.h"
-#include "ciao/Server_init.h" // write_IOR function
+#include "ciao/Server_init.h" // write_IOR function & NameUtility
#include "ciao/CIAO_common.h" // CIAO::debug_level
namespace CIAO
@@ -208,7 +208,7 @@ protected:
ACE_Null_Mutex> CCMComponent_Map;
typedef CCMComponent_Map::iterator Component_Iterator;
CCMComponent_Map component_map_;
-
+
const Static_Config_EntryPoints_Maps* static_entrypts_maps_;
};
}
diff --git a/TAO/CIAO/ciao/Server_init.cpp b/TAO/CIAO/ciao/Server_init.cpp
index 43eaabcd598..78efd9b27ed 100644
--- a/TAO/CIAO/ciao/Server_init.cpp
+++ b/TAO/CIAO/ciao/Server_init.cpp
@@ -6,52 +6,235 @@
#include "Cookies.h"
#include "ace/OS_NS_stdio.h"
-
-int
-CIAO::Server_init (CORBA::ORB_ptr o)
-{
- CIAO_REGISTER_VALUE_FACTORY (o, CIAO::Map_Key_Cookie_init,
- Components::Cookie);
- CIAO_REGISTER_VALUE_FACTORY (o, CIAO::Map_Key_Cookie_init,
- CIAO::Cookie);
- CIAO_REGISTER_VALUE_FACTORY (o, Components::PortDescription_init,
- Components::PortDescription);
- CIAO_REGISTER_VALUE_FACTORY (o, Components::FacetDescription_init,
- Components::FacetDescription);
- CIAO_REGISTER_VALUE_FACTORY (o, Components::ConnectionDescription_init,
- Components::ConnectionDescription);
- CIAO_REGISTER_VALUE_FACTORY (o, Components::ReceptacleDescription_init,
- Components::ReceptacleDescription);
- CIAO_REGISTER_VALUE_FACTORY (o, Components::ConsumerDescription_init,
- Components::ConsumerDescription);
- CIAO_REGISTER_VALUE_FACTORY (o, Components::EmitterDescription_init,
- Components::EmitterDescription);
- CIAO_REGISTER_VALUE_FACTORY (o, Components::SubscriberDescription_init,
- Components::SubscriberDescription);
- CIAO_REGISTER_VALUE_FACTORY (o, Components::PublisherDescription_init,
- Components::PublisherDescription);
- CIAO_REGISTER_VALUE_FACTORY (o, Components::ConfigValue_init,
- Components::ConfigValue);
- CIAO_REGISTER_VALUE_FACTORY (o, Components::ComponentPortDescription_init,
- Components::ComponentPortDescription);
- return 0;
-}
-
-int
-CIAO::Utility::write_IOR (const char *pathname,
- const char *ior)
+namespace CIAO
{
- FILE* ior_output_file_ =
- ACE_OS::fopen (pathname, "w");
+ int
+ CIAO::Server_init (CORBA::ORB_ptr o)
+ {
+ CIAO_REGISTER_VALUE_FACTORY (o, CIAO::Map_Key_Cookie_init,
+ Components::Cookie);
+ CIAO_REGISTER_VALUE_FACTORY (o, CIAO::Map_Key_Cookie_init,
+ CIAO::Cookie);
+ CIAO_REGISTER_VALUE_FACTORY (o, Components::PortDescription_init,
+ Components::PortDescription);
+ CIAO_REGISTER_VALUE_FACTORY (o, Components::FacetDescription_init,
+ Components::FacetDescription);
+ CIAO_REGISTER_VALUE_FACTORY (o, Components::ConnectionDescription_init,
+ Components::ConnectionDescription);
+ CIAO_REGISTER_VALUE_FACTORY (o, Components::ReceptacleDescription_init,
+ Components::ReceptacleDescription);
+ CIAO_REGISTER_VALUE_FACTORY (o, Components::ConsumerDescription_init,
+ Components::ConsumerDescription);
+ CIAO_REGISTER_VALUE_FACTORY (o, Components::EmitterDescription_init,
+ Components::EmitterDescription);
+ CIAO_REGISTER_VALUE_FACTORY (o, Components::SubscriberDescription_init,
+ Components::SubscriberDescription);
+ CIAO_REGISTER_VALUE_FACTORY (o, Components::PublisherDescription_init,
+ Components::PublisherDescription);
+ CIAO_REGISTER_VALUE_FACTORY (o, Components::ConfigValue_init,
+ Components::ConfigValue);
+ CIAO_REGISTER_VALUE_FACTORY (o, Components::ComponentPortDescription_init,
+ Components::ComponentPortDescription);
+ return 0;
+ }
+
+ namespace Utility
+ {
+ int write_IOR (const char *pathname,
+ const char *ior)
+ {
+ FILE* ior_output_file_ =
+ ACE_OS::fopen (pathname, "w");
+
+ if (ior_output_file_)
+ {
+ ACE_OS::fprintf (ior_output_file_,
+ "%s",
+ ior);
+ ACE_OS::fclose (ior_output_file_);
+ return 0;
+ }
+
+ return -1;
+ }
+
+ // --------------------------------------------------------------
+ // Implementation of NameUtility class
+ // --------------------------------------------------------------
+
+ void NameUtility::CreateContextPath (const CosNaming::NamingContextExt_ptr nc,
+ const CosNaming::Name& name)
+ {
+ bool isNotFound = false;
+ CORBA::ULong lengthMissing = 0;
+ CORBA::ULong OriginalLength = name.length();
+ CosNaming::Name tmpName;
- if (ior_output_file_)
+ CosNaming::NamingContext_var tmpCtxVar;
+
+ ACE_TRY
+ {
+ tmpCtxVar = nc->bind_new_context(name);
+ ACE_DEBUG ((LM_DEBUG, "Bound Context.\n\n"));
+ }
+ ACE_CATCH (CosNaming::NamingContext::AlreadyBound, ex)
+ {
+ ACE_DEBUG ((LM_DEBUG, "Context Already Bound.\n\n"));
+ }
+ ACE_CATCH (CosNaming::NamingContext::NotFound, nf)
+ {
+ ACE_DEBUG ((LM_DEBUG, "Context not found.\n\n"));
+ isNotFound = true;
+ lengthMissing = nf.rest_of_name.length();
+ }
+ ACE_ENDTRY;
+
+ if (lengthMissing == name.length())
+ {
+ ACE_DEBUG ((LM_ERROR, "Null name length.\n\n"));
+ }
+
+ if (isNotFound)
+ {
+ for (CORBA::ULong l = OriginalLength-lengthMissing;
+ l < OriginalLength;
+ l++)
+ {
+ tmpName.length(l+1);
+ for (CORBA::ULong i=0; i <= l; i++)
+ {
+ tmpName[i] = name[i];
+
+ CORBA::String_var newSCName = nc->to_string(tmpName);
+ ACE_DEBUG ((LM_DEBUG, "What's left of the name:%s\n",
+ newSCName.in ()));
+ }
+
+ tmpCtxVar = nc->bind_new_context(tmpName);
+ ACE_DEBUG ((LM_DEBUG, "Bound New Context.\n"));
+ }
+ }
+ }
+
+ //---------------------------------------------------------------------------------------------
+ void NameUtility::BindObjectPath (const CosNaming::NamingContextExt_ptr nc,
+ const CosNaming::Name& name,
+ const CORBA::Object_var obj)
{
- ACE_OS::fprintf (ior_output_file_,
- "%s",
- ior);
- ACE_OS::fclose (ior_output_file_);
- return 0;
+ CosNaming::Name tmpName;
+ CORBA::String_var newSCName = nc->to_string(name);
+ ACE_DEBUG ((LM_DEBUG, "The name is: %s\n", newSCName.in ()));
+
+ ACE_TRY
+ {
+ nc->rebind(name, obj);
+ }
+
+ ACE_CATCH (CosNaming::NamingContext::NotFound, ex )
+ {
+ ACE_DEBUG ((LM_DEBUG, "Name not found, doing new bind.\n"));
+ nc->bind(name, obj);
+ }
+ ACE_ENDTRY;
+ }
+
+ //---------------------------------------------------------------------------------------------
+ CosNaming::BindingList *
+ NameUtility::listBindings (const CosNaming::NamingContext_ptr nc,
+ const CosNaming::Name& name,
+ CORBA::ULong max_list_size)
+ {
+ CosNaming::BindingList_var basicListV;
+ CosNaming::BindingIterator_var bIterV;
+
+ CORBA::Object_var objV;
+ CosNaming::NamingContext_var tmpContextV;
+
+ if (name.length()==0)
+ {
+ tmpContextV = CosNaming::NamingContext::_duplicate(nc);
+ }
+ else
+ {
+ objV = nc->resolve(name);
+ tmpContextV = CosNaming::NamingContext::_narrow(objV);
+ }
+ if (CORBA::is_nil(tmpContextV))
+ {
+ ACE_DEBUG ((LM_ERROR, "listBindings: Nil context.\n"));
+ return 0;
+ }
+
+ tmpContextV->list(max_list_size, basicListV.out(), bIterV.out());
+
+ CORBA::Long max_remaining = max_list_size - basicListV->length();
+ CORBA::Boolean moreBindings = !CORBA::is_nil(bIterV);
+
+ if (moreBindings)
+ {
+ while (moreBindings && (max_remaining > 0) )
+ {
+ CosNaming::BindingList_var tmpListV;
+
+ moreBindings = bIterV->next_n(max_remaining, tmpListV.out());
+
+ //Append 'tmpListV' to 'basicListV'
+ CORBA::ULong basicListLen = basicListV->length();
+ basicListV->length(basicListLen+tmpListV->length());
+ for (CORBA::ULong i=0; i < tmpListV->length(); i++)
+ {
+ (*basicListV)[i+basicListLen] = (*tmpListV)[i];
+ }
+
+ //Re-calculate 'max_remaining'
+ max_remaining = max_list_size - basicListV->length();
+ }
+ bIterV->destroy();
+ }
+
+ return basicListV._retn();
+ }
+
+ //---------------------------------------------------------------------------------------------
+ void
+ NameUtility::recursiveUnbind (const CosNaming::NamingContext_ptr nc,
+ const CosNaming::Name& name)
+ {
+ CORBA::Object_var objV;
+ CosNaming::NamingContext_var tmpContextV;
+
+ objV = nc->resolve(name);
+ tmpContextV = CosNaming::NamingContext::_narrow(objV);
+ if (CORBA::is_nil(tmpContextV))
+ {
+ ACE_DEBUG ((LM_ERROR, "recursiveUnbind: Nil context reference.\n"));
+ return;
+ }
+
+ CosNaming::BindingList_var blV;
+ CosNaming::Name tmpName;
+ tmpName.length(0);
+
+ blV = NameUtility::listBindings(tmpContextV.in(),
+ tmpName,
+ 10000); // 'max_list_size'
+
+ for (CORBA::ULong i=0; i<blV->length(); i++)
+ {
+ tmpName = (*blV)[i].binding_name;
+
+ if ((*blV)[i].binding_type==CosNaming::nobject)
+ {
+ tmpContextV->unbind(tmpName);
+ }
+ else if ( (*blV)[i].binding_type==CosNaming::ncontext)
+ {
+ NameUtility::recursiveUnbind(tmpContextV.in(), tmpName);
+ }
+ }
+ nc->unbind(name);
+ tmpContextV->destroy();
}
- return -1;
-}
+ } /* namespace Utility */
+} /* namespace CIAO */
diff --git a/TAO/CIAO/ciao/Server_init.h b/TAO/CIAO/ciao/Server_init.h
index 728c4abdd10..c5fe53ed77d 100644
--- a/TAO/CIAO/ciao/Server_init.h
+++ b/TAO/CIAO/ciao/Server_init.h
@@ -7,6 +7,7 @@
* I'm also puting some utilities functions here.
*
* @author Nanbor Wang <nanbor@cs.wustl.edu>
+ * @author Gan Deng <dengg@dre.vanderbilt.edu>
*/
#ifndef CIAO_SERVER_INIT_H
@@ -15,6 +16,7 @@
#include "CIAO_Server_Export.h"
#include "tao/Versioned_Namespace.h"
+#include <orbsvcs/CosNamingC.h>
#if !defined ACE_LACKS_PRAGMA_ONCE
#pragma once
@@ -46,6 +48,42 @@ namespace CIAO
/// overwritten.
CIAO_SERVER_Export int write_IOR (const char *pathname,
const char *IOR);
+
+ class CIAO_SERVER_Export NameUtility
+ {
+ /**
+ * A utility class to bind naming context. This class is contributed by
+ * Dipa Suri <dipa.suri@lmco.com>.
+ *
+ * The concept/code are derived from
+ * http://www.informit.com/articles/article.asp?p=23266&seqNum=6
+ */
+
+ public:
+ /// For each 'NameComponent' in 'name', create a corresponding 'NamingContext'.
+ static void CreateContextPath (const CosNaming::NamingContextExt_ptr,
+ const CosNaming::Name &);
+
+ /// For the first [0, length-2] NameComponents of 'name', create a
+ /// corresponding 'NamingContext'.
+ /// For the length-1 NameComponent of 'name', bind it to the object
+ /// reference 'obj'.
+ static void BindObjectPath (const CosNaming::NamingContextExt_ptr,
+ const CosNaming::Name&,
+ const CORBA::Object_var);
+
+ /// Get a list of all bindings under the given context, up to
+ /// max_list_size.
+ static CosNaming::BindingList * listBindings (const CosNaming::NamingContext_ptr,
+ const CosNaming::Name&,
+ CORBA::ULong);
+
+ /// Recursively unbind all objects and contexts below the given name
+ /// context, given the initial context nc.
+ /// Assumes a tree shape to service (not cyclic)
+ static void recursiveUnbind (const CosNaming::NamingContext_ptr,
+ const CosNaming::Name&);
+ };
}
}