diff options
author | aky <aky@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2011-06-14 18:57:08 +0000 |
---|---|---|
committer | aky <aky@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2011-06-14 18:57:08 +0000 |
commit | aa110a041fecfa6fc0cd4fa6f73c5d31812f28da (patch) | |
tree | 5dfd220e5ea9406aa318822315bafa50ab77b89a | |
parent | 69ed28caca9ea3c12d65e96b8b1a2ee25bd70ebd (diff) | |
download | ATCD-aa110a041fecfa6fc0cd4fa6f73c5d31812f28da.tar.gz |
Tue Jun 14 18:50:43 UTC 2011 Akshay V. Dabholkar <aky@dre.vanderbilt.edu>
* CIAO_TAO_DAnCE.mwc:
* ciao/Containers/FTSession:
* ciao/Containers/FTSession/FT_Session_Container.h:
* ciao/Containers/FTSession/FT_Session_Container.idl:
* ciao/Containers/FTSession/FT_Session_Container.inl:
* ciao/Containers/FTSession/FT_Session_Container.cpp:
* ciao/Containers/FTSession/FT_Session_Container.mpc:
* ciao/Containers/FTSession/FT_Session_Container_export.h:
* ciao/Containers/Generic/ClientContainerInterceptorRegistration_Impl.h:
* ciao/Containers/Generic/Generic_Container.idl:
* ciao/Containers/Generic/ServantContainerInterceptorRegistration_Impl.h:
* ciao/Containers/Generic/ServerContainerInterceptorRegistration_Impl.h:
* ciao/Containers/Generic/StubContainerInterceptorRegistration_Impl.h:
* ciao/Containers/Swapping:
* ciao/Containers/Swapping/Dynamic_Component_Activator.h:
* ciao/Containers/Swapping/Dynamic_Component_Activator.inl:
* ciao/Containers/Swapping/Dynamic_Component_Activator.cpp:
* ciao/Containers/Swapping/Swapping_Container.h:
* ciao/Containers/Swapping/Swapping_Container.inl:
* ciao/Containers/Swapping/Swapping_Container.cpp:
* ciao/Containers/Swapping/Swapping_Container.mpc:
* ciao/Containers/Swapping/Swapping_Container_export.h:
* ciao/Contexts/Swapping:
* ciao/Contexts/Swapping/CIAO_UpgradeableContext.idl:
* ciao/Contexts/Swapping/Upgradeable_Context_Impl_T.h:
* ciao/Contexts/Swapping/Upgradeable_Context_Impl_T.cpp:
* ciao/FTComponentServer:
* ciao/FTComponentServer/CIAO_CS_Client.idl:
* ciao/FTComponentServer/CIAO_CS_Client_svnt_export.h:
* ciao/FTComponentServer/CIAO_ComponentInstallation_Impl.h:
* ciao/FTComponentServer/CIAO_ComponentInstallation_Impl.cpp:
* ciao/FTComponentServer/CIAO_ComponentServer.idl:
* ciao/FTComponentServer/CIAO_ComponentServer.mpc:
* ciao/FTComponentServer/CIAO_Container_Impl.h:
* ciao/FTComponentServer/CIAO_Container_Impl.cpp:
* ciao/FTComponentServer/CIAO_FTComponentServer.h:
* ciao/FTComponentServer/CIAO_FTComponentServer.cpp:
* ciao/FTComponentServer/CIAO_FTComponentServer_Impl.h:
* ciao/FTComponentServer/CIAO_FTComponentServer_Impl.cpp:
* ciao/FTComponentServer/CIAO_FTComponentServer_stub_export.h:
* ciao/FTComponentServer/CIAO_FTComponentServer_svnt_export.h:
* ciao/FTComponentServer/CIAO_Properties.idl:
* ciao/FTComponentServer/CIAO_ServerActivator_Impl.h:
* ciao/FTComponentServer/CIAO_ServerActivator_Impl.cpp:
* ciao/FTComponentServer/CIAO_ServerResources.idl:
* ciao/FTComponentServer/Configurator_Factory.h:
* ciao/FTComponentServer/Configurator_Factory.cpp:
* ciao/FTComponentServer/Configurators:
* ciao/FTComponentServer/Configurators/Basic_Config_Manager.h:
* ciao/FTComponentServer/Configurators/Basic_Config_Manager.inl:
* ciao/FTComponentServer/Configurators/Basic_Config_Manager.cpp:
* ciao/FTComponentServer/Configurators/Basic_Config_Manager_export.h:
* ciao/FTComponentServer/Configurators/Basic_Configurator_export.h:
* ciao/FTComponentServer/Configurators/ComponentServer_Configurator_export.h:
* ciao/FTComponentServer/Configurators/Config_Manager.h:
* ciao/FTComponentServer/Configurators/Config_Manager.cpp:
* ciao/FTComponentServer/Configurators/Configurators.mpc:
* ciao/FTComponentServer/Configurators/NA_Configurator_Export.h:
* ciao/FTComponentServer/Configurators/NoOp:
* ciao/FTComponentServer/Configurators/NoOp/FT_NoOp_Configurator.mpc:
* ciao/FTComponentServer/Configurators/NoOp/NoOp_Configurator.h:
* ciao/FTComponentServer/Configurators/NoOp/NoOp_Configurator.cpp:
* ciao/FTComponentServer/Configurators/NoOp/NoOp_Configurator_export.h:
* ciao/FTComponentServer/Configurators/RT:
* ciao/FTComponentServer/Configurators/RT/RTConfig_Manager.h:
* ciao/FTComponentServer/Configurators/RT/RTConfig_Manager.inl:
* ciao/FTComponentServer/Configurators/RT/RTConfig_Manager.cpp:
* ciao/FTComponentServer/Configurators/RT/RTNA_Configurator_Export.h:
* ciao/FTComponentServer/Configurators/RTNodeApp_Configurator.h:
* ciao/FTComponentServer/Configurators/RTNodeApp_Configurator.cpp:
* ciao/FTComponentServer/Configurators/Server_Configurator.h:
* ciao/FTComponentServer/Configurators/Server_Configurator.cpp:
* ciao/FTComponentServer/Name_Helper_T.h:
* ciao/Servants/Swapping:
* ciao/Servants/Swapping/CIAO_SwapExec.idl:
* ciao/Servants/Swapping/CIAO_Swapping_Servant_export.h:
* ciao/Servants/Swapping/Dynamic_Component_Servant_Base.h:
* ciao/Servants/Swapping/Dynamic_Component_Servant_Base.cpp:
* ciao/Servants/Swapping/Dynamic_Component_Servant_T.h:
* ciao/Servants/Swapping/Dynamic_Component_Servant_T.cpp:
* ciao/Servants/Swapping/Swapping_Servant_Home_Impl_Base.h:
* ciao/Servants/Swapping/Swapping_Servant_Home_Impl_Base.cpp:
* ciao/Servants/Swapping/Swapping_Servant_Home_Impl_T.h:
* ciao/Servants/Swapping/Swapping_Servant_Home_Impl_T.cpp:
* ciao/Servants/Swapping/Swapping_Servants.mpc:
Started CORFU and SwapCIAO integration
62 files changed, 7590 insertions, 12 deletions
diff --git a/CIAO/ciao/Containers/FTSession/FT_Session_Container.cpp b/CIAO/ciao/Containers/FTSession/FT_Session_Container.cpp new file mode 100644 index 00000000000..28541ca1b71 --- /dev/null +++ b/CIAO/ciao/Containers/FTSession/FT_Session_Container.cpp @@ -0,0 +1,933 @@ +// $Id$ + +#include "FT_Session_Container.h" + +#include "tao/Utils/PolicyList_Destroyer.h" +#include "ciao/CIAO_common.h" +#include "ciao/Containers/Servant_Activator.h" +#include "ccm/ComponentServer/CCM_ComponentServer_BaseC.h" +#include "ciao/ComponentServer/CIAO_ComponentServerC.h" +#include "ciao/Servants/Servant_Impl_Base.h" +#include "orbsvcs/orbsvcs/LWFT/ReplicatedApplicationS.h" + +#if !defined (__ACE_INLINE__) +# include "FT_Session_Container.inl" +#endif /* __ACE_INLINE__ */ + +namespace CIAO +{ + /////////////////////////////////////////////////////////////// + + ACE_Atomic_Op <TAO_SYNCH_MUTEX, unsigned long> + FT_Session_Container::serial_number_ (0); + + FT_Session_Container::FT_Session_Container (CORBA::ORB_ptr o, + Deployment::CIAO_Container_i *container_impl, + bool static_config_flag, + const Static_Config_EntryPoints_Maps* maps, + const char *name, + const CORBA::PolicyList *more_policies) + : Container_i (o, container_impl), + number_ (0), + static_config_flag_ (static_config_flag), + static_entrypts_maps_ (maps), + sa_ (0) + { + this->init (name, more_policies); + } + + FT_Session_Container::~FT_Session_Container (void) + { + if (! CORBA::is_nil (this->component_poa_.in ())) + { + this->component_poa_->destroy (1, 1); + } + + if (! CORBA::is_nil (this->facet_cons_poa_.in ())) + { + this->facet_cons_poa_->destroy (1, 1); + } + + if (! CORBA::is_nil (this->home_servant_poa_.in ())) + { + this->home_servant_poa_->destroy (1, 1); + } + + // delete this->sa_; + } + + void + FT_Session_Container::init (const char *name, + const CORBA::PolicyList *more_policies) + { + CIAO_TRACE ("FT_Session_Container::init"); + + char buffer[MAXPATHLEN]; + + if (name == 0) + { + this->number_ = ++FT_Session_Container::serial_number_; + CIAO_DEBUG ((LM_TRACE, CLINFO "FT_Session_Container::init - " + "Constructing container name from serial number %u\n", + this->number_)); + ACE_OS::sprintf (buffer, + "CIAO::FT_Session_Container-%ld", + this->number_); + name = buffer; + } + + CIAO_DEBUG ((LM_TRACE, CLINFO "FT_Session_Container::init - " + "Initializing a container with name %C\n", + name)); + + CORBA::Object_var poa_object = + this->orb_->resolve_initial_references ("RootPOA"); + + if (CORBA::is_nil (poa_object.in ())) + { + CIAO_ERROR ((LM_ERROR, CLINFO + "CIAO::FT_Session_Container: Unable to initialize the POA.\n")); + throw Components::CreateFailure (); + } + + PortableServer::POA_var root_poa = + PortableServer::POA::_narrow (poa_object.in ()); + + this->create_component_POA (name, + more_policies, + root_poa.in ()); + + ACE_CString port_poa_name (name); + port_poa_name += ":Port_POA"; + this->create_facet_consumer_POA (port_poa_name.c_str (), + more_policies, + root_poa.in ()); + + PortableServer::POAManager_var poa_manager = + root_poa->the_POAManager (); + + poa_manager->activate (); + } + + void + FT_Session_Container::create_component_POA (const char *name, + const CORBA::PolicyList *p, + PortableServer::POA_ptr root) + { + CIAO_TRACE ("FT_Session_Container::create_component_POA"); + + // Set up proper poa policies here. Default policies seems to be + // fine for session container. If you add some other default + // policies here, then you need to "add" more_policies below + // instead of simply assigning more_policies to the init policy + // list. + CORBA::PolicyList policies (0); + + if (p != 0) + { + policies = *p; + } + + PortableServer::POAManager_var poa_manager = + root->the_POAManager (); + + this->component_poa_ = + root->create_POA (name, poa_manager.in (), policies); + } + + void + FT_Session_Container::create_facet_consumer_POA (const char *name, + const CORBA::PolicyList *p, + PortableServer::POA_ptr root) + { + CIAO_TRACE ("FT_Session_Container::create_facet_consumer_POA"); + + PortableServer::POAManager_var poa_manager = root->the_POAManager (); + CORBA::ULong p_length = 0; + + if (p != 0) + { + p_length = p->length (); + } + + TAO::Utils::PolicyList_Destroyer policies (p_length + 3); + policies.length (p_length + 3); + + policies[0] = + root->create_id_assignment_policy (PortableServer::USER_ID); + + // Servant Manager Policy + policies[1] = + root->create_request_processing_policy (PortableServer::USE_SERVANT_MANAGER); + + // Servant Retention Policy + policies[2] = + root->create_servant_retention_policy (PortableServer::RETAIN); + + for (CORBA::ULong i = 0; i < p_length; ++i) + { + policies[i+3] = (*p)[i]; + } + + this->facet_cons_poa_ = + root->create_POA (name, + poa_manager.in (), + policies); + + Servant_Activator_i *sa = 0; + ACE_NEW_THROW_EX (sa, + Servant_Activator_i (this->orb_.in ()), + CORBA::NO_MEMORY ()); + this->sa_ = sa; + + this->facet_cons_poa_->set_servant_manager (this->sa_.in ()); + } + + CORBA::Object_ptr + FT_Session_Container::install_servant (PortableServer::Servant p, + Container_Types::OA_Type t, + PortableServer::ObjectId_out oid) + { + CIAO_TRACE ("FT_Session_Container::install_servant"); + + PortableServer::POA_ptr tmp = PortableServer::POA::_nil(); + + if (t == Container_Types::COMPONENT_t || + t == Container_Types::HOME_t) + { + tmp = this->component_poa_.in (); + } + else + { + tmp = this->facet_cons_poa_.in (); + } + + PortableServer::ObjectId_var tmp_id = tmp->activate_object (p); + + CORBA::Object_var objref = tmp->id_to_reference (tmp_id.in ()); + oid = tmp_id._retn (); + + CIAO_DEBUG ((LM_DEBUG, CLINFO "FT_Session_Container::install_servant () : servant activated\n")); + + return objref._retn (); + } + + CORBA::Object_ptr + FT_Session_Container::install_servant_with_id (PortableServer::Servant p, + Container_Types::OA_Type t, + const PortableServer::ObjectId & oid) + { + CIAO_TRACE ("FT_Session_Container::install_servant_with_id"); + + PortableServer::POA_ptr tmp = 0; + + if (t == Container_Types::COMPONENT_t || + t == Container_Types::HOME_t) + { + tmp = this->component_poa_.in (); + } + else + { + tmp = this->facet_cons_poa_.in (); + } + + CORBA::String_var name = PortableServer::ObjectId_to_string (oid); + CIAO_DEBUG ((LM_DEBUG, CLINFO + "FT_Session_Container::install_servant_with_id (%C)\n", + name.in ())); + + tmp->activate_object_with_id (oid, + p); + + CORBA::Object_var objref = tmp->id_to_reference (oid); + + CIAO_DEBUG ((LM_DEBUG, + CLINFO "FT_Session_Container::install_servant_with_id () : " + "servant activated\n")); + + return objref._retn (); + } + + + //@@ Apparently we need to be cautious when handling the exception + // thrown here. We should make sure that new DnC interfaces + // NodeApplication/NodeApplicationManager etc will cache the new + // exceptions--> rethrow of new exceptions is needed. + // --Tao + Components::CCMHome_ptr + FT_Session_Container::install_home (const char *primary_artifact, + const char *entry_point, + const char *servant_artifact, + const char *servant_entrypoint, + const char *name) + { + CIAO_TRACE ("FT_Session_Container::install_home"); + + HomeFactory hcreator = 0; + HomeServantFactory screator = 0; + + if (this->static_config_flag_ == false) + { + CIAO_DEBUG ((LM_DEBUG, CLINFO + "FT_Session_Container::install_home - " + "Loading home [%C] from shared libraries\n", + name)); + CIAO_DEBUG ((LM_DEBUG, CLINFO + "FT_Session_Container::install_home - " + "Executor library [%C] with entrypoint [%C]\n", + primary_artifact, entry_point)); + CIAO_DEBUG ((LM_DEBUG, CLINFO + "FT_Session_Container::install_home - " + "Servant library [%C] with entrypoint [%C]\n", + servant_artifact, servant_entrypoint)); + + ACE_DLL executor_dll; + ACE_DLL servant_dll; + + if (primary_artifact == 0 || servant_artifact == 0) + { + ACE_CString exception; + + if (primary_artifact == 0) + { + exception = "Null component executor DLL name"; + } + + if (servant_artifact == 0) + { + exception = "Null component servant DLL name"; + } + + CIAO_ERROR ((LM_ERROR, CLINFO + "FT_Session_Container::install_home -" + "ERROR: %C\n", + exception.c_str ())); + + throw Components::Deployment::UnknownImplId (); + } + + if (executor_dll.open (primary_artifact, + ACE_DEFAULT_SHLIB_MODE, + 0) != 0) + { + ACE_CString error ("Failed to open executor DLL: "); + error += primary_artifact; + + CIAO_ERROR ((LM_ERROR, CLINFO + "FT_Session_Container::install_home - " + "ERROR in opening the executor DLL [%C] \n", + primary_artifact)); + + throw Components::Deployment::UnknownImplId (); + } + + CIAO_DEBUG ((LM_TRACE, CLINFO + "FT_Session_Container::install_home - " + "Executor DLL successfully opened\n")); + + if (servant_dll.open (servant_artifact, + ACE_DEFAULT_SHLIB_MODE, + 0) != 0) + { + ACE_CString error ("Failed to open executor DLL: "); + error += servant_artifact; + + CIAO_ERROR ((LM_ERROR, CLINFO + "FT_Session_Container::install_home - " + "ERROR in opening the servant DLL [%C] \n", + servant_artifact)); + + throw Components::Deployment::UnknownImplId (); + } + + CIAO_DEBUG ((LM_TRACE, CLINFO + "FT_Session_Container::install_home - " + "Servant DLL successfully openend.\n")); + + if (entry_point == 0 || servant_entrypoint == 0) + { + ACE_CString error ("Entry point is null for "); + + if (entry_point == 0) + { + CIAO_ERROR ((LM_ERROR, CLINFO + "FT_Session_Container::install_home - " + "ERROR in opening the executor entry point " + "for executor DLL [%C] \n", + primary_artifact)); + error += primary_artifact; + } + else + { + CIAO_ERROR ((LM_ERROR, CLINFO + "FT_Session_Container::install_home - " + "ERROR in opening the servant entry point " + "for servant DLL [%C] \n", + servant_artifact)); + error += servant_artifact; + } + + throw Components::Deployment::ImplEntryPointNotFound (); + } + + // We have to do this casting in two steps because the C++ + // standard forbids casting a pointer-to-object (including + // void*) directly to a pointer-to-function. + void *void_ptr = executor_dll.symbol (entry_point); + ptrdiff_t tmp_ptr = reinterpret_cast<ptrdiff_t> (void_ptr); + hcreator = reinterpret_cast<HomeFactory> (tmp_ptr); + + void_ptr = servant_dll.symbol (servant_entrypoint); + tmp_ptr = reinterpret_cast<ptrdiff_t> (void_ptr); + screator = reinterpret_cast<HomeServantFactory> (tmp_ptr); + } + else + { + CIAO_DEBUG ((LM_DEBUG, CLINFO + "FT_Session_Container::install_home - " + "Loading statically linked home [%C]\n", + name)); + + if (static_entrypts_maps_ == 0 + || static_entrypts_maps_->home_creator_funcptr_map_ == 0 + || static_entrypts_maps_->home_servant_creator_funcptr_map_ == 0) + { + CIAO_DEBUG ((LM_ERROR, CLINFO + "FT_Session_Container::install_home - ERROR: Static entrypoint " + "maps are null or imcomplete.\n")); + throw Components::Deployment::ImplEntryPointNotFound (); + } + + ACE_CString entry_point_str (entry_point); + static_entrypts_maps_->home_creator_funcptr_map_->find (entry_point_str, + hcreator); + + ACE_CString servant_entrypoint_str (servant_entrypoint); + static_entrypts_maps_->home_servant_creator_funcptr_map_->find ( + servant_entrypoint_str, screator); + } + + if (hcreator == 0 || screator == 0) + { + ACE_CString error ("Entry point "); + + if (hcreator == 0) + { + error += entry_point; + error += " invalid in dll "; + error += primary_artifact; + } + else + { + error += servant_entrypoint; + error += " invalid in dll "; + error += servant_artifact; + } + + CIAO_ERROR ((LM_ERROR, CLINFO + "FT_Session_Container::install_home - Error:%C\n", + error.c_str ())); + + throw Components::Deployment::ImplEntryPointNotFound (); + } + + CIAO_DEBUG ((LM_TRACE, CLINFO + "FT_Session_Container::install_home - Loading home executor\n")); + Components::HomeExecutorBase_var home_executor = hcreator (); + + if (CORBA::is_nil (home_executor.in ())) + { + CIAO_ERROR ((LM_ERROR, CLINFO + "FT_Session_Container::install_home - " + "Home executor factory failed. \n")); + throw Components::Deployment::InstallationFailure (); + } + + CIAO_DEBUG ((LM_TRACE, CLINFO + "FT_Session_Container::install_home - Loading home servant\n")); + PortableServer::Servant home_servant = screator (home_executor.in (), + this, + name); + + if (home_servant == 0) + { + CIAO_ERROR ((LM_ERROR, CLINFO + "FT_Session_Container::install_home - " + "Home servant factory failed.\n")); + throw Components::Deployment::InstallationFailure (); + } + + PortableServer::ServantBase_var safe (home_servant); + + CIAO_DEBUG ((LM_TRACE, CLINFO + "FT_Session_Container::install_home - Installing home servant\n")); + + PortableServer::ObjectId_var oid; + + CORBA::Object_var objref = + this->install_servant (home_servant, Container_Types::HOME_t, oid.out ()); + + Components::CCMHome_var homeref = + Components::CCMHome::_narrow (objref.in ()); + + CIAO_DEBUG ((LM_TRACE, CLINFO + "FT_Session_Container::install_home - Home successfully created with name\n")); + + return homeref._retn (); + } + + Components::CCMObject_ptr + FT_Session_Container::install_component (const char *primary_artifact, + const char *entry_point, + const char *servant_artifact, + const char *servant_entrypoint, + const char *name) + { + CIAO_TRACE ("FT_Session_Container::install_component"); + + ComponentFactory ccreator = 0; + ComponentServantFactory screator = 0; + + if (this->static_config_flag_ == false) + { + CIAO_DEBUG ((LM_DEBUG, CLINFO + "FT_Session_Container::install_component - " + "Loading component [%C] from shared libraries\n", + name)); + CIAO_DEBUG ((LM_DEBUG, CLINFO + "FT_Session_Container::install_component - " + "Executor library [%C] with entrypoint [%C]\n", + primary_artifact, entry_point)); + CIAO_DEBUG ((LM_DEBUG, CLINFO + "FT_Session_Container::install_component - " + "Servant library [%C] with entrypoint [%C]\n", + servant_artifact, servant_entrypoint)); + + ACE_DLL executor_dll, servant_dll; + + if (primary_artifact == 0 || servant_artifact == 0) + { + ACE_CString exception; + + if (primary_artifact == 0) + { + exception = "Null component executor DLL name"; + } + + if (servant_artifact == 0) + { + exception = "Null component servant DLL name"; + } + + CIAO_ERROR ((LM_ERROR, CLINFO + "FT_Session_Container.cpp -" + "FT_Session_Container::ciao_install_component - " + "ERROR: %C\n", + exception.c_str ())); + + throw Components::Deployment::UnknownImplId (); + } + + if (executor_dll.open (primary_artifact, + ACE_DEFAULT_SHLIB_MODE, + 0) != 0) + { + ACE_CString error ("Failed to open executor DLL: "); + error += primary_artifact; + + CIAO_ERROR ((LM_ERROR, CLINFO + "FT_Session_Container::install_component - " + "ERROR in opening the executor DLL [%C] - code \n", + primary_artifact)); + + throw Components::Deployment::UnknownImplId (); + } + + CIAO_DEBUG ((LM_TRACE, CLINFO + "FT_Session_Container::install_component - Executor DLL successfully opened\n")); + + if (servant_dll.open (servant_artifact, + ACE_DEFAULT_SHLIB_MODE, + 0) != 0) + { + ACE_CString error ("Failed to open executor DLL: "); + error += servant_artifact; + + CIAO_ERROR ((LM_ERROR, CLINFO + "FT_Session_Container::install_component -" + "ERROR in opening the servant DLL [%C] \n", + servant_artifact)); + + throw Components::Deployment::UnknownImplId (); + } + + CIAO_DEBUG ((LM_TRACE, CLINFO + "FT_Session_Container::install_component - Servant DLL successfully openend.\n")); + + if (entry_point == 0 || servant_entrypoint == 0) + { + ACE_CString error ("Entry point is null for "); + + if (entry_point == 0) + { + CIAO_ERROR ((LM_ERROR, CLINFO + "FT_Session_Container::install_component -" + "ERROR in opening the executor entry point " + "for executor DLL [%C] \n", + primary_artifact)); + error += primary_artifact; + } + else + { + CIAO_ERROR ((LM_ERROR, CLINFO + "FT_Session_Container::install_component -" + "ERROR in opening the servant entry point " + "for servant DLL [%C] \n", + servant_artifact)); + error += servant_artifact; + } + + throw Components::Deployment::ImplEntryPointNotFound (); + } + + // We have to do this casting in two steps because the C++ + // standard forbids casting a pointer-to-object (including + // void*) directly to a pointer-to-function. + void *void_ptr = executor_dll.symbol (entry_point); + ACE_DEBUG ((LM_EMERGENCY, "***** vp: %u\n", void_ptr)); + ptrdiff_t tmp_ptr = reinterpret_cast<ptrdiff_t> (void_ptr); + ccreator = reinterpret_cast<ComponentFactory> (tmp_ptr); + ACE_DEBUG ((LM_EMERGENCY, "***** cc: %u\n", ccreator)); + void_ptr = servant_dll.symbol (servant_entrypoint); + tmp_ptr = reinterpret_cast<ptrdiff_t> (void_ptr); + screator = reinterpret_cast<ComponentServantFactory> (tmp_ptr); + } + else + { + CIAO_DEBUG ((LM_DEBUG, CLINFO + "FT_Session_Container::install_component - Loading statically linked component [%C]\n", + name)); + + if (static_entrypts_maps_ == 0 + || static_entrypts_maps_->component_creator_funcptr_map_ == 0 + || static_entrypts_maps_->component_servant_creator_funcptr_map_ == 0) + { + CIAO_DEBUG ((LM_ERROR, CLINFO + "FT_Session_Container::install_component - ERROR: Static entrypoint " + "maps are null or imcomplete.\n")); + throw Components::Deployment::ImplEntryPointNotFound (); + } + + ACE_CString entry_point_str (entry_point); + static_entrypts_maps_->component_creator_funcptr_map_->find (entry_point_str, + ccreator); + + ACE_CString servant_entrypoint_str (servant_entrypoint); + static_entrypts_maps_->component_servant_creator_funcptr_map_->find (servant_entrypoint_str, + screator); + } + + if (ccreator == 0 || screator == 0) + { + ACE_CString error ("Entry point "); + + if (ccreator == 0) + { + error += entry_point; + error += " invalid in dll "; + error += primary_artifact; + } + else + { + error += servant_entrypoint; + error += " invalid in dll "; + error += servant_artifact; + } + + CIAO_ERROR ((LM_ERROR, CLINFO + "FT_Session_Container::ciao_install_component - Error:%C\n", + error.c_str ())); + + throw Components::Deployment::ImplEntryPointNotFound (); + } + + CIAO_DEBUG ((LM_TRACE, CLINFO + "FT_Session_Container::install_component - Loading component executor\n")); + Components::EnterpriseComponent_var component_executor = ccreator (); + + if (CORBA::is_nil (component_executor.in ())) + { + CIAO_ERROR ((LM_ERROR, CLINFO + "FT_Session_Container::Ciao_install_hoe - Component executor factory failed. \n")); + throw Components::Deployment::InstallationFailure (); + } + + CIAO_DEBUG ((LM_TRACE, CLINFO + "FT_Session_Container::install_component - Loading component servant\n")); + PortableServer::Servant component_servant = screator (component_executor.in (), + this, + name); + + if (component_servant == 0) + { + CIAO_ERROR ((LM_ERROR, CLINFO + "FT_Session_Container::ciao_install_component - Component servant factory failed.\n")); + throw Components::Deployment::InstallationFailure (); + } + + PortableServer::ServantBase_var safe (component_servant); + + CIAO_DEBUG ((LM_TRACE, CLINFO + "FT_Session_Container::install_component - Installing component servant\n")); + + PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId (name); + + CORBA::Object_var objref = + this->install_servant_with_id (component_servant, Container_Types::COMPONENT_t, oid); + + Components::CCMObject_var componentref = + Components::CCMObject::_narrow (objref.in ()); + + CIAO_DEBUG ((LM_TRACE, CLINFO + "FT_Session_Container::install_component - Component successfully created\n")); + + return componentref._retn (); + } + + void + FT_Session_Container::activate_component (Components::CCMObject_ptr compref) + { + CIAO_TRACE("FT_Session_Container::activate_component"); + + try + { + + PortableServer::Servant svt; + + try + { + svt = this->component_poa_->reference_to_servant (compref); + } + catch (...) + { + throw InvalidComponent (); + } + + CIAO::Servant_Impl_Base *sess = dynamic_cast<CIAO::Servant_Impl_Base *> (svt); + + if (sess == 0) + throw CIAO::InvalidComponent (); + + CIAO_DEBUG ((LM_TRACE, CLINFO "FT_Session_Container::activate_component - " + "Invoking CCM activate on provided component object reference.\n")); + sess->activate_component (); + } + catch (const CIAO::InvalidComponent &) + { + CIAO_ERROR ((LM_ERROR, CLINFO "FT_Session_Container::activate_component - " + "Failed to retrieve servant and/or cast to servant pointer.\n")); + throw; + } + catch (const CORBA::Exception &ex) + { + CIAO_ERROR ((LM_ERROR, CLINFO "FT_Session_Container::activate_component - " + "Caught CORBA exception while activating a component: %C\n", + ex._info ().c_str ())); + throw; + } + catch (...) + { + CIAO_ERROR ((LM_ERROR, CLINFO "FT_Session_Container::activate_component - " + "Caught unknown C++ eception while activating a component.\n")); + throw; + } + } + + void + FT_Session_Container::passivate_component (Components::CCMObject_ptr compref) + { + CIAO_TRACE ("FT_Session_Container::passivate_component"); + + try + { + PortableServer::Servant svt; + + try + { + svt = this->component_poa_->reference_to_servant (compref); + } + catch (...) + { + throw InvalidComponent (); + } + + CIAO::Servant_Impl_Base *sess = dynamic_cast<CIAO::Servant_Impl_Base *> (svt); + + if (sess == 0) + throw CIAO::InvalidComponent (); + + CIAO_DEBUG ((LM_TRACE, CLINFO "FT_Session_Container::passivate_component - " + "Invoking CCM activate on provided component object reference.")); + sess->passivate_component (); + } + catch (const CIAO::InvalidComponent &) + { + throw; + } + catch (const CORBA::Exception &ex) + { + CIAO_ERROR ((LM_ERROR, CLINFO "FT_Session_Container::passivate_component - " + "Caught CORBA exception while passivating a component: %C\n", + ex._info ().c_str ())); + throw; + } + catch (...) + { + CIAO_ERROR ((LM_ERROR, CLINFO "FT_Session_Container::passivate_component - " + "Caught unknown C++ eception while passivating a component.\n")); + throw; + } + } + + void + FT_Session_Container::uninstall (CORBA::Object_ptr objref, Container_Types::OA_Type y) + { + CIAO_TRACE ("FT_Session_Container::uninstall"); + + PortableServer::Servant svnt; + + switch (y) + { + case Container_Types::COMPONENT_t: + case Container_Types::HOME_t: + svnt = this->component_poa_->reference_to_servant (objref); + break; + default: + svnt = this->facet_cons_poa_->reference_to_servant (objref); + break; + } + + PortableServer::ObjectId_var oid; + this->uninstall_servant (svnt, y, oid.out ()); + } + + void + FT_Session_Container::uninstall_home (Components::CCMHome_ptr homeref) + { + CIAO_TRACE ("FT_Session_Container::uninstall_home"); + + this->uninstall (homeref, Container_Types::HOME_t); + } + + void + FT_Session_Container::uninstall_component (Components::CCMObject_ptr homeref) + { + CIAO_TRACE ("FT_Session_Container::uninstall_component"); + + this->uninstall (homeref, Container_Types::COMPONENT_t); + } + + void + FT_Session_Container::uninstall_servant (PortableServer::Servant svnt, + Container_Types::OA_Type t, + PortableServer::ObjectId_out oid) + { + CIAO_TRACE ("FT_Session_Container::uninstall_servant"); + + PortableServer::POA_ptr tmp = PortableServer::POA::_nil(); + + if ((t == Container_Types::COMPONENT_t) || + (t == Container_Types::HOME_t)) + { + CIAO_DEBUG ((LM_TRACE, CLINFO "FT_Session_Container::uninstall_servant - " + "Removing component or home servant\n")); + tmp = this->component_poa_.in (); + } + else + { + CIAO_DEBUG ((LM_TRACE, CLINFO "FT_Session_Container::uninstall_servant - " + "Removing facet or consumer servant\n")); + tmp = this->facet_cons_poa_.in (); + } + + try + { + PortableServer::ObjectId_var tmp_id; + tmp_id = tmp->servant_to_id (svnt); + tmp->deactivate_object (tmp_id); + svnt->_remove_ref (); + + CIAO_DEBUG ((LM_TRACE, CLINFO "FT_Session_Container::uninstall_servant - " + "Servant successfully removed, reference count is %u\n", + svnt->_refcount_value ())); + + oid = tmp_id._retn (); + } + catch (const CORBA::Exception &ex) + { + CIAO_ERROR ((LM_ERROR, CLINFO "FT_Session_Container::uninstall_servant - " + "Caught CORBA exception while uninstalling servant: %C\n", + ex._info ().c_str ())); + throw Components::RemoveFailure (); + } + + } + + void + FT_Session_Container::add_servant_to_map (PortableServer::ObjectId &, + Dynamic_Component_Servant_Base*) + { + CIAO_TRACE ("FT_Session_Container::add_servant_to_map"); + throw CORBA::NO_IMPLEMENT (); + } + + void + FT_Session_Container::delete_servant_from_map (PortableServer::ObjectId &) + { + CIAO_TRACE ("FT_Session_Container::delete_servant_from_map"); + throw CORBA::NO_IMPLEMENT (); + } + + void + FT_Session_Container::deactivate_facet (const PortableServer::ObjectId &) + { + CIAO_TRACE ("FT_Session_Container::deactivate_facet"); + } + + CORBA::Object_ptr + FT_Session_Container::get_home_objref (PortableServer::Servant) + { + CIAO_TRACE ("FT_Session_Container::get_home_objref"); + throw CORBA::NO_IMPLEMENT (); + } + + CORBA::Object_ptr + FT_Session_Container::generate_reference (const char *obj_id, + const char *repo_id, + Container_Types::OA_Type t) + { + CIAO_TRACE ("FT_Session_Container::generate_reference"); + + PortableServer::POA_ptr tmp = 0; + + if (t == Container_Types::COMPONENT_t || + t == Container_Types::HOME_t) + { + tmp = this->component_poa_.in (); + } + else + { + tmp = this->facet_cons_poa_.in (); + } + + PortableServer::ObjectId_var oid = + PortableServer::string_to_ObjectId (obj_id); + + CORBA::String_var str = PortableServer::ObjectId_to_string (oid.in ()); + + CORBA::Object_var objref = + tmp->create_reference_with_id (oid.in (), repo_id); + + return objref._retn (); + } +} diff --git a/CIAO/ciao/Containers/FTSession/FT_Session_Container.h b/CIAO/ciao/Containers/FTSession/FT_Session_Container.h new file mode 100644 index 00000000000..79bce0591f0 --- /dev/null +++ b/CIAO/ciao/Containers/FTSession/FT_Session_Container.h @@ -0,0 +1,236 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file FT_Session_Container.h + * + * $Id$ + * + * Header file for CIAO's container implementations + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + * @author Gan Deng <dengg@dre.vanderbilt.edu> + */ +//============================================================================= + +#ifndef CIAO_SESSION_CONTAINER_H +#define CIAO_SESSION_CONTAINER_H + +#include /**/ "ace/pre.h" + +#include "ciao/Containers/FTSession/FT_Session_Container_export.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/PortableServer/Servant_Base.h" +#include "ciao/Containers/Container_Base.h" + +namespace CIAO +{ + class FT_Session_Container; + class Servant_Activator; + class Home_Servant_Impl_Base; + + namespace Deployment + { + class CIAO_Container_i; + } + + typedef ::Components::HomeExecutorBase_ptr (*HomeFactory) (void); + typedef ::PortableServer::Servant (*HomeServantFactory) (::Components::HomeExecutorBase_ptr p, + ::CIAO::Container_ptr c, + const char *ins_name); + typedef ::Components::EnterpriseComponent_ptr (*ComponentFactory) (void); + typedef ::PortableServer::Servant (*ComponentServantFactory) (::Components::EnterpriseComponent_ptr, + ::CIAO::Container_ptr, + const char *); + typedef ACE_Hash_Map_Manager_Ex<ACE_CString, + HomeFactory, + ACE_Hash<ACE_CString>, + ACE_Equal_To<ACE_CString>, + ACE_Null_Mutex> + HOMECREATOR_FUNCPTR_MAP; + + typedef ACE_Hash_Map_Manager_Ex<ACE_CString, + HomeServantFactory, + ACE_Hash<ACE_CString>, + ACE_Equal_To<ACE_CString>, + ACE_Null_Mutex> + HOMESERVANTCREATOR_FUNCPTR_MAP; + + + typedef ACE_Hash_Map_Manager_Ex<ACE_CString, + ComponentFactory, + ACE_Hash<ACE_CString>, + ACE_Equal_To<ACE_CString>, + ACE_Null_Mutex> + COMPONENTCREATOR_FUNCPTR_MAP; + + typedef ACE_Hash_Map_Manager_Ex<ACE_CString, + ComponentServantFactory, + ACE_Hash<ACE_CString>, + ACE_Equal_To<ACE_CString>, + ACE_Null_Mutex> + COMPONENTSERVANTCREATOR_FUNCPTR_MAP; + + + struct FT_Session_Container_Export Static_Config_EntryPoints_Maps + { + /// Map of home creator entry point name and func ptr + HOMECREATOR_FUNCPTR_MAP* home_creator_funcptr_map_; + + /// Map of home servant creator entry point name and func ptr + HOMESERVANTCREATOR_FUNCPTR_MAP* home_servant_creator_funcptr_map_; + + /// Map of home creator entry point name and func ptr + COMPONENTCREATOR_FUNCPTR_MAP* component_creator_funcptr_map_; + + /// Map of home servant creator entry point name and func ptr + COMPONENTSERVANTCREATOR_FUNCPTR_MAP* component_servant_creator_funcptr_map_; + }; + + class FT_Session_Container_Export FT_Session_Container : public Container_i + { + public: + FT_Session_Container (CORBA::ORB_ptr o, + Deployment::CIAO_Container_i *container_impl, + bool static_config_flag = false, + const Static_Config_EntryPoints_Maps* static_entrypts_maps =0, + const char *name = 0, + const CORBA::PolicyList *more_policies = 0); + + virtual ~FT_Session_Container (void); + + /** + * @brief Simply installing a home executor into the component. + * + * This operation install a home executor into the component. It + * requires the name of the DLLs to executor and the servant glue + * code, and the entry points to the respective DLLs. Currently, + * we don't try to manage the lifetime of DLL objects, but we + * should at some later point. + * + * @retval Home objref of the installed home. + */ + /// Install a new home + virtual Components::CCMHome_ptr install_home (const char *primary_artifact, + const char *entry_point, + const char *servant_artifact, + const char *servant_entrypoint, + const char *name); + + virtual void uninstall_home (Components::CCMHome_ptr homeref); + + virtual Components::CCMObject_ptr install_component (const char *primary_artifact, + const char *entry_point, + const char *servant_artifact, + const char *servant_entrypoint, + const char *name); + + virtual void activate_component (Components::CCMObject_ptr compref); + + virtual void passivate_component (Components::CCMObject_ptr compref); + + virtual void uninstall_component (Components::CCMObject_ptr compref); + + + /// Uninstall a servant + virtual void uninstall_servant (PortableServer::Servant objref, + Container_Types::OA_Type type, + PortableServer::ObjectId_out oid); + + /// Install a servant for component or home. + virtual CORBA::Object_ptr install_servant (PortableServer::Servant p, + Container_Types::OA_Type type, + PortableServer::ObjectId_out oid); + + /// Install a servant for component or home. + virtual CORBA::Object_ptr install_servant_with_id (PortableServer::Servant p, + Container_Types::OA_Type type, + const PortableServer::ObjectId & oid); + + /// Get an object reference to a component or home from the servant. + virtual CORBA::Object_ptr get_objref (PortableServer::Servant p); + + /// Uninstall a servant for component or home. + void uninstall (CORBA::Object_ptr objref, Container_Types::OA_Type t); + + /// Uninstall a servant for component or home. + void uninstall (PortableServer::Servant svt, Container_Types::OA_Type t); + + virtual void add_servant_to_map (PortableServer::ObjectId &oid, + Dynamic_Component_Servant_Base* servant); + + virtual void delete_servant_from_map (PortableServer::ObjectId &oid); + + // @@Jai, could yo please add documentation? + /* + * @@Jai, you may want to consider moving these away from the + * container interface. I know what you are going to say + * :-). Consider using dynamic_cast <> to access + * add_servant_to_map, delete_servant_from_map and + * deactivate_facet from the Swapping_Conatiner's interface. It + * would make the base container interface much cleaner. + */ + virtual void deactivate_facet (const PortableServer::ObjectId &oid); + + virtual CORBA::Object_ptr get_home_objref (PortableServer::Servant p); + + /// Analog of the POA method that creates an object reference from + /// an object id string. + CORBA::Object_ptr generate_reference (const char *obj_id, + const char *repo_id, + Container_Types::OA_Type t); + + /// Return the servant activator factory that activates the + /// servants for facets and consumers. + ::CIAO::Servant_Activator_ptr ports_servant_activator (void); + + private: + + /// Initialize the container with a name. + virtual void init (const char *name = 0, + const CORBA::PolicyList *more_policies = 0); + + /// Create POA for the component. + /** + * This is the POA that is returned to the component applications + * if they need one. + */ + void create_component_POA (const char *name, + const CORBA::PolicyList *p, + PortableServer::POA_ptr root); + + /// Create POA for the facets and consumers alone. + void create_facet_consumer_POA (const char *name, + const CORBA::PolicyList *p, + PortableServer::POA_ptr root); + + /// Not allowed to be + FT_Session_Container (void); + + protected: + unsigned long number_; + + /// Static variable to store the highest number we have given out until + /// now + static ACE_Atomic_Op <TAO_SYNCH_MUTEX, unsigned long> serial_number_; + + const bool static_config_flag_; + const Static_Config_EntryPoints_Maps* static_entrypts_maps_; + + /// The servant activator factory used to activate facets and + /// consumer servants. + Servant_Activator_var sa_; + }; +} + +#if defined (__ACE_INLINE__) +# include "FT_Session_Container.inl" +#endif /* __ACE_INLINE__ */ + +#include /**/ "ace/post.h" + +#endif /* CIAO_SESSION_CONTAINER_H */ diff --git a/CIAO/ciao/Containers/FTSession/FT_Session_Container.idl b/CIAO/ciao/Containers/FTSession/FT_Session_Container.idl new file mode 100644 index 00000000000..6c37172f4e5 --- /dev/null +++ b/CIAO/ciao/Containers/FTSession/FT_Session_Container.idl @@ -0,0 +1,21 @@ +/** + * @file Session_Container.idl + * @author William R. Otte <wotte@dre.vanderbilt.edu> + * + * Extends the basic container interface for session capabilities. + */ + +#include "ciao/Containers/Container_Base.idl" + +module CIAO +{ + local interface FT_Session_Container : Container + { + // *** Methods used by component specific container portions + /* + Object install_servant_with_id (in PortableServer::Servant svnt, + in Container_Types::OA_Type type, + in PortableServer::ObjectId oid); + */ + }; +}; diff --git a/CIAO/ciao/Containers/FTSession/FT_Session_Container.inl b/CIAO/ciao/Containers/FTSession/FT_Session_Container.inl new file mode 100644 index 00000000000..83d8dafe530 --- /dev/null +++ b/CIAO/ciao/Containers/FTSession/FT_Session_Container.inl @@ -0,0 +1,13 @@ +// $Id$ -*- C++ -*- + +ACE_INLINE CORBA::Object_ptr +CIAO::FT_Session_Container::get_objref (PortableServer::Servant p) +{ + return this->the_POA ()->servant_to_reference (p); +} + +ACE_INLINE CIAO::Servant_Activator_ptr +CIAO::FT_Session_Container::ports_servant_activator (void) +{ + return Servant_Activator::_duplicate(this->sa_.in ()); +} diff --git a/CIAO/ciao/Containers/FTSession/FT_Session_Container.mpc b/CIAO/ciao/Containers/FTSession/FT_Session_Container.mpc new file mode 100644 index 00000000000..d305209c7ae --- /dev/null +++ b/CIAO/ciao/Containers/FTSession/FT_Session_Container.mpc @@ -0,0 +1,22 @@ +// -*- MPC -*- +// $Id$ + +project(CIAO_FT_Session_Container) : ccm_svnt, ciao_lib, ciao_container_base, utils, \ + ccm_componentserver_stub, ciao_servant_activator, ciao_servant { + dynamicflags += FT_SESSION_CONTAINER_BUILD_DLL + idlflags += -Wb,export_include=FT_Session_Container_export.h + idlflags += -Wb,export_macro=FT_Session_Container_Export + libs += LWFT_StateSyncAgent + + IDL_Files { + } + Source_Files { + FT_Session_Container.cpp + } + Inline_Files { + FT_Session_Container.inl + } + Header_Files { + FT_Session_Container.h + } +} diff --git a/CIAO/ciao/Containers/FTSession/FT_Session_Container_export.h b/CIAO/ciao/Containers/FTSession/FT_Session_Container_export.h new file mode 100644 index 00000000000..16f1c128d99 --- /dev/null +++ b/CIAO/ciao/Containers/FTSession/FT_Session_Container_export.h @@ -0,0 +1,58 @@ + +// -*- C++ -*- +// $Id$ +// Definition for Win32 Export directives. +// This file is generated automatically by generate_export_file.pl FT_Session_Container +// ------------------------------ +#ifndef FT_SESSION_CONTAINER_EXPORT_H +#define FT_SESSION_CONTAINER_EXPORT_H + +#include "ace/config-all.h" + +#if defined (ACE_AS_STATIC_LIBS) && !defined (FT_SESSION_CONTAINER_HAS_DLL) +# define FT_SESSION_CONTAINER_HAS_DLL 0 +#endif /* ACE_AS_STATIC_LIBS && FT_SESSION_CONTAINER_HAS_DLL */ + +#if !defined (FT_SESSION_CONTAINER_HAS_DLL) +# define FT_SESSION_CONTAINER_HAS_DLL 1 +#endif /* ! FT_SESSION_CONTAINER_HAS_DLL */ + +#if defined (FT_SESSION_CONTAINER_HAS_DLL) && (FT_SESSION_CONTAINER_HAS_DLL == 1) +# if defined (FT_SESSION_CONTAINER_BUILD_DLL) +# define FT_Session_Container_Export ACE_Proper_Export_Flag +# define FT_SESSION_CONTAINER_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) +# define FT_SESSION_CONTAINER_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# else /* FT_SESSION_CONTAINER_BUILD_DLL */ +# define FT_Session_Container_Export ACE_Proper_Import_Flag +# define FT_SESSION_CONTAINER_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) +# define FT_SESSION_CONTAINER_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# endif /* FT_SESSION_CONTAINER_BUILD_DLL */ +#else /* FT_SESSION_CONTAINER_HAS_DLL == 1 */ +# define FT_Session_Container_Export +# define FT_SESSION_CONTAINER_SINGLETON_DECLARATION(T) +# define FT_SESSION_CONTAINER_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +#endif /* FT_SESSION_CONTAINER_HAS_DLL == 1 */ + +// Set FT_SESSION_CONTAINER_NTRACE = 0 to turn on library specific tracing even if +// tracing is turned off for ACE. +#if !defined (FT_SESSION_CONTAINER_NTRACE) +# if (ACE_NTRACE == 1) +# define FT_SESSION_CONTAINER_NTRACE 1 +# else /* (ACE_NTRACE == 1) */ +# define FT_SESSION_CONTAINER_NTRACE 0 +# endif /* (ACE_NTRACE == 1) */ +#endif /* !FT_SESSION_CONTAINER_NTRACE */ + +#if (FT_SESSION_CONTAINER_NTRACE == 1) +# define FT_SESSION_CONTAINER_TRACE(X) +#else /* (FT_SESSION_CONTAINER_NTRACE == 1) */ +# if !defined (ACE_HAS_TRACE) +# define ACE_HAS_TRACE +# endif /* ACE_HAS_TRACE */ +# define FT_SESSION_CONTAINER_TRACE(X) ACE_TRACE_IMPL(X) +# include "ace/Trace.h" +#endif /* (FT_SESSION_CONTAINER_NTRACE == 1) */ + +#endif /* FT_SESSION_CONTAINER_EXPORT_H */ + +// End of auto generated file. diff --git a/CIAO/ciao/Containers/Generic/ClientContainerInterceptorRegistration_Impl.h b/CIAO/ciao/Containers/Generic/ClientContainerInterceptorRegistration_Impl.h index 3a952337f6e..2b2531e9139 100644 --- a/CIAO/ciao/Containers/Generic/ClientContainerInterceptorRegistration_Impl.h +++ b/CIAO/ciao/Containers/Generic/ClientContainerInterceptorRegistration_Impl.h @@ -12,8 +12,8 @@ #include "ciao/Containers/Generic/Generic_Container_export.h" -#include "ccm/Generic/CCM_ClientContainerInterceptorC.h" -#include "ccm/Generic/CCM_ClientContainerInterceptorRegistrationC.h" +#include "ccm/Extension/CCM_ClientContainerInterceptorC.h" +#include "ccm/Extension/CCM_ClientContainerInterceptorRegistrationC.h" #include "ciao/Containers/Generic/Interceptor_Registration_T.h" namespace CIAO diff --git a/CIAO/ciao/Containers/Generic/Generic_Container.idl b/CIAO/ciao/Containers/Generic/Generic_Container.idl index cf20b14ad9b..07ff8c5c146 100644 --- a/CIAO/ciao/Containers/Generic/Generic_Container.idl +++ b/CIAO/ciao/Containers/Generic/Generic_Container.idl @@ -6,10 +6,10 @@ */ #include "ciao/Containers/Container_Base.idl" -#include "ccm/Generic/CCM_ClientContainerInterceptorRegistration.idl" -#include "ccm/Generic/CCM_ServantContainerInterceptorRegistration.idl" -#include "ccm/Generic/CCM_ServerContainerInterceptorRegistration.idl" -#include "ccm/Generic/CCM_StubContainerInterceptorRegistration.idl" +#include "ccm/Extension/CCM_ClientContainerInterceptorRegistration.idl" +#include "ccm/Extension/CCM_ServantContainerInterceptorRegistration.idl" +#include "ccm/Extension/CCM_ServerContainerInterceptorRegistration.idl" +#include "ccm/Extension/CCM_StubContainerInterceptorRegistration.idl" module CIAO { @@ -33,4 +33,55 @@ module CIAO get_servant_interceptor_registration() raises (Components::CCMException); }; + + local interface InstanceManager + { + readonly attribute string instance_type; + + readonly attribute ::CORBA::StringSeq dependencies; + + void configure (/*in ::Deployment::Properties config*/); + + void install_instance (/*in ::Deployment::DeploymentPlan plan,*/ + in unsigned long instanceRef, + out any instance_reference); + /*raises (Deployment::StartError, + Deployment::InvalidProperty, + Deployment::InvalidNodeExecParameter, + Deployment::InvalidComponentExecParameter);*/ + + + void connect_instance (/*in ::Deployment::DeploymentPlan plan,*/ + in unsigned long connectionRef, + in any provided_reference); + //raises (Deployment::StartError, + // Deployment::InvalidConnection); + + void disconnect_instance (/*in ::Deployment::DeploymentPlan plan,*/ + in unsigned long connectionRef); + //raises (::Deployment::StopError); + + void instance_configured (/*in ::Deployment::DeploymentPlan plan,*/ + in unsigned long instanceRef); + //raises (Deployment::StartError); + + void activate_instance (/*in ::Deployment::DeploymentPlan plan,*/ + in unsigned long instanceRef, + in any instance_re:Dference); + //raises (Deployment::StartError); + + void passivate_instance (/*in ::Deployment::DeploymentPlan plan,*/ + in unsigned long instanceRef, + in any instance_reference); + //raises (Deployment::StopError); + + void remove_instance (/*in ::Deployment::DeploymentPlan plan,*/ + in unsigned long instanceRef, + in any instance_reference); + //raises (::Deployment::StopError); + + /// Instruct the handler to release any resources prior to deallocation. + void close (); + }; + }; diff --git a/CIAO/ciao/Containers/Generic/ServantContainerInterceptorRegistration_Impl.h b/CIAO/ciao/Containers/Generic/ServantContainerInterceptorRegistration_Impl.h index c9f6c7d24be..7620dbb25f5 100644 --- a/CIAO/ciao/Containers/Generic/ServantContainerInterceptorRegistration_Impl.h +++ b/CIAO/ciao/Containers/Generic/ServantContainerInterceptorRegistration_Impl.h @@ -12,8 +12,8 @@ #include "ciao/Containers/Generic/Generic_Container_export.h" -#include "ccm/Generic/CCM_ServantContainerInterceptorC.h" -#include "ccm/Generic/CCM_ServantContainerInterceptorRegistrationC.h" +#include "ccm/Extension/CCM_ServantContainerInterceptorC.h" +#include "ccm/Extension/CCM_ServantContainerInterceptorRegistrationC.h" #include "ciao/Containers/Generic/Interceptor_Registration_T.h" namespace CIAO diff --git a/CIAO/ciao/Containers/Generic/ServerContainerInterceptorRegistration_Impl.h b/CIAO/ciao/Containers/Generic/ServerContainerInterceptorRegistration_Impl.h index c522f9fb6c6..9a9b6aea1d8 100644 --- a/CIAO/ciao/Containers/Generic/ServerContainerInterceptorRegistration_Impl.h +++ b/CIAO/ciao/Containers/Generic/ServerContainerInterceptorRegistration_Impl.h @@ -12,8 +12,8 @@ #include "ciao/Containers/Generic/Generic_Container_export.h" -#include "ccm/Generic/CCM_ServerContainerInterceptorC.h" -#include "ccm/Generic/CCM_ServerContainerInterceptorRegistrationC.h" +#include "ccm/Extension/CCM_ServerContainerInterceptorC.h" +#include "ccm/Extension/CCM_ServerContainerInterceptorRegistrationC.h" #include "ciao/Containers/Generic/Interceptor_Registration_T.h" namespace CIAO diff --git a/CIAO/ciao/Containers/Generic/StubContainerInterceptorRegistration_Impl.h b/CIAO/ciao/Containers/Generic/StubContainerInterceptorRegistration_Impl.h index a79fa574d8b..11ce78b1731 100644 --- a/CIAO/ciao/Containers/Generic/StubContainerInterceptorRegistration_Impl.h +++ b/CIAO/ciao/Containers/Generic/StubContainerInterceptorRegistration_Impl.h @@ -12,8 +12,8 @@ #include "ciao/Containers/Generic/Generic_Container_export.h" -#include "ccm/Generic/CCM_StubContainerInterceptorC.h" -#include "ccm/Generic/CCM_StubContainerInterceptorRegistrationC.h" +#include "ccm/Extension/CCM_StubContainerInterceptorC.h" +#include "ccm/Extension/CCM_StubContainerInterceptorRegistrationC.h" #include "ciao/Containers/Generic/Interceptor_Registration_T.h" namespace CIAO diff --git a/CIAO/ciao/Containers/Swapping/Dynamic_Component_Activator.cpp b/CIAO/ciao/Containers/Swapping/Dynamic_Component_Activator.cpp new file mode 100644 index 00000000000..e25fbe1a9e4 --- /dev/null +++ b/CIAO/ciao/Containers/Swapping/Dynamic_Component_Activator.cpp @@ -0,0 +1,48 @@ +#include "ciao/Containers/Swapping/Dynamic_Component_Activator.h" +#include "ciao/Servants/Swapping/Dynamic_Component_Servant_Base.h" +#include "ciao/Logger/Log_Macros.h" + +ACE_RCSID (ciao, + Dynamic_Component_Activator, + "$Id$") + +#if !defined (__ACE_INLINE__) +# include "Dynamic_Component_Activator.inl" +#endif /* __ACE_INLINE__ */ + +namespace CIAO +{ + Dynamic_Component_Activator::Dynamic_Component_Activator (CORBA::ORB_ptr o) + : orb_ (CORBA::ORB::_duplicate (o)) + { + } + + Dynamic_Component_Activator::~Dynamic_Component_Activator (void) + { + } + + PortableServer::Servant + Dynamic_Component_Activator::incarnate (const PortableServer::ObjectId &oid, + PortableServer::POA_ptr) + { + Dynamic_Component_Servant_Base* servant = 0; + PortableServer::ObjectId new_oid (oid); + + if (this->servant_map_.find (oid, servant) == 0) + { + return servant->create (new_oid); + } + + return 0; + } + + void + Dynamic_Component_Activator::etherealize ( + const PortableServer::ObjectId &, + PortableServer::POA_ptr, + PortableServer::Servant, + CORBA::Boolean, + CORBA::Boolean) + { + } +} diff --git a/CIAO/ciao/Containers/Swapping/Dynamic_Component_Activator.h b/CIAO/ciao/Containers/Swapping/Dynamic_Component_Activator.h new file mode 100644 index 00000000000..8c59e8c8087 --- /dev/null +++ b/CIAO/ciao/Containers/Swapping/Dynamic_Component_Activator.h @@ -0,0 +1,102 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Dynamic_Component_Activator.h + * + * $Id$ + * + * @authors Jaiganesh Balasubramanian <jai@dre.vanderbilt.edu> + * Balachandran Natarajan <bala@dre.vanderbilt.edu> + */ +//============================================================================= + +#ifndef CIAO_DYNAMIC_COMPONENT_ACTIVATOR_H +#define CIAO_DYNAMIC_COMPONENT_ACTIVATOR_H + +#include /**/ "ace/pre.h" + +#include "ciao/Containers/Swapping/Swapping_Container_export.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ace/Hash_Map_Manager_T.h" +#include "tao/PortableServer/Key_Adapters.h" +#include "tao/LocalObject.h" +#include "tao/PortableServer/ServantActivatorC.h" +#include "ccm/CCM_ContainerC.h" +#include "ciao/Logger/Log_Macros.h" + +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable:4250) +#endif /* _MSC_VER */ + +namespace CIAO +{ + + class Dynamic_Component_Servant_Base; + /** + * @class Dynamic_Component_Activator + * + * @brief Activator that is registered with the POA for facet and + * consumer servants. + * + */ + class CIAO_Swapping_Container_Export Dynamic_Component_Activator + : public virtual PortableServer::ServantActivator, + public virtual ::CORBA::LocalObject + { + public: + Dynamic_Component_Activator (CORBA::ORB_ptr o); + + virtual ~Dynamic_Component_Activator (void); + + /// Template methods overridden to get callbacks. + /** + * If you would like to know the details of the following two + * methods, please PortableServer documentation. This is probably + * not the place to document what these mean. + */ + virtual PortableServer::Servant incarnate ( + const PortableServer::ObjectId &oid, + PortableServer::POA_ptr poa); + + virtual void etherealize ( + const PortableServer::ObjectId &oid, + PortableServer::POA_ptr adapter, + PortableServer::Servant servant, + CORBA::Boolean cleanup_in_progress, + CORBA::Boolean remaining_activations); + + void add_servant_to_map (PortableServer::ObjectId &oid, + Dynamic_Component_Servant_Base* servant); + + void delete_servant_from_map (PortableServer::ObjectId &oid); + + private: + /// Pointer to our ORB + CORBA::ORB_var orb_; + + ACE_Hash_Map_Manager_Ex<PortableServer::ObjectId, + Dynamic_Component_Servant_Base *, + TAO_ObjectId_Hash, + ACE_Equal_To<PortableServer::ObjectId>, + TAO_SYNCH_MUTEX> + servant_map_; + }; +} + +#if defined(_MSC_VER) +#pragma warning(pop) +#endif /* _MSC_VER */ + +#if defined (__ACE_INLINE__) +# include "Dynamic_Component_Activator.inl" +#endif /* __ACE_INLINE__ */ + +#include /**/ "ace/post.h" + +#endif /* CIAO_DYNAMIC_COMPONENT_ACTIVATOR_H */ diff --git a/CIAO/ciao/Containers/Swapping/Dynamic_Component_Activator.inl b/CIAO/ciao/Containers/Swapping/Dynamic_Component_Activator.inl new file mode 100644 index 00000000000..c35b7d498b6 --- /dev/null +++ b/CIAO/ciao/Containers/Swapping/Dynamic_Component_Activator.inl @@ -0,0 +1,24 @@ +// $Id$ + +namespace CIAO +{ + ACE_INLINE void + Dynamic_Component_Activator::add_servant_to_map( + PortableServer::ObjectId &oid, + Dynamic_Component_Servant_Base* servant) + { + this->servant_map_.bind (oid, servant); + } + + ACE_INLINE void + Dynamic_Component_Activator::delete_servant_from_map( + PortableServer::ObjectId &oid) + { + Dynamic_Component_Servant_Base* servant = 0; + + if (this->servant_map_.unbind (oid, servant) != 0) + { + CIAO_DEBUG ((LM_DEBUG, "Invalid object reference\n")); + } + } +} diff --git a/CIAO/ciao/Containers/Swapping/Swapping_Container.cpp b/CIAO/ciao/Containers/Swapping/Swapping_Container.cpp new file mode 100644 index 00000000000..5bc8577a2c8 --- /dev/null +++ b/CIAO/ciao/Containers/Swapping/Swapping_Container.cpp @@ -0,0 +1,230 @@ +// $Id$ + +#include "Swapping_Container.h" +#include "ciao/Containers/Servant_Activator.h" +#include "ciao/Containers/Swapping/Dynamic_Component_Activator.h" +#include "ciao/Logger/Log_Macros.h" + +#include "tao/Utils/PolicyList_Destroyer.h" + +#if !defined (__ACE_INLINE__) +# include "Swapping_Container.inl" +#endif /* __ACE_INLINE__ */ + +namespace CIAO +{ + + ACE_Atomic_Op <TAO_SYNCH_MUTEX, unsigned long> + Swapping_Container::serial_number_ (0); + + Swapping_Container::Swapping_Container (CORBA::ORB_ptr o, + Deployment::CIAO_Container_i *container_impl) + : Session_Container (o, container_impl), + number_ (0) + { + } + + Swapping_Container::~Swapping_Container () + { + } + + PortableServer::POA_ptr + Swapping_Container::the_home_servant_POA (void) const + { + return this->home_servant_poa_.in (); + } + + CORBA::Object_ptr + Swapping_Container::get_home_objref (PortableServer::Servant p) + { + return this->the_home_servant_POA ()->servant_to_reference (p); + } + + void + Swapping_Container::deactivate_facet (const PortableServer::ObjectId &) + { + // @todo + // this->the_facet_cons_POA ()->deactivate_object (oid); + } + + void + Swapping_Container::init (const char *name, + const CORBA::PolicyList *more_policies) + { + char buffer[MAXPATHLEN]; + + if (name == 0) + { + this->number_ = ++Swapping_Container::serial_number_; + ACE_OS::sprintf (buffer, + "CIAO::Swapping_Container-%ld", + this->number_); + name = buffer; + } + + CORBA::Object_var poa_object = + this->orb_->resolve_initial_references("RootPOA"); + + if (CORBA::is_nil (poa_object.in ())) + { + CIAO_ERROR ((LM_ERROR, CLINFO + "CIAO::Swapping_Container: Unable to initialize the POA.\n")); + } + + PortableServer::POA_var root_poa = + PortableServer::POA::_narrow (poa_object.in ()); + + this->create_servant_POA (name, more_policies, root_poa.in ()); + + this->create_home_servant_POA ("home servant POA", + more_policies, + root_poa.in ()); + + this->create_connections_POA (root_poa.in ()); + + PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); + + poa_manager->activate (); + } + + void + Swapping_Container::add_servant_to_map ( + PortableServer::ObjectId &oid, + Dynamic_Component_Servant_Base* servant) + { + this->dsa_->add_servant_to_map (oid, servant); + } + + void + Swapping_Container::delete_servant_from_map ( + PortableServer::ObjectId &oid) + { + this->dsa_->delete_servant_from_map (oid); + } + + void + Swapping_Container::create_home_servant_POA ( + const char *name, + const CORBA::PolicyList *p, + PortableServer::POA_ptr root) + { + CORBA::PolicyList policies (0); + + if (p != 0) + { + policies = *p; + } + + PortableServer::POAManager_var poa_manager = root->the_POAManager (); + + this->home_servant_poa_ = + root->create_POA (name, poa_manager.in (), policies); + } + + void + Swapping_Container::create_connections_POA (PortableServer::POA_ptr root) + { + PortableServer::POAManager_var poa_manager = + root->the_POAManager (); + + TAO::Utils::PolicyList_Destroyer policies (3); + policies.length (3); + + policies[0] = + root->create_id_assignment_policy (PortableServer::USER_ID); + + policies[1] = + root->create_request_processing_policy ( + PortableServer::USE_SERVANT_MANAGER); + + + // Servant Retention Policy. + policies[2] = + root->create_servant_retention_policy (PortableServer::RETAIN); + + this->facet_cons_poa_ = + root->create_POA ("facet_consumer_poa", poa_manager.in (), policies); + + ACE_NEW_THROW_EX (this->sa_, + Servant_Activator_i (this->orb_.in ()), + CORBA::NO_MEMORY ()); + + this->facet_cons_poa_->set_servant_manager (this->sa_); + } + + void + Swapping_Container::create_servant_POA (const char *name, + const CORBA::PolicyList *p, + PortableServer::POA_ptr root) + { + // @@ Jai, see how this method more or less does things (like + // setting policies) like create_connections_POA (). Could you + // please refactor them into a seperate method? + CORBA::PolicyList policies (0); + + if (p != 0) + { + policies = *p; + } + + PortableServer::POAManager_var poa_manager = + root->the_POAManager (); + + CORBA::ULong policy_length = policies.length (); + policies.length (policy_length + 1); + policies[policy_length] = + root->create_id_assignment_policy (PortableServer::USER_ID); + + policy_length = policies.length (); + policies.length (policy_length + 1); + policies[policy_length] = + root->create_request_processing_policy ( + PortableServer::USE_SERVANT_MANAGER); + + policy_length = policies.length (); + policies.length (policy_length + 1); + policies[policy_length] = + root->create_servant_retention_policy (PortableServer::RETAIN); + + this->component_poa_ = root->create_POA (name, poa_manager.in (), policies); + + ACE_NEW_THROW_EX (this->dsa_, + Dynamic_Component_Activator (this->orb_.in ()), + CORBA::NO_MEMORY ()); + + this->component_poa_->set_servant_manager (this->dsa_); + } + + void + Swapping_Container::ciao_uninstall_home (Components::CCMHome_ptr homeref) + { + PortableServer::POA_ptr tmp = this->home_servant_poa_.in (); + PortableServer::ObjectId_var oid = + tmp->reference_to_id (homeref); + + tmp->deactivate_object (oid.in ()); + } + + CORBA::Object_ptr + Swapping_Container::install_servant (PortableServer::Servant p, + Container_Types::OA_Type t, + PortableServer::ObjectId_out ) + { + PortableServer::POA_ptr tmp = 0; + + if (t == Container_Types::COMPONENT_t) + { + tmp = this->home_servant_poa_.in (); + } + else + { + tmp = this->facet_cons_poa_.in (); + } + + PortableServer::ObjectId_var oid_var = tmp->activate_object (p); + + CORBA::Object_var objref = tmp->id_to_reference (oid_var.in ()); + + return objref._retn (); + } +} diff --git a/CIAO/ciao/Containers/Swapping/Swapping_Container.h b/CIAO/ciao/Containers/Swapping/Swapping_Container.h new file mode 100644 index 00000000000..988caf8c058 --- /dev/null +++ b/CIAO/ciao/Containers/Swapping/Swapping_Container.h @@ -0,0 +1,115 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Swapping_Container.h + * + * $Id$ + * + * Header file for CIAO's Dynamic Swapping container implementations + * + * @author Jaiganesh Balasubramanian <jai@dre.vanderbilt.edu> + * Balachandran Natarajan <bala@dre.vanderbilt.edu> + */ +//============================================================================= + +#ifndef CIAO_SWAPPING_CONTAINER_H +#define CIAO_SWAPPING_CONTAINER_H + +#include /**/ "ace/pre.h" + +#include "ciao/Containers/Swapping/Swapping_Container_export.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ciao/Containers/Session/Session_Container.h" +#include "tao/PortableServer/Servant_Base.h" +#include "ciao/Containers/Container_Base.h" + +namespace CIAO +{ + class Dynamic_Component_Servant_Base; + class Dynamic_Component_Activator; + + class CIAO_Swapping_Container_Export Swapping_Container : public Session_Container + { + public: + Swapping_Container (CORBA::ORB_ptr o, Deployment::CIAO_Container_i *container_impl); + + virtual ~Swapping_Container (void); + + /// Initialize the container with a name. + virtual void init (const char *name = 0, + const CORBA::PolicyList *more_policies = 0); + + /// Install a servant for component or home. + virtual CORBA::Object_ptr install_servant (PortableServer::Servant p, + Container_Types::OA_Type type, + PortableServer::ObjectId_out oid); + + virtual CORBA::Object_ptr get_objref (PortableServer::Servant p); + + virtual void ciao_uninstall_home (Components::CCMHome_ptr homeref); + + virtual CORBA::Object_ptr get_home_objref (PortableServer::Servant p); + + virtual void add_servant_to_map (PortableServer::ObjectId &oid, + Dynamic_Component_Servant_Base* servant); + + virtual void delete_servant_from_map (PortableServer::ObjectId &oid); + + virtual void deactivate_facet (const PortableServer::ObjectId &oid); + + PortableServer::POA_ptr the_home_servant_POA (void) const; + + private: + /// Create POA for the component. + void create_servant_POA (const char *name, + const CORBA::PolicyList *p, + PortableServer::POA_ptr root); + + void create_home_servant_POA (const char *name, + const CORBA::PolicyList *p, + PortableServer::POA_ptr root); + + void create_connections_POA (PortableServer::POA_ptr root); + + protected: + unsigned long number_; + + /// Static variable to store the highest number we have given out until + /// now + static ACE_Atomic_Op <TAO_SYNCH_MUTEX, unsigned long> serial_number_; + + Dynamic_Component_Activator *dsa_; + }; +} + +// Macro for registration of an OBV factory in the generated +// servant class. Similar to the macro for TAO in +// tao/ValueType/ValueFactory.h but here we take advantage of +// the fact that we have access to the current ORB indirectly +// through the context and container. +// @@Jai, is this macro required here? +#define CIAO_REGISTER_OBV_FACTORY(FACTORY, VALUETYPE) \ + { \ + CORBA::ValueFactory factory = new FACTORY; \ + CORBA::ORB_ptr orb = \ + this->context_->_ciao_the_Container ()->the_ORB (); \ + CORBA::ValueFactory prev_factory = \ + orb->register_value_factory ( \ + VALUETYPE::_tao_obv_static_repository_id (), \ + factory); \ + CORBA::remove_ref (prev_factory); \ + CORBA::add_ref (factory); \ + } + +#if defined (__ACE_INLINE__) +# include "Swapping_Container.inl" +#endif /* __ACE_INLINE__ */ + +#include /**/ "ace/post.h" + +#endif /* CIAO_SWAPPING_CONTAINER_H */ diff --git a/CIAO/ciao/Containers/Swapping/Swapping_Container.inl b/CIAO/ciao/Containers/Swapping/Swapping_Container.inl new file mode 100644 index 00000000000..698eec0324d --- /dev/null +++ b/CIAO/ciao/Containers/Swapping/Swapping_Container.inl @@ -0,0 +1,7 @@ +// $Id$ + +ACE_INLINE CORBA::Object_ptr +CIAO::Swapping_Container::get_objref (PortableServer::Servant p) +{ + return this->the_POA ()->servant_to_reference (p); +} diff --git a/CIAO/ciao/Containers/Swapping/Swapping_Container.mpc b/CIAO/ciao/Containers/Swapping/Swapping_Container.mpc new file mode 100644 index 00000000000..f5313a4e49e --- /dev/null +++ b/CIAO/ciao/Containers/Swapping/Swapping_Container.mpc @@ -0,0 +1,6 @@ +// $Id$ + +project(CIAO_Swapping_Container) : ciao_lib, ciao_container_base, utils, \ + ccm_componentserver_stub, ciao_servant_activator, ciao_session_container { + dynamicflags = SWAPPING_CONTAINER_BUILD_DLL +} diff --git a/CIAO/ciao/Containers/Swapping/Swapping_Container_export.h b/CIAO/ciao/Containers/Swapping/Swapping_Container_export.h new file mode 100644 index 00000000000..e0e25ac317d --- /dev/null +++ b/CIAO/ciao/Containers/Swapping/Swapping_Container_export.h @@ -0,0 +1,58 @@ + +// -*- C++ -*- +// $Id$ +// Definition for Win32 Export directives. +// This file is generated automatically by generate_export_file.pl Swapping_Container +// ------------------------------ +#ifndef SWAPPING_CONTAINER_EXPORT_H +#define SWAPPING_CONTAINER_EXPORT_H + +#include "ace/config-all.h" + +#if defined (ACE_AS_STATIC_LIBS) && !defined (SWAPPING_CONTAINER_HAS_DLL) +# define SWAPPING_CONTAINER_HAS_DLL 0 +#endif /* ACE_AS_STATIC_LIBS && SWAPPING_CONTAINER_HAS_DLL */ + +#if !defined (SWAPPING_CONTAINER_HAS_DLL) +# define SWAPPING_CONTAINER_HAS_DLL 1 +#endif /* ! SWAPPING_CONTAINER_HAS_DLL */ + +#if defined (SWAPPING_CONTAINER_HAS_DLL) && (SWAPPING_CONTAINER_HAS_DLL == 1) +# if defined (SWAPPING_CONTAINER_BUILD_DLL) +# define CIAO_Swapping_Container_Export ACE_Proper_Export_Flag +# define SWAPPING_CONTAINER_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) +# define SWAPPING_CONTAINER_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# else /* SWAPPING_CONTAINER_BUILD_DLL */ +# define CIAO_Swapping_Container_Export ACE_Proper_Import_Flag +# define SWAPPING_CONTAINER_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) +# define SWAPPING_CONTAINER_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# endif /* SWAPPING_CONTAINER_BUILD_DLL */ +#else /* SWAPPING_CONTAINER_HAS_DLL == 1 */ +# define CIAO_Swapping_Container_Export +# define SWAPPING_CONTAINER_SINGLETON_DECLARATION(T) +# define SWAPPING_CONTAINER_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +#endif /* SWAPPING_CONTAINER_HAS_DLL == 1 */ + +// Set SWAPPING_CONTAINER_NTRACE = 0 to turn on library specific tracing even if +// tracing is turned off for ACE. +#if !defined (SWAPPING_CONTAINER_NTRACE) +# if (ACE_NTRACE == 1) +# define SWAPPING_CONTAINER_NTRACE 1 +# else /* (ACE_NTRACE == 1) */ +# define SWAPPING_CONTAINER_NTRACE 0 +# endif /* (ACE_NTRACE == 1) */ +#endif /* !SWAPPING_CONTAINER_NTRACE */ + +#if (SWAPPING_CONTAINER_NTRACE == 1) +# define SWAPPING_CONTAINER_TRACE(X) +#else /* (SWAPPING_CONTAINER_NTRACE == 1) */ +# if !defined (ACE_HAS_TRACE) +# define ACE_HAS_TRACE +# endif /* ACE_HAS_TRACE */ +# define SWAPPING_CONTAINER_TRACE(X) ACE_TRACE_IMPL(X) +# include "ace/Trace.h" +#endif /* (SWAPPING_CONTAINER_NTRACE == 1) */ + +#endif /* SWAPPING_CONTAINER_EXPORT_H */ + +// End of auto generated file. diff --git a/CIAO/ciao/FTComponentServer/CIAO_CS_Client.idl b/CIAO/ciao/FTComponentServer/CIAO_CS_Client.idl new file mode 100644 index 00000000000..883c87450d3 --- /dev/null +++ b/CIAO/ciao/FTComponentServer/CIAO_CS_Client.idl @@ -0,0 +1,35 @@ +/** + * @file CIAO_CS_Client.idl + * @author William R. Otte <wotte@dre.vanderbilt.edu> + * + * A couple CIAO-specific extensions to the component server client + * interfaces. + */ + +#ifndef CIAO_COMPONENTSERVER_IDL_ +#define CIAO_COMPONENTSERVER_IDL_ + +#include <ccm/ComponentServer/CCM_ComponentServer_Client.idl> + +module CIAO +{ + module Deployment + { + interface ServerActivator : ::Components::Deployment::ServerActivator + { + /// Used by spawned component servers to notify the server + /// activator of their object reference and retrieve + /// configuration information. + void component_server_callback (in ::Components::Deployment::ComponentServer serverref, + in string server_UUID, + out ::Components::ConfigValues config); + + void configuration_complete (in string server_UUID); + }; + }; +}; + + +#endif + + diff --git a/CIAO/ciao/FTComponentServer/CIAO_CS_Client_svnt_export.h b/CIAO/ciao/FTComponentServer/CIAO_CS_Client_svnt_export.h new file mode 100644 index 00000000000..32a2ea33fd5 --- /dev/null +++ b/CIAO/ciao/FTComponentServer/CIAO_CS_Client_svnt_export.h @@ -0,0 +1,58 @@ + +// -*- C++ -*- +// $Id$ +// Definition for Win32 Export directives. +// This file is generated automatically by generate_export_file.pl CIAO_CS_Client_svnt +// ------------------------------ +#ifndef CIAO_CS_CLIENT_SVNT_EXPORT_H +#define CIAO_CS_CLIENT_SVNT_EXPORT_H + +#include "ace/config-all.h" + +#if defined (ACE_AS_STATIC_LIBS) && !defined (CIAO_CS_CLIENT_SVNT_HAS_DLL) +# define CIAO_CS_CLIENT_SVNT_HAS_DLL 0 +#endif /* ACE_AS_STATIC_LIBS && CIAO_CS_CLIENT_SVNT_HAS_DLL */ + +#if !defined (CIAO_CS_CLIENT_SVNT_HAS_DLL) +# define CIAO_CS_CLIENT_SVNT_HAS_DLL 1 +#endif /* ! CIAO_CS_CLIENT_SVNT_HAS_DLL */ + +#if defined (CIAO_CS_CLIENT_SVNT_HAS_DLL) && (CIAO_CS_CLIENT_SVNT_HAS_DLL == 1) +# if defined (CIAO_CS_CLIENT_SVNT_BUILD_DLL) +# define CIAO_CS_Client_svnt_Export ACE_Proper_Export_Flag +# define CIAO_CS_CLIENT_SVNT_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) +# define CIAO_CS_CLIENT_SVNT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# else /* CIAO_CS_CLIENT_SVNT_BUILD_DLL */ +# define CIAO_CS_Client_svnt_Export ACE_Proper_Import_Flag +# define CIAO_CS_CLIENT_SVNT_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) +# define CIAO_CS_CLIENT_SVNT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# endif /* CIAO_CS_CLIENT_SVNT_BUILD_DLL */ +#else /* CIAO_CS_CLIENT_SVNT_HAS_DLL == 1 */ +# define CIAO_CS_Client_svnt_Export +# define CIAO_CS_CLIENT_SVNT_SINGLETON_DECLARATION(T) +# define CIAO_CS_CLIENT_SVNT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +#endif /* CIAO_CS_CLIENT_SVNT_HAS_DLL == 1 */ + +// Set CIAO_CS_CLIENT_SVNT_NTRACE = 0 to turn on library specific tracing even if +// tracing is turned off for ACE. +#if !defined (CIAO_CS_CLIENT_SVNT_NTRACE) +# if (ACE_NTRACE == 1) +# define CIAO_CS_CLIENT_SVNT_NTRACE 1 +# else /* (ACE_NTRACE == 1) */ +# define CIAO_CS_CLIENT_SVNT_NTRACE 0 +# endif /* (ACE_NTRACE == 1) */ +#endif /* !CIAO_CS_CLIENT_SVNT_NTRACE */ + +#if (CIAO_CS_CLIENT_SVNT_NTRACE == 1) +# define CIAO_CS_CLIENT_SVNT_TRACE(X) +#else /* (CIAO_CS_CLIENT_SVNT_NTRACE == 1) */ +# if !defined (ACE_HAS_TRACE) +# define ACE_HAS_TRACE +# endif /* ACE_HAS_TRACE */ +# define CIAO_CS_CLIENT_SVNT_TRACE(X) ACE_TRACE_IMPL(X) +# include "ace/Trace.h" +#endif /* (CIAO_CS_CLIENT_SVNT_NTRACE == 1) */ + +#endif /* CIAO_CS_CLIENT_SVNT_EXPORT_H */ + +// End of auto generated file. diff --git a/CIAO/ciao/FTComponentServer/CIAO_ComponentInstallation_Impl.cpp b/CIAO/ciao/FTComponentServer/CIAO_ComponentInstallation_Impl.cpp new file mode 100644 index 00000000000..5492df95404 --- /dev/null +++ b/CIAO/ciao/FTComponentServer/CIAO_ComponentInstallation_Impl.cpp @@ -0,0 +1,120 @@ +// $Id$ + +#include "ComponentInstallation_Impl.h" +#include "DAnCE/Logger/Log_Macros.h" + +using namespace DAnCE; + +ComponentInstallation_Impl::ComponentInstallation_Impl() +{ + DANCE_DEBUG ( (LM_DEBUG, "[%M] ComponentInstallation_Impl::ComponentInstallation_Impl - started\n")); + DANCE_DEBUG ( (LM_DEBUG, "[%M] ComponentInstallation_Impl::ComponentInstallation_Impl - finished\n")); +} + +ComponentInstallation_Impl::~ComponentInstallation_Impl() +{ + DANCE_DEBUG ( (LM_DEBUG, "[%M] ComponentInstallation_Impl::~ComponentInstallation_Impl - started\n")); + DANCE_DEBUG ( (LM_DEBUG, "[%M] ComponentInstallation_Impl::~ComponentInstallation_Impl - finished\n")); +} + +void +ComponentInstallation_Impl::install (const char * implUUID, const char * component_loc) +{ + DANCE_DEBUG ( (LM_DEBUG, "[%M] ComponentInstallation_Impl::install - started\n")); + + DANCE_DEBUG ( (LM_DEBUG, "[%M] ComponentInstallation_Impl::install - implUUID %s, component_loc %s\n", implUUID, component_loc)); + if (0 != this->locations_.find (implUUID)) + { + ACE_CString location = component_loc; + this->locations_.bind (implUUID, location); + } + else + { + // I don't certaint that we should throw exception here + //throw ::Components::Deployment::InstallationFailure(); + } + + DANCE_DEBUG ( (LM_DEBUG, "[%M] ComponentInstallation_Impl::install - finished\n")); +} + + +void +ComponentInstallation_Impl::replace (const char * , const char *) +{ + DANCE_DEBUG ( (LM_DEBUG, "[%M] ComponentInstallation_Impl::replace - started\n")); + DANCE_DEBUG ( (LM_DEBUG, "[%M] ComponentInstallation_Impl::replace - finished\n")); +} + +void +ComponentInstallation_Impl::remove (const char *) +{ + DANCE_DEBUG ( (LM_DEBUG, "[%M] ComponentInstallation_Impl::remove - started\n")); + DANCE_DEBUG ( (LM_DEBUG, "[%M] ComponentInstallation_Impl::remove - finished\n")); +} + +char * +ComponentInstallation_Impl::get_implementation (const char * implUUID) +{ + DANCE_DEBUG ( (LM_DEBUG, "[%M] ComponentInstallation_Impl::get_implementation - started\n")); + + ACE_CString s; + if (0 == this->locations_.find (implUUID, s)) + { + DANCE_DEBUG ( (LM_DEBUG, "[%M] ComponentInstallation_Impl::get_implementation - ComponentInstallation_Impl::get_implementation for UUID %s, location %s\n", implUUID, s.c_str())); + DANCE_DEBUG ( (LM_DEBUG, "[%M] ComponentInstallation_Impl::get_implementation - finished\n")); + return CORBA::string_dup (s.c_str()); + } + else + { + DANCE_ERROR ( (LM_ERROR, "[%M] ComponentInstallation_Impl::get_implementation - cannot find location for specified implementation UUID\n")); + throw ::Components::Deployment::UnknownImplId(); + return 0; + } +} + + +char * +ComponentInstallation_Impl::get_valuetypefactory_location ( + const char * implUUID, + const char * repid +) +{ + DANCE_DEBUG ( (LM_DEBUG, "[%M] ComponentInstallation_Impl::get_valuetypefactory_location - started\n")); + ACE_CString key = ComponentInstallation_Impl::valuefactory_key (implUUID, repid); + ACE_CString s; + if (0 == this->locations_.find (implUUID, s)) + { + DANCE_DEBUG ( (LM_DEBUG, "[%M] ComponentInstallation_Impl::get_valuetypefactory_location - UUID:\"%s\" repid:\"%s\" -> location:\"%s\"\n", implUUID, repid, s.c_str())); + return CORBA::string_dup (s.c_str()); + } + else + { + DANCE_ERROR ( (LM_ERROR, "[%M] ComponentInstallation_Impl::get_valuetypefactory_location - cannot find location for specified implementation UUID and repid.\n")); + throw ::Components::Deployment::InstallationFailure(); + return 0; + } + DANCE_DEBUG ( (LM_DEBUG, "[%M] ComponentInstallation_Impl::get_valuetypefactory_location - finished\n")); + return 0; +} + + +void +ComponentInstallation_Impl::install_valuetypefactory_location ( + const char * implUUID, + const char * repid, + const char * loc +) +{ + ACE_CString key = ComponentInstallation_Impl::valuefactory_key (implUUID, repid); + if (0 != this->locations_.find (key)) + { + ACE_CString location = loc; + this->locations_.bind (implUUID, location); + } + else + { + // I don't certaint that we should throw exception here + //throw ::Components::Deployment::InstallationFailure(); + } +} + diff --git a/CIAO/ciao/FTComponentServer/CIAO_ComponentInstallation_Impl.h b/CIAO/ciao/FTComponentServer/CIAO_ComponentInstallation_Impl.h new file mode 100644 index 00000000000..c291adcb346 --- /dev/null +++ b/CIAO/ciao/FTComponentServer/CIAO_ComponentInstallation_Impl.h @@ -0,0 +1,76 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file CIAO_ComponentInstallation_Impl.h + * + * $Id$ + * + * @Brief Return location of component artifact + * + * @author Erwin Gottlieb <eg@prismtech.com> + */ +//============================================================================= + +#ifndef COMPONENTINSTALLATION_IMPL_H_ +#define COMPONENTINSTALLATION_IMPL_H_ + +#include "ace/Map_Manager.h" +#include "ccm/CCM_ComponentC.h" + +#include "Cdmw/CDMW_DeploymentS.h" +#include "tao/ORB.h" +#include "NodeApplication_Export.h" + +namespace DAnCE + { + + class NodeApplication_Export ComponentInstallation_Impl + : public virtual POA_CdmwDeployment::ComponentInstallation + { + public: + ComponentInstallation_Impl(); + + virtual ~ComponentInstallation_Impl(); + + virtual void install ( + const char * implUUID, + const char * component_loc + ); + + virtual void replace ( + const char * implUUID, + const char * component_loc + ); + + virtual void remove ( + const char * implUUID + ); + + virtual char * get_implementation ( + const char * implUUID + ); + + virtual char * get_valuetypefactory_location ( + const char * implUUID, + const char * repid + ); + + void install_valuetypefactory_location ( + const char * implUUID, + const char * repid, + const char * loc + ); + + private: + typedef ACE_Map_Manager< ACE_CString, ACE_CString, ACE_Null_Mutex > TLocations; + TLocations locations_; + + static ACE_CString valuefactory_key (const char* uuid, const char* repid) + { + return ACE_CString (repid) + "@" + uuid; + }; + }; + +}; +#endif /*COMPONENTINSTALLATION_IMPL_H_*/ diff --git a/CIAO/ciao/FTComponentServer/CIAO_ComponentServer.idl b/CIAO/ciao/FTComponentServer/CIAO_ComponentServer.idl new file mode 100644 index 00000000000..69c1bdc1e00 --- /dev/null +++ b/CIAO/ciao/FTComponentServer/CIAO_ComponentServer.idl @@ -0,0 +1,68 @@ +/** + * @file CIAO_ComponentServer.idl + * @author William R. Otte <wotte@dre.vanderbilt.edu> + * + * $Id$ + * + * A couple CIAO-specific extensions to the component server + * interfaces. + */ + +#ifndef CIAO_COMPONENTSERVER_IDL_ +#define CIAO_COMPONENTSERVER_IDL_ + +#include <ccm/CCM_Object.idl> +#include <ccm/ComponentServer/CCM_ComponentServer.idl> + +module CIAO +{ + module Deployment + { + interface ComponentServer : ::Components::Deployment::ComponentServer + { + oneway void shutdown (); + }; + + exception InvalidComponent + { + }; + + /** + * @interface CIAO_Container + * @brief CIAO specific extensions to the component server interface. + */ + interface Container : Components::Deployment::Container + { + /// Instruct the container to install a component without + /// an explicit home. + ::Components::CCMObject install_component (in ::Components::Deployment::UUID id, + in string entrypt, + in ::Components::ConfigValues config) + raises (::Components::Deployment::UnknownImplId, + ::Components::Deployment::ImplEntryPointNotFound, + ::Components::Deployment::InstallationFailure, + ::Components::Deployment::InvalidConfiguration); + + /// Activate component with specified ID, if no ID provided, + /// activates all components. + void activate_component (in ::Components::CCMObject comp) + raises (InvalidComponent); + + /// Passivate component with specified ID, if no ID provided, + /// passivates all components. + void passivate_component (in ::Components::CCMObject comp) + raises (InvalidComponent); + + /// Instruct the container to remove a component installed + /// without an explicit home. If the component was installed + /// with an explicit home, this operation will fail. + void remove_component (in ::Components::CCMObject cref) + raises (::Components::RemoveFailure); + + /// Returns a sequence of all homeless components. + ::Components::CCMObjectSeq get_components (); + }; + }; +}; + +#endif /* CIAO_COMPONENTSERVER_IDL_ */ diff --git a/CIAO/ciao/FTComponentServer/CIAO_ComponentServer.mpc b/CIAO/ciao/FTComponentServer/CIAO_ComponentServer.mpc new file mode 100644 index 00000000000..62e17d7d7ad --- /dev/null +++ b/CIAO/ciao/FTComponentServer/CIAO_ComponentServer.mpc @@ -0,0 +1,94 @@ +project(CIAO_FTComponentServer_IDL) : ciaoidldefaults, anytypecode { + idlflags += -Wb,stub_export_macro=CIAO_FTComponentServer_stub_Export + idlflags += -Wb,stub_export_include=CIAO_FTComponentServer_stub_export.h + idlflags += -Wb,skel_export_macro=CIAO_FTComponentServer_svnt_Export + idlflags += -Wb,skel_export_include=CIAO_FTComponentServer_svnt_export.h + + custom_only=1 + + IDL_Files { + CIAO_ComponentServer.idl + CIAO_ServerResources.idl + } +} + +project(CIAO_FTCS_Client_IDL) : ciaoidldefaults, anytypecode { + idlflags += -Wb,stub_export_macro=CIAO_FTComponentServer_stub_Export + idlflags += -Wb,stub_export_include=CIAO_FTComponentServer_stub_export.h + idlflags += -Wb,skel_export_macro=CIAO_CS_Client_svnt_Export + idlflags += -Wb,skel_export_include=CIAO_CS_Client_svnt_export.h + + custom_only=1 + + IDL_Files { + CIAO_CS_Client.idl + CIAO_Properties.idl + } +} + +project(CIAO_FTComponentServer_stub) : ccm_componentserver_stub, ciaolib_with_idl, ciao_output, \ + messaging, anytypecode, ciao_lib { + after += CIAO_FTComponentServer_IDL CIAO_FTCS_Client_IDL + dynamicflags = CIAO_FTCOMPONENTSERVER_STUB_BUILD_DLL + + IDL_Files { + } + Source_Files { + CIAO_ComponentServerC.cpp + CIAO_CS_ClientC.cpp + CIAO_ServerResourcesC.cpp + CIAO_PropertiesC.cpp + } + Header_Files { + CIAO_FTComponentServer_stub_export.h + } +} + +project(CIAO_FTCS_Client_svnt) : ccm_svnt, ccm_componentserver_svnt, ciao_ft_componentserver_stub, portableserver, ciao_client, ciao_lib { + dynamicflags = CIAO_CS_CLIENT_SVNT_BUILD_DLL + after += CIAO_FTCS_Client_IDL CIAO_FTComponentServer_stub + + IDL_Files { + } + Source_Files { + CIAO_ServerActivator_Impl.cpp + CIAO_CS_ClientS.cpp + } + Header_Files { + CIAO_ServerActivator_Impl.h + CIAO_CS_ClientS.h + CIAO_CS_Client_svnt_export.h + } +} + +project(CIAO_FTComponentServer_svnt) : ccm_componentserver_svnt, ciao_ft_componentserver_stub, portableserver, ciao_ft_componentserver_configurator, ciao_ft_session_container, naming, ciao_server { + + dynamicflags = CIAO_FTCOMPONENTSERVER_SVNT_BUILD_DLL + + IDL_Files { + } + Source_Files { + CIAO_FTComponentServer_Impl.cpp + CIAO_ComponentServerS.cpp + CIAO_ServerResourcesS.cpp + CIAO_Container_Impl.cpp + Configurator_Factory.cpp + } + Header_Files { + CIAO_FTComponentServer_svnt_export.h + } +} + +project(CIAO_FTComponentServer_exe) : ccm_componentserver_svnt, portableserver, ciao_ft_componentserver_svnt, messaging, anytypecode, ciao_server, ciaoexe, ciao_ft_session_container, pi_server, iorinterceptor {// , rtcorba + exename = ciao_ft_componentserver + libs += CIAO_FT_Basic_Configurator CIAO_Logger LWFT_StateSyncAgent LWFT_ReplicationManager LWFT_Client LWFT_Server + after += CIAO_FT_Basic_Configurator CIAO_Logger + macros += CIAO_BUILD_COMPONENTSERVER_EXE + includes += $(TAO_ROOT)/orbsvcs/orbsvcs/LWFT + + Source_Files { + CIAO_FTComponentServer.cpp + } + IDL_Files { + } +} diff --git a/CIAO/ciao/FTComponentServer/CIAO_Container_Impl.cpp b/CIAO/ciao/FTComponentServer/CIAO_Container_Impl.cpp new file mode 100644 index 00000000000..5a08aaea716 --- /dev/null +++ b/CIAO/ciao/FTComponentServer/CIAO_Container_Impl.cpp @@ -0,0 +1,460 @@ +// $Id$ +#include "CIAO_Container_Impl.h" + +#include "ace/Log_Msg.h" +#include "ccm/CCM_HomeC.h" +#include "ciao/CIAO_common.h" +#include "ciao/Server_init.h" +#include "ciao/Client_init.h" +#include "CIAO_PropertiesC.h" + +namespace CIAO +{ + namespace Deployment + { + // Constructor + CIAO_Container_i::CIAO_Container_i (const Components::ConfigValues &config, + const Static_Config_EntryPoints_Maps *static_entrypts, + const char *name, + const CORBA::PolicyList *policies, + CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa) + : orb_ (CORBA::ORB::_duplicate (orb)), + poa_ (PortableServer::POA::_duplicate (poa)), + config_ (config.length ()), + static_entrypts_maps_ (static_entrypts) + { + CIAO_TRACE("CIAO_Container_i::CIAO_Container_i"); + + for (CORBA::ULong i = 0; i < config.length (); ++i) + { + this->config_[i] = config[i]; + } + + try + { + if (this->static_entrypts_maps_ == 0) + { + CIAO_DEBUG((LM_DEBUG, CLINFO "CIAO_Container_i: creating FT Session container with dynamic linkage\n")); + this->container_ = new CIAO::FT_Session_Container (this->orb_.in (), this, false, + 0, name, policies); + } + else + { + CIAO_DEBUG((LM_DEBUG, CLINFO "CIAO_Container_i: creating FT Session container with static linkage\n")); + this->container_ = new CIAO::FT_Session_Container (this->orb_.in (), this, true, + this->static_entrypts_maps_, + name, policies); + } + } + catch (...) + { + CIAO_ERROR((LM_ERROR, CLINFO "CIAO_Container_i::CIAO_Container_i - " + "Caught exception while allocating container implementation\n")); + throw; + } + } + + + // Destructor + CIAO_Container_i::~CIAO_Container_i (void) + { + CIAO_TRACE("CIAO_Container_i::~CIAO_Container_i"); + } + + ::Components::CCMObject_ptr + CIAO_Container_i::install_component (const char * id, + const char * entrypt, + const ::Components::ConfigValues & config) + { + CIAO_TRACE("CIAO_Container_i::install_component"); + + const char *tmp; + CORBA::String_var name; + + CIAO::Utility::CONFIGVALUE_MAP cm; + CIAO::Utility::build_config_values_map (cm, config); + CORBA::Any val; + + if (cm.find (OBJECT_ID, val) == 0) + { + val >>= tmp; + name = tmp; + CIAO_DEBUG ((LM_TRACE, CLINFO + "CIAO_Container_i::install_component - " + "Found ObjectId %C\n", name.in ())); + } + else + { + CIAO_ERROR ((LM_ERROR, CLINFO + "CIAO_Container_i::install_component - " + "Found no ObjectId property, using component id instead\n")); + name = id; + } + + if (name == 0) + { + CIAO_ERROR ((LM_ERROR, CLINFO "CIAO_Container_i::install_component - " + "No home ID provided\n")); + throw ::Components::Deployment::InvalidConfiguration (); + } + + Components::CCMObject_var comp; + + if (this->component_map_.find (name.in (), comp) == 0) + { + CIAO_ERROR ((LM_ERROR, CLINFO "CIAO_Container_i::install_component - " + "Component with id %C already installed, aborting\n", + name.in ())); + throw Components::CreateFailure (); + } + + if (entrypt == 0) + { + CIAO_ERROR ((LM_ERROR, CLINFO "CIAO_Container_i::install_component - " + "No executor entrypoint found.\n")); + throw ::Components::Deployment::InvalidConfiguration (); + } + + CIAO_DEBUG ((LM_INFO, CLINFO "CIAO_Container_i::install_component - " + "Attempting to install home with id [%C]\n", + name.in ())); + + CIAO_DEBUG ((LM_TRACE, CLINFO + "CIAO_Container_i::install_component - " + "Extracting ConfigValues from sequence of length [%u]\n", + config.length ())); + + CORBA::String_var exec_art, svnt_art, svnt_entry; + + if (cm.find (SVNT_ENTRYPT, val) == 0) + { + val >>= tmp; + svnt_entry = tmp; + CIAO_DEBUG ((LM_TRACE, CLINFO + "CIAO_Container_i::install_component - " + "Found Servant entrypoint %C\n", svnt_entry.in ())); + } + else + { + CIAO_ERROR ((LM_ERROR, CLINFO + "CIAO_Container_i::install_component - " + "Error: No Servant entrypoint porovided, aborting installation\n")); + throw Components::InvalidConfiguration (); + } + + if (cm.find (SVNT_ARTIFACT, val) == 0) + { + val >>= tmp; + svnt_art = tmp; + CIAO_DEBUG ((LM_TRACE, CLINFO + "CIAO_Container_i::install_component - " + "Found Servant artifact %C\n", svnt_art.in ())); + } + else + { + CIAO_ERROR ((LM_ERROR, CLINFO + "CIAO_Container_i::install_component - " + "Error: No Servant artifact porovided, aborting installation\n")); + throw Components::InvalidConfiguration (); + } + + + if (cm.find (EXEC_ARTIFACT, val) == 0) + { + val >>= tmp; + exec_art = tmp; + CIAO_DEBUG ((LM_TRACE, CLINFO + "CIAO_Container_i::install_component - " + "Found executor artifact: %C\n", exec_art.in ())); + } + else + { + CIAO_ERROR ((LM_ERROR, CLINFO + "CIAO_Container_i::install_component - " + "Error: No Executor artifact porovided, aborting installation\n")); + } + + CIAO_DEBUG ((LM_TRACE, CLINFO + "CIAO_Container_i::install_component - " + "Extraction resulted in map of [%u] values\n", cm.current_size ())); + + comp = this->container_->install_component (exec_art, + entrypt, + svnt_art, + svnt_entry, + name.in ()); + + if (this->component_map_.bind (name.in (), + Components::CCMObject::_duplicate (comp.in ())) == -1) + { + CIAO_ERROR ((LM_ERROR, CLINFO + "CIAO_Container_i::install_component - " + "Unable to bind componnet into component map\n")); + } + + + return comp._retn (); + } + + void + CIAO_Container_i::remove_component (::Components::CCMObject_ptr /*cref*/) + { + CIAO_TRACE("CIAO_Container_i::remove_component"); + throw CORBA::NO_IMPLEMENT (); + } + + ::Components::CCMObjectSeq * + CIAO_Container_i::get_components (void) + { + CIAO_TRACE("CIAO_Container_i::get_components"); + throw CORBA::NO_IMPLEMENT (); + return 0; + } + + ::Components::ConfigValues * + CIAO_Container_i::configuration (void) + { + CIAO_TRACE("CIAO_Container_i::configuration"); + throw CORBA::NO_IMPLEMENT (); + return 0; + } + + ::Components::Deployment::ComponentServer_ptr + CIAO_Container_i::get_component_server (void) + { + CIAO_TRACE("CIAO_Container_i::get_component_server"); + throw CORBA::NO_IMPLEMENT (); + return 0; + } + + ::Components::CCMHome_ptr + CIAO_Container_i::install_home (const char * id, + const char * entrypt, + const ::Components::ConfigValues & config) + { + CIAO_TRACE("CIAO_Container_i::install_home"); + + if (id == 0) + { + CIAO_ERROR ((LM_ERROR, CLINFO "CIAO_Container_i::install_home - " + "No home ID provided\n")); + throw ::Components::Deployment::InvalidConfiguration (); + } + + Components::CCMHome_var home; + + if (this->home_map_.find (id, home) == 0) + { + CIAO_ERROR ((LM_ERROR, CLINFO "CIAO_Container_i::install_home - " + "Home with id %C already installed, aborting\n", + id)); + throw Components::CreateFailure (); + } + + if (entrypt == 0) + { + CIAO_ERROR ((LM_ERROR, CLINFO "CIAO_Container_i::install_home - " + "No executor entrypoint found.\n")); + throw ::Components::Deployment::InvalidConfiguration (); + } + + CIAO_DEBUG ((LM_INFO, CLINFO "CIAO_Container_i::install_home - " + "Attempting to install home with id [%C]\n", id)); + + CIAO_DEBUG ((LM_TRACE, CLINFO + "CIAO_Container_i::install_home - " + "Extracting ConfigValues from sequence of length [%u]\n", + config.length ())); + + CIAO::Utility::CONFIGVALUE_MAP cm; + CIAO::Utility::build_config_values_map (cm, config); + CORBA::Any val; + + const char *tmp = 0; + CORBA::String_var exec_art, svnt_art, svnt_entry; + if (cm.find (SVNT_ENTRYPT, val) == 0) + { + val >>= tmp; + svnt_entry = tmp; + CIAO_DEBUG ((LM_TRACE, CLINFO + "CIAO_Container_i::install_home - " + "Found Servant entrypoint %C\n", svnt_entry.in ())); + } + else + { + CIAO_ERROR ((LM_ERROR, CLINFO + "CIAO_Container_i::install_home - " + "Error: No Servant entrypoint porovided, aborting installation\n")); + throw Components::InvalidConfiguration (); + } + + if (cm.find (SVNT_ARTIFACT, val) == 0) + { + val >>= tmp; + svnt_art = tmp; + CIAO_DEBUG ((LM_TRACE, CLINFO + "CIAO_Container_i::install_home - " + "Found Servant artifact %C\n", svnt_art.in ())); + } + else + { + CIAO_ERROR ((LM_ERROR, CLINFO + "CIAO_Container_i::install_home - " + "Error: No Servant artifact porovided, aborting installation\n")); + throw Components::InvalidConfiguration (); + } + + + if (cm.find (EXEC_ARTIFACT, val) == 0) + { + val >>= tmp; + exec_art = tmp; + CIAO_DEBUG ((LM_TRACE, CLINFO + "CIAO_Container_i::install_home - " + "Found executor artifact: %C\n", exec_art.in ())); + } + else + { + CIAO_ERROR ((LM_ERROR, CLINFO + "CIAO_Container_i::install_home - " + "Error: No Executor artifact porovided, aborting installation\n")); + } + + CIAO_DEBUG ((LM_TRACE, CLINFO + "CIAO_Container_i::install_home - " + "Extraction resulted in map of [%u] values\n", cm.current_size ())); + + + // extract config values here... + + //CIAO_DEBUG ((LM_DEBUG, CLINFO "CIAO_Container_i::install_home - ", + //"Executor entrypoint [%C], servant entrypoint [%C], servant library [%C]\n", + //entrypt, svnt_entrypt.in (), svnt_library.in ())); + + home = this->container_->install_home (exec_art, + entrypt, + svnt_art, + svnt_entry, + id); + + if (this->home_map_.bind (id, + Components::CCMHome::_duplicate (home.in ())) == -1) + { + CIAO_ERROR ((LM_ERROR, CLINFO + "CIAO_Container_i::install_home - " + "Unable to bind home into home map\n")); + } + + return home._retn (); + } + + void + CIAO_Container_i::remove_home (::Components::CCMHome_ptr href) + { + CIAO_TRACE("CIAO_Container_i::remove_home"); + + ::Components::CCMHome_var home (href); + + Home_Iterator i = this->home_map_.begin (); + while (!i.done ()) + { + if (i->item ()->_is_equivalent (home.in ())) + { + CIAO_DEBUG ((LM_TRACE, CLINFO "CIAO_Container_i::remove_home - " + "Successfully found matching home\n")); + break; + } + i.advance (); + } + + if (i.done ()) + { + CIAO_ERROR ((LM_ERROR, CLINFO "CIAO_Container_i::remove_home - " + "Unable to find matching home managed by this container, throwing RemoveFailure\n")); + throw Components::RemoveFailure (); + } + + CIAO_DEBUG ((LM_TRACE, CLINFO "CIAO_Container_i::remove_home - " + "Invoking remove on the container impl for home %C.\n", + i->key ().c_str ())); + this->container_->uninstall_home (home.in ()); + CIAO_DEBUG ((LM_INFO, CLINFO "CIAO_Container_i::remove_home - " + "Successfully removed home %C\n", + i->key ().c_str ())); + + if (this->home_map_.unbind (i->key ()) != 0) + { + CIAO_ERROR ((LM_ERROR, CLINFO "CIAO_Container_i::remove_home - " + "Unable to unbind removed home with id %C from home map\n", + i->key ().c_str ())); + } + } + + ::Components::CCMHomes * + CIAO_Container_i::get_homes (void) + { + CIAO_TRACE("CIAO_Container_i::get_homes"); + + ::Components::CCMHomes *tmp_homes = 0; + + ACE_NEW_THROW_EX (tmp_homes, + ::Components::CCMHomes (this->home_map_.current_size ()), + CORBA::NO_MEMORY ()); + + ::Components::CCMHomes_var retval (tmp_homes); + retval->length (this->home_map_.current_size ()); + Home_Iterator i = this->home_map_.begin (); + CORBA::ULong pos = 0; + while (!i.done ()) + { + retval[pos++] = ::Components::CCMHome::_duplicate (i->item ().in ()); + i.advance (); + } + + return retval._retn (); + } + + void + CIAO_Container_i::remove (void) + { + CIAO_TRACE("CIAO_Container_i::remove"); + + if (this->home_map_.current_size () != 0 || + this->component_map_.current_size () != 0) + { + CIAO_ERROR ((LM_WARNING, CLINFO "CIAO_Container_i::remove - " + "Attempting to remove container that still has %u homes and %u components installed\n", + this->home_map_.current_size (), + this->component_map_.current_size ())); + } + + //this->container_->_remove_ref (); + } + + void + CIAO_Container_i::activate_component (::Components::CCMObject_ptr comp) + { + CIAO_TRACE ("CIAO_Container_i::activate_component"); + + this->container_->activate_component (comp); + } + + + void + CIAO_Container_i::passivate_component (::Components::CCMObject_ptr comp) + { + CIAO_TRACE ("CIAO_Container_i::passivate_component"); + + this->container_->passivate_component (comp); + } + + + PortableServer::POA_ptr + CIAO_Container_i::_default_POA (void) + { + CIAO_TRACE ("CIAO_Container_i::_default_POA"); + return PortableServer::POA::_duplicate (this->poa_.in ()); + } + } +} diff --git a/CIAO/ciao/FTComponentServer/CIAO_Container_Impl.h b/CIAO/ciao/FTComponentServer/CIAO_Container_Impl.h new file mode 100644 index 00000000000..87c9977cdb1 --- /dev/null +++ b/CIAO/ciao/FTComponentServer/CIAO_Container_Impl.h @@ -0,0 +1,115 @@ +// $Id$ +/** + * @file CIAO_Container_Impl.h + * @author William R. Otte <wotte@dre.vanderbilt.edu> + */ + +#ifndef CIAO_CONTAINER_H_ +#define CIAO_CONTAINER_H_ + +#include "CIAO_ComponentServerS.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +#pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ciao/Containers/FTSession/FT_Session_Container.h" + +#include "CIAO_FTComponentServer_svnt_export.h" + +namespace CIAO +{ + namespace Deployment + { + /** + * @class CIAO_Container + * @brief Implements external interface for CIAO container. + */ + class CIAO_FTComponentServer_svnt_Export CIAO_Container_i + : public virtual POA_CIAO::Deployment::Container + { + public: + /// Constructor + CIAO_Container_i (const Components::ConfigValues &config, + const Static_Config_EntryPoints_Maps *, + const char *, + const CORBA::PolicyList *, + CORBA::ORB_ptr, + PortableServer::POA_ptr); + + /// Destructor + virtual ~CIAO_Container_i (void); + + virtual ::Components::CCMObject_ptr install_component ( + const char * id, + const char * entrypt, + const ::Components::ConfigValues & config); + + virtual void remove_component (::Components::CCMObject_ptr cref); + + virtual ::Components::CCMObjectSeq * get_components (void); + + virtual ::Components::ConfigValues * configuration (void); + + virtual + ::Components::Deployment::ComponentServer_ptr get_component_server (void); + + virtual ::Components::CCMHome_ptr install_home (const char * id, + const char * entrypt, + const ::Components::ConfigValues & config); + + virtual void remove_home (::Components::CCMHome_ptr href); + + virtual ::Components::CCMHomes * get_homes (void); + + virtual void remove (void); + + virtual void activate_component (::Components::CCMObject_ptr comp); + + virtual void passivate_component (::Components::CCMObject_ptr comp); + + virtual PortableServer::POA_ptr _default_POA (void); + + private: + /// Keep a pointer to the managing ORB serving this servant. + CORBA::ORB_var orb_; + + PortableServer::POA_var poa_; + + CIAO::Container_var container_; + + Components::ConfigValues config_; + + const Static_Config_EntryPoints_Maps* static_entrypts_maps_; + + /// To store all created CCMHome object + typedef ACE_Hash_Map_Manager_Ex<ACE_CString, + Components::CCMHome_var, + ACE_Hash<ACE_CString>, + ACE_Equal_To<ACE_CString>, + ACE_Null_Mutex> CCMHome_Map; + + typedef CCMHome_Map::iterator Home_Iterator; + CCMHome_Map home_map_; + + /// To store all created Component object. + // @@Gan, see how this caching is duplicated.. + typedef ACE_Hash_Map_Manager_Ex<ACE_CString, + Components::CCMObject_var, + ACE_Hash<ACE_CString>, + ACE_Equal_To<ACE_CString>, + ACE_Null_Mutex> CCMComponent_Map; + + typedef CCMComponent_Map::iterator Component_Iterator; + CCMComponent_Map component_map_; + + typedef ACE_Hash_Map_Manager_Ex<ACE_CString, + ACE_CString, + ACE_Hash<ACE_CString>, + ACE_Equal_To<ACE_CString>, + ACE_Null_Mutex> CCMNaming_Map; + CCMNaming_Map naming_map_; + }; + } +} +#endif /* CIAO_CONTAINER_H_ */ diff --git a/CIAO/ciao/FTComponentServer/CIAO_FTComponentServer.cpp b/CIAO/ciao/FTComponentServer/CIAO_FTComponentServer.cpp new file mode 100644 index 00000000000..8dcef805233 --- /dev/null +++ b/CIAO/ciao/FTComponentServer/CIAO_FTComponentServer.cpp @@ -0,0 +1,590 @@ +/** + * @file CIAO_ComponentServer.cpp + * @author William R. Otte + * + * Implementation and main for CIAO_ComponentServer. + */ + +#include "CIAO_FTComponentServer.h" + +#include <sstream> +#include "ace/OS_NS_string.h" +#include "ace/Log_Msg.h" +#include "ace/Get_Opt.h" +#include "ace/Sched_Params.h" +#include "ace/Trace.h" +#include "ace/Env_Value_T.h" +#include "tao/ORB.h" +#include "tao/Object.h" +#include "tao/CORBA_methods.h" +#include "tao/PortableServer/PortableServer.h" +#include "tao/ORB_Core.h" +#include "tao/ORBInitializer_Registry.h" +#include "orbsvcs/orbsvcs/LWFT/StateSynchronizationAgent_i.h" +#include "orbsvcs/orbsvcs/LWFT/LWFT_Server_Init.h" +#include "orbsvcs/orbsvcs/LWFT/LWFT_Client_Init.h" +#include "orbsvcs/orbsvcs/LWFT/AppOptions.h" +#include "orbsvcs/orbsvcs/LWFT/AppSideMonitor_Thread.h" +#include "orbsvcs/orbsvcs/LWFT/ReplicationManagerC.h" +#include "ciao/CIAO_common.h" +#include "ciao/Logger/Logger_Service.h" +#include "ciao/Logger/Log_Macros.h" +#include "ciao/Server_init.h" + +#include "Name_Helper_T.h" +#include "CIAO_FTComponentServer_Impl.h" +#include "CIAO_CS_ClientC.h" +#include "Configurator_Factory.h" +#include "Configurators/Server_Configurator.h" + +#ifdef CIAO_BUILD_COMPONENTSERVER_EXE + +int ACE_TMAIN (int argc, ACE_TCHAR **argv) +{ + // Tracing disabled by default + CIAO_DISABLE_TRACE (); + + CIAO_TRACE ("CIAO_ComponentServer::ACE_TMAIN"); + + try + { + CIAO::Deployment::ComponentServer_Task cs (argc, argv); + cs.run (); + return 0; + } + catch (CIAO::Deployment::ComponentServer_Task::Error &e) + { + CIAO_DEBUG ((LM_ALERT, CLINFO "CIAO_ComponentServer main: Caught ComponentServer exception: %s\n", + e.err_.c_str ())); + } + catch (...) + { + CIAO_DEBUG ((LM_ALERT, CLINFO "CIAO_ComponentServer main: Caught unknown exception.\n")); + } + + return -1; +} + +#endif /* CIAO_BUILD_COMPONENTSERVER_EXE */ + +bool +write_IOR (const char * ior_file_name, const char* ior) +{ + FILE* ior_output_file_ = + ACE_OS::fopen (ior_file_name, "w"); + + if (ior_output_file_) + { + ACE_OS::fprintf (ior_output_file_, + "%s", + ior); + ACE_OS::fclose (ior_output_file_); + return true; + } + return false; +} + +namespace CIAO +{ + namespace Deployment + { + ComponentServer_Task::ComponentServer_Task (int argc, ACE_TCHAR **argv) + : orb_ (0), + uuid_ (""), + callback_ior_str_ ("") + { + CIAO_TRACE ("CIAO_ComponentServer_Task::CIAO_ComponentServer_Task ()"); + + Logger_Service + *clf = ACE_Dynamic_Service<Logger_Service>::instance ("CIAO_Logger_Backend_Factory"); + + if (!clf) + clf = new Logger_Service; + + this->logger_.reset (clf); + + this->logger_->init (argc, argv); + + CIAO_DEBUG ((LM_TRACE, CLINFO "CIAO_ComponentServer_Task::CIAO_ComponentServer_Task - " + "Creating server object\n")); + Configurator_Factory cf; + this->configurator_.reset (cf (argc, argv)); + + if (!this->configurator_->create_config_managers ()) + { + CIAO_ERROR ((LM_ERROR, CLINFO + "ComponentServer_Task::ComponentServer_Task - " + "Error configuring ComponentServer configurator, exiting.\n")); + throw Error ("Unable to load ComponentServer configurator."); + } + + this->configurator_->pre_orb_initialize (); + + LWFT_Client_Init initializer; + + CIAO_DEBUG ((LM_TRACE, CLINFO "CIAO_ComponentServer_Task::CIAO_ComponentServer_Task - " + "Creating ORB\n")); + this->orb_ = initializer.init (argc, argv); + + AppOptions::instance ()->parse_args (argc, argv); + AppOptions::instance ()->process_id (this->get_process_id ()); + AppOptions::instance ()->orb (CORBA::ORB::_duplicate (orb_.in ())); + + CIAO_DEBUG ((LM_TRACE, CLINFO "ComponentServer_Task - " + "starting AppSideMonitor thread.\n")); + + int result = AppSideMonitor_Thread::instance ()->activate ();; + + if (result != 0) + { + CIAO_DEBUG ((LM_ERROR, + CLINFO "CIAO_ComponentServer_Task::CIAO_ComponentServer_Task - " + "AppSideMonitor_Thread::activate () returned %d\n", + result)); + } + + this->configurator_->post_orb_initialize (this->orb_.in ()); + + this->parse_args (argc, argv); + this->configure_logging_backend (); + + CIAO::Server_init (this->orb_.in ()); + + CIAO_DEBUG ((LM_TRACE, CLINFO "CIAO_ComponentServer_Task::CIAO_ComponentServer_Task - " + "CIAO_ComponentServer object created.\n")); + } + + int + ComponentServer_Task::svc (void) + { + try + { + CIAO_TRACE ("ComponentServer_Task::svc"); + + CIAO_DEBUG ((LM_TRACE, CLINFO "ComponentServer_Task::svc - " + "Activating the root POA\n")); + + CORBA::Object_var object = + this->orb_->resolve_initial_references ("RootPOA"); + + PortableServer::POA_var root_poa = + PortableServer::POA::_narrow (object.in ()); + + PortableServer::POAManager_var poa_manager = + root_poa->the_POAManager (); + + poa_manager->activate (); + + CIAO_DEBUG ((LM_TRACE, CLINFO "ComponentServer_Task::svc - " + "Creating state synchronization servant\n")); + + // start up SSA + StateSynchronizationAgent_i* ssa_servant = 0; + ACE_NEW_NORETURN (ssa_servant, StateSynchronizationAgent_i ( + this->get_hostname (), // this has to be replaced by the + this->get_process_id ())); // real hostname and process id + + if (ssa_servant == 0) + { + CIAO_ERROR ((LM_CRITICAL, "ComponentServer_Task::run - " + "Out of memory error while allocating ssa servant.")); + throw Error ("Out of memory whilst allocating ssa servant."); + } + + PortableServer::ServantBase_var safe_ssa (ssa_servant); + + // activate servant here + StateSynchronizationAgent_var ssa (ssa_servant->_this ()); + + Name_Helper_T <StateSynchronizationAgent> nsh (orb_); + nsh.bind (this->get_obj_path () + "/StateSynchronizationAgent", ssa.in ()); + + // register ssa with the replication manager + Name_Helper_T <ReplicationManager> rmh (orb_.in ()); + + ReplicationManager_var rm = rmh.resolve ("ReplicationManager"); + + rm->register_state_synchronization_agent (this->get_hostname ().c_str (), + this->get_process_id ().c_str (), + ssa); + + CIAO_DEBUG ((LM_TRACE, CLINFO "ComponentServer_Task::svc - " + "Creating server implementation object\n")); + CIAO::Deployment::CIAO_ComponentServer_i *ci_srv = 0; + ACE_NEW_NORETURN (ci_srv, CIAO_ComponentServer_i (this->uuid_, this->orb_.in (), root_poa.in ())); + + if (ci_srv == 0) + { + CIAO_ERROR ((LM_CRITICAL, "ComponentServer_Task::run - " + "Out of memory error while allocating servant.")); + throw Error ("Out of memory whilst allocating servant."); + } + + PortableServer::ServantBase_var safe (ci_srv); + + ComponentServer_var cs (ci_srv->_this ()); + + if (this->output_file_ != "") + { + CORBA::String_var ior = this->orb_->object_to_string (cs.in ()); + write_IOR (this->output_file_.c_str (), ior.in ()); + } + + if (this->callback_ior_str_ != "") + { + CIAO_DEBUG ((LM_TRACE, CLINFO " resolving callback IOR\n")); + CORBA::Object_ptr obj = this->orb_->string_to_object (this->callback_ior_str_.c_str ()); + ServerActivator_var sa (ServerActivator::_narrow (obj)); + + if (CORBA::is_nil (sa.in ())) + { + CIAO_DEBUG ((LM_ERROR, CLINFO "ComponentServer_Task::svc - " + "Failed to narrow callback IOR\n")); + throw Error ("Failed to narrow callback IOR"); + } + + Components::ConfigValues_var config; + { + Components::ConfigValues *cf; + ACE_NEW_NORETURN (cf, Components::ConfigValues (0)); + + if (cf == 0) + { + CIAO_ERROR ((LM_CRITICAL, "ComponentServer_Task::run - " + "Out of memory error while allocating config values\n")); + } + else config = cf; + } + + // Make callback. + CIAO_DEBUG ((LM_TRACE, CLINFO "ComponentServer_Task::svc - " + "Making callback on my ServerActivator\n")); + + CIAO_DEBUG ((LM_TRACE, CLINFO "ComponentServer_Task::svc - " + "Calling back to ServerActivator\n")); + + try + { + // Callback to NodeApplication to get configuration + sa->component_server_callback (cs.in (), + this->uuid_.c_str (), + config.out ()); + + CIAO_DEBUG ((LM_TRACE, CLINFO "ComponentServer_Task::svc - " + "Configuration received\n")); + // @@WO: Probably need to do something with these config values. + + ci_srv->init (sa.in (), config._retn ()); + + CIAO_DEBUG ((LM_NOTICE, CLINFO "ComponentServer_Task::svc - " + "Configuration complete for component server %s\n", + this->uuid_.c_str ())); + + sa->configuration_complete (this->uuid_.c_str ()); + } + catch (CORBA::BAD_PARAM &) + { + CIAO_ERROR ((LM_ERROR, CLINFO "ComponentServer_Task::svc - " + "The Callback IOR provided pointed to the wrong ServerActivator\n")); + throw Error ("Bad callback IOR"); + } + catch (...) + { + CIAO_ERROR ((LM_ERROR, CLINFO "ComponentServer_Task::svc - " + "Caught exception while calling back\n")); + throw Error ("Caught exception while calling back"); + } + } + else + { + CIAO_DEBUG ((LM_TRACE, CLINFO "ComponentServer_Task::svc - " + "Initializing ComponentServer without ServantActivator callback\n")); + ci_srv->init (0, 0); + } + + this->orb_->run (); + CIAO_DEBUG ((LM_TRACE, CLINFO "ComponentServer_Task::svc - " + "ORB Event loop completed.\n")); + + root_poa->destroy (1, 1); + + this->orb_->destroy (); + return 0; + } + catch (CORBA::Exception & ex) + { + CIAO_ERROR ((LM_ERROR, CLINFO "ComponentServer_Task::svc - " + "caught: %s.\n", ex._info ().c_str ())); + } + catch (Name_Helper_Exception & ex) + { + CIAO_ERROR ((LM_ERROR, CLINFO "ComponentServer_Task::svc - " + "Name helper exception: %s\n", ex.what ())); + } + + return -1; + } + + void + ComponentServer_Task::run (void) + { + CIAO_TRACE ("ComponentServer_Task::run"); + + if (this->configurator_->rt_support ()) + { + CIAO_DEBUG ((LM_DEBUG, CLINFO "ComponentServer_Task::run - Starting ORB with RT support\n")); + + this->check_supported_priorities (); + + // spawn a thread + // Task activation flags. + long flags = + THR_NEW_LWP | + THR_JOINABLE | + this->orb_->orb_core ()->orb_params ()->thread_creation_flags (); + + // Activate task. + int result = + this->activate (flags); + if (result == -1) + { + if (errno == EPERM) + { + CIAO_ERROR ((LM_EMERGENCY, CLINFO + "ComponentServer_Task::run - Cannot create thread with scheduling policy %s\n" + "because the user does not have the appropriate privileges, terminating program. " + "Check svc.conf options and/or run as root\n", + sched_policy_name (this->orb_->orb_core ()->orb_params ()->ace_sched_policy ()))); + throw Error ("Unable to start RT support due to permissions problem."); + } + else + throw Error ("Unknown error while spawning ORB thread."); + } + + // Wait for task to exit. + result = + this->wait (); + + if (result != -1) + throw Error ("Unknown error waiting for ORB thread to complete"); + + CIAO_DEBUG ((LM_INFO, CLINFO "ComponentServer_Task::run - ORB thread completed, terminating ComponentServer %s\n", + this->uuid_.c_str ())); + } + else + { + CIAO_DEBUG ((LM_DEBUG, CLINFO "ComponentServer_Task::run - Starting ORB without RT support\n")); + this->svc (); + CIAO_DEBUG ((LM_INFO, CLINFO "ComponentServer_Task::run - ORB has shutdown, terminating ComponentServer \n")); + } + } + + void + ComponentServer_Task::parse_args (int argc, ACE_TCHAR **argv) + { + CIAO_TRACE ("ComponentServer_Task::parse_args"); + + CIAO_DEBUG ((LM_TRACE, CLINFO "ComponentServer_Task::parse_args - parsing arguments...\n")); + + ACE_Get_Opt opts (argc, argv, "hu:c:", 1, 0, + ACE_Get_Opt::RETURN_IN_ORDER); + opts.long_option ("uuid", 'u', ACE_Get_Opt::ARG_REQUIRED); + opts.long_option ("callback-ior", 'c', ACE_Get_Opt::ARG_REQUIRED); + opts.long_option ("help", 'h'); + opts.long_option ("log-level",'l', ACE_Get_Opt::ARG_REQUIRED); + opts.long_option ("trace",'t', ACE_Get_Opt::NO_ARG); + opts.long_option ("output-ior",'o', ACE_Get_Opt::ARG_REQUIRED); + + //int j; + char c; + ACE_CString s; + + while ((c = opts ()) != -1) + { + CIAO_DEBUG ((LM_TRACE, CLINFO "ComponentServer_Task::parse_args - " + "Found option: \"%s\" with argument \"%s\"\n", + opts.last_option (), opts.opt_arg ())); + + switch (c) + { + case 'u': + CIAO_DEBUG ((LM_DEBUG, CLINFO "ComponentServer_Task::parse_args - " + "uuid is %s\n", + opts.opt_arg ())); + this->uuid_ = opts.opt_arg (); + break; + + case 'c': + CIAO_DEBUG ((LM_DEBUG, CLINFO "ComponentServer_Task::parse_args - " + "callback ior is %s\n", + opts.opt_arg ())); + this->callback_ior_str_ = opts.opt_arg (); + break; + + case 'l': + { + continue; // no-op, already taken care of + } + + case 't': + continue; // already taken care of + + case 'o': + CIAO_DEBUG ((LM_DEBUG, CLINFO "ComponentServer_Task::parse_args - " + "IOR Output file: %s\n", + opts.opt_arg ())); + this->output_file_ = opts.opt_arg (); + break; + + case 'h': + this->usage (); + throw Error ("Command line help requested, bailing out...."); + + default: + CIAO_ERROR ((LM_ERROR, CLINFO " Unknown option: %s\n", + opts.last_option ())); + this->usage (); + ACE_CString err ("Unknown option "); + err += opts.last_option (); + throw Error (err); + } + } + + // check required options. + if (this->uuid_ == "") + throw Error ("Option required: -u|--uuid"); + if (this->callback_ior_str_ == "") + CIAO_ERROR ((LM_WARNING, CLINFO + "ComponentServer_Task::parse_args - Starting ComponentServer without a callback IOR\n")); + } + + void + ComponentServer_Task::usage (void) + { + CIAO_TRACE ("ComponentServer_Task::usage"); + // Shouldn't be subject to CIAO's logging policy + ACE_ERROR ((LM_EMERGENCY, "Usage: CIAO_ComponentServer <options>\n" + "Options: \n" + "\t-h|--help\t\t\t\tShow help\n" + "\t-l|--log-level <level>\t\t\tSets log level (default 5). 1 - most detailed.\n" + "\t-u|--uuid <uuid> \t\t\tSets UUID of spawned component server (required)\n" + "\t-c|--callback-ior <string ior>\t\tSets callback url for the spawning ServerActivator.\n" + "\t-o|--output-ior <filename>\t\tOutputs the IOR of the component server object to file\n" + )); + + } + + const char * + ComponentServer_Task::sched_policy_name (int sched_policy) + { + const char *name = 0; + + switch (sched_policy) + { + case ACE_SCHED_OTHER: + name = "SCHED_OTHER"; + break; + case ACE_SCHED_RR: + name = "SCHED_RR"; + break; + case ACE_SCHED_FIFO: + name = "SCHED_FIFO"; + break; + } + + return name; + } + + /// The following check is taken from $(TAO_ROOT)/tests/RTCORBA/ + void + ComponentServer_Task::check_supported_priorities (void) + { + CIAO_TRACE ("ComponentServer_Task::check_supported_priorities"); + + int const sched_policy = + this->orb_->orb_core ()->orb_params ()->ace_sched_policy (); + + // Check that we have sufficient priority range to run, + // i.e., more than 1 priority level. + int const max_priority = + ACE_Sched_Params::priority_max (sched_policy); + int const min_priority = + ACE_Sched_Params::priority_min (sched_policy); + + if (max_priority == min_priority) + { + CIAO_DEBUG ((LM_DEBUG, CLINFO "ComponentServer_Task::check_supported_priorities - " + " Not enough priority levels with the %s scheduling policy\n" + "on this platform to run, terminating ....\n" + "Check svc.conf options\n", + sched_policy_name (sched_policy))); + + throw Error ("Bad scheduling policy."); + } + } + + void + ComponentServer_Task::configure_logging_backend (void) + { + Logger_Service + *clf = ACE_Dynamic_Service<Logger_Service>::instance ("CIAO_Logger_Backend_Factory"); + if (clf) + { + CIAO_DEBUG ((LM_TRACE, CLINFO "ComponentServer_Task::configure_logging_backend - " + "Replacing logger backend\n")); + ACE_Log_Msg_Backend * backend = clf->get_logger_backend(this->orb_); + backend->open(0); + ACE_Log_Msg::msg_backend (backend); + ACE_Log_Msg * ace = ACE_Log_Msg::instance(); + ace->clr_flags(ace->flags()); + ace->set_flags(ACE_Log_Msg::CUSTOM); + } + } + + std::string + ComponentServer_Task::get_hostname () + { + char hostname [100]; + gethostname (hostname, sizeof (hostname)); + + return std::string (hostname);; + } + + std::string + ComponentServer_Task::get_process_id () + { + pid_t pid = ACE_OS::getpid (); + std::stringstream ss; + ss << pid; + + return ss.str (); + } + + std::string + ComponentServer_Task::get_obj_path () + { + std::string path; + path += ("FLARe/"); + std::string hostname = this->get_hostname (); + + // replace all dots in the hostname with escaped dots for + //to_name conversion. + for (size_t pos = hostname.find ('.', 0); + pos < hostname.length (); + pos = hostname.find ('.', pos)) + { + hostname.replace (pos, 1, "\\."); + pos += 2; + } + + path += hostname; + path += "/"; + path += this->get_process_id (); + + return path; + } + + } +} + + diff --git a/CIAO/ciao/FTComponentServer/CIAO_FTComponentServer.h b/CIAO/ciao/FTComponentServer/CIAO_FTComponentServer.h new file mode 100644 index 00000000000..24a8ca4f484 --- /dev/null +++ b/CIAO/ciao/FTComponentServer/CIAO_FTComponentServer.h @@ -0,0 +1,78 @@ +/** + * @file CIAO_ComponentServer.h + * @author William R. Otte + * + * Defines interface for the bootstrap element of the CIAO Component + * Server. + */ + +#ifndef CIAO_COMPONENTSERVER_H_ +#define CIAO_COMPONENTSERVER_H_ + +#include "ace/String_Base.h" +#include "ace/Task.h" +#include "tao/ORB.h" +#include "ciao/Logger/Logger_Service.h" +#include "orbsvcs/CosNamingC.h" + +class StateSynchronizationAgent; + +namespace CIAO +{ + namespace Deployment + { + class ComponentServer_Configurator; + + + class ComponentServer_Task : ACE_Task_Base + { + public: + ComponentServer_Task (int argc, ACE_TCHAR **argv); + + int svc (void); + + struct Error + { + Error (const ACE_CString &err) : err_(err) {} + + ACE_CString err_; + }; + + void run (void); + + private: + void parse_args (int argc, ACE_TCHAR **argv); + + void get_log_level (int argc, ACE_TCHAR **argv); + + void set_log_level (void); + + void configure_logging_backend (void); + + void usage (void); + + const char * sched_policy_name (int sched_policy); + + void check_supported_priorities (void); + + /// helper functions for naming service operations + std::string get_hostname (); + + std::string get_process_id (); + + std::string get_obj_path (); + + CORBA::ORB_var orb_; + + auto_ptr<CIAO::Logger_Service> logger_; + + ACE_CString uuid_; + ACE_CString callback_ior_str_; + ACE_CString output_file_; + auto_ptr<ComponentServer_Configurator> configurator_; + + }; + } +} + +#endif diff --git a/CIAO/ciao/FTComponentServer/CIAO_FTComponentServer_Impl.cpp b/CIAO/ciao/FTComponentServer/CIAO_FTComponentServer_Impl.cpp new file mode 100644 index 00000000000..bd0cd957d99 --- /dev/null +++ b/CIAO/ciao/FTComponentServer/CIAO_FTComponentServer_Impl.cpp @@ -0,0 +1,269 @@ +#include "CIAO_FTComponentServer_Impl.h" + +#include "ciao/CIAO_common.h" + +#include "CIAO_CS_ClientC.h" +#include "CIAO_Container_Impl.h" +//#include "tao/RTCORBA/RTCORBA.h" + +const size_t CS_DEFAULT_PRIORITY = 0; + +namespace CIAO +{ + namespace Deployment + { + CIAO_ComponentServer_i::CIAO_ComponentServer_i (const ACE_CString &uuid, + CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa) + : uuid_ (uuid), + orb_ (CORBA::ORB::_duplicate (orb)), + poa_ (PortableServer::POA::_duplicate (poa)), + containers_ () + { + CIAO_TRACE("CIAO_ComponentServer_i::CIAO_ComponentServer_i"); + } + + // Destructor + CIAO_ComponentServer_i::~CIAO_ComponentServer_i (void) + { + CIAO_TRACE("CIAO_ComponentServer_i::~CIAO_ComponentServer_i"); + } + + + void + CIAO_ComponentServer_i::shutdown (void) + { + CIAO_TRACE("CIAO_ComponentServer_i::shutdown"); + + CIAO_DEBUG ((LM_DEBUG, CLINFO "CIAO_ComponentServer_i::shutdown - ORB shutdown request received at %s.\n", + this->uuid_.c_str ())); + + if (!this->containers_.is_empty ()) + CIAO_ERROR ((LM_ERROR, CLINFO "CIAO_ComponentServer_i::shutdown - ComponentServer %s still containers!\n", + this->uuid_.c_str ())); + + this->orb_->shutdown (); + } + + + ::Components::ConfigValues * + CIAO_ComponentServer_i::configuration (void) + { + CIAO_TRACE("CIAO_ComponentServer_i::configuration"); + return this->config_values_.out (); + } + + + ::Components::Deployment::ServerActivator_ptr + CIAO_ComponentServer_i::get_server_activator (void) + { + CIAO_TRACE("CIAO_ComponentServer_i::get_server_activator"); + return this->serv_act_.in (); + } + + + ::Components::Deployment::Container_ptr + CIAO_ComponentServer_i::create_container (const ::Components::ConfigValues & config) + { + CIAO_TRACE("CIAO_ComponentServer_i::create_container"); + + try + { + CIAO_DEBUG ((LM_INFO, CLINFO "CIAO_ComponentServer_i::create_container - Request received with %u config values\n", + config.length ())); + + CORBA::PolicyList policies (0); + + // get RT ORB and set client_propagated priority + /* + CORBA::Object_var obj = orb_->resolve_initial_references ("RTORB"); + RTCORBA::RTORB_var rtorb = RTCORBA::RTORB::_narrow (obj); + + CORBA::PolicyList policies (1); + + if (!CORBA::is_nil (rtorb)) + { + policies.length (1); + policies[0] = RTCORBA::PriorityModelPolicy::_duplicate (rtorb->create_priority_model_policy ( + RTCORBA::CLIENT_PROPAGATED, + CS_DEFAULT_PRIORITY)); + } + */ + const char *name = 0; + + CIAO_Container_i *cont = 0; + ACE_NEW_THROW_EX (cont, + CIAO_Container_i (config, 0, name, &policies, this->orb_.in (), this->poa_.in ()), + CORBA::NO_MEMORY ()); + + CIAO_DEBUG ((LM_DEBUG, CLINFO "CIAO_ComponentServer_i::create_container - " + "Container servant successfully allocated.\n")); + + PortableServer::ServantBase_var safe_config = cont; + CIAO::Deployment::Container_var cont_var = cont->_this (); + + this->containers_.insert (CIAO::Deployment::Container::_duplicate(cont_var.in ())); + + CIAO_DEBUG ((LM_INFO, CLINFO "CIAO_ComponentServer_i::create_container - Container successfully activated and stored," + "now manage %u containers\n", + this->containers_.size ())); + + return cont_var._retn (); + } + catch (CORBA::NO_MEMORY &) + { + CIAO_ERROR ((LM_CRITICAL, CLINFO "CIAO_ComponentServer_Impl: Out of memory exception whilst creating container.\n")); + throw; + } + catch (...) + { + CIAO_ERROR ((LM_ERROR, "CIAO_ComponentServer_Impl: Caught unknown exception\n")); + } + + throw Components::CreateFailure (); + } + + + + void + CIAO_ComponentServer_i::remove_container (::Components::Deployment::Container_ptr cref) + { + CIAO_TRACE("CIAO_ComponentServer_i::remove_container"); + + CIAO_DEBUG ((LM_TRACE, CLINFO "CIAO_ComponentServer_i::remove_container - remove request received.\n")); + + if (CORBA::is_nil (cref)) + { + CIAO_ERROR ((LM_ERROR, CLINFO + "CIAO_ComponentServer_i::remove_container - " + "Error: Received nil container reference\n")); + throw Components::RemoveFailure (); + } + + + if (this->containers_.is_empty ()) + { + CIAO_ERROR ((LM_ERROR, CLINFO + "CIAO_ComponentServer_i::remove_container - " + "Error: I don't manage any containers!\n")); + throw Components::RemoveFailure (); + } + + + try + { + CONTAINERS::ITERATOR i (this->containers_.begin ()); + + // @@ TODO: artifact from when this was a sequence, should probably use .find, + // which will work properly with the new parameterized set class. + for (CONTAINERS::iterator i = this->containers_.begin (); + i.done () != 1; i.advance ()) + { + if (CORBA::is_nil (*i)) + { + ACE_ERROR ((LM_WARNING, CLINFO + "CIAO_ComponentServer_i::remove_container - " + "Managed container reference is nil, skipping.\n")); + continue; + } + + if ((*i)->_is_equivalent (cref)) + { + CIAO_DEBUG ((LM_TRACE, CLINFO "CIAO_ComponentServer_i::remove_container - Found container, invoking remove....\n")); + cref->remove (); + if (this->containers_.remove (*i) != 0) + CIAO_ERROR ((LM_ERROR, CLINFO + "CIAO_ComponentServer_i::remove_container - Unable to remove " + "container reference from internal structure....\n")); + CIAO_DEBUG ((LM_TRACE, CLINFO "CIAO_ComponentServer_i::remove_container - Remove completed, destroying object, " + "now manage %u containers\n", this->containers_.size ())); + return; + } + } + } + catch (CORBA::Exception &ex) + { + CIAO_ERROR ((LM_ERROR, CLINFO "CIAO_ComponentServer_i::remove_container - " + "Caught CORBA exception whilst removing container: %s\n", + ex._info ().c_str ())); + } + + catch (...) + { + CIAO_ERROR ((LM_ERROR, CLINFO "CIAO_ComponentServer_i::remove_container - Error: Unknown exception caught while removing a container.\n")); + } + throw Components::RemoveFailure (); + } + + + ::Components::Deployment::Containers * + CIAO_ComponentServer_i::get_containers (void) + { + CIAO_TRACE("CIAO_ComponentServer_i::get_containers"); + + ::Components::Deployment::Containers *tmp(0); + // tmp = new ::Components::Deployment::Containers (); + ACE_NEW_THROW_EX (tmp, + ::Components::Deployment::Containers (this->containers_.size ()), + CORBA::NO_MEMORY ()); + + ::Components::Deployment::Containers_var retval (tmp); + CORBA::ULong pos (0); + retval->length (this->containers_.size ()); + + for (CONTAINERS::iterator i = this->containers_.begin (); + i.done () != 1; i.advance ()) + { + retval[pos++] = ::CIAO::Deployment::Container::_duplicate (*i); + } + + return retval._retn (); + } + + + void + CIAO_ComponentServer_i::remove (void) + { + CIAO_TRACE("CIAO_ComponentServer_i::remove"); + + bool successful = true; + + for (CONTAINERS::iterator i = this->containers_.begin (); + i.done () != 1; i.advance ()) + { + try + { + (*i)->remove (); + } + catch (CORBA::Exception &ex) + { + successful = false; + CIAO_ERROR ((LM_ERROR, CLINFO + "CIAO_ComponentServer_i::remove - " + "Intercepted CORBA exception while trying to remove a container:%s\n", + ex._info ().c_str ())); + } + catch (...) + { + successful = false; + CIAO_ERROR ((LM_ERROR, CLINFO + "CIAO_ComponentServer_i::remove - " + "Intercepted exception while trying to remove a container\n")); + } + } + + this->containers_.reset (); + + if (!successful) + throw ::Components::RemoveFailure (); + } + + void + CIAO_ComponentServer_i::init (::Components::Deployment::ServerActivator_ptr sa, + Components::ConfigValues *cvs) + { + this->serv_act_ = ::Components::Deployment::ServerActivator::_duplicate(sa); + this->config_values_ = cvs; + } + } +} diff --git a/CIAO/ciao/FTComponentServer/CIAO_FTComponentServer_Impl.h b/CIAO/ciao/FTComponentServer/CIAO_FTComponentServer_Impl.h new file mode 100644 index 00000000000..63ed835a644 --- /dev/null +++ b/CIAO/ciao/FTComponentServer/CIAO_FTComponentServer_Impl.h @@ -0,0 +1,78 @@ +/** + * @file CIAO_ComponentServer.h + * @author William R. Otte <wotte@dre.vanderbilt.edu> + */ + +#ifndef CIAO_COMPONENTSERVER_IMPL_H_ +#define CIAO_COMPONENTSERVER_IMPL_H_ + +#include "ciao/ComponentServer/CIAO_ComponentServerS.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +#pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ace/String_Base.h" +#include "ace/Unbounded_Set_Ex.h" + +namespace CIAO +{ + namespace Deployment + { + class CIAO_ComponentServer_svnt_Export CIAO_ComponentServer_i + : public virtual POA_CIAO::Deployment::ComponentServer + { + public: + // Constructor + CIAO_ComponentServer_i (const ACE_CString &uuid, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa); + + // Destructor + virtual ~CIAO_ComponentServer_i (void); + + virtual void shutdown (void); + + virtual ::Components::ConfigValues * configuration (void); + + virtual + ::Components::Deployment::ServerActivator_ptr get_server_activator (void); + + virtual + ::Components::Deployment::Container_ptr create_container (const ::Components::ConfigValues & config); + + virtual + void remove_container (::Components::Deployment::Container_ptr cref); + + virtual + ::Components::Deployment::Containers * get_containers (void); + + virtual + void remove (void); + + void init (::Components::Deployment::ServerActivator_ptr sa, + Components::ConfigValues *cvs); + + private: + ACE_CString uuid_; + CORBA::ORB_var orb_; + PortableServer::POA_var poa_; + ::Components::Deployment::ServerActivator_var serv_act_; + Components::ConfigValues_var config_values_; + + template<typename T> + struct _is_equivalent + { + bool operator() (const T &a, const T &b) const + { + return a->_is_equivalent (const_cast <T&> (b)); + } + }; + + typedef ACE_Unbounded_Set_Ex <Container_var, + _is_equivalent<Container_var> > CONTAINERS; + + CONTAINERS containers_; + }; + } +} + +#endif diff --git a/CIAO/ciao/FTComponentServer/CIAO_FTComponentServer_stub_export.h b/CIAO/ciao/FTComponentServer/CIAO_FTComponentServer_stub_export.h new file mode 100644 index 00000000000..8f5dddc8c9e --- /dev/null +++ b/CIAO/ciao/FTComponentServer/CIAO_FTComponentServer_stub_export.h @@ -0,0 +1,58 @@ + +// -*- C++ -*- +// $Id$ +// Definition for Win32 Export directives. +// This file is generated automatically by generate_export_file.pl CIAO_FTComponentServer_stub +// ------------------------------ +#ifndef CIAO_FTCOMPONENTSERVER_STUB_EXPORT_H +#define CIAO_FTCOMPONENTSERVER_STUB_EXPORT_H + +#include "ace/config-all.h" + +#if defined (ACE_AS_STATIC_LIBS) && !defined (CIAO_FTCOMPONENTSERVER_STUB_HAS_DLL) +# define CIAO_FTCOMPONENTSERVER_STUB_HAS_DLL 0 +#endif /* ACE_AS_STATIC_LIBS && CIAO_FTCOMPONENTSERVER_STUB_HAS_DLL */ + +#if !defined (CIAO_FTCOMPONENTSERVER_STUB_HAS_DLL) +# define CIAO_FTCOMPONENTSERVER_STUB_HAS_DLL 1 +#endif /* ! CIAO_FTCOMPONENTSERVER_STUB_HAS_DLL */ + +#if defined (CIAO_FTCOMPONENTSERVER_STUB_HAS_DLL) && (CIAO_FTCOMPONENTSERVER_STUB_HAS_DLL == 1) +# if defined (CIAO_FTCOMPONENTSERVER_STUB_BUILD_DLL) +# define CIAO_FTComponentServer_stub_Export ACE_Proper_Export_Flag +# define CIAO_FTCOMPONENTSERVER_STUB_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) +# define CIAO_FTCOMPONENTSERVER_STUB_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# else /* CIAO_FTCOMPONENTSERVER_STUB_BUILD_DLL */ +# define CIAO_FTComponentServer_stub_Export ACE_Proper_Import_Flag +# define CIAO_FTCOMPONENTSERVER_STUB_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) +# define CIAO_FTCOMPONENTSERVER_STUB_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# endif /* CIAO_FTCOMPONENTSERVER_STUB_BUILD_DLL */ +#else /* CIAO_FTCOMPONENTSERVER_STUB_HAS_DLL == 1 */ +# define CIAO_FTComponentServer_stub_Export +# define CIAO_FTCOMPONENTSERVER_STUB_SINGLETON_DECLARATION(T) +# define CIAO_FTCOMPONENTSERVER_STUB_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +#endif /* CIAO_FTCOMPONENTSERVER_STUB_HAS_DLL == 1 */ + +// Set CIAO_FTCOMPONENTSERVER_STUB_NTRACE = 0 to turn on library specific tracing even if +// tracing is turned off for ACE. +#if !defined (CIAO_FTCOMPONENTSERVER_STUB_NTRACE) +# if (ACE_NTRACE == 1) +# define CIAO_FTCOMPONENTSERVER_STUB_NTRACE 1 +# else /* (ACE_NTRACE == 1) */ +# define CIAO_FTCOMPONENTSERVER_STUB_NTRACE 0 +# endif /* (ACE_NTRACE == 1) */ +#endif /* !CIAO_FTCOMPONENTSERVER_STUB_NTRACE */ + +#if (CIAO_FTCOMPONENTSERVER_STUB_NTRACE == 1) +# define CIAO_FTCOMPONENTSERVER_STUB_TRACE(X) +#else /* (CIAO_FTCOMPONENTSERVER_STUB_NTRACE == 1) */ +# if !defined (ACE_HAS_TRACE) +# define ACE_HAS_TRACE +# endif /* ACE_HAS_TRACE */ +# define CIAO_FTCOMPONENTSERVER_STUB_TRACE(X) ACE_TRACE_IMPL(X) +# include "ace/Trace.h" +#endif /* (CIAO_FTCOMPONENTSERVER_STUB_NTRACE == 1) */ + +#endif /* CIAO_FTCOMPONENTSERVER_STUB_EXPORT_H */ + +// End of auto generated file. diff --git a/CIAO/ciao/FTComponentServer/CIAO_FTComponentServer_svnt_export.h b/CIAO/ciao/FTComponentServer/CIAO_FTComponentServer_svnt_export.h new file mode 100644 index 00000000000..ecd2a4ba8e4 --- /dev/null +++ b/CIAO/ciao/FTComponentServer/CIAO_FTComponentServer_svnt_export.h @@ -0,0 +1,58 @@ + +// -*- C++ -*- +// $Id$ +// Definition for Win32 Export directives. +// This file is generated automatically by generate_export_file.pl CIAO_FTComponentServer_svnt +// ------------------------------ +#ifndef CIAO_FTCOMPONENTSERVER_SVNT_EXPORT_H +#define CIAO_FTCOMPONENTSERVER_SVNT_EXPORT_H + +#include "ace/config-all.h" + +#if defined (ACE_AS_STATIC_LIBS) && !defined (CIAO_FTCOMPONENTSERVER_SVNT_HAS_DLL) +# define CIAO_FTCOMPONENTSERVER_SVNT_HAS_DLL 0 +#endif /* ACE_AS_STATIC_LIBS && CIAO_FTCOMPONENTSERVER_SVNT_HAS_DLL */ + +#if !defined (CIAO_FTCOMPONENTSERVER_SVNT_HAS_DLL) +# define CIAO_FTCOMPONENTSERVER_SVNT_HAS_DLL 1 +#endif /* ! CIAO_FTCOMPONENTSERVER_SVNT_HAS_DLL */ + +#if defined (CIAO_FTCOMPONENTSERVER_SVNT_HAS_DLL) && (CIAO_FTCOMPONENTSERVER_SVNT_HAS_DLL == 1) +# if defined (CIAO_FTCOMPONENTSERVER_SVNT_BUILD_DLL) +# define CIAO_FTComponentServer_svnt_Export ACE_Proper_Export_Flag +# define CIAO_FTCOMPONENTSERVER_SVNT_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) +# define CIAO_FTCOMPONENTSERVER_SVNT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# else /* CIAO_FTCOMPONENTSERVER_SVNT_BUILD_DLL */ +# define CIAO_FTComponentServer_svnt_Export ACE_Proper_Import_Flag +# define CIAO_FTCOMPONENTSERVER_SVNT_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) +# define CIAO_FTCOMPONENTSERVER_SVNT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# endif /* CIAO_FTCOMPONENTSERVER_SVNT_BUILD_DLL */ +#else /* CIAO_FTCOMPONENTSERVER_SVNT_HAS_DLL == 1 */ +# define CIAO_FTComponentServer_svnt_Export +# define CIAO_FTCOMPONENTSERVER_SVNT_SINGLETON_DECLARATION(T) +# define CIAO_FTCOMPONENTSERVER_SVNT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +#endif /* CIAO_FTCOMPONENTSERVER_SVNT_HAS_DLL == 1 */ + +// Set CIAO_FTCOMPONENTSERVER_SVNT_NTRACE = 0 to turn on library specific tracing even if +// tracing is turned off for ACE. +#if !defined (CIAO_FTCOMPONENTSERVER_SVNT_NTRACE) +# if (ACE_NTRACE == 1) +# define CIAO_FTCOMPONENTSERVER_SVNT_NTRACE 1 +# else /* (ACE_NTRACE == 1) */ +# define CIAO_FTCOMPONENTSERVER_SVNT_NTRACE 0 +# endif /* (ACE_NTRACE == 1) */ +#endif /* !CIAO_FTCOMPONENTSERVER_SVNT_NTRACE */ + +#if (CIAO_FTCOMPONENTSERVER_SVNT_NTRACE == 1) +# define CIAO_FTCOMPONENTSERVER_SVNT_TRACE(X) +#else /* (CIAO_FTCOMPONENTSERVER_SVNT_NTRACE == 1) */ +# if !defined (ACE_HAS_TRACE) +# define ACE_HAS_TRACE +# endif /* ACE_HAS_TRACE */ +# define CIAO_FTCOMPONENTSERVER_SVNT_TRACE(X) ACE_TRACE_IMPL(X) +# include "ace/Trace.h" +#endif /* (CIAO_FTCOMPONENTSERVER_SVNT_NTRACE == 1) */ + +#endif /* CIAO_FTCOMPONENTSERVER_SVNT_EXPORT_H */ + +// End of auto generated file. diff --git a/CIAO/ciao/FTComponentServer/CIAO_Properties.idl b/CIAO/ciao/FTComponentServer/CIAO_Properties.idl new file mode 100644 index 00000000000..6f0cf0e47e1 --- /dev/null +++ b/CIAO/ciao/FTComponentServer/CIAO_Properties.idl @@ -0,0 +1,29 @@ +/** + * @file CIAO_Properties.idl + * @author William R. Otte + * $Id$ + * Standardizes names of configvalues used by CIAO. + */ + +#ifndef CIAO_PROPERTIES_IDL +#define CIAO_PROPERTIES_IDL + +module CIAO +{ + module Deployment + { + const string SVNT_ENTRYPT = "edu.vanderbilt.dre.CIAO.ServantEntrypoint"; + const string SVNT_ARTIFACT = "edu.vanderbilt.dre.CIAO.ServantArtifact"; + const string EXEC_ARTIFACT = "edu.vanderbilt.dre.CIAO.ExecutorArtifact"; + const string SERVER_RESOURCES = "edu.vanderbilt.dre.CIAO.ServerResources"; + const string SERVER_UUID = "edu.vanderbilt.dre.CIAO.ServerUUID"; + const string SERVER_EXECUTABLE = "edu.vanderbilt.dre.CIAO.ComponentServerExecutable"; + const string SERVER_ARGUMENTS = "edu.vanderbilt.dre.CIAO.ComponentServerArgs"; + const string SERVER_TIMEOUT = "edu.vanderbilt.dre.CIAO.ServerTimeout"; + const string SERVER_MULTITHREAD = "edu.vanderbilt.dre.CIAO.Multithreaded"; + const string REGISTER_NAMING = "edu.vanderbilt.dre.CIAO.RegisterNaming"; + const string OBJECT_ID = "edu.vanderbilt.dre.CIAO.ObjectId"; + + }; +}; +#endif /* CIAO_PROPERTIES_IDL */ diff --git a/CIAO/ciao/FTComponentServer/CIAO_ServerActivator_Impl.cpp b/CIAO/ciao/FTComponentServer/CIAO_ServerActivator_Impl.cpp new file mode 100644 index 00000000000..cb4e5c5a9a0 --- /dev/null +++ b/CIAO/ciao/FTComponentServer/CIAO_ServerActivator_Impl.cpp @@ -0,0 +1,530 @@ +// $Id$ +#include "CIAO_ServerActivator_Impl.h" + +#include "ace/Log_Msg.h" +#include "ace/UUID.h" +#include "ciao/CIAO_common.h" +#include "ciao/Client_init.h" +#include "ciao/CIAO_FailureReasonsC.h" + +#include "CIAO_ServerResourcesC.h" +#include "CIAO_ComponentServerC.h" +#include "CIAO_PropertiesC.h" + +namespace CIAO +{ + namespace Deployment + { + CIAO_ServerActivator_i::CIAO_ServerActivator_i (CORBA::ULong def_spawn_delay, + const char * default_cs_path, + const char * cs_args, + bool multithreaded, + CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa) + : spawn_delay_ (def_spawn_delay), + multithreaded_ (multithreaded), + orb_ (CORBA::ORB::_duplicate (orb)), + poa_ (PortableServer::POA::_duplicate (poa)), + cs_path_ (default_cs_path), + cs_args_ (cs_args), + mutex_ (), + condition_ (mutex_) + { + CIAO_TRACE (CLINFO "CIAO_ServerActivator_i::CIAO_ServerActivator_i"); + } + + CIAO_ServerActivator_i::~CIAO_ServerActivator_i(void) + { + } + + void + CIAO_ServerActivator_i::component_server_callback (::Components::Deployment::ComponentServer_ptr serverref, + const char * server_UUID, + ::Components::ConfigValues_out config) + { + CIAO_TRACE(CLINFO "CIAO_ServerActivator_i::component_server_callback"); + + CIAO_DEBUG ((LM_TRACE, CLINFO + "CIAO_ServerActivator_i::component_server_callback - " + "Received callback from ComponentServer %C\n", + server_UUID)); + + if (this->server_infos_.is_empty ()) + { + CIAO_ERROR ((LM_ERROR, CLINFO + "CIAO_ServerActivator_i::component_server_callback - " + "Received callback from ComponentServer %C, but I don't manage any.\n", + server_UUID)); + throw CORBA::BAD_PARAM (); + } + + //SERVER_INFOS::iterator i (this->server_infos_.begin ()); + //i.first (); + Server_Info *info = 0; + + for (SERVER_INFOS::iterator i (this->server_infos_.begin ()); + !i.done (); ++i) + { + CIAO_DEBUG ((LM_TRACE, CLINFO + "CIAO_ServerActivator_i::component_server_callback - " + "Comparing %C with %C\n", (*i)->uuid_.c_str (), server_UUID)); + if ((*i)->uuid_ == server_UUID) + { + info = (*i).get (); + } + } + + if (info == 0) + { CIAO_ERROR ((LM_WARNING, CLINFO + "CIAO_ServerActivator_i::component_server_callback - " + "Received callback from ComponentServer %C, which doesn't belong to me.\n", + server_UUID)); + throw CORBA::BAD_PARAM (); + } + + if (info->activated_) + { + CIAO_ERROR ((LM_ERROR, CLINFO + "CIAO_ServerActivator_i::component_server_callback - " + "Received callback from ComponentServer %C, which has already been configured.\n", + server_UUID)); + throw CORBA::BAD_INV_ORDER (); + } + + if (!CORBA::is_nil (info->ref_)) + { + CIAO_ERROR ((LM_ERROR, CLINFO + "CIAO_ServerActivator_i::component_server_callback - " + "Received callback from ComponentServer %C, which has already called back.\n", + server_UUID)); + throw CORBA::BAD_INV_ORDER (); + } + + CIAO_DEBUG ((LM_TRACE, CLINFO + "CIAO_ServerActivator_i::component_server_callback - " + "Received callback from ComponentServer %C\n", + server_UUID)); + + info->ref_ = ::Components::Deployment::ComponentServer::_duplicate (serverref); + + this->create_component_server_config_values (*info, config); + + // @@TODO: May want to print out configvalues here. + CIAO_DEBUG ((LM_DEBUG, CLINFO + "CIAO_ServerActivator_i::component_server_callback - " + "Generated %u ConfigValues for ComponentServer %C\n", + config->length (), server_UUID)); + } + + void + CIAO_ServerActivator_i::configuration_complete (const char *server_UUID) + { + CIAO_TRACE (CLINFO "CIAO_ServerActivator_i::configuration_complete"); + + CIAO_DEBUG ((LM_TRACE, CLINFO + "CIAO_ServerActivator_i::configuration_complete - " + "Received configuration_complete from ComponentServer %C\n", + server_UUID)); + + try + { + if (this->server_infos_.is_empty ()) + { + CIAO_ERROR ((LM_ERROR, CLINFO + "CIAO_ServerActivator_i::configuration_complete - " + "Received callback from ComponentServer %C, but I don't manage any.\n", + server_UUID)); + throw CORBA::BAD_PARAM (); + } + + Server_Info *info = 0; + + for (SERVER_INFOS::ITERATOR j (this->server_infos_); + !j.done (); ++j) + { + if ((*j)->uuid_ == server_UUID) + { + info = (*j).get (); + } + } + + if (info == 0) + { + CIAO_ERROR ((LM_WARNING, CLINFO + "CIAO_ServerActivator_i::configuration_complete - " + "Received configuration_complete from ComponentServer %C, which doesn't belong to me.\n", + server_UUID)); + throw CORBA::BAD_PARAM (); + } + + if (info->activated_) + { + CIAO_ERROR ((LM_ERROR, CLINFO + "CIAO_ServerActivator_i::configuration_complete - " + "Received configuration_complete from ComponentServer %C, which has already been completed.\n", + server_UUID)); + throw CORBA::BAD_INV_ORDER (); + } + + if (CORBA::is_nil (info->ref_.in ())) + { + CIAO_ERROR ((LM_ERROR, CLINFO + "CIAO_ServerActivator_i::configuration_complete - " + "Received configuration_complete from ComponentServer %C, which has not called back.\n", + server_UUID)); + throw CORBA::BAD_INV_ORDER (); + } + + info->activated_ = true; + } + catch (...) + { + CIAO_ERROR ((LM_ERROR, CLINFO + "CIAO_ServerActivator_i::configuration_complete - " + "Caught unknown exception while processing configuration_complete\n")); + throw; + } + } + + ::Components::Deployment::ComponentServer_ptr + CIAO_ServerActivator_i::create_component_server (const ::Components::ConfigValues & config) + { + CIAO_TRACE(CLINFO "CIAO_ServerActivator_i::create_component_server"); + + Safe_Server_Info server (new Server_Info (config.length () + 1)); + + CIAO::Utility::build_config_values_map (*server->cmap_, config); + + ACE_CString cmd_options = this->construct_command_line (*server); + + CIAO_DEBUG ((LM_DEBUG, CLINFO + "CIAO_ServerActivator_i::create_component_server - ComponentServer arguments: %C\n", + cmd_options.c_str ())); + + server_infos_.insert_tail (server); + + CIAO_DEBUG ((LM_TRACE, CLINFO + "CIAO_ServerActivator_i::create_component_server - " + "Attempting to spawn ComponentServer with UUID %C\n", + server->uuid_.c_str ())); + // Now we need to get a copy of the one that was inserted... + pid_t pid = this->spawn_component_server (*server, cmd_options); + ACE_UNUSED_ARG (pid); + + ACE_Time_Value timeout (this->spawn_delay_); + + CORBA::Any val; + + if (server->cmap_->find (SERVER_TIMEOUT, val) == 0) + { + CORBA::ULong t; + if (val >>= t) + { + CIAO_DEBUG ((LM_DEBUG, CLINFO "CIAO_ServerActivator_i::create_component_server - " + "Using provided non-default server timeout of %u\n", t)); + timeout = ACE_Time_Value (t); + } + else + { + CIAO_ERROR ((LM_WARNING, CLINFO "CIAO_ServerActivator_i::create_component_server - " + "Failed to extract provided non-default server timeout from property '%C', " + "falling back to default timeout of %u\n", + this->spawn_delay_)); + } + } + + if (this->multithreaded_) + this->multi_threaded_wait_for_callback (*server, timeout/*, pid*/); + else + this->single_threaded_wait_for_callback (*server, timeout/*, pid*/); + + CIAO_DEBUG ((LM_DEBUG, CLINFO + "CIAO_ServerActivator_i::create_component_server - " + "ComponentServer %C successfully spawned and configured!\n", + server->uuid_.c_str ())); + + return ::Components::Deployment::ComponentServer::_duplicate (server->ref_.in ()); + } + + ACE_CString + CIAO_ServerActivator_i::construct_command_line (Server_Info &server) + { + CIAO_TRACE (CLINFO "CIAO_ServerActivator_i::construct_command_line"); + // Build our command line to launch the compoent server + ACE_CString cmd_options (this->cs_args_); + + CORBA::Any val; + + if (server.cmap_->find (SERVER_UUID, val) == 0) + { + // Nodeapplication has requested a custom uuid + CIAO_DEBUG ((LM_TRACE, CLINFO + "CIAO_ServerActivator_i::construct_command_line - Using provided UUID\n")); + const char *uuid = 0; + val >>= uuid; + server.uuid_ = uuid; + } + else + { + CIAO_DEBUG ((LM_TRACE, CLINFO + "CIAO_ServerActivator_i::construct_command_line - Using generated UUID\n")); + ACE_Utils::UUID uuid; + ACE_Utils::UUID_GENERATOR::instance ()->generate_UUID (uuid); + server.uuid_ = *uuid.to_string (); + } + + CIAO_DEBUG ((LM_DEBUG, CLINFO + "CIAO_ServerActivator_i::construct_command_line - Creating component server " + " with UUID %C\n", server.uuid_.c_str ())); + + cmd_options += " -u "; + cmd_options += server.uuid_; + + if (server.cmap_->find (SERVER_RESOURCES, val) == 0) + { + // There may be command line arguments specified in the plan + ServerResource_var sr; + val >>= sr; + + // If command line options are specified through RTCCM descriptors, + // then we should honor these command line options as well. + for (CORBA::ULong arg_i = 0; + arg_i < sr->args.length (); + ++arg_i) + { + CIAO_DEBUG ((LM_TRACE, CLINFO + "CIAO_ServerActivator_i::construct_command_line - Adding argument %C from ServerResource\n ", + sr->args[arg_i].in ())); + cmd_options += " "; // space between command line args + cmd_options += sr->args[arg_i]; + } + + // If service configuration file is specified through RTCCM + // descriptors, then we should honor it as well. + if (ACE_OS::strcmp (sr->svcconf.in (), + "") != 0) + { + CIAO_DEBUG ((LM_TRACE, CLINFO + "CIAO_ServerActivator_i::construct_command_line - Using SvcConf file %C\n ", + sr->svcconf.in ())); + cmd_options += " -ORBSvcConf "; + cmd_options += sr->svcconf; + } + } + + return cmd_options; + } + + pid_t + CIAO_ServerActivator_i::spawn_component_server (const Server_Info &si, + const ACE_CString &cmd_line) + { + CIAO_TRACE ("CIAO_ServerActivator_i::spawn_component_server"); + + ACE_Process_Options options; + + // Get my object reference + CORBA::Object_var obj = this->poa_->servant_to_reference (this); + CORBA::String_var ior = this->orb_->object_to_string (obj.in ()); + CORBA::Any val; + + const char *path = this->cs_path_.c_str (); + + if (si.cmap_->find (SERVER_EXECUTABLE, val) == 0) + { + val >>= path; + CIAO_DEBUG ((LM_DEBUG, CLINFO "CIAO_ServerActivator_i::spawn_component_server - " + "Using provided component server executable:%C\n", path)); + } + else + { + CIAO_DEBUG ((LM_DEBUG, CLINFO "CIAO_ServerActivator_i::spawn_component_server - " + "Using default component server execuable\n")); + } + + options.command_line ("%s %s -c %s", + path, + cmd_line.c_str (), + ior.in ()); + + options.avoid_zombies (0); + + CIAO_DEBUG ((LM_TRACE, CLINFO + "CIAO_ServerActivator_i::spawn_component_server - Spawning process, command line is %C\n", + options.command_line_buf ())); + + pid_t const pid = this->process_manager_.spawn (options, + &this->child_handler_); + + if (pid == ACE_INVALID_PID) + { + CIAO_ERROR ((LM_ERROR, CLINFO + "Failed to spawn a ComponentServer process\n")); + throw Components::CreateFailure (CIAO::SERVER_SPAWN_FAILURE); + } + + CIAO_DEBUG ((LM_TRACE, CLINFO + "CIAO_ServerActivator_i::spawn_component_server - Process successfully spawned with pid %u\n", + pid)); + return pid; + } + + void + CIAO_ServerActivator_i:: + single_threaded_wait_for_callback (const Server_Info &si, + ACE_Time_Value &timeout) + { + CIAO_TRACE (CLINFO "CIAO_ServerActivator_i::single_threaded_wait_for_callback"); + // Below code is broken for thread-per-connection concurrency model, + // since the main thread is running ORB event loop and will spawn + // a different thread to handle the call <register_node_application>, + // the <perform_work> operation will not be invoked and finally + // a timeout will occur. For a similar reason, it won't work + // for thread-pool concurrency model. + while (true) + { + this->orb_->perform_work (timeout); + + if (timeout == ACE_Time_Value::zero) + { + CIAO_ERROR ((LM_ERROR, CLINFO + "CIAO_ServerActivator_i::single_threaded_wait_for_callback - " + "Timed out while waiting for ComponentServer %C to call back.\n", + si.uuid_.c_str ())); + throw ::Components::CreateFailure (CIAO::CALLBACK_TIMEOUT_EXCEEDED); + } + + if (si.activated_) + { + break; + } + } + } + + void + CIAO_ServerActivator_i:: + multi_threaded_wait_for_callback (const Server_Info &si, + ACE_Time_Value &timeout) + { + CIAO_TRACE (CLINFO "CIAO_ServerActivator_i::multi_threaded_wait_for_callback"); + + // Wait for a conditional variable + ACE_GUARD_THROW_EX ( ACE_SYNCH_MUTEX, + guard, + this->mutex_, + CORBA::NO_RESOURCES ()); + + while (! si.activated_ ) + if (this->condition_.wait (&timeout) == -1) + { + CIAO_ERROR ((LM_ERROR, CLINFO + "CIAO_ServerActivator_i::multi_threaded_wait_for_callback - " + "Timed out while waiting for ComponentServer %C to call back.\n", + si.uuid_.c_str ())); + throw Components::CreateFailure (CIAO::CALLBACK_TIMEOUT_EXCEEDED); + } + } + + void + CIAO_ServerActivator_i::remove_component_server (::Components::Deployment::ComponentServer_ptr server) + { + CIAO_TRACE(CLINFO "CIAO_ServerActivator_i::remove_component_server"); + + if (this->server_infos_.is_empty ()) + { + CIAO_ERROR ((LM_ERROR, CLINFO + "CIAO_ServerActivator_i::remove_component_server - " + "I don't manage any ComponentServers.\n")); + throw CORBA::BAD_PARAM (); + } + + Server_Info *info = 0; + + for (SERVER_INFOS::ITERATOR i (this->server_infos_); + !i.done (); ++i) + { + if ((*i)->ref_->_is_equivalent (server)) + { + info = (*i).get (); + } + } + + if (info == 0) + { + CIAO_ERROR ((LM_ERROR, CLINFO + "CIAO_ServerActivator_i::remove_component_server - " + "Failed to find equivalent ComponentServer under my management.\n")); + throw ::Components::RemoveFailure (); + } + + try + { + CIAO_DEBUG ((LM_TRACE, CLINFO + "CIAO_ServerActivator_i::remove_component_server - " + "Calling remove () on ComponentServer %C\n", + info->uuid_.c_str ())); + server->remove (); + } + catch (::Components::RemoveFailure &) + { + CIAO_ERROR ((LM_WARNING, CLINFO + "CIAO_ServerActivator_i::remove_component_server - " + "Received RemoveFailure exception from ComponentServer %C\n", + info->uuid_.c_str ())); + } + + // If this is a CIAO component server, call shutdown + CIAO::Deployment::ComponentServer_var ccs = + CIAO::Deployment::ComponentServer::_narrow (server); + if (!CORBA::is_nil (ccs)) + { + CIAO_DEBUG ((LM_TRACE, CLINFO + "CIAO_ServerActivator_i::remove_component_server - " + "Calling shutdown () on ComponentServer %C\n", + info->uuid_.c_str ())); + ccs->shutdown (); + } + else + CIAO_DEBUG ((LM_TRACE, CLINFO + "CIAO_ServerActivator_i::remove_component_server - " + "ComponentServer %C is not a CIAO_ComponentServer, not calling shutdown.\n", + info->uuid_.c_str ())); + + CIAO_DEBUG ((LM_INFO, CLINFO + "CIAO_ServerActivator_i::remove_component_server - " + "ComponentServer %C successfully shut down.\n", + info->uuid_.c_str ())); + } + + ::Components::Deployment::ComponentServers * + CIAO_ServerActivator_i::get_component_servers (void) + { + CIAO_TRACE(CLINFO "CIAO_ServerActivator_i::get_component_servers"); + + ::Components::Deployment::ComponentServers_var retval = new + Components::Deployment::ComponentServers (this->server_infos_.size ()); + + CORBA::ULong pos = 0; + + for (SERVER_INFOS::ITERATOR i (this->server_infos_); + !i.done (); ++i) + { + retval[pos++] = + ::Components::Deployment::ComponentServer::_duplicate ((*i)->ref_); + } + + return retval._retn (); + } + + void + CIAO_ServerActivator_i::create_component_server_config_values ( + const Server_Info &, + Components::ConfigValues_out &config) + { + ACE_NEW_THROW_EX (config, + Components::ConfigValues (0), + CORBA::NO_MEMORY ()); + } + } +} + diff --git a/CIAO/ciao/FTComponentServer/CIAO_ServerActivator_Impl.h b/CIAO/ciao/FTComponentServer/CIAO_ServerActivator_Impl.h new file mode 100644 index 00000000000..83a41b813ff --- /dev/null +++ b/CIAO/ciao/FTComponentServer/CIAO_ServerActivator_Impl.h @@ -0,0 +1,194 @@ +// $Id$ +/** + * @file CIAO_ServerActivator.h + * @author William R. Otte + */ + +#ifndef CIAO_SERVERACTIVATOR_H_ +#define CIAO_SERVERACTIVATOR_H_ + +#include "ace/Process_Manager.h" +#include "ace/Event_Handler.h" +#include "ace/Condition_T.h" +#include "ace/OS_NS_sys_wait.h" +#include "ace/Refcounted_Auto_Ptr.h" +#include "ace/Unbounded_Set_Ex.h" +#include "ace/Synch_Traits.h" +#include "tao/PortableServer/PortableServer.h" +#include "tao/orbconf.h" +#include "ciao/Client_init.h" +#include "ciao/FTComponentServer/CIAO_CS_ClientS.h" +#include "ciao/FTComponentServer/CIAO_ComponentServerC.h" +#include "ciao/FTComponentServer/CIAO_CS_Client_svnt_export.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +#pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +namespace CIAO +{ + namespace Deployment + { + //namespace + //{ + /** + * @class Child_Handler + * @brief The signal handler class for the SIGCHLD handling to avoid + * zombies + */ + class Child_Handler : public virtual ACE_Event_Handler + { + public: + virtual int handle_signal (int, + siginfo_t *, + ucontext_t *) + { + // @@ Note that this code is not portable to all OS platforms + // since it uses print statements within signal handler context. + ACE_exitcode status; + // makes a claal to the underlying os system call + // -1 to wait for any child process + // and WNOHANG so that it retuurns immediately + ACE_OS::waitpid (-1 ,&status, WNOHANG, 0); + + return 0; + } + }; + // } + + + /** + * @author William R. Otte <wotte@dre.vanderbilt.edu> + * @brief Default server activator for CIAO component servers. + * + * Implements the default component server activation strategy + * which is to spawn new processes. This is not thread-safe, + * nor is it intended to be. Containers are reated serially, + * so there will be only one actor *modifying* data at a particular + * point in time. + */ + class CIAO_CS_Client_svnt_Export CIAO_ServerActivator_i + : public virtual POA_CIAO::Deployment::ServerActivator + { + public: + // Constructor + CIAO_ServerActivator_i (CORBA::ULong def_spawn_delay, + const char * default_cs_path, + const char * cs_args, + bool multithreaded, + CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa_); + + + // Destructor + virtual ~CIAO_ServerActivator_i (void); + + virtual + void component_server_callback ( + ::Components::Deployment::ComponentServer_ptr serverref, + const char * server_UUID, + ::Components::ConfigValues_out config); + + virtual void configuration_complete (const char *server_UUID); + + virtual + ::Components::Deployment::ComponentServer_ptr + create_component_server (const ::Components::ConfigValues & config); + + virtual + void remove_component_server ( + ::Components::Deployment::ComponentServer_ptr server); + + virtual + ::Components::Deployment::ComponentServers * get_component_servers (void); + + private: + struct Server_Info; + + /// Builds command line options based on configuration information. + /// May modify the uuid of the component server. + ACE_CString construct_command_line (Server_Info &si); + + /// Spawns the component server process, but does not wait for it + /// to call back. + pid_t spawn_component_server (const Server_Info &si, + const ACE_CString &cmd_line); + + /// This method is only applicable when our program is configured as + /// singled threaded . Internally it uses a <perform_work> blocking + /// call to wait for NA object to call back + void single_threaded_wait_for_callback (const Server_Info &si, + ACE_Time_Value &timeout); + + /// This method is only applicable when our program is configured as + /// multiple threaded. Internally it waits on a conditional variable + /// that could be modified by the callback servant which runs in + /// another thread + void multi_threaded_wait_for_callback (const Server_Info &si, + ACE_Time_Value &timeout); + + void create_component_server_config_values (const Server_Info &info, + Components::ConfigValues_out &config); + + struct Server_Info + { + Server_Info (size_t cmap_size_hint = 128) + : cmap_ (new CIAO::Utility::CONFIGVALUE_MAP (cmap_size_hint)), + ref_ (Components::Deployment::ComponentServer::_nil ()), + pid_ (ACE_INVALID_PID), + activated_ (false) {} + + typedef ACE_Refcounted_Auto_Ptr <CIAO::Utility::CONFIGVALUE_MAP, + ACE_Null_Mutex> CONFIGVALUE_MAP_PTR; + + ACE_CString uuid_; + CONFIGVALUE_MAP_PTR cmap_; + Components::Deployment::ComponentServer_var ref_; + pid_t pid_; + bool activated_; + }; + + typedef ACE_Refcounted_Auto_Ptr<Server_Info, ACE_Null_Mutex> Safe_Server_Info; + + struct _server_info + { + bool operator() (const Safe_Server_Info &a, const Safe_Server_Info &b) const + { + return a->uuid_ == b->uuid_; + } + }; + + // Presumably, there won't be too many component servers per node application + typedef ACE_Unbounded_Set_Ex <Safe_Server_Info, _server_info> SERVER_INFOS; + + /// Default args to pass to all componentservers. + ACE_CString default_args_; + + SERVER_INFOS server_infos_; + + ACE_Process_Manager process_manager_; + + Child_Handler child_handler_; + + CORBA::ULong spawn_delay_; + + /////*******NEW + bool multithreaded_; + + CORBA::ORB_var orb_; + + PortableServer::POA_var poa_; + + ACE_CString cs_path_; + + ACE_CString cs_args_; + + ACE_Thread_Mutex mutex_; + + ACE_Condition<ACE_SYNCH_MUTEX> condition_; + }; + + + } +} +#endif /* CIAO_SERVERACTIVATOR_H_ */ diff --git a/CIAO/ciao/FTComponentServer/CIAO_ServerResources.idl b/CIAO/ciao/FTComponentServer/CIAO_ServerResources.idl new file mode 100644 index 00000000000..5c00205a39b --- /dev/null +++ b/CIAO/ciao/FTComponentServer/CIAO_ServerResources.idl @@ -0,0 +1,268 @@ +// $Id$ + +/** + * @file CIAO_ServerResources.idl + * + * @brief A collection of IDL data types for + * + * @author Nanbor Wang + */ + +#if !defined (CIAO_SERVERRESOURCES_IDL) +#define CIAO_SERVERRESOURCES_IDL + +#include <orb.idl> + +module CIAO +{ + module Deployment + { + /** + * @brief A single command line argument corresponds to a string as + * in the case of "argv". + */ + typedef string CommandlineArg; + /** + * @brief A list of command line arguments which a + * NodeApplicationManager will use to start up the NodeApplication + * this list is associated to. The command line arguments will be + * appended to the command line in order. + */ + typedef sequence<CommandlineArg> CommandlineArgs; + + /** + * @brief A string containing the filename of the svc.conf file the + * NodeApplication uses. The current approach of specifying + * svc.conf filename directly some harder problems such as + * distribution of svc.conf files and the relative/absolute path to + * the svc.conf file (the ServerResrouces xml document will have to + * assume the svc.conf file will be available at specific location.) + */ + typedef string SvcconfURI; + + /** + * @brief enumeration of ORB Resource Types (ORT) supported in RT + * extension. + */ + enum ORBResourceType + { + ORT_THREADPOOL, + ORT_THREADPOOLWITHLANES, + ORT_CONNECTIONBANDS + }; + + typedef short Priority; + + /** + * @brief Define a threadpool resource that an ORB must provide + */ + struct ORS_Threadpool + { + string Id; + unsigned long stacksize; + unsigned long static_threads; + unsigned long dynamic_threads; + Priority default_priority; + boolean allow_request_buffering; + unsigned long max_buffered_requests; + unsigned long max_request_buffer_size; + }; + + typedef sequence<ORS_Threadpool> ORS_ThreadpoolSeq; + + /** + * @brief Defines the configuration of a threadpool lane. We need + * to redefine it here to avoid dependency to RTCORBA library. + */ + struct ORS_ThreadpoolLane + { + Priority lane_priority; + unsigned long static_threads; + unsigned long dynamic_threads; + }; + + /** + * @brief Defines a set of threadpool lanes. We need + * to redefine it here to avoid dependency to RTCORBA library. + */ + typedef sequence<ORS_ThreadpoolLane> ORS_ThreadpoolLanes; + + /** + * @brief Defines a Threadpool with Lanes resource that an ORB + * must provide. + */ + struct ORS_ThreadpoolWithLanes + { + string Id; + unsigned long stacksize; + ORS_ThreadpoolLanes threadpool_lanes; + boolean allow_borrowing; + boolean allow_request_buffering; + unsigned long max_buffered_requests; + unsigned long max_request_buffer_size; + }; + + typedef sequence<ORS_ThreadpoolWithLanes> ORS_ThreadpoolWithLanesSeq; + + /** + * @brief Define a priority band for BandedConnection policies. + */ + struct ORS_PriorityBand + { + Priority low; + Priority high; + }; + /** + * @brief Define a list of priority bands for BandedConnection + * policies. + */ + typedef sequence<ORS_PriorityBand> ORS_PriorityBands; + + /** + * @brief Define the information needed to create a + * BandedConnection policy. This info can be referred to via its + * name (Id). + */ + struct ORS_ConnectionBands + { + string Id; + ORS_PriorityBands bands; + }; + + typedef sequence<ORS_ConnectionBands> ORS_ConnectionBandsSeq; + + /** + * @brief Collection of resources managed by the NodeApplication + * ORB. + */ + struct ORBResource + { + ORS_ThreadpoolSeq threadpool_list; + + ORS_ThreadpoolWithLanesSeq threadpool_with_lanes_list; + + ORS_ConnectionBandsSeq connection_bands_list; + }; + + typedef sequence<ORBResource, 1> ORBResources; + + // ================================================================= + + /** + * @brief PolicyType supported by DAnCE extension. Again, we are + * redefining these value to avoid dependencies to various ORB + * modules such as RTCORBA and DiffServ policy libraries. + * @JW This is a bad thing to redefine. Maybe we have to make a seperate + * IDL lib for these libraries, but redefinition is really a bad thing + */ + const CORBA::PolicyType PRIORITY_MODEL_POLICY_TYPE = 40; + const CORBA::PolicyType THREADPOOL_POLICY_TYPE = 41; + const CORBA::PolicyType PRIORITY_BANDED_CONNECTION_POLICY_TYPE = 45; + const CORBA::PolicyType CLIENT_NETWORK_PRIORITY_TYPE = 86; + const CORBA::PolicyType NETWORK_PRIORITY_TYPE = 87; + + enum PriorityModel + { + CLIENT_PROPAGATED, + SERVER_DECLARED + }; + + enum NWPriorityModel + { + CLIENT_PROPAGATED_NWPRIORITY, + SERVER_DECLARED_NWPRIORITY + }; + + /** + * @brief Defines data required for creating a PriorityModel Policy + */ + struct PriorityModelPolicyDef + { + PriorityModel priority_model; + Priority server_priority; + }; + + /** + * @brief Defines data required for creating a server side DiffServ policy + */ + struct NWPriorityModelPolicyDef + { + NWPriorityModel nw_priority_model; + long request_dscp; + long reply_dscp; + }; + + /** + * @brief Defines data required for creating a client side DiffServ policy + */ + struct CNWPriorityModelPolicyDef + { + long request_dscp; + long reply_dscp; + }; + + /** + * @brief Define data required for creating a Threadpool policy + */ + struct ThreadpoolPolicyDef + { + // Threadpool name defined in ORBResource + string Id; + }; + + /** + * @brief Define data required for creating a PriorityBandedConnection + * policy + */ + struct PriorityBandedConnectionPolicyDef + { + string Id; // PriorityBands name defined in + // ORBResource + }; + + union PolicyDef switch (CORBA::PolicyType) + { + case PRIORITY_MODEL_POLICY_TYPE: PriorityModelPolicyDef PriorityModelDef; + case THREADPOOL_POLICY_TYPE: ThreadpoolPolicyDef ThreadpoolDef; + case PRIORITY_BANDED_CONNECTION_POLICY_TYPE: PriorityBandedConnectionPolicyDef PriorityBandedConnectionDef; + case CLIENT_NETWORK_PRIORITY_TYPE: CNWPriorityModelPolicyDef CNWPriorityModelDef; + case NETWORK_PRIORITY_TYPE: NWPriorityModelPolicyDef NWPriorityModelDef; + }; + + /** + * @brief Define a set of policy definitions. + */ + typedef sequence<PolicyDef> PolicyDefs; + + /** + * @brief A policy set is named. + */ + struct PolicySet + { + string Id; // Name of this policy set + PolicyDefs policies; + }; + + /** + * @brief A list of all policy sets. + */ + typedef sequence<PolicySet> PolicySets; + + struct ORBConfigs + { + ORBResources orb_resources; + PolicySets policy_set; + }; + + struct ServerResource + { + string Id; + + CommandlineArgs args; + SvcconfURI svcconf; + ORBConfigs orb_config; + }; + }; +}; + +#endif /* CIAO_SERVERRESOURCES_IDL */ diff --git a/CIAO/ciao/FTComponentServer/Configurator_Factory.cpp b/CIAO/ciao/FTComponentServer/Configurator_Factory.cpp new file mode 100644 index 00000000000..2db7cec6ef3 --- /dev/null +++ b/CIAO/ciao/FTComponentServer/Configurator_Factory.cpp @@ -0,0 +1,49 @@ +#include "Configurator_Factory.h" +// $Id$ +#include "ace/Arg_Shifter.h" +#include "ciao/CIAO_common.h" +#include "Configurators/Server_Configurator.h" + +namespace CIAO +{ + namespace Deployment + { + ComponentServer_Configurator * + Configurator_Factory::operator() (int &argc, ACE_TCHAR **argv) + { + CIAO_TRACE ("Configurator_Factory::operator()"); + bool const rt = this->parse_args (argc, argv); + + ComponentServer_Configurator *ptr = 0; + ACE_NEW_THROW_EX (ptr, + ComponentServer_Configurator (rt), + CORBA::NO_MEMORY (TAO::VMCID, + CORBA::COMPLETED_NO)); + + return ptr; + } + + bool + Configurator_Factory::parse_args (int &argc, ACE_TCHAR **argv) + { + CIAO_TRACE ("Configurator_Factory::parse_args"); + ACE_Arg_Shifter shifter (argc, argv); + bool retval = false; + + while (shifter.is_anything_left ()) + { + if (shifter.cur_arg_strncasecmp (ACE_TEXT("-r")) == 0) + { + retval = true; + shifter.consume_arg (); + } + else + { + shifter.ignore_arg (); + } + } + + return retval; + } + } +} diff --git a/CIAO/ciao/FTComponentServer/Configurator_Factory.h b/CIAO/ciao/FTComponentServer/Configurator_Factory.h new file mode 100644 index 00000000000..5f62473a5da --- /dev/null +++ b/CIAO/ciao/FTComponentServer/Configurator_Factory.h @@ -0,0 +1,39 @@ +// $Id$ +/** + * @file Configurator_Factory.h + * @author William R. Otte <wotte@dre.vanderbilt.edu> + * @author Nanbor Wang <> + * + * Factory for creating configurators, based on old NodeApplication_Options + * class + */ + +#ifndef CIAO_CONFIGURATOR_FACTORY_H +#define CIAO_CONFIGURATOR_FACTORY_H +#include /**/ "ace/pre.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "CIAO_FTComponentServer_svnt_export.h" + +namespace CIAO +{ + namespace Deployment + { + class ComponentServer_Configurator; + + class CIAO_FTComponentServer_svnt_Export Configurator_Factory + { + public: + ComponentServer_Configurator * operator () (int &argc, ACE_TCHAR **argv); + + private: + bool parse_args (int &argc, ACE_TCHAR **argv); + }; + } +} +#include /**/ "ace/post.h" + +#endif diff --git a/CIAO/ciao/FTComponentServer/Configurators/Basic_Config_Manager.cpp b/CIAO/ciao/FTComponentServer/Configurators/Basic_Config_Manager.cpp new file mode 100644 index 00000000000..a34353fe5c7 --- /dev/null +++ b/CIAO/ciao/FTComponentServer/Configurators/Basic_Config_Manager.cpp @@ -0,0 +1,240 @@ +// $Id$ + +#include "Basic_Config_Manager.h" +#include "ciao/CIAO_common.h" +#include "ace/SString.h" +#include "tao/SystemException.h" +#include "tao/DiffServPolicy/DiffServPolicy.h" +#include "tao/DiffServPolicy/Client_Network_Priority_Policy.h" +#include "tao/DiffServPolicy/Server_Network_Priority_Policy.h" + +namespace CIAO +{ + namespace Deployment + { + + void + Basic_Config_Manager::init (CORBA::ORB_ptr orb) + { + this->orb_ = CORBA::ORB::_duplicate (orb); + } + + int + Basic_Config_Manager::pre_orb_initialize (void) + { + return 0; + } + + int + Basic_Config_Manager::post_orb_initialize (CORBA::ORB_ptr) + { + return 0; + } + + void + Basic_Config_Manager::init_resources + (const ServerResource &server_resource) + { + CIAO_DEBUG ((LM_DEBUG,"Basic_Config_Manager::init_resources\n")); + + if (CORBA::is_nil (this->orb_.in())) + { + CIAO_ERROR ((LM_ERROR, + "Basic_Config_Manager has not been properly initialized\n")); + throw CORBA::INTERNAL (); + } + + const PolicySets &sets = server_resource.orb_config.policy_set; + for (CORBA::ULong i = 0; i < sets.length (); ++i) + { + CORBA::ULong np = sets[i].policies.length (); + if (np == 0) + continue; + + CORBA::PolicyList_var policy_list = new CORBA::PolicyList (np); + policy_list->length (np); + CORBA::ULong index = 0; + CORBA::ULong array_index = np; + + // Create a list of policies + for (CORBA::ULong pc = 0; pc < np; ++pc) + { + CORBA::Policy_var temp_policy = + this->create_single_policy (sets[i].policies[pc]); + + if (CORBA::is_nil (temp_policy.in ())) + { + array_index = array_index - 1; + policy_list->length (array_index); + } + else + { + policy_list[index] = temp_policy; + index = index + 1; + } + } + + // Bind the policy list to the name. The bind operation should + // surrender the ownership of the newly created PolicyList + // sequence to the map. + if (array_index != 0) + { + if (this->policy_map_.bind (sets[i].Id.in (), + policy_list) != 0) + { + CIAO_ERROR ((LM_ERROR, + "Error binding Policy_Set with name: %s\n", + sets[i].Id.in ())); + throw CORBA::INTERNAL (); + } + else + { + CIAO_DEBUG ((LM_DEBUG, + "Basic_Config_Manager::init_resource" + " added policy set : %s with %d policies\n", + sets[i].Id.in (), array_index)); + } + } + else + { + CIAO_DEBUG ((LM_DEBUG, + "Basic_Config_Manager::init_resource" + " added policy set : %s with %d policies\n", + sets[i].Id.in (), array_index)); + } + } + } + + bool + Basic_Config_Manager::policy_exists (const char *name) + { + if (name == 0) + { + CIAO_ERROR ((LM_ERROR, + "Invalid name string found in " + "Basic_Config_Manager::policy_exists\n")); + throw CORBA::INTERNAL (); + } + + POLICY_MAP::ENTRY *entry = 0; + + if (this->policy_map_.find (name, entry) != 0) + { + return false; + } + + return true; + } + + CORBA::PolicyList * + Basic_Config_Manager::find_policies_by_name (const char *name) + { + if (name == 0) + { + CIAO_DEBUG ((LM_DEBUG, + "Invalid name string found in find_policies_by_name\n")); + throw CORBA::INTERNAL (); + } + + POLICY_MAP::ENTRY *entry = 0; + + CORBA::PolicyList_var retv; + + if (this->policy_map_.find (name, entry) != 0) + { + CIAO_DEBUG ((LM_DEBUG, + "Unable to find a PolicyList named %s\n", + name)); + retv = 0; + } + else + { + retv = new CORBA::PolicyList (entry->int_id_.in ()); + } + return retv._retn (); + } + + CORBA::Policy_ptr + Basic_Config_Manager::create_single_policy + (const PolicyDef &policy_def) + { + CORBA::Policy_var retv; + + switch (policy_def._d ()) + { + case TAO::NETWORK_PRIORITY_TYPE: + { + const NWPriorityModelPolicyDef &nw_tmp + = policy_def.NWPriorityModelDef (); + retv = this->orb_->_create_policy (TAO::NETWORK_PRIORITY_TYPE); + + TAO::NetworkPriorityPolicy_var nw_priority = + TAO::NetworkPriorityPolicy::_narrow (retv.in ()); + + nw_priority->network_priority_model ( + (TAO::NetworkPriorityModel) nw_tmp.nw_priority_model); + + nw_priority->request_diffserv_codepoint ( + (TAO::DiffservCodepoint) nw_tmp.request_dscp); + + nw_priority->reply_diffserv_codepoint ( + (TAO::DiffservCodepoint) nw_tmp.reply_dscp); + + retv = nw_priority._retn (); + + if (! CORBA::is_nil (retv.in ())) + CIAO_DEBUG ((LM_DEBUG, + "NAConfigManager::Create NetworkPriority policy: %d\n", + nw_tmp.nw_priority_model)); + } + break; + + case TAO::CLIENT_NETWORK_PRIORITY_TYPE: + { + const CNWPriorityModelPolicyDef &cnw_tmp + = policy_def.CNWPriorityModelDef (); + retv = this->orb_->_create_policy (TAO::CLIENT_NETWORK_PRIORITY_TYPE); + + TAO::NetworkPriorityPolicy_var cnw_priority = + TAO::NetworkPriorityPolicy::_narrow (retv.in ()); + + cnw_priority->request_diffserv_codepoint ( + (TAO::DiffservCodepoint) cnw_tmp.request_dscp); + + cnw_priority->reply_diffserv_codepoint ( + (TAO::DiffservCodepoint) cnw_tmp.reply_dscp); + + retv = cnw_priority._retn (); + + if (! CORBA::is_nil (retv.in ())) + CIAO_DEBUG ((LM_DEBUG, + "NAConfigManager::Create NetworkPriority policy \n")); + } + break; + + default: + retv = 0; + } + + return retv._retn (); + } + + } +} + +using CIAO::Deployment::Config_Manager; +using CIAO::Deployment::Basic_Config_Manager; + +extern "C" Basic_Config_Manager_Export Config_Manager *create_basic_config_manager (void); + +extern "C" +{ + Config_Manager * + create_basic_config_manager (void) + { + Basic_Config_Manager *config; + ACE_NEW_RETURN (config, Basic_Config_Manager, 0); + return config; + } +} + diff --git a/CIAO/ciao/FTComponentServer/Configurators/Basic_Config_Manager.h b/CIAO/ciao/FTComponentServer/Configurators/Basic_Config_Manager.h new file mode 100644 index 00000000000..0f1f0b03b64 --- /dev/null +++ b/CIAO/ciao/FTComponentServer/Configurators/Basic_Config_Manager.h @@ -0,0 +1,79 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Basic_Config_Manager.h + * + * $Id$ + * + */ +//============================================================================= + + +#ifndef CIAO_NACONFIG_MANAGER_H +#define CIAO_NACONFIG_MANAGER_H +#include /**/ <ace/pre.h> + +#include "ace/config-all.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ace/Null_Mutex.h" +#include "ace/SString.h" +#include "ace/Hash_Map_Manager_T.h" +#include "ciao/ComponentServer/CIAO_ServerResourcesC.h" + +#include "Config_Manager.h" +#include "Basic_Config_Manager_export.h" + +namespace CIAO +{ + namespace Deployment + { + /** + */ + class Basic_Config_Manager_Export Basic_Config_Manager + : public Config_Manager + { + public: + virtual ~Basic_Config_Manager (void) {} + + virtual int pre_orb_initialize (void); + + virtual int post_orb_initialize (CORBA::ORB_ptr o); + + virtual void init (CORBA::ORB_ptr orb); + + /// Initializing the NAResource_Config_Manager + virtual void init_resources (const ServerResource &info); + + /// Query a policy set by name + virtual CORBA::PolicyList *find_policies_by_name (const char *name); + + virtual bool policy_exists (const char *name); + + private: + /// Cached an ORB reference. + CORBA::ORB_var orb_; + + CORBA::Policy_ptr create_single_policy + (const PolicyDef &policy_def); + + /// Hash_Map stuff. + typedef ACE_Hash_Map_Manager_Ex<ACE_CString, + CORBA::PolicyList_var, + ACE_Hash<ACE_CString>, + ACE_Equal_To<ACE_CString>, + ACE_Null_Mutex> POLICY_MAP; + + /// Internal TP names to id map. + POLICY_MAP policy_map_; + }; +} + } + +#include /**/ "ace/post.h" +#endif /* CIAO_NACONFIG_MANAGER_H */ + diff --git a/CIAO/ciao/FTComponentServer/Configurators/Basic_Config_Manager.inl b/CIAO/ciao/FTComponentServer/Configurators/Basic_Config_Manager.inl new file mode 100644 index 00000000000..67203a91ff8 --- /dev/null +++ b/CIAO/ciao/FTComponentServer/Configurators/Basic_Config_Manager.inl @@ -0,0 +1,12 @@ +// $Id$ + +ACE_INLINE +CIAO::NAResource_Config_Manager::NAResource_Config_Manager () +{ +} + +ACE_INLINE +CIAO::NAResource_Config_Manager::~NAResource_Config_Manager () +{ +} + diff --git a/CIAO/ciao/FTComponentServer/Configurators/Basic_Config_Manager_export.h b/CIAO/ciao/FTComponentServer/Configurators/Basic_Config_Manager_export.h new file mode 100644 index 00000000000..51cb9778168 --- /dev/null +++ b/CIAO/ciao/FTComponentServer/Configurators/Basic_Config_Manager_export.h @@ -0,0 +1,58 @@ + +// -*- C++ -*- +// $Id$ +// Definition for Win32 Export directives. +// This file is generated automatically by generate_export_file.pl Basic_Config_Manager +// ------------------------------ +#ifndef BASIC_CONFIG_MANAGER_EXPORT_H +#define BASIC_CONFIG_MANAGER_EXPORT_H + +#include "ace/config-all.h" + +#if defined (ACE_AS_STATIC_LIBS) && !defined (BASIC_CONFIG_MANAGER_HAS_DLL) +# define BASIC_CONFIG_MANAGER_HAS_DLL 0 +#endif /* ACE_AS_STATIC_LIBS && BASIC_CONFIG_MANAGER_HAS_DLL */ + +#if !defined (BASIC_CONFIG_MANAGER_HAS_DLL) +# define BASIC_CONFIG_MANAGER_HAS_DLL 1 +#endif /* ! BASIC_CONFIG_MANAGER_HAS_DLL */ + +#if defined (BASIC_CONFIG_MANAGER_HAS_DLL) && (BASIC_CONFIG_MANAGER_HAS_DLL == 1) +# if defined (BASIC_CONFIG_MANAGER_BUILD_DLL) +# define Basic_Config_Manager_Export ACE_Proper_Export_Flag +# define BASIC_CONFIG_MANAGER_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) +# define BASIC_CONFIG_MANAGER_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# else /* BASIC_CONFIG_MANAGER_BUILD_DLL */ +# define Basic_Config_Manager_Export ACE_Proper_Import_Flag +# define BASIC_CONFIG_MANAGER_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) +# define BASIC_CONFIG_MANAGER_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# endif /* BASIC_CONFIG_MANAGER_BUILD_DLL */ +#else /* BASIC_CONFIG_MANAGER_HAS_DLL == 1 */ +# define Basic_Config_Manager_Export +# define BASIC_CONFIG_MANAGER_SINGLETON_DECLARATION(T) +# define BASIC_CONFIG_MANAGER_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +#endif /* BASIC_CONFIG_MANAGER_HAS_DLL == 1 */ + +// Set BASIC_CONFIG_MANAGER_NTRACE = 0 to turn on library specific tracing even if +// tracing is turned off for ACE. +#if !defined (BASIC_CONFIG_MANAGER_NTRACE) +# if (ACE_NTRACE == 1) +# define BASIC_CONFIG_MANAGER_NTRACE 1 +# else /* (ACE_NTRACE == 1) */ +# define BASIC_CONFIG_MANAGER_NTRACE 0 +# endif /* (ACE_NTRACE == 1) */ +#endif /* !BASIC_CONFIG_MANAGER_NTRACE */ + +#if (BASIC_CONFIG_MANAGER_NTRACE == 1) +# define BASIC_CONFIG_MANAGER_TRACE(X) +#else /* (BASIC_CONFIG_MANAGER_NTRACE == 1) */ +# if !defined (ACE_HAS_TRACE) +# define ACE_HAS_TRACE +# endif /* ACE_HAS_TRACE */ +# define BASIC_CONFIG_MANAGER_TRACE(X) ACE_TRACE_IMPL(X) +# include "ace/Trace.h" +#endif /* (BASIC_CONFIG_MANAGER_NTRACE == 1) */ + +#endif /* BASIC_CONFIG_MANAGER_EXPORT_H */ + +// End of auto generated file. diff --git a/CIAO/ciao/FTComponentServer/Configurators/Basic_Configurator_export.h b/CIAO/ciao/FTComponentServer/Configurators/Basic_Configurator_export.h new file mode 100644 index 00000000000..098b4c87f0d --- /dev/null +++ b/CIAO/ciao/FTComponentServer/Configurators/Basic_Configurator_export.h @@ -0,0 +1,58 @@ + +// -*- C++ -*- +// $Id$ +// Definition for Win32 Export directives. +// This file is generated automatically by generate_export_file.pl Basic_Configurator +// ------------------------------ +#ifndef BASIC_CONFIGURATOR_EXPORT_H +#define BASIC_CONFIGURATOR_EXPORT_H + +#include "ace/config-all.h" + +#if defined (ACE_AS_STATIC_LIBS) && !defined (BASIC_CONFIGURATOR_HAS_DLL) +# define BASIC_CONFIGURATOR_HAS_DLL 0 +#endif /* ACE_AS_STATIC_LIBS && BASIC_CONFIGURATOR_HAS_DLL */ + +#if !defined (BASIC_CONFIGURATOR_HAS_DLL) +# define BASIC_CONFIGURATOR_HAS_DLL 1 +#endif /* ! BASIC_CONFIGURATOR_HAS_DLL */ + +#if defined (BASIC_CONFIGURATOR_HAS_DLL) && (BASIC_CONFIGURATOR_HAS_DLL == 1) +# if defined (BASIC_CONFIGURATOR_BUILD_DLL) +# define Basic_Configurator_Export ACE_Proper_Export_Flag +# define BASIC_CONFIGURATOR_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) +# define BASIC_CONFIGURATOR_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# else /* BASIC_CONFIGURATOR_BUILD_DLL */ +# define Basic_Configurator_Export ACE_Proper_Import_Flag +# define BASIC_CONFIGURATOR_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) +# define BASIC_CONFIGURATOR_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# endif /* BASIC_CONFIGURATOR_BUILD_DLL */ +#else /* BASIC_CONFIGURATOR_HAS_DLL == 1 */ +# define Basic_Configurator_Export +# define BASIC_CONFIGURATOR_SINGLETON_DECLARATION(T) +# define BASIC_CONFIGURATOR_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +#endif /* BASIC_CONFIGURATOR_HAS_DLL == 1 */ + +// Set BASIC_CONFIGURATOR_NTRACE = 0 to turn on library specific tracing even if +// tracing is turned off for ACE. +#if !defined (BASIC_CONFIGURATOR_NTRACE) +# if (ACE_NTRACE == 1) +# define BASIC_CONFIGURATOR_NTRACE 1 +# else /* (ACE_NTRACE == 1) */ +# define BASIC_CONFIGURATOR_NTRACE 0 +# endif /* (ACE_NTRACE == 1) */ +#endif /* !BASIC_CONFIGURATOR_NTRACE */ + +#if (BASIC_CONFIGURATOR_NTRACE == 1) +# define BASIC_CONFIGURATOR_TRACE(X) +#else /* (BASIC_CONFIGURATOR_NTRACE == 1) */ +# if !defined (ACE_HAS_TRACE) +# define ACE_HAS_TRACE +# endif /* ACE_HAS_TRACE */ +# define BASIC_CONFIGURATOR_TRACE(X) ACE_TRACE_IMPL(X) +# include "ace/Trace.h" +#endif /* (BASIC_CONFIGURATOR_NTRACE == 1) */ + +#endif /* BASIC_CONFIGURATOR_EXPORT_H */ + +// End of auto generated file. diff --git a/CIAO/ciao/FTComponentServer/Configurators/ComponentServer_Configurator_export.h b/CIAO/ciao/FTComponentServer/Configurators/ComponentServer_Configurator_export.h new file mode 100644 index 00000000000..9793cd0ed44 --- /dev/null +++ b/CIAO/ciao/FTComponentServer/Configurators/ComponentServer_Configurator_export.h @@ -0,0 +1,58 @@ + +// -*- C++ -*- +// $Id$ +// Definition for Win32 Export directives. +// This file is generated automatically by generate_export_file.pl ComponentServer_Configurator +// ------------------------------ +#ifndef COMPONENTSERVER_CONFIGURATOR_EXPORT_H +#define COMPONENTSERVER_CONFIGURATOR_EXPORT_H + +#include "ace/config-all.h" + +#if defined (ACE_AS_STATIC_LIBS) && !defined (COMPONENTSERVER_CONFIGURATOR_HAS_DLL) +# define COMPONENTSERVER_CONFIGURATOR_HAS_DLL 0 +#endif /* ACE_AS_STATIC_LIBS && COMPONENTSERVER_CONFIGURATOR_HAS_DLL */ + +#if !defined (COMPONENTSERVER_CONFIGURATOR_HAS_DLL) +# define COMPONENTSERVER_CONFIGURATOR_HAS_DLL 1 +#endif /* ! COMPONENTSERVER_CONFIGURATOR_HAS_DLL */ + +#if defined (COMPONENTSERVER_CONFIGURATOR_HAS_DLL) && (COMPONENTSERVER_CONFIGURATOR_HAS_DLL == 1) +# if defined (COMPONENTSERVER_CONFIGURATOR_BUILD_DLL) +# define ComponentServer_Configurator_Export ACE_Proper_Export_Flag +# define COMPONENTSERVER_CONFIGURATOR_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) +# define COMPONENTSERVER_CONFIGURATOR_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# else /* COMPONENTSERVER_CONFIGURATOR_BUILD_DLL */ +# define ComponentServer_Configurator_Export ACE_Proper_Import_Flag +# define COMPONENTSERVER_CONFIGURATOR_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) +# define COMPONENTSERVER_CONFIGURATOR_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# endif /* COMPONENTSERVER_CONFIGURATOR_BUILD_DLL */ +#else /* COMPONENTSERVER_CONFIGURATOR_HAS_DLL == 1 */ +# define ComponentServer_Configurator_Export +# define COMPONENTSERVER_CONFIGURATOR_SINGLETON_DECLARATION(T) +# define COMPONENTSERVER_CONFIGURATOR_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +#endif /* COMPONENTSERVER_CONFIGURATOR_HAS_DLL == 1 */ + +// Set COMPONENTSERVER_CONFIGURATOR_NTRACE = 0 to turn on library specific tracing even if +// tracing is turned off for ACE. +#if !defined (COMPONENTSERVER_CONFIGURATOR_NTRACE) +# if (ACE_NTRACE == 1) +# define COMPONENTSERVER_CONFIGURATOR_NTRACE 1 +# else /* (ACE_NTRACE == 1) */ +# define COMPONENTSERVER_CONFIGURATOR_NTRACE 0 +# endif /* (ACE_NTRACE == 1) */ +#endif /* !COMPONENTSERVER_CONFIGURATOR_NTRACE */ + +#if (COMPONENTSERVER_CONFIGURATOR_NTRACE == 1) +# define COMPONENTSERVER_CONFIGURATOR_TRACE(X) +#else /* (COMPONENTSERVER_CONFIGURATOR_NTRACE == 1) */ +# if !defined (ACE_HAS_TRACE) +# define ACE_HAS_TRACE +# endif /* ACE_HAS_TRACE */ +# define COMPONENTSERVER_CONFIGURATOR_TRACE(X) ACE_TRACE_IMPL(X) +# include "ace/Trace.h" +#endif /* (COMPONENTSERVER_CONFIGURATOR_NTRACE == 1) */ + +#endif /* COMPONENTSERVER_CONFIGURATOR_EXPORT_H */ + +// End of auto generated file. diff --git a/CIAO/ciao/FTComponentServer/Configurators/Config_Manager.cpp b/CIAO/ciao/FTComponentServer/Configurators/Config_Manager.cpp new file mode 100644 index 00000000000..47ee45a81a4 --- /dev/null +++ b/CIAO/ciao/FTComponentServer/Configurators/Config_Manager.cpp @@ -0,0 +1,11 @@ +#include "Config_Manager.h" + +namespace CIAO +{ + namespace Deployment + { + Config_Manager::~Config_Manager (void) + { + } + } +} diff --git a/CIAO/ciao/FTComponentServer/Configurators/Config_Manager.h b/CIAO/ciao/FTComponentServer/Configurators/Config_Manager.h new file mode 100644 index 00000000000..2ce46aa980f --- /dev/null +++ b/CIAO/ciao/FTComponentServer/Configurators/Config_Manager.h @@ -0,0 +1,53 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Config_Manager.h + * + * $Id$ + * + */ +//============================================================================= + + +#ifndef CIAO_CONFIG_MANAGER_H +#define CIAO_CONFIG_MANAGER_H +#include /**/ "ace/pre.h" + +#include "ace/config-all.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ciao/ComponentServer/CIAO_ServerResourcesC.h" + +namespace CIAO +{ + namespace Deployment + { + /** + */ + class Config_Manager + { + public: + virtual ~Config_Manager (void) {}; + + virtual int pre_orb_initialize (void) = 0; + + virtual int post_orb_initialize (CORBA::ORB_ptr o) = 0; + + virtual void init_resources (const ServerResource &info) = 0; + + virtual void init (CORBA::ORB_ptr orb) = 0; + + virtual CORBA::PolicyList *find_policies_by_name (const char *name)= 0; + + virtual bool policy_exists (const char *name) = 0; + }; + } +} + +#include /**/ "ace/post.h" +#endif /* CIAO_CONFIG_MANAGER_H */ + diff --git a/CIAO/ciao/FTComponentServer/Configurators/Configurators.mpc b/CIAO/ciao/FTComponentServer/Configurators/Configurators.mpc new file mode 100644 index 00000000000..dc072ddb6dc --- /dev/null +++ b/CIAO/ciao/FTComponentServer/Configurators/Configurators.mpc @@ -0,0 +1,21 @@ +project(CIAO_FT_Basic_Configurator) : ccm_stub, ciao_ft_componentserver_stub, ciao_lib { + dynamicflags += COMPONENTSERVER_CONFIGURATOR_BUILD_DLL + Source_Files { + Server_Configurator.cpp + } + Header_Files { + Server_Configurator.h + } +} + +project(CIAO_FT_Basic_Config_Manager) : ciao_lib, ciao_config_manager, ciao_ft_componentserver_stub, \ + diffservpolicy { + dynamicflags += BASIC_CONFIG_MANAGER_BUILD_DLL + Source_Files { + Basic_Config_Manager.cpp + } + Header_Files { + Basic_Config_Manager.h + } +} + diff --git a/CIAO/ciao/FTComponentServer/Configurators/NA_Configurator_Export.h b/CIAO/ciao/FTComponentServer/Configurators/NA_Configurator_Export.h new file mode 100644 index 00000000000..2e30fd59cc1 --- /dev/null +++ b/CIAO/ciao/FTComponentServer/Configurators/NA_Configurator_Export.h @@ -0,0 +1,58 @@ + +// -*- C++ -*- +// $Id$ +// Definition for Win32 Export directives. +// This file is generated automatically by generate_export_file.pl CIAO_NA_Configurator +// ------------------------------ +#ifndef CIAO_NA_CONFIGURATOR_EXPORT_H +#define CIAO_NA_CONFIGURATOR_EXPORT_H + +#include "ace/config-all.h" + +#if defined (ACE_AS_STATIC_LIBS) && !defined (CIAO_NA_CONFIGURATOR_HAS_DLL) +# define CIAO_NA_CONFIGURATOR_HAS_DLL 0 +#endif /* ACE_AS_STATIC_LIBS && CIAO_NA_CONFIGURATOR_HAS_DLL */ + +#if !defined (CIAO_NA_CONFIGURATOR_HAS_DLL) +# define CIAO_NA_CONFIGURATOR_HAS_DLL 1 +#endif /* ! CIAO_NA_CONFIGURATOR_HAS_DLL */ + +#if defined (CIAO_NA_CONFIGURATOR_HAS_DLL) && (CIAO_NA_CONFIGURATOR_HAS_DLL == 1) +# if defined (CIAO_NA_CONFIGURATOR_BUILD_DLL) +# define CIAO_NA_Configurator_Export ACE_Proper_Export_Flag +# define CIAO_NA_CONFIGURATOR_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) +# define CIAO_NA_CONFIGURATOR_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# else /* CIAO_NA_CONFIGURATOR_BUILD_DLL */ +# define CIAO_NA_Configurator_Export ACE_Proper_Import_Flag +# define CIAO_NA_CONFIGURATOR_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) +# define CIAO_NA_CONFIGURATOR_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# endif /* CIAO_NA_CONFIGURATOR_BUILD_DLL */ +#else /* CIAO_NA_CONFIGURATOR_HAS_DLL == 1 */ +# define CIAO_NA_Configurator_Export +# define CIAO_NA_CONFIGURATOR_SINGLETON_DECLARATION(T) +# define CIAO_NA_CONFIGURATOR_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +#endif /* CIAO_NA_CONFIGURATOR_HAS_DLL == 1 */ + +// Set CIAO_NA_CONFIGURATOR_NTRACE = 0 to turn on library specific tracing even if +// tracing is turned off for ACE. +#if !defined (CIAO_NA_CONFIGURATOR_NTRACE) +# if (ACE_NTRACE == 1) +# define CIAO_NA_CONFIGURATOR_NTRACE 1 +# else /* (ACE_NTRACE == 1) */ +# define CIAO_NA_CONFIGURATOR_NTRACE 0 +# endif /* (ACE_NTRACE == 1) */ +#endif /* !CIAO_NA_CONFIGURATOR_NTRACE */ + +#if (CIAO_NA_CONFIGURATOR_NTRACE == 1) +# define CIAO_NA_CONFIGURATOR_TRACE(X) +#else /* (CIAO_NA_CONFIGURATOR_NTRACE == 1) */ +# if !defined (ACE_HAS_TRACE) +# define ACE_HAS_TRACE +# endif /* ACE_HAS_TRACE */ +# define CIAO_NA_CONFIGURATOR_TRACE(X) ACE_TRACE_IMPL(X) +# include "ace/Trace.h" +#endif /* (CIAO_NA_CONFIGURATOR_NTRACE == 1) */ + +#endif /* CIAO_NA_CONFIGURATOR_EXPORT_H */ + +// End of auto generated file. diff --git a/CIAO/ciao/FTComponentServer/Configurators/NoOp/FT_NoOp_Configurator.mpc b/CIAO/ciao/FTComponentServer/Configurators/NoOp/FT_NoOp_Configurator.mpc new file mode 100644 index 00000000000..50cb9d50665 --- /dev/null +++ b/CIAO/ciao/FTComponentServer/Configurators/NoOp/FT_NoOp_Configurator.mpc @@ -0,0 +1,12 @@ +project(CIAO_FT_NoOp_Configurator) : ccm_stub, ciao_ft_componentserver_stub, ciao_ft_componentserver_configurator, ciao_lib { + + Source_Files { + NoOp_Configurator.cpp + } + + Header_Files { + NoOp_Configurator.h + } +} + + diff --git a/CIAO/ciao/FTComponentServer/Configurators/NoOp/NoOp_Configurator.cpp b/CIAO/ciao/FTComponentServer/Configurators/NoOp/NoOp_Configurator.cpp new file mode 100644 index 00000000000..e4c377e436a --- /dev/null +++ b/CIAO/ciao/FTComponentServer/Configurators/NoOp/NoOp_Configurator.cpp @@ -0,0 +1,46 @@ +// $Id$ + +#include "NoOp_Configurator.h" + +namespace CIAO +{ + namespace Deployment + { + + NoOp_Configurator::~NoOp_Configurator (void) + { + // Not much to do. + } + + int + NoOp_Configurator::pre_orb_initialize () + { + return 0; + } + + int + NoOp_Configurator::post_orb_initialize (CORBA::ORB_ptr) + { + return 0; + } + + int + NoOp_Configurator::init_resource_manager + (const ::Components::ConfigValues & /*properties*/) + { + // @@ Currently do thing. We should go over the resource struct in + // the future and throw exceptions if there are + // un-recognizable/supported stuff in it. + return 0; + } + + CORBA::PolicyList * + NoOp_Configurator::find_container_policies + (const ::Components::ConfigValues & /*properties*/) + { + // Not much to do. + + return 0; + } + } +} diff --git a/CIAO/ciao/FTComponentServer/Configurators/NoOp/NoOp_Configurator.h b/CIAO/ciao/FTComponentServer/Configurators/NoOp/NoOp_Configurator.h new file mode 100644 index 00000000000..d84715d5bca --- /dev/null +++ b/CIAO/ciao/FTComponentServer/Configurators/NoOp/NoOp_Configurator.h @@ -0,0 +1,66 @@ +/** $Id$ + * @file NoOp_Configurator.h + * @brief This file contains the noop configurator. + */ + +#ifndef NOOP_CONFIGURATOR_H +#define NOOP_CONFIGURATOR_H + +#include /**/ "ace/pre.h" + +#include "ace/config-all.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include <ccm/CCM_StandardConfiguratorC.h> + +#include "ciao/ComponentServer/Configurators/Server_Configurator.h" +#include "NoOp_Configurator_export.h" + +namespace CIAO +{ + namespace Deployment + { + /** + * @class NoOP_Configurator + * + * @brief The NoOp_Configurator doesn't do anything. + */ + class NoOp_Configurator_Export NoOp_Configurator + : public ComponentServer_Configurator + { + public: + /// Default destructor. + virtual ~NoOp_Configurator (void); + + /** + * @brief "pre_orb_initialize" is called before ORB_init. + */ + virtual int pre_orb_initialize (void); + + /** + * @brief "post_orb_initialize" is called after NodeApplication + * get a hold at this object. + */ + virtual int post_orb_initialize (CORBA::ORB_ptr o); + + /** + * @brief "init_resource_manager" is called by NodeApplication when + * it receives an "install" commands. + */ + virtual int + init_resource_manager (const ::Components::ConfigValues &properties); + + /** + * @brief get a policyset by its name. + */ + virtual CORBA::PolicyList * + find_container_policies (const ::Components::ConfigValues &properties); + }; + } +} + +#include /**/ "ace/post.h" +#endif /* NOOP_CONFIGURATOR_H */ diff --git a/CIAO/ciao/FTComponentServer/Configurators/NoOp/NoOp_Configurator_export.h b/CIAO/ciao/FTComponentServer/Configurators/NoOp/NoOp_Configurator_export.h new file mode 100644 index 00000000000..b6b3a9ec841 --- /dev/null +++ b/CIAO/ciao/FTComponentServer/Configurators/NoOp/NoOp_Configurator_export.h @@ -0,0 +1,58 @@ + +// -*- C++ -*- +// $Id$ +// Definition for Win32 Export directives. +// This file is generated automatically by generate_export_file.pl NoOp_Configurator +// ------------------------------ +#ifndef NOOP_CONFIGURATOR_EXPORT_H +#define NOOP_CONFIGURATOR_EXPORT_H + +#include "ace/config-all.h" + +#if defined (ACE_AS_STATIC_LIBS) && !defined (NOOP_CONFIGURATOR_HAS_DLL) +# define NOOP_CONFIGURATOR_HAS_DLL 0 +#endif /* ACE_AS_STATIC_LIBS && NOOP_CONFIGURATOR_HAS_DLL */ + +#if !defined (NOOP_CONFIGURATOR_HAS_DLL) +# define NOOP_CONFIGURATOR_HAS_DLL 1 +#endif /* ! NOOP_CONFIGURATOR_HAS_DLL */ + +#if defined (NOOP_CONFIGURATOR_HAS_DLL) && (NOOP_CONFIGURATOR_HAS_DLL == 1) +# if defined (NOOP_CONFIGURATOR_BUILD_DLL) +# define NoOp_Configurator_Export ACE_Proper_Export_Flag +# define NOOP_CONFIGURATOR_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) +# define NOOP_CONFIGURATOR_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# else /* NOOP_CONFIGURATOR_BUILD_DLL */ +# define NoOp_Configurator_Export ACE_Proper_Import_Flag +# define NOOP_CONFIGURATOR_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) +# define NOOP_CONFIGURATOR_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# endif /* NOOP_CONFIGURATOR_BUILD_DLL */ +#else /* NOOP_CONFIGURATOR_HAS_DLL == 1 */ +# define NoOp_Configurator_Export +# define NOOP_CONFIGURATOR_SINGLETON_DECLARATION(T) +# define NOOP_CONFIGURATOR_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +#endif /* NOOP_CONFIGURATOR_HAS_DLL == 1 */ + +// Set NOOP_CONFIGURATOR_NTRACE = 0 to turn on library specific tracing even if +// tracing is turned off for ACE. +#if !defined (NOOP_CONFIGURATOR_NTRACE) +# if (ACE_NTRACE == 1) +# define NOOP_CONFIGURATOR_NTRACE 1 +# else /* (ACE_NTRACE == 1) */ +# define NOOP_CONFIGURATOR_NTRACE 0 +# endif /* (ACE_NTRACE == 1) */ +#endif /* !NOOP_CONFIGURATOR_NTRACE */ + +#if (NOOP_CONFIGURATOR_NTRACE == 1) +# define NOOP_CONFIGURATOR_TRACE(X) +#else /* (NOOP_CONFIGURATOR_NTRACE == 1) */ +# if !defined (ACE_HAS_TRACE) +# define ACE_HAS_TRACE +# endif /* ACE_HAS_TRACE */ +# define NOOP_CONFIGURATOR_TRACE(X) ACE_TRACE_IMPL(X) +# include "ace/Trace.h" +#endif /* (NOOP_CONFIGURATOR_NTRACE == 1) */ + +#endif /* NOOP_CONFIGURATOR_EXPORT_H */ + +// End of auto generated file. diff --git a/CIAO/ciao/FTComponentServer/Configurators/RT/RTConfig_Manager.cpp b/CIAO/ciao/FTComponentServer/Configurators/RT/RTConfig_Manager.cpp new file mode 100644 index 00000000000..4ec837c06fe --- /dev/null +++ b/CIAO/ciao/FTComponentServer/Configurators/RT/RTConfig_Manager.cpp @@ -0,0 +1,513 @@ +// $Id$ + +#include "RTConfig_Manager.h" +#include "ciao/CIAO_common.h" +#include "ace/SString.h" + +#if !defined (__ACE_INLINE__) +# include "RTConfig_Manager.inl" +#endif /* __ACE_INLINE__ */ + +void +CIAO::Deployment::RTResource_Config_Manager::init (CORBA::ORB_ptr orb) +{ + CORBA::Object_var object = + orb->resolve_initial_references ("RTORB"); + this->rtorb_ = RTCORBA::RTORB::_narrow (object.in ()); +} + +int +CIAO::Deployment::RTResource_Config_Manager::pre_orb_initialize (void) +{ + return 0; +} + +int +CIAO::Deployment::RTResource_Config_Manager::post_orb_initialize (CORBA::ORB_ptr) +{ + return 0; +} + +void +CIAO::Deployment::RTResource_Config_Manager::print_resources +(const ServerResource &server_resource) +{ + const ORBResource &orb_resource + = server_resource.orb_config.orb_resources[0]; + + CORBA::ULong i; + + // Creating and binding name with RT Threadpool + for (i = 0; i < orb_resource.threadpool_list.length (); ++i) + { + CIAO_DEBUG ((LM_DEBUG, + "-RTResource_Config_Manager::print_resource threadpool: %s\n" + "\tStack size: %d\n" + "\tStatic: %d\n" + "\tDynamic %d\n" + "\tDefault Prio: %d\n" + "\tBuffering %s\n" + "\tMax Buffered: %d\n" + "\tBuffer Size %d\n", + orb_resource.threadpool_list[i].Id.in (), + orb_resource.threadpool_list[i].stacksize, + orb_resource.threadpool_list[i].static_threads, + orb_resource.threadpool_list[i].dynamic_threads, + orb_resource.threadpool_list[i].default_priority, + (orb_resource.threadpool_list[i].allow_request_buffering ? "Y" : "N"), + orb_resource.threadpool_list[i].max_buffered_requests, + orb_resource.threadpool_list[i].max_request_buffer_size)); + } + + for (i = 0; i < orb_resource.threadpool_with_lanes_list.length (); ++i) + { + CIAO_DEBUG ((LM_DEBUG, + "-RTResource_Config_Manager::print_resource threadpool_with %d, lanes: %s\n", + orb_resource.threadpool_with_lanes_list[i].threadpool_lanes.length (), + orb_resource.threadpool_with_lanes_list[i].Id.in ())); + + for (CORBA::ULong l = 0; + l < orb_resource.threadpool_with_lanes_list[i].threadpool_lanes.length (); + ++l) + { + CIAO_DEBUG ((LM_DEBUG, + "\tLane %d:\n" + "\t\tPriority: %d\n" + "\t\tStatic: %d\n" + "\t\tDynamic: %d\n", + l, + orb_resource.threadpool_with_lanes_list[i].threadpool_lanes[l].lane_priority, + orb_resource.threadpool_with_lanes_list[i].threadpool_lanes[l].static_threads, + orb_resource.threadpool_with_lanes_list[i].threadpool_lanes[l].dynamic_threads)); + } + CIAO_DEBUG ((LM_DEBUG, + "\tStack size: %d\n" + "\tBorrowing: %s\n" + "\tBuffering %s\n" + "\tMax Buffered: %d\n" + "\tBuffer Size %d\n", + orb_resource.threadpool_with_lanes_list[i].stacksize, + (orb_resource.threadpool_with_lanes_list[i].allow_borrowing ? "Y" : "N"), + (orb_resource.threadpool_with_lanes_list[i].allow_request_buffering ? "Y" : "N"), + orb_resource.threadpool_with_lanes_list[i].max_buffered_requests, + orb_resource.threadpool_with_lanes_list[i].max_request_buffer_size)); + } + + for (i = 0; i < orb_resource.connection_bands_list.length (); ++i) + { + CIAO_DEBUG ((LM_DEBUG, + "-RTResource_Config_Manager::print_resource connection %d bands: %s\n", + orb_resource.connection_bands_list[i].bands.length (), + orb_resource.connection_bands_list[i].Id.in ())); + + for (CORBA::ULong l = 0; + l < orb_resource.connection_bands_list[i].bands.length (); + ++l) + { + CIAO_DEBUG ((LM_DEBUG, + "\tBand %d Prio: %d -- %d\n", + l, + orb_resource.connection_bands_list[i].bands[l].low, + orb_resource.connection_bands_list[i].bands[l].high)); + } + } +} + +void +CIAO::Deployment::RTResource_Config_Manager::init_resources +(const ServerResource &server_resource) +{ + CIAO_DEBUG ((LM_DEBUG, + "RTResource_Config_Manager::init_resource.\n")); + + if (CORBA::is_nil (this->rtorb_.in())) + { + CIAO_ERROR ((LM_ERROR, + "RTResource_Config_Manager has not been properly initialized.\n")); + throw CORBA::INTERNAL (); + } + + this->print_resources (server_resource); + // return; + + const ORBResource &orb_resource + = server_resource.orb_config.orb_resources[0]; + + CORBA::ULong i; + + // Creating and binding name with RT Threadpool + for (i = 0; i < orb_resource.threadpool_list.length (); ++i) + { + CIAO_DEBUG ((LM_DEBUG, + "RTResource_Config_Manager::init_resource threadpool: %s\n", + orb_resource.threadpool_list[i].Id.in ())); + RTCORBA::ThreadpoolId thr_id = + this->rtorb_->create_threadpool + (orb_resource.threadpool_list[i].stacksize, + orb_resource.threadpool_list[i].static_threads, + orb_resource.threadpool_list[i].dynamic_threads, + orb_resource.threadpool_list[i].default_priority, + orb_resource.threadpool_list[i].allow_request_buffering, + orb_resource.threadpool_list[i].max_buffered_requests, + orb_resource.threadpool_list[i].max_request_buffer_size); + // Simply pass back the exception here + // for now. We need to have a better way + // to handle execption here. + if (this->threadpool_map_.bind (orb_resource.threadpool_list[i].Id.in (), + thr_id) != 0) + { + CIAO_ERROR ((LM_ERROR, "Error binding thread pool Id: %s to map when initializing RTNodeApplication resources.\n", orb_resource.threadpool_list[i].Id.in ())); + throw CORBA::INTERNAL (); + } + else + { + CIAO_DEBUG ((LM_DEBUG, + "RTResource_Config_Manager::init_resource added thread pool: %s\n", + orb_resource.threadpool_list[i].Id.in ())); + } + } + + for (i = 0; i < orb_resource.threadpool_with_lanes_list.length (); ++i) + { + CIAO_DEBUG ((LM_DEBUG, + "RTResource_Config_Manager::init_resource threadpool_with %d, lanes: %s\n", + orb_resource.threadpool_with_lanes_list[i].threadpool_lanes.length (), + orb_resource.threadpool_with_lanes_list[i].Id.in ())); + + // Duplicate RTCORBA lanes + RTCORBA::ThreadpoolLanes lanes + (orb_resource.threadpool_with_lanes_list[i].threadpool_lanes.length ()); + lanes.length (orb_resource.threadpool_with_lanes_list[i].threadpool_lanes.length ()); + + for (CORBA::ULong l = 0; + l < orb_resource.threadpool_with_lanes_list[i].threadpool_lanes.length (); + ++l) + { + lanes[l].lane_priority + = orb_resource.threadpool_with_lanes_list[i].threadpool_lanes[l].lane_priority; + lanes[l].static_threads + = orb_resource.threadpool_with_lanes_list[i].threadpool_lanes[l].static_threads; + lanes[l].dynamic_threads + = orb_resource.threadpool_with_lanes_list[i].threadpool_lanes[l].dynamic_threads; + } + + RTCORBA::ThreadpoolId thr_id = + this->rtorb_->create_threadpool_with_lanes + (orb_resource.threadpool_with_lanes_list[i].stacksize, + lanes, + orb_resource.threadpool_with_lanes_list[i].allow_borrowing, + orb_resource.threadpool_with_lanes_list[i].allow_request_buffering, + orb_resource.threadpool_with_lanes_list[i].max_buffered_requests, + orb_resource.threadpool_with_lanes_list[i].max_request_buffer_size); + // Simply pass back the exception here + // for now. We need to have a better way + // to handle execption here. + + if (this->threadpool_map_.bind (orb_resource.threadpool_with_lanes_list[i].Id.in (), + thr_id) != 0) + { + CIAO_ERROR ((LM_ERROR, + "Error binding thread pool name: %s to map when " + "initializing RTNodeApplication resources.\n", + orb_resource.threadpool_with_lanes_list[i].Id.in ())); + throw CORBA::INTERNAL (); + } + + else + { + CIAO_DEBUG ((LM_DEBUG, + "RTResource_Config_Manager::init_resource added thread pool with lanes: %s\n", + orb_resource.threadpool_with_lanes_list[i].Id.in ())); + } + } + + for (i = 0; i < orb_resource.connection_bands_list.length (); ++i) + { + RTCORBA::PriorityBands + safebands(orb_resource.connection_bands_list[i].bands.length ()); + safebands.length (orb_resource.connection_bands_list[i].bands.length ()); + + for (CORBA::ULong l = 0; + l < orb_resource.connection_bands_list[i].bands.length (); + ++l) + { + safebands[l].low = orb_resource.connection_bands_list[i].bands[l].low; + safebands[l].high = orb_resource.connection_bands_list[i].bands[l].high; + } + + if (this->priority_bands_map_.bind (orb_resource.connection_bands_list[i].Id.in (), + safebands) != 0) + { + CIAO_ERROR ((LM_ERROR, + "Error binding priority bands name: %s to map " + "when initializing RTNodeApplication resources.\n", + orb_resource.connection_bands_list[i].Id.in ())); + throw CORBA::INTERNAL (); + } + else + { + CIAO_DEBUG ((LM_DEBUG, + "RTResource_Config_Manager::init_resource added connection bands: %s\n", + orb_resource.connection_bands_list[i].Id.in ())); + } + } + + // now initialize the policy set part of it. + // server_resource.orb_config.policy_set + const PolicySets &sets = server_resource.orb_config.policy_set; + for (CORBA::ULong i = 0; i < sets.length (); ++i) + { + CORBA::ULong const np = sets[i].policies.length (); + if (np == 0) + continue; + + CORBA::PolicyList_var policy_list = new CORBA::PolicyList (np); + policy_list->length (np); + CORBA::ULong index = 0; + CORBA::ULong array_index = np; + + // Create a list of policies + for (CORBA::ULong pc = 0; pc < np; ++pc) + { + CORBA::Policy_var temp_policy = + this->create_single_policy (sets[i].policies[pc]); + if (CORBA::is_nil (temp_policy.in ())) + { + array_index = array_index - 1; + policy_list->length (array_index); + } + else + { + policy_list[index] = CORBA::Policy::_duplicate (temp_policy.in ()); + index = index + 1; + } + } + + // Bind the policy list to the name. The bind operation should + // surrender the ownership of the newly created PolicyList + // sequence to the map. + if (array_index != 0) + { + if (this->policy_map_.bind (sets[i].Id.in (), + policy_list._retn ()) != 0) + { + CIAO_ERROR ((LM_ERROR, + "Error binding Policy_Set with name: %s\n", + sets[i].Id.in ())); + throw CORBA::INTERNAL (); + } + else + { + CIAO_DEBUG ((LM_DEBUG, + "RTResource_Config_Manager::init_resource " + "added policy set: %s with %d policies\n", + sets[i].Id.in (), array_index)); + } + } + else + { + CIAO_DEBUG ((LM_DEBUG, + "RTResource_Config_Manager::init_resource " + "added policy set: %s with %d policies\n", + sets[i].Id.in (), array_index)); + } + } +} + +void +CIAO::Deployment::RTResource_Config_Manager::fini () +{ + TP_MAP::ITERATOR iter = this->threadpool_map_.begin (); + TP_MAP::ITERATOR end = this->threadpool_map_.end (); + + for (; iter != end; ++iter) + { + this->rtorb_->destroy_threadpool ((*iter).int_id_); + } + +} + +RTCORBA::ThreadpoolId +CIAO::Deployment::RTResource_Config_Manager::find_threadpool_by_name (const char *name) +{ + if (name == 0) + { + CIAO_ERROR ((LM_ERROR, + "Invalid name string found in \"find_threadpool_by_name\"\n")); + throw CORBA::BAD_PARAM (); + } + + + RTCORBA::ThreadpoolId ret_id = 0; // return id + + if (this->threadpool_map_.find (name, ret_id) != 0) + { + CIAO_ERROR ((LM_ERROR, + "Unable to find a threadpool named %s\n", + name)); + throw CORBA::INTERNAL (); + } + + return ret_id; +} + +RTCORBA::PriorityBands * +CIAO::Deployment::RTResource_Config_Manager::find_priority_bands_by_name (const char *name) +{ + if (name == 0) + { + CIAO_ERROR ((LM_ERROR, + "Invalid name string found in \"find_priority_bands_by_name\"\n")); + throw CORBA::BAD_PARAM (); + } + + PB_MAP::ENTRY *entry = 0; + + if (this->priority_bands_map_.find (name, entry) != 0) + { + CIAO_ERROR ((LM_ERROR, + "Unable to find a connection bands named %s\n", + name)); + throw CORBA::INTERNAL (); + } + + RTCORBA::PriorityBands_var retv = new RTCORBA::PriorityBands; + (*retv.ptr ()) = (*entry->int_id_.ptr ()); + return retv._retn (); +} + +bool +CIAO::Deployment::RTResource_Config_Manager::policy_exists (const char *name) +{ + if (name == 0) + { + CIAO_DEBUG ((LM_DEBUG, + "Invalid name string found in " + "CIAO::Deployment::NAResource_Config_Manager::policy_exists\n")); + throw CORBA::INTERNAL (); + } + + POLICY_MAP::ENTRY *entry = 0; + + if (this->policy_map_.find (name, entry) != 0) + { + return false; + } + + return true; +} + +CORBA::PolicyList * +CIAO::Deployment::RTResource_Config_Manager::find_policies_by_name (const char *name) +{ + if (name == 0) + { + CIAO_ERROR ((LM_ERROR, + "Invalid name string found in \"find_policies_by_name\"\n")); + throw CORBA::BAD_PARAM (); + } + + + CIAO_DEBUG ((LM_DEBUG, "RTResource_Config_Manager::find_policies_by_name: %s\n", + name)); + + POLICY_MAP::ENTRY *entry = 0; + + if (this->policy_map_.find (name, entry) != 0) + { + CIAO_ERROR ((LM_ERROR, + "Unable to find a PolicyList named %s\n", + name)); + throw CORBA::INTERNAL (); + } + + // duplicate the sequence PolicyList. + CORBA::PolicyList_var retv = + new CORBA::PolicyList (entry->int_id_.in ()); + + CIAO_DEBUG ((LM_DEBUG, "RTResource_Config_Manager::find_policies_by_name ok.\n")); + + return retv._retn (); +} + +CORBA::Policy_ptr +CIAO::Deployment::RTResource_Config_Manager::create_single_policy +(const PolicyDef &policy_def) +{ + // if (CIAO::Deployment::debug_level () > 9) + CIAO_DEBUG ((LM_DEBUG, + "RTResource_Config_Manager::create_single_policy: %d\n", + policy_def._d ())); + + CORBA::Policy_var retv; + + switch (policy_def._d ()) + { + case RTCORBA::PRIORITY_MODEL_POLICY_TYPE: + { + const PriorityModelPolicyDef &tmp + = policy_def.PriorityModelDef (); + + retv = this->rtorb_->create_priority_model_policy ((RTCORBA::PriorityModel) tmp.priority_model, + tmp.server_priority); + + if (! CORBA::is_nil (retv.in ())) + CIAO_DEBUG ((LM_DEBUG, + "Create PriorityModel policy: %d - %d\n", + tmp.priority_model, tmp.server_priority)); + } + break; + + case RTCORBA::THREADPOOL_POLICY_TYPE: + { + RTCORBA::ThreadpoolId tpid = + this->find_threadpool_by_name (policy_def.ThreadpoolDef().Id.in ()); + + retv = this->rtorb_->create_threadpool_policy (tpid); + + if (! CORBA::is_nil (retv.in ())) + CIAO_DEBUG ((LM_DEBUG, + "Create Threadpool policy: %s, TPid: %d\n", + policy_def.ThreadpoolDef().Id.in (), tpid)); + } + break; + + case RTCORBA::PRIORITY_BANDED_CONNECTION_POLICY_TYPE: + { + RTCORBA::PriorityBands_var bands = + this->find_priority_bands_by_name (policy_def.PriorityBandedConnectionDef().Id.in ()); + + retv = + this->rtorb_->create_priority_banded_connection_policy (bands.in ()); + + if (! CORBA::is_nil (retv.in ())) + { + CIAO_DEBUG ((LM_DEBUG, + "Created Banded Connection policy: %s\n", + policy_def.PriorityBandedConnectionDef().Id.in ())); + } + } + break; + + default: + retv = 0; + } + + return retv._retn (); +} + +CIAO::Deployment::RTResource_Config_Manager::~RTResource_Config_Manager () +{ + this->fini (); +} + +extern "C" CIAO_RTNA_Configurator_Export CIAO::Deployment::Config_Manager +*create_rt_config_manager (void); + +CIAO::Deployment::Config_Manager * +create_rt_config_manager (void) +{ + CIAO::Deployment::RTResource_Config_Manager *config; + ACE_NEW_RETURN (config, CIAO::Deployment::RTResource_Config_Manager, 0); + return config; +} diff --git a/CIAO/ciao/FTComponentServer/Configurators/RT/RTConfig_Manager.h b/CIAO/ciao/FTComponentServer/Configurators/RT/RTConfig_Manager.h new file mode 100644 index 00000000000..fbbea84d706 --- /dev/null +++ b/CIAO/ciao/FTComponentServer/Configurators/RT/RTConfig_Manager.h @@ -0,0 +1,138 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file RTConfig_Manager.h + * + * $Id$ + * + * This file contains classes that manage name to configuration + * mapping info in a RTComponentServer. + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= + + +#ifndef CIAO_RTCONFIG_MANAGER_H +#define CIAO_RTCONFIG_MANAGER_H +#include /**/ "ace/pre.h" + +#include "ace/config-all.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ace/Null_Mutex.h" +#include "ace/SString.h" +#include "ace/Hash_Map_Manager_T.h" +#include "tao/RTCORBA/RTCORBA.h" +#include "ciao/ComponentServer/CIAO_ServerResourcesC.h" + +#include "ciao/ComponentServer/Configurators/Config_Manager.h" +#include "RTNA_Configurator_Export.h" + +namespace CIAO +{ + namespace Deployment + { + /** + * @brief RTResource_Config_Manager maintains a collection of + * RTCORBA related resources. + * + * This class is responsible to create and manage a list of RTCORBA + * related resources that are global to an RT ComponentServer. The + * information required to create and configure these resources are + * passed in via the @a info argument in the @c init method. These + * resources are identified by names and can be used to associate + * these resources with related RTPolicies. These resources are + * destoryed along with this class. + * + * Currently, the only resources supported (and managed) by this + * class are Threadpool and Threadpool_with_Lanes. + */ + class RTResource_Config_Manager : public Config_Manager + { + public: + RTResource_Config_Manager (void); + ~RTResource_Config_Manager (void); + + virtual void init (CORBA::ORB_ptr orb); + + virtual int pre_orb_initialize (void); + + virtual int post_orb_initialize (CORBA::ORB_ptr o); + + /// Initializing the RTResource_Config_Manager + virtual void init_resources (const ServerResource &info); + + /// Finalizing the RTResource_Config_Manager and the resources it + /// manages. + void fini (); + + /// Query a policy set by name + virtual CORBA::PolicyList *find_policies_by_name (const char *name); + + virtual bool policy_exists (const char *name); + + protected: + void print_resources (const ServerResource &info); + + /// Query a thread pool by name. + RTCORBA::ThreadpoolId find_threadpool_by_name (const char *name); + + + /// Query a priority bands info by name. + RTCORBA::PriorityBands *find_priority_bands_by_name (const char *name); + + private: + /// Cached an ORB reference. + CORBA::ORB_var orb_; + + // Cached an RTORB reference. + RTCORBA::RTORB_var rtorb_; + + /// Hash_Map stuff. + typedef ACE_Hash_Map_Manager_Ex<ACE_CString, + RTCORBA::ThreadpoolId, + ACE_Hash<ACE_CString>, + ACE_Equal_To<ACE_CString>, + ACE_Null_Mutex> TP_MAP; + + typedef ACE_Hash_Map_Manager_Ex<ACE_CString, + RTCORBA::PriorityBands_var, + ACE_Hash<ACE_CString>, + ACE_Equal_To<ACE_CString>, + ACE_Null_Mutex> PB_MAP; + + /// Internal TP name to id map. + TP_MAP threadpool_map_; + + /// Internal PB name to priority bands map. + PB_MAP priority_bands_map_; + + /// create a single policy + CORBA::Policy_ptr create_single_policy + (const PolicyDef &policy_def); + + /// Hash_Map stuff. + typedef ACE_Hash_Map_Manager_Ex<ACE_CString, + CORBA::PolicyList_var, + ACE_Hash<ACE_CString>, + ACE_Equal_To<ACE_CString>, + ACE_Null_Mutex> POLICY_MAP; + + /// Internal TP names to id map. + POLICY_MAP policy_map_; +}; +} +} + +#if defined (__ACE_INLINE__) +# include "RTConfig_Manager.inl" +#endif /* __ACE_INLINE__ */ + +#include /**/ "ace/post.h" +#endif /* CIAO_RTCONFIG_MANAGER_H */ + diff --git a/CIAO/ciao/FTComponentServer/Configurators/RT/RTConfig_Manager.inl b/CIAO/ciao/FTComponentServer/Configurators/RT/RTConfig_Manager.inl new file mode 100644 index 00000000000..08aaef9f6ad --- /dev/null +++ b/CIAO/ciao/FTComponentServer/Configurators/RT/RTConfig_Manager.inl @@ -0,0 +1,8 @@ +// $Id$ + + +ACE_INLINE +CIAO::Deployment::RTResource_Config_Manager::RTResource_Config_Manager () +{ +} + diff --git a/CIAO/ciao/FTComponentServer/Configurators/RT/RTNA_Configurator_Export.h b/CIAO/ciao/FTComponentServer/Configurators/RT/RTNA_Configurator_Export.h new file mode 100644 index 00000000000..689a871c7e5 --- /dev/null +++ b/CIAO/ciao/FTComponentServer/Configurators/RT/RTNA_Configurator_Export.h @@ -0,0 +1,58 @@ + +// -*- C++ -*- +// $Id$ +// Definition for Win32 Export directives. +// This file is generated automatically by generate_export_file.pl CIAO_RTNA_Configurator +// ------------------------------ +#ifndef CIAO_RTNA_CONFIGURATOR_EXPORT_H +#define CIAO_RTNA_CONFIGURATOR_EXPORT_H + +#include "ace/config-all.h" + +#if defined (ACE_AS_STATIC_LIBS) && !defined (CIAO_RTNA_CONFIGURATOR_HAS_DLL) +# define CIAO_RTNA_CONFIGURATOR_HAS_DLL 0 +#endif /* ACE_AS_STATIC_LIBS && CIAO_RTNA_CONFIGURATOR_HAS_DLL */ + +#if !defined (CIAO_RTNA_CONFIGURATOR_HAS_DLL) +# define CIAO_RTNA_CONFIGURATOR_HAS_DLL 1 +#endif /* ! CIAO_RTNA_CONFIGURATOR_HAS_DLL */ + +#if defined (CIAO_RTNA_CONFIGURATOR_HAS_DLL) && (CIAO_RTNA_CONFIGURATOR_HAS_DLL == 1) +# if defined (CIAO_RTNA_CONFIGURATOR_BUILD_DLL) +# define CIAO_RTNA_Configurator_Export ACE_Proper_Export_Flag +# define CIAO_RTNA_CONFIGURATOR_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) +# define CIAO_RTNA_CONFIGURATOR_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# else /* CIAO_RTNA_CONFIGURATOR_BUILD_DLL */ +# define CIAO_RTNA_Configurator_Export ACE_Proper_Import_Flag +# define CIAO_RTNA_CONFIGURATOR_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) +# define CIAO_RTNA_CONFIGURATOR_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# endif /* CIAO_RTNA_CONFIGURATOR_BUILD_DLL */ +#else /* CIAO_RTNA_CONFIGURATOR_HAS_DLL == 1 */ +# define CIAO_RTNA_Configurator_Export +# define CIAO_RTNA_CONFIGURATOR_SINGLETON_DECLARATION(T) +# define CIAO_RTNA_CONFIGURATOR_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +#endif /* CIAO_RTNA_CONFIGURATOR_HAS_DLL == 1 */ + +// Set CIAO_RTNA_CONFIGURATOR_NTRACE = 0 to turn on library specific tracing even if +// tracing is turned off for ACE. +#if !defined (CIAO_RTNA_CONFIGURATOR_NTRACE) +# if (ACE_NTRACE == 1) +# define CIAO_RTNA_CONFIGURATOR_NTRACE 1 +# else /* (ACE_NTRACE == 1) */ +# define CIAO_RTNA_CONFIGURATOR_NTRACE 0 +# endif /* (ACE_NTRACE == 1) */ +#endif /* !CIAO_RTNA_CONFIGURATOR_NTRACE */ + +#if (CIAO_RTNA_CONFIGURATOR_NTRACE == 1) +# define CIAO_RTNA_CONFIGURATOR_TRACE(X) +#else /* (CIAO_RTNA_CONFIGURATOR_NTRACE == 1) */ +# if !defined (ACE_HAS_TRACE) +# define ACE_HAS_TRACE +# endif /* ACE_HAS_TRACE */ +# define CIAO_RTNA_CONFIGURATOR_TRACE(X) ACE_TRACE_IMPL(X) +# include "ace/Trace.h" +#endif /* (CIAO_RTNA_CONFIGURATOR_NTRACE == 1) */ + +#endif /* CIAO_RTNA_CONFIGURATOR_EXPORT_H */ + +// End of auto generated file. diff --git a/CIAO/ciao/FTComponentServer/Configurators/RTNodeApp_Configurator.cpp b/CIAO/ciao/FTComponentServer/Configurators/RTNodeApp_Configurator.cpp new file mode 100644 index 00000000000..5f199f366aa --- /dev/null +++ b/CIAO/ciao/FTComponentServer/Configurators/RTNodeApp_Configurator.cpp @@ -0,0 +1,108 @@ +// $Id$ + +#include "RTNodeApp_Configurator.h" +#include "DAnCE/Deployment/CIAO_ServerResourcesC.h" +#include "tao/RTPortableServer/RTPortableServer.h" + +CIAO::RTNodeApp_Configurator::~RTNodeApp_Configurator () +{ +} + +int +CIAO::RTNodeApp_Configurator::pre_orb_initialize () +{ + CIAO_DEBUG ((LM_DEBUG, "RTNodeApp_Configurator::pre_orb_init\n")); + + return 0; +} + +int +CIAO::RTNodeApp_Configurator::post_orb_initialize (CORBA::ORB_ptr o) +{ + CIAO_DEBUG ((LM_DEBUG, "RTNodeApp_Configurator::post_orb_init\n")); + + this->orb_ = CORBA::ORB::_duplicate (o); + + CORBA::Object_var object = + this->orb_->resolve_initial_references ("RTORB"); + + this->rtorb_ = + RTCORBA::RTORB::_narrow (object.in ()); + + this->config_manager_.init (this->rtorb_.in ()); + + return 0; +} + +int +CIAO::RTNodeApp_Configurator::init_resource_manager +(const ::Deployment::Properties &properties) +{ + + // if (CIAO::debug_level () > 9) + CIAO_DEBUG ((LM_DEBUG, "RTNodeApp_Configurator::init_resource_manager\n")); + // @@ Should we cache the properties that we consumed here? + + for (CORBA::ULong i = 0; i < properties.length (); ++i) + { + // if (CIAO::debug_level () > 9) + CIAO_DEBUG ((LM_DEBUG, "RTNodeApp_Configurator::init_resource_manager processing property: %s\n", + properties[i].name.in ())); + + if (ACE_OS::strcmp ("CIAOServerResources", properties[i].name.in ()) == 0) + { + const CIAO::DAnCE::ServerResource *svr_resource; + if (properties[i].value >>= svr_resource) + { + this->config_manager_.init_resources (*svr_resource); + // Now we have the information to initialize the manager. + } + else + CIAO_ERROR_RETURN ((LM_ERROR, + "ERROR: RTNodeApp_Configurator::init_resource_manager unable to extract CIAOServerResources\n"), -1); + } + + // Ignore other stuff + } + + return 0; +} + +CORBA::PolicyList * +CIAO::RTNodeApp_Configurator::find_container_policies +(const ::Deployment::Properties &properties) +{ + CIAO_DEBUG ((LM_DEBUG, "RTNodeApp_Configurator::find_container_policies\n")); + // @@ Should we cache the properties that we consumed here? + + for (CORBA::ULong i = 0; i < properties.length (); ++i) + { + CIAO_DEBUG ((LM_DEBUG, "RTNodeApp_Configurator::find_container_policies processing property: %s\n", + properties[i].name.in ())); + + if (ACE_OS::strcmp ("ContainerPolicySet", properties[i].name) == 0) + { + const char *policy_name = 0; + if (properties[i].value >>= policy_name) + { + return this->config_manager_.find_policies_by_name (policy_name); + } + else + CIAO_ERROR_RETURN ((LM_ERROR, + "ERROR: RTNodeApp_Configurator::find_container_policies unable to extract ContainerPolicySet\n"), 0); + } + } + + return 0; +} + + +extern "C" CIAO_RTNA_Configurator_Export CIAO::NodeApp_Configurator *create_nodeapp_configurator (void); + +CIAO::NodeApp_Configurator * +create_nodeapp_configurator (void) +{ + CIAO::RTNodeApp_Configurator *config = 0; + ACE_NEW_RETURN (config, CIAO::RTNodeApp_Configurator, 0); + return config; +} diff --git a/CIAO/ciao/FTComponentServer/Configurators/RTNodeApp_Configurator.h b/CIAO/ciao/FTComponentServer/Configurators/RTNodeApp_Configurator.h new file mode 100644 index 00000000000..fc2388b6aff --- /dev/null +++ b/CIAO/ciao/FTComponentServer/Configurators/RTNodeApp_Configurator.h @@ -0,0 +1,78 @@ +// $Id$ +/**======================================================== + * + * @file RTNodeApp_Configurator.h + * + * @Brief This file contains the implementation of + * the RTNodeApp_Configurator, a concrete NodeApp_Configurator for + * setting up real-time support for NodeApplication. + * + * + * @author Nanbor Wang <nanbor@exothermic.txcorp.com> + *========================================================*/ + +#ifndef RTNODEAPP_CONFIGURATOR_H +#define RTNODEAPP_CONFIGURATOR_H +#include /**/ "ace/pre.h" + +#include "ace/config-all.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "NodeApp_Configurator.h" +#include "RTNA_Configurator_Export.h" +#include "tao/RTCORBA/RTCORBA.h" +#include "RTConfig_Manager.h" + +namespace CIAO +{ + /** + * @class RTNodeApp_Configurator + * + * @brief This class implements a concrete NodeApp_Configurator for + * setting up the NodeApplication process for RT support. + **/ + class CIAO_RTNA_Configurator_Export RTNodeApp_Configurator : + public NodeApp_Configurator + { + public: + /// Default destructor. + virtual ~RTNodeApp_Configurator (void); + + /** + * @brief "pre_orb_initialize" is called before ORB_init. + */ + virtual int pre_orb_initialize (void); + + /** + * @brief "initialize" is called after NodeApplication get a hold + * at this object. + */ + virtual int post_orb_initialize (CORBA::ORB_ptr o); + + /** + * @brief "init_resource_manager" is called by NodeApplication when + * it receives an "install" commands. + */ + virtual int + init_resource_manager (const ::Deployment::Properties &properties); + + /** + * @brief get a policyset by its name. + */ + virtual CORBA::PolicyList * + find_container_policies (const ::Deployment::Properties &properties); + + protected: + CORBA::ORB_var orb_; + + RTCORBA::RTORB_var rtorb_; + + RTResource_Config_Manager config_manager_; + }; +} + +#include /**/ "ace/post.h" +#endif /* RTNODEAPP_CONFIGURATOR_H */ diff --git a/CIAO/ciao/FTComponentServer/Configurators/Server_Configurator.cpp b/CIAO/ciao/FTComponentServer/Configurators/Server_Configurator.cpp new file mode 100644 index 00000000000..406817972de --- /dev/null +++ b/CIAO/ciao/FTComponentServer/Configurators/Server_Configurator.cpp @@ -0,0 +1,334 @@ +// $Id$ + +#include "Server_Configurator.h" +#include "ace/Log_Msg.h" +#include "ciao/CIAO_common.h" +#include "ciao/ComponentServer/CIAO_ServerResourcesC.h" + +namespace CIAO +{ + namespace Deployment + { + + ComponentServer_Configurator::ComponentServer_Configurator (bool rt) + : rt_support_ (rt) + { + } + + ComponentServer_Configurator::~ComponentServer_Configurator (void) + { + // Not much to do. + } + + void + ComponentServer_Configurator::set_rt_support (void) + { + this->rt_support_ = 1; + } + + bool + ComponentServer_Configurator::rt_support (void) + { + return this->rt_support_; + } + + bool + ComponentServer_Configurator::create_config_managers (void) + { + typedef CIAO::Deployment::Config_Manager * (*na_intelligent_designer)(void); + typedef CIAO::Deployment::Config_Manager * (*rtna_intelligent_designer)(void); + CIAO::Deployment::Config_Manager* ptr = 0; + CIAO::Deployment::Config_Manager* rt_ptr = 0; + + int retval = this->config_dll_.open (/*ACE_DLL_PREFIX*/ ACE_TEXT ("CIAO_Basic_Config_Manager"), + ACE_DEFAULT_SHLIB_MODE, + 0); + + if (0 != retval) + { + CIAO_ERROR_RETURN ((LM_ERROR, + CLINFO "ComponentServer_Configurator - Error loading CIAO_Basic_Config_manager DLL: %p\n", + "dll.open"), + false); + } + + // Cast the void* to non-pointer type first - it's not legal to + // cast a pointer-to-object directly to a pointer-to-function. + void *void_ptr = + this->config_dll_.symbol (ACE_TEXT ("create_basic_config_manager")); + + ptrdiff_t tmp = reinterpret_cast<ptrdiff_t> (void_ptr); + + // "id" is for na_intelligent-designer. + na_intelligent_designer config_id = + reinterpret_cast<na_intelligent_designer> (tmp); + + if (0 == config_id) + { + CIAO_ERROR_RETURN ((LM_ERROR, + CLINFO "ComponentServer_Configurator - Error loading CIAO_Basic_Configurator entrypoint: %p\n", + "dll.symbol"), + false); + } + + ptr = config_id (); + + if (0 == ptr) + { + CIAO_ERROR_RETURN ((LM_ERROR, + CLINFO "ComponentServer_Configurator: Error creating ComponentServer_Configurator\n"), + false); + } + + this->na_config_manager_.reset (ptr); + + if (this->rt_support_) + { + int rt_retval = this->config_dll_.open (ACE_DLL_PREFIX ACE_TEXT ("CIAO_RTNA_Configurator"), + ACE_DEFAULT_SHLIB_MODE, + false); + + if (0 != rt_retval) + { + CIAO_ERROR_RETURN ((LM_ERROR, + "ComponentServer_Configurator - Error while loading CIAO_RTNA_Configurator: %p\n", + "dll.open"), + false); + } + + // Cast the void* to non-pointer type first - it's not legal to + // cast a pointer-to-object directly to a pointer-to-function. + void *rt_void_ptr = + this->config_dll_.symbol (ACE_TEXT ("create_rt_config_manager")); + ptrdiff_t rt_tmp = reinterpret_cast<ptrdiff_t> (rt_void_ptr); + + // "id" is for na_intelligent-designer. + rtna_intelligent_designer rt_config_id = + reinterpret_cast<rtna_intelligent_designer> (rt_tmp); + + if (0 == rt_config_id) + { + CIAO_ERROR_RETURN ((LM_ERROR, + CLINFO "ComponentServer_Configurator: Error while using RTNA entrypoint: %p", + "dll.symbol"), + false); + } + + rt_ptr = rt_config_id (); + + if (0 == rt_ptr) + { + CIAO_ERROR_RETURN ((LM_ERROR, + CLINFO "ComponentServer_Configurator: Error creating RTComponentServer_Configurator\n"), + false); + } + + this->rt_config_manager_.reset (rt_ptr); + } + + return true; + } + + int + ComponentServer_Configurator::pre_orb_initialize () + { + CIAO_DEBUG ((LM_TRACE,CLINFO "ComponentServer_Configurator::pre_orb_init\n")); + + (*this->na_config_manager_.get ()).pre_orb_initialize (); + if (this->rt_support_) + { + (*this->rt_config_manager_.get ()).pre_orb_initialize (); + } + + return 0; + } + + int + ComponentServer_Configurator::post_orb_initialize (CORBA::ORB_ptr o) + { + CIAO_DEBUG ((LM_TRACE, CLINFO "ComponentServer_Configurator::post_orb_init\n")); + this->orb_ = CORBA::ORB::_duplicate (o); + + (*this->na_config_manager_.get ()).init (this->orb_.in ()); + if (this->rt_support_ == 1) + { + (*this->rt_config_manager_.get ()).init (this->orb_.in ()); + } + + (*this->na_config_manager_.get ()).post_orb_initialize (this->orb_.in ()); + if (this->rt_support_ == 1) + { + (*this->rt_config_manager_.get ()).post_orb_initialize (this->orb_.in ()); + } + + return 0; + } + + int + ComponentServer_Configurator::init_resource_manager + (const ::Components::ConfigValues &properties) + { + for (CORBA::ULong i = 0; i < properties.length (); ++i) + { + if (ACE_OS::strcmp ("CIAOServerResources", properties[i]->name ()) == 0) + { + const ServerResource *svr_resource; + if (properties[i]->value () >>= svr_resource) + { + (*this->na_config_manager_.get ()). + init_resources (*svr_resource); + + if (this->rt_support_ == 1) + { + (*this->rt_config_manager_.get ()). + init_resources (*svr_resource); + } + } + else + { + CIAO_ERROR_RETURN ((LM_ERROR, + CLINFO "ERROR: ComponentServer_Configurator::" + "init_resource_manager unable to extract" + "CIAOServerResources\n"), -1); + } + } + } + + return 0; + } + + CORBA::PolicyList * + ComponentServer_Configurator::find_container_policies + (const ::Components::ConfigValues &properties) + { + if (!this->na_config_manager_.get ()) + return 0; + + CORBA::PolicyList *configured_policies = 0; + CORBA::PolicyList *rt_configured_policies = 0; + + for (CORBA::ULong i = 0; i < properties.length (); ++i) + { + if (ACE_OS::strcmp ("ContainerPolicySet", properties[i]->name ()) == 0) + { + const char *policy_name; + if (properties[i]->value () >>= policy_name) + { + configured_policies = (*this->na_config_manager_.get ()). + find_policies_by_name (policy_name); + + CORBA::ULong p_length = 0; + if (configured_policies != 0) + { + p_length = configured_policies->length (); + } + + if (this->rt_support_ == 1) + { + rt_configured_policies = (*this->rt_config_manager_.get ()). + find_policies_by_name (policy_name); + } + + CORBA::PolicyList_var temp_policies; + CORBA::ULong rtp_length = 0; + if (rt_configured_policies != 0) + { + rtp_length = rt_configured_policies->length (); + temp_policies = rt_configured_policies; + } + else + { + return configured_policies; + } + + CORBA::ULong final_length = p_length + rtp_length; + temp_policies->length (final_length); + + for (CORBA::ULong i = 0; i < p_length; ++i) + { + temp_policies[i+rtp_length] = + CORBA::Policy::_duplicate ((*configured_policies)[i]); + } + return temp_policies._retn (); + } + else + { + CIAO_ERROR_RETURN ((LM_ERROR, + CLINFO "ERROR: ComponentServer_Configurator:" + "find_container_policies unable to extract" + "ContainerPolicySet\n"), 0); + } + } + } + return 0; + } + + CORBA::PolicyList * + ComponentServer_Configurator::find_policies_by_name (const char *policy_name) + { + if (!this->na_config_manager_.get ()) + return 0; + + CORBA::PolicyList *configured_policies = 0; + CORBA::PolicyList *rt_configured_policies = 0; + + configured_policies = (*this->na_config_manager_.get ()). + find_policies_by_name (policy_name); + + CORBA::ULong p_length = 0; + if (configured_policies != 0) + { + p_length = configured_policies->length (); + } + + if (this->rt_support_ == 1) + { + rt_configured_policies = (*this->rt_config_manager_.get ()). + find_policies_by_name (policy_name); + } + + CORBA::PolicyList_var temp_policies; + CORBA::ULong rtp_length = 0; + if (rt_configured_policies != 0) + { + rtp_length = rt_configured_policies->length (); + temp_policies = rt_configured_policies; + } + else + { + return configured_policies; + } + + CORBA::ULong final_length = p_length + rtp_length; + temp_policies->length (final_length); + + for (CORBA::ULong i = 0; i < p_length; ++i) + { + temp_policies[i+rtp_length] = + CORBA::Policy::_duplicate ((*configured_policies)[i]); + } + return temp_policies._retn (); + } + + bool + ComponentServer_Configurator::policy_exists (const char *policy_set_id) + { + if (!this->na_config_manager_.get ()) + return 0; + + bool result; + result = (*this->na_config_manager_.get ()). + policy_exists (policy_set_id); + + if (result == false) + { + if (this->rt_support_ == 1) + { + result = (*this->rt_config_manager_.get ()). + policy_exists (policy_set_id); + } + } + return result; + } + } +} diff --git a/CIAO/ciao/FTComponentServer/Configurators/Server_Configurator.h b/CIAO/ciao/FTComponentServer/Configurators/Server_Configurator.h new file mode 100644 index 00000000000..4a8074b083d --- /dev/null +++ b/CIAO/ciao/FTComponentServer/Configurators/Server_Configurator.h @@ -0,0 +1,125 @@ +//$Id$ +/**======================================================== + * + * @file ComponentServer_Configurator.h + * + * @Brief This file contains the implementation of + * the basic ComponentServer_Configurator interface, the one + * that does nothing more + * + * @author Nanbor Wang <nanbor@exothermic.txcorp.com> + *========================================================*/ + +#ifndef COMPONENTSERVER_CONFIGURATOR_H +#define COMPONENTSERVER_CONFIGURATOR_H +#include /**/ "ace/pre.h" + +#include "ace/config-all.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ace/DLL.h" +#include "ace/Auto_Ptr.h" +#include "ccm/CCM_StandardConfiguratorC.h" +#include "ComponentServer_Configurator_export.h" +#include "Config_Manager.h" + +namespace CIAO +{ + namespace Deployment + { + /** + * + * @class ComponentServer_Configurator + * + * @brief This class defines and implements the default + * ComponentServer_Configurator base class that's needed for configuring the + * ComponentServer application process. + **/ + class ComponentServer_Configurator_Export ComponentServer_Configurator + { + public: + + /// Default constructor. + ComponentServer_Configurator (bool rt); + + /// Default destructor. + virtual ~ComponentServer_Configurator (void); + + /** + * @brief "pre_orb_initialize" is called before ORB_init. + */ + virtual int pre_orb_initialize (void); + + /** + * @brief "post_orb_initialize" is called after ComponentServer + * get a hold at this object. + */ + virtual int post_orb_initialize (CORBA::ORB_ptr o); + + /** + * @brief "init_resource_manager" is called by ComponentServer when + * it receives an "install" commands. + */ + virtual int + init_resource_manager (const ::Components::ConfigValues &properties); + + /** + * @brief get a policyset by its name. + */ + virtual CORBA::PolicyList * + find_container_policies (const ::Components::ConfigValues &properties); + + /// @@ Perhaps we also need a finalizer method here. Perhaps we + /// even need to differentiate finalizer before ORB is destroyed + /// and the one after that. + + bool rt_support (void); + + void set_rt_support (void); + + virtual bool create_config_managers (void); + + bool policy_exists (const char *policy_set_id); + + CORBA::PolicyList * + find_policies_by_name (const char *name); + + protected: + + int rt_support_; + + CORBA::ORB_var orb_; + + auto_ptr<Config_Manager> rt_config_manager_; + + auto_ptr<Config_Manager> na_config_manager_; + + ACE_DLL config_dll_; + }; + } +} + +/** + * For dynamically linkable concrete ComponentServer_Configurator + * implementation, remember to create a factory method using "C" + * calling convention in the CPP file as follow: + + extern "C" EXPORT_MACRO CIAO::ComponentServer_Configurator *create_nodeapp_configurator (void); + + CIAO::ComponentServer_Configurator * + create_nodeapp_configurator (void) + { + concrete_ComponentServer_Configurator *config; + ACE_NEW_RETURN (config, concrete_ComponentServer_Configurator, 0); + return config; + } + +*/ + + +#include /**/ "ace/post.h" +#endif /* NODEAPP_CONFIGURATOR_H */ + diff --git a/CIAO/ciao/FTComponentServer/Name_Helper_T.h b/CIAO/ciao/FTComponentServer/Name_Helper_T.h new file mode 100644 index 00000000000..16da1d6c901 --- /dev/null +++ b/CIAO/ciao/FTComponentServer/Name_Helper_T.h @@ -0,0 +1,196 @@ +#ifndef _NAME_HELPER_T_H_ +#define _NAME_HELPER_T_H_ + +#include <stdexcept> +#include <orbsvcs/CosNamingC.h> +#include <ace/Env_Value_T.h> + +class Name_Helper_Exception : public std::domain_error +{ + public: + Name_Helper_Exception (const std::string & reason = "") + : std::domain_error (reason) {} +}; + +template <typename T> +class Name_Helper_T +{ + public: + Name_Helper_T (CORBA::ORB_ptr orb, bool use_env_var = false) + { + CORBA::Object_var ns_obj; + + if (use_env_var) + { + std::string ns_ior = ACE_Env_Value<std::string> ("NameServiceIOR", + std::string ()); + + if (ns_ior.empty ()) + { + throw Name_Helper_Exception ("Name_Helper_T - no NameServiceIOR env variable"); + } + + ns_obj = orb->string_to_object (ns_ior.c_str ()); + } + else + { + ns_obj = orb->resolve_initial_references ("NameService"); + } + + if (CORBA::is_nil (ns_obj.in ())) + { + throw Name_Helper_Exception ("Name_Helper_T - could not resolve NameService"); + } + + ns_ = CosNaming::NamingContextExt::_narrow (ns_obj.in ()); + + if (CORBA::is_nil (ns_.in ())) + { + throw Name_Helper_Exception ("Name_Helper_T - could not narrow to NameContextExt"); + } + } + + void bind (std::string path, typename T::_ptr_type obj) + { + size_t last_slash = path.find_last_of ('/'); + + std::string obj_name; + std::string obj_path; + + if (last_slash != std::string::npos) + { + obj_path = path.substr (0, last_slash); + obj_name = path.substr (last_slash + 1); + } + else + { + obj_name = path; + } + + if (obj_name.empty ()) + throw Name_Helper_Exception ("Name_Helper_T::bind - no object name."); + + ACE_DEBUG ((LM_INFO, "path=%s, name=%s\n", obj_path.c_str (), obj_name.c_str ())); + + CosNaming::Name_var name; + CosNaming::NamingContext_var nc; + + if (!obj_path.empty ()) + { + name = ns_->to_name (obj_path.c_str ()); + + nc = CosNaming::NamingContext::_narrow (ns_.in ()); + + CosNaming::Name entry; + entry.length (1); + + for (size_t i = 0; + i < name->length (); + ++i) + { + entry[0] = CosNaming::NameComponent (name[i]); + try + { + nc = nc->bind_new_context (entry); + } + catch (CosNaming::NamingContext::AlreadyBound & ex) + { + // if the entry is already there just go on + nc = CosNaming::NamingContext::_narrow (nc->resolve (entry)); + } + } + } + + name = ns_->to_name (obj_name.c_str ()); + + try + { + nc->bind (name, obj); + } + catch (CosNaming::NamingContext::AlreadyBound & e) + { + nc->rebind (name, obj); + } + } + + void unbind (const std::string & path, size_t depth = 0) + { + std::string current_path = path; + size_t current_depth = 0; + CosNaming::Name_var name; + + if (path.empty ()) + throw Name_Helper_Exception ("Name_Helper_T::unbind - empty path"); + + do + { + name = ns_->to_name (current_path.c_str ()); + + CosNaming::NamingContext_var nc = + CosNaming::NamingContext::_narrow ( + ns_->resolve (name.in ())); + + bool no_more_entries = true; + + if (!CORBA::is_nil (nc.in ())) + { + CosNaming::BindingList_var bl; + CosNaming::BindingIterator_var bit; + nc->list (2, bl.out (), bit.out ()); + + if (bl->length () > 0) + no_more_entries = false; + } + + if (no_more_entries) + ns_->unbind (name.in ()); + + if (current_depth < depth) + { + size_t pos = current_path.find_last_of ('/'); + + if (pos == std::string::npos) + break; + + current_path = current_path.substr (0, pos); + ++current_depth; + } + } + while (depth >= current_depth); + } + + typename T::_ptr_type resolve (const std::string & path) + { + CORBA::Object_var obj = ns_->resolve_str (path.c_str ()); + + typename T::_var_type ret = T::_narrow (obj.in ()); + + if (CORBA::is_nil (ret.in ())) + throw Name_Helper_Exception ("Name_Helper_T::resolve - could not narrow resolved obj"); + + return ret._retn (); + } + + std::string escape_dots (const std::string &path) + { + std::string esc_path (path); + + // replace all dots in the path with excaped dots for + // to_name conversion. + for (size_t pos = esc_path.find ('.', 0); + pos < esc_path.length (); + pos = esc_path.find ('.', pos)) + { + esc_path.replace (pos, 1, "\\."); + pos += 2; + } + + return esc_path; + } + + private: + CORBA::ORB_var orb_; + CosNaming::NamingContextExt_var ns_; +}; + +#endif /* _NAME_HELPER_T_H_ */ |