diff options
author | William R. Otte <wotte@dre.vanderbilt.edu> | 2010-05-19 12:18:10 +0000 |
---|---|---|
committer | William R. Otte <wotte@dre.vanderbilt.edu> | 2010-05-19 12:18:10 +0000 |
commit | 414013db64dafc014d4a7dae1cde9edcc9510dee (patch) | |
tree | 5a1c6a1e2c5c51aa5f9e4857964d998874bfac10 | |
parent | 1686537f5179565daeeaaba440de2f03ae55ad62 (diff) | |
download | ATCD-414013db64dafc014d4a7dae1cde9edcc9510dee.tar.gz |
Wed May 19 12:17:27 UTC 2010 William R. Otte <wotte@dre.vanderbilt.edu>
* ciao/ComponentServer/CIAO_ComponentServer.mpc:
* ciao/ComponentServer/CIAO_Properties.idl:
* ciao/ComponentServer/Client_init.h:
* ciao/ComponentServer/Server_init.h:
* ciao/Deployment:
* ciao/Deployment/Handlers:
* ciao/Deployment/Handlers/CIAO_Deployment_Handlers.mpc:
* ciao/Deployment/Handlers/CIAO_Handler_Common.h:
* ciao/Deployment/Handlers/CIAO_Handler_Common.cpp:
* ciao/Deployment/Handlers/CIAO_Locality_Handler_Export.h:
* ciao/Deployment/Handlers/CIAO_State.h:
* ciao/Deployment/Handlers/CIAO_State.cpp:
* ciao/Deployment/Handlers/Component_Handler.h:
* ciao/Deployment/Handlers/Component_Handler.cpp:
* ciao/Deployment/Handlers/Connection_Handler.h:
* ciao/Deployment/Handlers/Connection_Handler.cpp:
* ciao/Deployment/Handlers/Container_Handler.h:
* ciao/Deployment/Handlers/Container_Handler.cpp:
* ciao/Deployment/Handlers/Home_Handler.h:
* ciao/Deployment/Handlers/Home_Handler.cpp:
* ciao/Deployment/Handlers/Homed_Component_Handler.h:
* ciao/Deployment/Handlers/Homed_Component_Handler.cpp:
* ciao/Deployment/Interceptors:
First round CIAO deployment handlers.
21 files changed, 2888 insertions, 11 deletions
diff --git a/modules/CIAO/ChangeLog b/modules/CIAO/ChangeLog index 69719bfa02b..80fce4bb79e 100644 --- a/modules/CIAO/ChangeLog +++ b/modules/CIAO/ChangeLog @@ -1,11 +1,14 @@ -Wed May 19 12:14:47 UTC 2010 William R. Otte <wotte@dre.vanderbilt.edu> +Wed May 19 12:17:27 UTC 2010 William R. Otte <wotte@dre.vanderbilt.edu> * ciao/ComponentServer/CIAO_ComponentServer.mpc: * ciao/ComponentServer/CIAO_Properties.idl: * ciao/ComponentServer/Client_init.h: * ciao/ComponentServer/Server_init.h: + * ciao/Deployment: + * ciao/Deployment/Handlers: + * ciao/Deployment/Handlers/CIAO_Deployment_Handlers.mpc: * ciao/Deployment/Handlers/CIAO_Handler_Common.h: * ciao/Deployment/Handlers/CIAO_Handler_Common.cpp: @@ -22,9 +25,10 @@ Wed May 19 12:14:47 UTC 2010 William R. Otte <wotte@dre.vanderbilt.edu> * ciao/Deployment/Handlers/Home_Handler.cpp: * ciao/Deployment/Handlers/Homed_Component_Handler.h: * ciao/Deployment/Handlers/Homed_Component_Handler.cpp: + * ciao/Deployment/Interceptors: - First round CIAO deployment handlers. + First round CIAO deployment handlers. Wed May 19 12:11:34 UTC 2010 William R. Otte <wotte@dre.vanderbilt.edu> diff --git a/modules/CIAO/ciao/ComponentServer/CIAO_ComponentServer.mpc b/modules/CIAO/ciao/ComponentServer/CIAO_ComponentServer.mpc index 1c0f73505a9..fd3eb551c68 100644 --- a/modules/CIAO/ciao/ComponentServer/CIAO_ComponentServer.mpc +++ b/modules/CIAO/ciao/ComponentServer/CIAO_ComponentServer.mpc @@ -46,6 +46,8 @@ project(CIAO_ComponentServer_stub) : ccm_componentserver_stub, ciaolib_with_idl, CIAO_ComponentServerC.cpp CIAO_CS_ClientC.cpp CIAO_PropertiesC.cpp + Server_init.cpp + Client_init.cpp } Header_Files { CIAO_ComponentServer_stub_export.h @@ -60,8 +62,6 @@ project(CIAO_CS_Client_svnt) : ccm_svnt, ccm_componentserver_svnt, ciao_componen } Source_Files { CIAO_ServerActivator_Impl.cpp - Server_init.cpp - Client_init.cpp CIAO_ComponentInstallation_Impl.cpp CIAO_CS_ClientS.cpp } diff --git a/modules/CIAO/ciao/ComponentServer/CIAO_Properties.idl b/modules/CIAO/ciao/ComponentServer/CIAO_Properties.idl index bb4a39995c4..f4d4d6c491b 100644 --- a/modules/CIAO/ciao/ComponentServer/CIAO_Properties.idl +++ b/modules/CIAO/ciao/ComponentServer/CIAO_Properties.idl @@ -15,6 +15,10 @@ module CIAO 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 COMPONENT_FACTORY = "component factory"; + const string HOME_FACTORY = "home factory"; + const string COMPONENT_HOME = "edu.vanderbilt.dre.CIAO.ComponentHomeId"; + const string CONTAINER_ID = "edu.vanderbilt.dre.CIAO.ContainerId"; const string SERVER_UUID = "edu.vanderbilt.dre.CIAO.ServerUUID"; const string SERVER_EXECUTABLE = "edu.vanderbilt.dre.CIAO.ComponentServer.Executable"; const string SERVER_ARGUMENTS = "edu.vanderbilt.dre.CIAO.ComponentServer.Args"; diff --git a/modules/CIAO/ciao/ComponentServer/Client_init.h b/modules/CIAO/ciao/ComponentServer/Client_init.h index d50f4b92605..38c7c997e0e 100644 --- a/modules/CIAO/ciao/ComponentServer/Client_init.h +++ b/modules/CIAO/ciao/ComponentServer/Client_init.h @@ -23,7 +23,8 @@ #include "tao/orbconf.h" #include "tao/AnyTypeCode/Any.h" #include "ccm/CCM_StandardConfiguratorC.h" -#include "ciao/ComponentServer/CIAO_CS_Client_svnt_export.h" + +#include "ciao/ComponentServer/CIAO_ComponentServer_stub_export.h" TAO_BEGIN_VERSIONED_NAMESPACE_DECL namespace CORBA @@ -42,7 +43,7 @@ namespace CIAO * should be call right after ORB initialization but we should try * to register these stuff automatically. */ - CIAO_CS_CLIENT_SVNT_Export int Client_init (CORBA::ORB_ptr o); + CIAO_COMPONENTSERVER_STUB_Export int Client_init (CORBA::ORB_ptr o); namespace Utility { @@ -52,10 +53,10 @@ namespace CIAO ACE_Equal_To<ACE_CString>, ACE_Null_Mutex> CONFIGVALUE_MAP; - CIAO_CS_CLIENT_SVNT_Export void build_config_values_map (CONFIGVALUE_MAP &map, + CIAO_COMPONENTSERVER_STUB_Export void build_config_values_map (CONFIGVALUE_MAP &map, const ::Components::ConfigValues &config); - CIAO_CS_CLIENT_SVNT_Export void build_config_values_sequence (::Components::ConfigValues &config, + CIAO_COMPONENTSERVER_STUB_Export void build_config_values_sequence (::Components::ConfigValues &config, const CONFIGVALUE_MAP &map); } } diff --git a/modules/CIAO/ciao/ComponentServer/Server_init.h b/modules/CIAO/ciao/ComponentServer/Server_init.h index b475dc8312f..d56c5fe50fc 100644 --- a/modules/CIAO/ciao/ComponentServer/Server_init.h +++ b/modules/CIAO/ciao/ComponentServer/Server_init.h @@ -16,7 +16,7 @@ #include /**/ "ace/pre.h" -#include "ciao/ComponentServer/CIAO_CS_Client_svnt_export.h" +#include "ciao/ComponentServer/CIAO_ComponentServer_stub_export.h" #if !defined ACE_LACKS_PRAGMA_ONCE #pragma once @@ -42,14 +42,14 @@ namespace CIAO * should be call right after ORB initialization but we should try * to register these stuff automatically. */ - CIAO_CS_CLIENT_SVNT_Export int Server_init (CORBA::ORB_ptr o); + CIAO_COMPONENTSERVER_STUB_Export int Server_init (CORBA::ORB_ptr o); namespace Utility { /// Write a string (usually a stringified IOR) to a file /// designated by the @c pathname. The file named will always get /// overwritten. - CIAO_CS_CLIENT_SVNT_Export int write_IOR (const ACE_TCHAR *pathname, + CIAO_COMPONENTSERVER_STUB_Export int write_IOR (const ACE_TCHAR *pathname, const char *IOR); } } diff --git a/modules/CIAO/ciao/Deployment/Handlers/CIAO_Deployment_Handlers.mpc b/modules/CIAO/ciao/Deployment/Handlers/CIAO_Deployment_Handlers.mpc new file mode 100644 index 00000000000..c4135507ebc --- /dev/null +++ b/modules/CIAO/ciao/Deployment/Handlers/CIAO_Deployment_Handlers.mpc @@ -0,0 +1,23 @@ +project (CIAO_Deployment_Handlers) : dance_stub, ciao_lib, ciao_output, \ + ciao_session_container, ciao_logger, ciao_componentserver_stub { + dynamicflags = CIAO_LOCALITY_HANDLER_BUILD_DLL + + Source_Files { + Component_Handler.cpp + Container_Handler.cpp + Home_Handler.cpp + Homed_Component_Handler.cpp + CIAO_State.cpp + CIAO_Handler_Common.cpp + Connection_Handler.cpp + } + + Header_Files { + Component_Handler.h + Container_Handler.h + Home_Handler.h + Homed_Component_Handler.h + CIAO_State.h + CIAO_Locality_Handler_Export.h + } +} diff --git a/modules/CIAO/ciao/Deployment/Handlers/CIAO_Handler_Common.cpp b/modules/CIAO/ciao/Deployment/Handlers/CIAO_Handler_Common.cpp new file mode 100644 index 00000000000..3ea45b63aea --- /dev/null +++ b/modules/CIAO/ciao/Deployment/Handlers/CIAO_Handler_Common.cpp @@ -0,0 +1,47 @@ +// $Id$ +#include "CIAO_Handler_Common.h" + +#include "Deployment/Deployment_PlanErrorC.h" +#include "ciao/Logger/Log_Macros.h" + +namespace CIAO +{ + const char * + Deployment_Common::get_implementation (const char *name, + const ::Deployment::DeploymentPlan &plan) + { + if (name == 0) + throw ::Deployment::PlanError (name, + "No such artifact"); + + for (CORBA::ULong i = 0; + i < plan.artifact.length (); + ++i) + { + if (ACE_OS::strcmp (plan.artifact[i].name.in (), + name) == 0) + { + if (plan.artifact[i].location.length () >= 1 && + plan.artifact[i].location[0] != 0) + return plan.artifact[i].location[0].in (); + else + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Component_Handler_i::get_implementation - " + "No valid location for artifact <%C>\n", + name)); + throw ::Deployment::PlanError (name, + "No valid location field\n"); + } + } + } + + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Component_Handler_i::get_implementation - " + "Unable to locate artifact <%C>\n", + name)); + throw ::Deployment::PlanError (name, + "Nonexistant artifact"); + return 0; + } +} diff --git a/modules/CIAO/ciao/Deployment/Handlers/CIAO_Handler_Common.h b/modules/CIAO/ciao/Deployment/Handlers/CIAO_Handler_Common.h new file mode 100644 index 00000000000..30614f91e8b --- /dev/null +++ b/modules/CIAO/ciao/Deployment/Handlers/CIAO_Handler_Common.h @@ -0,0 +1,38 @@ +/** + * @file CIAO_Handler_Common.h + * @author William R. Otte + * + * Operations common to all CIAO handlers. + * $Id$ + */ +#ifndef CIAO_HANDLER_COMMON_H +#define CIAO_HANDLER_COMMON_H + +#include <map> +#include <string> + +#include "Deployment/Deployment_DeploymentPlanC.h" +#include "DAnCE/DAnCE_Utility.h" + +namespace CIAO +{ + class Deployment_Common + { + public: + // Temporary hack until Martin's artifact installation work can + // be implemented. + static const char * get_implementation (const char *name, + const ::Deployment::DeploymentPlan &plan); + + struct Instance_Info + { + std::string name; + ::DAnCE::Utility::PMAP_PTR pmap; + }; + + typedef std::map < std::string, Instance_Info > INSTANCES; + + }; +} + +#endif diff --git a/modules/CIAO/ciao/Deployment/Handlers/CIAO_Locality_Handler_Export.h b/modules/CIAO/ciao/Deployment/Handlers/CIAO_Locality_Handler_Export.h new file mode 100644 index 00000000000..e62e00464f2 --- /dev/null +++ b/modules/CIAO/ciao/Deployment/Handlers/CIAO_Locality_Handler_Export.h @@ -0,0 +1,58 @@ + +// -*- C++ -*- +// $Id$ +// Definition for Win32 Export directives. +// This file is generated automatically by generate_export_file.pl CIAO_Locality_Handler +// ------------------------------ +#ifndef CIAO_LOCALITY_HANDLER_EXPORT_H +#define CIAO_LOCALITY_HANDLER_EXPORT_H + +#include "ace/config-all.h" + +#if defined (ACE_AS_STATIC_LIBS) && !defined (CIAO_LOCALITY_HANDLER_HAS_DLL) +# define CIAO_LOCALITY_HANDLER_HAS_DLL 0 +#endif /* ACE_AS_STATIC_LIBS && CIAO_LOCALITY_HANDLER_HAS_DLL */ + +#if !defined (CIAO_LOCALITY_HANDLER_HAS_DLL) +# define CIAO_LOCALITY_HANDLER_HAS_DLL 1 +#endif /* ! CIAO_LOCALITY_HANDLER_HAS_DLL */ + +#if defined (CIAO_LOCALITY_HANDLER_HAS_DLL) && (CIAO_LOCALITY_HANDLER_HAS_DLL == 1) +# if defined (CIAO_LOCALITY_HANDLER_BUILD_DLL) +# define CIAO_Locality_Handler_Export ACE_Proper_Export_Flag +# define CIAO_LOCALITY_HANDLER_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) +# define CIAO_LOCALITY_HANDLER_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# else /* CIAO_LOCALITY_HANDLER_BUILD_DLL */ +# define CIAO_Locality_Handler_Export ACE_Proper_Import_Flag +# define CIAO_LOCALITY_HANDLER_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) +# define CIAO_LOCALITY_HANDLER_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# endif /* CIAO_LOCALITY_HANDLER_BUILD_DLL */ +#else /* CIAO_LOCALITY_HANDLER_HAS_DLL == 1 */ +# define CIAO_Locality_Handler_Export +# define CIAO_LOCALITY_HANDLER_SINGLETON_DECLARATION(T) +# define CIAO_LOCALITY_HANDLER_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +#endif /* CIAO_LOCALITY_HANDLER_HAS_DLL == 1 */ + +// Set CIAO_LOCALITY_HANDLER_NTRACE = 0 to turn on library specific tracing even if +// tracing is turned off for ACE. +#if !defined (CIAO_LOCALITY_HANDLER_NTRACE) +# if (ACE_NTRACE == 1) +# define CIAO_LOCALITY_HANDLER_NTRACE 1 +# else /* (ACE_NTRACE == 1) */ +# define CIAO_LOCALITY_HANDLER_NTRACE 0 +# endif /* (ACE_NTRACE == 1) */ +#endif /* !CIAO_LOCALITY_HANDLER_NTRACE */ + +#if (CIAO_LOCALITY_HANDLER_NTRACE == 1) +# define CIAO_LOCALITY_HANDLER_TRACE(X) +#else /* (CIAO_LOCALITY_HANDLER_NTRACE == 1) */ +# if !defined (ACE_HAS_TRACE) +# define ACE_HAS_TRACE +# endif /* ACE_HAS_TRACE */ +# define CIAO_LOCALITY_HANDLER_TRACE(X) ACE_TRACE_IMPL(X) +# include "ace/Trace.h" +#endif /* (CIAO_LOCALITY_HANDLER_NTRACE == 1) */ + +#endif /* CIAO_LOCALITY_HANDLER_EXPORT_H */ + +// End of auto generated file. diff --git a/modules/CIAO/ciao/Deployment/Handlers/CIAO_State.cpp b/modules/CIAO/ciao/Deployment/Handlers/CIAO_State.cpp new file mode 100644 index 00000000000..da27aae66af --- /dev/null +++ b/modules/CIAO/ciao/Deployment/Handlers/CIAO_State.cpp @@ -0,0 +1,158 @@ +// $Id$ + +#include "CIAO_State.h" +#include "ciao/Logger/Log_Macros.h" + +namespace CIAO +{ + void + Deployment_State::add_container (const char *id, + CIAO::Container_ptr container) + { + CIAO_TRACE ("Deployment_State::add_container"); + + if (CIAO_debug_level && // Let's only perform this lookup if we have logging enabled. + this->containers_.find (id) != this->containers_.end ()) + { + CIAO_ERROR (1, (LM_WARNING, CLINFO + "Deployment_State::add_container - " + "Warning: Attempting to add duplicate container reference\n")); + } + + this->containers_[id] = CIAO::Container::_duplicate (container); + } + + void + Deployment_State::remove_container (const char *id) + { + CIAO_TRACE ("Deployment_State::remove_container"); + + CONTAINERS::iterator pos = this->containers_.find (id); + + if (pos != this->containers_.end ()) + this->containers_.erase (pos); + } + + CIAO::Container_ptr + Deployment_State::fetch_container (const char *id) + { + CIAO_TRACE ("Deployment_State::fetch_container"); + + CONTAINERS::iterator pos = this->containers_.find (id); + + if (pos == this->containers_.end ()) return 0; + return CIAO::Container::_duplicate (pos->second.in ()); + } + + void + Deployment_State::add_home (const char *id, + const char *cont_id, + Components::CCMHome_ptr home) + { + CIAO_TRACE ("Deployment_State::add_home"); + + if (CIAO_debug_level && // Let's only perform this lookup if we have logging enabled. + this->homes_.find (id) != this->homes_.end ()) + { + CIAO_ERROR (1, (LM_WARNING, CLINFO + "Deployment_State::add_home - " + "Warning: Attempting to add duplicate home reference\n")); + } + + this->instance_container_[id] = cont_id; + this->homes_[id] = Components::CCMHome::_duplicate (home); + } + + void + Deployment_State::remove_home (const char *id) + { + CIAO_TRACE ("Deployment_State::remove_home"); + + HOMES::iterator pos = this->homes_.find (id); + + if (pos != this->homes_.end ()) + this->homes_.erase (pos); + + INSTANCE_CONTAINER::iterator cont = + this->instance_container_.find (id); + + if (cont != this->instance_container_.end ()) + this->instance_container_.erase (cont); + } + + Components::CCMHome_ptr + Deployment_State::fetch_home (const char *id) + { + CIAO_TRACE ("Deployment_State::fetch_home"); + + HOMES::iterator pos = this->homes_.find (id); + + if (pos == this->homes_.end ()) return 0; + return Components::CCMHome::_duplicate (pos->second.in ()); + } + + void + Deployment_State::add_component (const char *id, + const char *cont_id, + Components::CCMObject_ptr component) + { + CIAO_TRACE ("Deployment_State::add_component"); + + if (CIAO_debug_level && // Let's only perform this lookup if we have logging enabled. + this->components_.find (id) != this->components_.end ()) + { + CIAO_ERROR (1, (LM_WARNING, CLINFO + "Deployment_State::add_component - " + "Warning: Attempting to add duplicate component reference\n")); + } + + this->instance_container_[id] = cont_id; + this->components_[id] = Components::CCMObject::_duplicate (component); + } + + void + Deployment_State::remove_component (const char *id) + { + CIAO_TRACE ("Deployment_State::remove_component"); + + COMPONENTS::iterator pos = this->components_.find (id); + + if (pos != this->components_.end ()) + this->components_.erase (pos); + + INSTANCE_CONTAINER::iterator cont = + this->instance_container_.find (id); + + if (cont != this->instance_container_.end ()) + this->instance_container_.erase (cont); + } + + Components::CCMObject_ptr + Deployment_State::fetch_component (const char *id) + { + CIAO_TRACE ("Deployment_State::fetch_component"); + + COMPONENTS::iterator pos = this->components_.find (id); + + if (pos == this->components_.end ()) return 0; + return Components::CCMObject::_duplicate (pos->second.in ()); + } + + const char * + Deployment_State::instance_to_container (const char *id) + { + CIAO_TRACE ("Deployment_State::instance_to_container"); + + INSTANCE_CONTAINER::const_iterator cont = + this->instance_container_.find (id); + + if (cont != this->instance_container_.end ()) + return cont->second.c_str (); + + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Deployment_State::instance_to_container - " + "Error: Unknown instance ID <%C>\n", + id)); + return 0; + } +} diff --git a/modules/CIAO/ciao/Deployment/Handlers/CIAO_State.h b/modules/CIAO/ciao/Deployment/Handlers/CIAO_State.h new file mode 100644 index 00000000000..557f827745a --- /dev/null +++ b/modules/CIAO/ciao/Deployment/Handlers/CIAO_State.h @@ -0,0 +1,88 @@ +/** + * @file CIAO_State.h + * @author William R. Otte <wotte@dre.vanderbilt.edu> + * + * $Id$ + */ + +#ifndef CIAO_STATE_H +#define CIAO_STATE_H + +#include <map> +#include <string> + +#include "ace/Singleton.h" +#include "ciao/Containers/Container_BaseC.h" +#include "ccm/CCM_HomeC.h" +#include "ccm/CCM_ObjectC.h" +#include "CIAO_Locality_Handler_Export.h" +#include "ciao/Deployment/Handlers/Connection_Handler.h" + +namespace CIAO +{ + /** + * @class Deployment_State + * @brief Singleton collecting state for the instance handlers. + * + */ + class CIAO_Locality_Handler_Export Deployment_State + { + public: + + void add_container (const char *id, + CIAO::Container_ptr container); + + void remove_container (const char *id); + + CIAO::Container_ptr fetch_container (const char *id); + + const char * instance_to_container (const char *id); + + void add_home (const char *id, const char *container_id, + Components::CCMHome_ptr home); + + void remove_home (const char *id); + + Components::CCMHome_ptr fetch_home (const char *id); + + void add_component (const char *id, const char *container_id, + Components::CCMObject_ptr component); + + void remove_component (const char *id); + + Components::CCMObject_ptr fetch_component (const char *id); + + Connection_Handler connection_handler; + + private: + typedef std::map < std::string, + CIAO::Container_var > CONTAINERS; + + CONTAINERS containers_; + + typedef std::map < std::string, std::string > INSTANCE_CONTAINER; + + /// maps instance ids to containers. + INSTANCE_CONTAINER instance_container_; + + typedef std::map < std::string, + Components::CCMHome_var > HOMES; + + HOMES homes_; + + typedef std::map < std::string, + Components::CCMObject_var > COMPONENTS; + + COMPONENTS components_; + }; + + typedef ACE_Singleton <Deployment_State, + ACE_SYNCH_MUTEX> DEPLOYMENT_STATE; + +} + +CIAO_LOCALITY_HANDLER_SINGLETON_DECLARE (ACE_Singleton, + CIAO::Deployment_State, + ACE_SYNCH_MUTEX); + +#endif diff --git a/modules/CIAO/ciao/Deployment/Handlers/Component_Handler.cpp b/modules/CIAO/ciao/Deployment/Handlers/Component_Handler.cpp new file mode 100644 index 00000000000..b4cb687761a --- /dev/null +++ b/modules/CIAO/ciao/Deployment/Handlers/Component_Handler.cpp @@ -0,0 +1,449 @@ +// $Id$ + +#include "Component_Handler.h" +#include "ciao/Logger/Log_Macros.h" +#include "ciao/ComponentServer/CIAO_PropertiesC.h" +#include "ciao/Containers/Container_BaseC.h" +#include "ccm/CCM_ObjectC.h" +#include "CIAO_State.h" + +namespace CIAO +{ + Component_Handler_i::Component_Handler_i (void) + { + CIAO_TRACE ("Component_Handler_i::Component_Handler_i"); + } + + // Destructor + Component_Handler_i::~Component_Handler_i (void) + { + CIAO_TRACE ("Component_Handler_i::~Component_Handler_i"); + } + + + char * + Component_Handler_i::instance_type (void) + { + CIAO_TRACE ("Component_Handler_i::instance_type"); + return CORBA::string_dup ("edu.dre.vanderbilt.dre.CCM.Component"); + } + + + void + Component_Handler_i::install_instance (const ::Deployment::DeploymentPlan &plan, + ::CORBA::ULong instanceRef, + ::CORBA::Any_out instance_reference) + { + CIAO_TRACE ("Component_Handler_i::install_instance"); + + const ::Deployment::InstanceDeploymentDescription &idd (plan.instance[instanceRef]); + const ::Deployment::MonolithicDeploymentDescription &mdd (plan.implementation[idd.implementationRef]); + + DAnCE::Utility::PROPERTY_MAP *pmap; + + ACE_NEW_THROW_EX (pmap, + DAnCE::Utility::PROPERTY_MAP (idd.configProperty.length () + + mdd.execParameter.length ()), + CORBA::NO_MEMORY ()); + + Deployment_Common::Instance_Info info; + info.name = idd.name.in (); + info.pmap.reset (pmap); + + + DAnCE::Utility::build_property_map (*pmap, + mdd.execParameter); + DAnCE::Utility::build_property_map (*pmap, + idd.configProperty); + + CORBA::String_var exec_art, exec_entry, svnt_art, svnt_entry, cont_id; + + using namespace CIAO::Deployment; + CORBA::Any val; + const char *tmp; + + if (pmap->find (SVNT_ENTRYPT, val) == 0) + { + val >>= tmp; + svnt_entry = tmp; + CIAO_DEBUG (9, (LM_TRACE, CLINFO + "Component_Handler_i::install_instance - " + "Found Servant entrypoint %C\n", svnt_entry.in ())); + } + else + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Component_Handler_i::install_instance - " + "Error: No Servant entrypoint provided, aborting installation\n")); + throw ::Deployment::PlanError (idd.name.in (), + "No servant entrypoint identified."); + } + + if (pmap->find (SVNT_ARTIFACT, val) == 0) + { + val >>= tmp; + svnt_art = Deployment_Common::get_implementation (tmp, plan); + CIAO_DEBUG (9, (LM_TRACE, CLINFO + "Component_Handler_i::install_instance - " + "Found Servant artifact %C\n", svnt_art.in ())); + } + else + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Component_Handler_i::install_instance - " + "Error: No Servant artifact provided, aborting installation\n")); + throw ::Deployment::PlanError (idd.name.in (), + "No servant artifact identified."); + } + + + if (pmap->find (EXEC_ARTIFACT, val) == 0) + { + val >>= tmp; + exec_art = Deployment_Common::get_implementation (tmp, plan); + CIAO_DEBUG (9, (LM_TRACE, CLINFO + "Component_Handler_i::install_instance - " + "Found executor artifact: %C\n", exec_art.in ())); + } + else + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Component_Handler_i::install_instance - " + "Error: No Executor artifact provided, aborting installation\n")); + throw ::Deployment::PlanError (idd.name.in (), + "No executory artifact identified.\n"); + } + + if (pmap->find (COMPONENT_FACTORY, val) == 0) + { + val >>= tmp; + exec_entry = tmp; + CIAO_DEBUG (9, (LM_TRACE, CLINFO + "Component_Handler_i::install_instance - " + "Found executor entrypoint: %C\n", exec_entry.in ())); + } + else + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Component_Handler_i::install_instance - " + "Error: No Executor artifact provided, aborting installation\n")); + throw ::Deployment::PlanError (idd.name.in (), + "No executor entrypoint provided\n"); + } + + if (pmap->find (CONTAINER_ID, val) == 0) + { + val >>= tmp; + cont_id = tmp; + CIAO_DEBUG (9, (LM_TRACE, CLINFO + "Component_Handler_i::install_instance - " + "Found executor entrypoint: %C\n", exec_entry.in ())); + } + else + { + CIAO_ERROR (4, (LM_INFO, CLINFO + "Component_Handler_i::install_instance - " + "No container provided, using default container for instance <%C>\n", + idd.name.in ())); + cont_id = ""; + } + + ::CIAO::Container_var container = DEPLOYMENT_STATE::instance ()->fetch_container (cont_id); + + if (CORBA::is_nil (container)) + { + CIAO_ERROR (1, (LM_INFO, CLINFO + "Component_Handler_i::install_instance - " + "Container with Id <%C> not installed, aborting.\n", + cont_id.in ())); + throw ::Deployment::PlanError (idd.name.in (), + "Invalid container\n"); + } + + Components::CCMObject_var comp_ref; + + try + { + comp_ref = container->install_component (exec_art, + exec_entry, + svnt_art, + svnt_entry, + idd.name.in ()); + } + catch (::CORBA::Exception &ex) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Component_Handler_i::install_instance - " + "Caught CORBA exception <%C>\n", + ex._info ().c_str ())); + throw ::Deployment::StartError (idd.name.in (), + ex._info ().c_str ()); + } + catch (...) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Component_Handler_i::install_instance - " + "Caught unknown C++ exception\n")); + throw ::Deployment::StartError (idd.name.in (), + "Unknown C++ exception\n"); + } + + if (CORBA::is_nil (comp_ref)) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Component_Handler_i::install_instance - " + "Container provided nil object reference for component.\n")); + throw ::Deployment::StartError (idd.name.in (), + "Container provided nil object reference"); + } + + this->instances_[idd.name.in ()] = info; + + DEPLOYMENT_STATE::instance ()->add_component (idd.name.in (), + cont_id, + comp_ref.in ()); + + CORBA::Any *retval; + ACE_NEW_THROW_EX (retval, + CORBA::Any (), + CORBA::NO_MEMORY ()); + + (*retval) <<= comp_ref; + instance_reference = retval; + } + + void + Component_Handler_i::activate_instance (const ::Deployment::DeploymentPlan &plan, + ::CORBA::ULong instanceRef, + const ::CORBA::Any &) + { + CIAO_TRACE ("Component_Handler_i::activate_instance"); + + const char *name = plan.instance[instanceRef].name.in (); + + const char *container = + DEPLOYMENT_STATE::instance ()->instance_to_container (name); + + CIAO::Container_var cont = + DEPLOYMENT_STATE::instance ()->fetch_container (container); + + Components::CCMObject_var comp = + DEPLOYMENT_STATE::instance ()->fetch_component (name); + + try + { + cont->activate_component (comp.in ()); + } + catch (CORBA::Exception &ex) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Component_Handler_i::activate_instance - " + "Caught CORBA Exception while activating instance <%C>: %C\n", + name, + ex._info ().c_str ())); + throw ::Deployment::StartError (name, + ex._info ().c_str ()); + } + catch (...) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Component_Handler_i::activate_instance - " + "Caught C++ Exception while activating instance <%C>\n", + name)); + throw ::Deployment::StartError (name, + "Unknown C++ exception during activation"); + } + } + + void + Component_Handler_i::passivate_instance (const ::Deployment::DeploymentPlan &plan, + ::CORBA::ULong instanceRef, + const ::CORBA::Any &) + { + CIAO_TRACE ("Component_Handler_i::passivate_instance"); + + const char *name = plan.instance[instanceRef].name.in (); + + const char *container = + DEPLOYMENT_STATE::instance ()->instance_to_container (name); + + CIAO::Container_var cont = + DEPLOYMENT_STATE::instance ()->fetch_container (container); + + Components::CCMObject_var comp = + DEPLOYMENT_STATE::instance ()->fetch_component (name); + + try + { + cont->passivate_component (comp.in ()); + } + catch (CORBA::Exception &ex) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Component_Handler_i::passivate_instance - " + "Caught CORBA Exception while passivating instance <%C>: %C\n", + name, + ex._info ().c_str ())); + throw ::Deployment::StopError (name, + ex._info ().c_str ()); + } + catch (...) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Component_Handler_i::passivate_instance - " + "Caught C++ Exception while passivating instance <%C>\n", + name)); + throw ::Deployment::StartError (name, + "Unknown C++ exception during passivation"); + } + } + + void + Component_Handler_i::remove_instance (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong instanceRef, + const ::CORBA::Any & instance_reference) + { + CIAO_TRACE ("Component_Handler_i::remove_instance"); + + const char *name = plan.instance[instanceRef].name.in (); + Deployment_Common::INSTANCES::iterator instance + = this->instances_.find (name); + + if (instance == this->instances_.end ()) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Component_Handler_i::remove_instance - " + "Instructed to remove unknown component instance <%C>\n", + name)); + throw ::Deployment::StopError (name, + "Wrong instance handler for component instance\n"); + } + + CIAO_DEBUG (8, (LM_DEBUG, CLINFO + "Component_Handler_i::remove_instance - " + "Attempting removal of component instance <%C>\n", + name)); + + Components::CCMObject_var ref; + + if (!(instance_reference >>= ref) || + CORBA::is_nil (ref)) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Component_Handler_i::remove_instance - " + "Unable to convert provided instance reference to CCMObject " + "while removing instance <%C>\n", + name)); + throw ::Deployment::StopError (name, + "Unable to narrow reference to CCMObject"); + } + + CORBA::Any val; + const char *cont_id; + + if (instance->second.pmap->find (Deployment::CONTAINER_ID, val) == 0) + { + val >>= cont_id; + CIAO_DEBUG (9, (LM_TRACE, CLINFO + "Component_Handler_i::remove_instance - " + "Found component container: %C\n", cont_id)); + } + else + { + CIAO_ERROR (4, (LM_INFO, CLINFO + "Component_Handler_i::install_instance - " + "No container provided, using default container for instance <%C>\n", + name)); + cont_id = ""; + } + + ::CIAO::Container_var container = DEPLOYMENT_STATE::instance ()->fetch_container (cont_id); + + if (CORBA::is_nil (container)) + { + CIAO_ERROR (1, (LM_INFO, CLINFO + "Component_Handler_i::remove_instance - " + "Container with Id <%C> not installed, aborting.\n", + cont_id)); + throw ::Deployment::StopError (name, + "Invalid container\n"); + } + + try + { + container->uninstall_component (ref); + } + catch (CORBA::Exception &ex) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Component_Handler_i::remove_instance - " + "Caught CORBA exception <%C>\n", + ex._info ().c_str ())); + throw ::Deployment::StopError (name, + ex._info ().c_str ()); + } + catch (...) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Component_Handler_i::remove_instance - " + "Caught unknown C++ exception\n")); + throw ::Deployment::StopError (name, + "Unknown C++ exception\n"); + } + + this->instances_.erase (instance); + + CIAO_DEBUG (4, (LM_INFO, CLINFO + "Component_Handler_i::remove_instance - " + "Instance <%C> successfully removed\n", + name)); + } + + void + Component_Handler_i::provide_endpoint_reference (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef, + ::CORBA::Any_out endpoint_reference) + { + CIAO_TRACE ("Component_Handler_i::provide_endpoint_reference"); + + DEPLOYMENT_STATE::instance ()->connection_handler.provide_endpoint_reference (plan, + connectionRef, + endpoint_reference); + } + + void + Component_Handler_i::connect_instance (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef, + const ::CORBA::Any & provided_reference) + { + CIAO_TRACE ("Component_Handler_i::connect_instance"); + + DEPLOYMENT_STATE::instance ()->connection_handler.connect_instance (plan, + connectionRef, + provided_reference); + } + + + void + Component_Handler_i::disconnect_instance (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef) + { + CIAO_TRACE ("Component_Handler_i::disconnect_instance"); + DEPLOYMENT_STATE::instance ()->connection_handler.disconnect_instance (plan, + connectionRef); + + } + + void + Component_Handler_i::instance_configured (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong instanceRef) + { + CIAO_TRACE ("Component_Handler_i::instance_configured"); + + Components::CCMObject_var ref = + DEPLOYMENT_STATE::instance ()->fetch_component (plan.instance[instanceRef].name.in ()); + + ref->configuration_complete (); + } + +} diff --git a/modules/CIAO/ciao/Deployment/Handlers/Component_Handler.h b/modules/CIAO/ciao/Deployment/Handlers/Component_Handler.h new file mode 100644 index 00000000000..abbede50524 --- /dev/null +++ b/modules/CIAO/ciao/Deployment/Handlers/Component_Handler.h @@ -0,0 +1,84 @@ + +// -*- C++ -*- +// $Id$ + +/** + * @file Locality_Manager_Handler_Impl.h + * @author William R. Otte <wotte@dre.vanderbilt.edu> + * + * Installation handler implementation for spawning LocalityManagers. + */ + +#ifndef CIAO_COMPONENT_HANDLER_H +#define CIAO_COMPONENT_HANDLER_H + +#include "DAnCE/DAnCE_LocalityManagerS.h" +#include "DAnCE/DAnCE_Utility.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +#pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/LocalObject.h" +#include "ciao/Deployment/Handlers/CIAO_Locality_Handler_Export.h" +#include "ciao/Deployment/Handlers/CIAO_Handler_Common.h" + +namespace CIAO +{ + class CIAO_LocalityActivator_i; + + class CIAO_Locality_Handler_Export Component_Handler_i + : public virtual DAnCE::InstanceDeploymentHandler, + public virtual ::CORBA::LocalObject + { + public: + // Constructor + Component_Handler_i (void); + + // Destructor + virtual ~Component_Handler_i (void); + + virtual + char * instance_type (void); + + virtual + void install_instance (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong instanceRef, + ::CORBA::Any_out instance_reference); + + virtual + void remove_instance (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong instanceRef, + const ::CORBA::Any & instance_reference); + + virtual + void activate_instance (const ::Deployment::DeploymentPlan & , + ::CORBA::ULong , + const ::CORBA::Any &); + virtual + void passivate_instance (const ::Deployment::DeploymentPlan & , + ::CORBA::ULong , + const ::CORBA::Any &); + + virtual + void provide_endpoint_reference (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef, + ::CORBA::Any_out endpoint_reference); + + virtual + void connect_instance (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef, + const ::CORBA::Any & provided_reference); + + virtual + void disconnect_instance (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef); + + virtual + void instance_configured (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong instanceRef); + private: + Deployment_Common::INSTANCES instances_; + }; +} +#endif diff --git a/modules/CIAO/ciao/Deployment/Handlers/Connection_Handler.cpp b/modules/CIAO/ciao/Deployment/Handlers/Connection_Handler.cpp new file mode 100644 index 00000000000..b002561b85f --- /dev/null +++ b/modules/CIAO/ciao/Deployment/Handlers/Connection_Handler.cpp @@ -0,0 +1,605 @@ +#include "Connection_Handler.h" +#include "ciao/Logger/Log_Macros.h" +#include "Deployment/Deployment_InvalidConnectionC.h" +#include "CIAO_State.h" +namespace CIAO +{ + void + Connection_Handler::provide_endpoint_reference (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef, + ::CORBA::Any_out endpoint_reference) + { + CIAO_TRACE ("Component_Handler_i::provide_endpoint_reference"); + + const ::Deployment::PlanConnectionDescription &conn = + plan.connection[connectionRef]; + + try + { + CIAO_DEBUG (9, (LM_TRACE, CLINFO + "Connection_Handler::provide_endpoint_reference - " + "Called for connection <%C>\n", + conn.name.in ())); + + for (CORBA::ULong i = 0; + i < conn.internalEndpoint.length (); + ++i) + { + if (conn.internalEndpoint[i].provider) + { + CORBA::Any *out; + CORBA::Object_var ref; + CORBA::ULong instanceRef = conn.internalEndpoint[i].instanceRef; + Components::CCMObject_var comp = + DEPLOYMENT_STATE::instance ()-> + fetch_component (plan.instance[instanceRef].name.in ()); + + if (CORBA::is_nil (comp.in ())) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Connection_Handler::provide_endpoint_reference - " + "Nil component reference from CIAO_State for <%C>\n", + plan.instance[instanceRef].name.in ())); + throw ::Deployment::InvalidConnection (conn.name.in (), + "Component instance not deployed when " + "gathering connections."); + } + + ACE_NEW_THROW_EX (out, + CORBA::Any (), + CORBA::NO_MEMORY ()); + + endpoint_reference = out; + + switch (conn.internalEndpoint[i].kind) + { + case ::Deployment::Facet: + ref = + comp->provide_facet (conn.internalEndpoint[i].portName.in ()); + (*out) <<= ref.in (); + break; + + case ::Deployment::EventConsumer: + ref = + comp->get_consumer (conn.internalEndpoint[i].portName.in ()); + (*out) <<= ref.in (); + break; + + default: + throw ::Deployment::InvalidConnection (conn.name.in (), + "Invalid provider port type."); + }; + + return; + } + } + } + catch (const CORBA::Exception &ex) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Connection_Handler::provide_endpoint_reference - " + "Caught CORBA Exception <%C> while fetching reference for " + "connection <%C>\n", + ex._info ().c_str (), + plan.connection[connectionRef].name.in ())); + throw ::Deployment::InvalidConnection (plan.connection[connectionRef].name.in (), + ex._info ().c_str ()); + + } + } + + void + Connection_Handler::connect_instance (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong c_id, + const ::CORBA::Any & provided_reference) + { + CIAO_TRACE ("Connection_Handler::connect_instance"); + + const ::Deployment::PlanConnectionDescription &conn = plan.connection[c_id]; + const char *name = conn.name.in (); + + if (conn.internalEndpoint.length () == 0) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Connection_Handler::connect_instance - " + "Connection <%C> lacks an internalEndpoint.\n", + name)); + throw ::Deployment::InvalidConnection (name, + "No internal endpoint for connection\n"); + } + + CORBA::ULong endpoint (0); + + if (conn.internalEndpoint.length () > 1) + { + for (CORBA::ULong i = 0; + i < conn.internalEndpoint.length (); + ++i) + { + if (!conn.internalEndpoint[i].provider) + endpoint = i; + } + } + + switch (conn.internalEndpoint[endpoint].kind) + { + case Deployment::Facet: + this->connect_facet (plan, c_id, endpoint, provided_reference); + break; + + case Deployment::SimplexReceptacle: + case Deployment::MultiplexReceptacle: + this->connect_receptacle (plan, c_id, endpoint, provided_reference); + break; + + case Deployment::EventEmitter: + this->connect_emitter (plan, c_id, endpoint, provided_reference); + break; + + case Deployment::EventPublisher: + this->connect_publisher (plan, c_id, endpoint, provided_reference); + break; + + case Deployment::EventConsumer: + this->connect_consumer (plan, c_id, endpoint, provided_reference); + break; + + default: + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Connection_Handler::connect_instance - " + "Unsupported port type.\n")); + throw ::Deployment::InvalidConnection (name, + "Unsupported port type"); + + } + } + + void + Connection_Handler::disconnect_instance (const ::Deployment::DeploymentPlan &, + ::CORBA::ULong) + { + CIAO_TRACE ("Connection_Handler::disconnect_instance"); + // no-op is current behavior, we'll do that for now. + } + + void + Connection_Handler::connect_facet (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef, + ::CORBA::ULong endpointRef, + const ::CORBA::Any & provided_reference) + { + CIAO_TRACE ("Connection_Handler::connect_facet"); + + const ::Deployment::PlanConnectionDescription &conn = + plan.connection[connectionRef]; + const ::Deployment::PlanSubcomponentPortEndpoint &endpoint = + conn.internalEndpoint[endpointRef]; + + CIAO_DEBUG (6, (LM_DEBUG, CLINFO + "Connection_Handler::connect_facet - " + "Connecting connection <%C> on instance <%C>\n", + conn.name.in (), + plan.instance[endpoint.instanceRef].name.in ())); + + if (this->is_local_facet (conn)) + { + CORBA::ULong other_endpointRef = (endpointRef + 1) % 2; + if (conn.internalEndpoint.length () == 2 && + (conn.internalEndpoint[other_endpointRef].kind == ::Deployment::MultiplexReceptacle || + conn.internalEndpoint[other_endpointRef].kind == ::Deployment::SimplexReceptacle)) + { + const ::Deployment::PlanSubcomponentPortEndpoint &other_endpoint = + conn.internalEndpoint[other_endpointRef]; + this->connect_local_port (plan.instance[endpoint.instanceRef].name.in (), + endpoint.portName.in (), + plan.instance[other_endpoint.instanceRef].name.in (), + other_endpoint.portName.in ()); + return; + } + else + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Connection_Handler::connect_facet - " + "Error: Wrong number of internal endpoints for local facet connection\n")); + throw ::Deployment::InvalidConnection (conn.name.in (), + "Local facet connections require exactly 2 internalEndpoints"); + } + } + + if (conn.externalReference.length () == 0) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Connection_Handler::connect_facet - " + "Error: Expected external reference endpoint for connection <%C>", + conn.name.in ())); + throw ::Deployment::InvalidConnection (conn.name.in (), + "Expected external reference connection."); + } + + ::Components::CCMObject_var provided; + + if (!(provided_reference >>= provided) && + CORBA::is_nil (provided)) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Connection_Handler::connect_facet - " + "While connecting <%C>:" + "Provided reference for connection where primary is Facet must be " + "non-nil.", + plan.connection[connectionRef].name.in ())); + throw ::Deployment::InvalidConnection (plan.connection[connectionRef].name.in (), + "Provided reference for connection where primary is Facet must " + "be non-nil."); + + } + + ::Components::CCMObject_var facet_provider = + DEPLOYMENT_STATE::instance ()->fetch_component (plan.instance[endpoint.instanceRef].name.in ()); + + if (CORBA::is_nil (facet_provider)) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Connection_Handler::connect_facet - " + "While connecting <%C>:" + "Providing component not deployed.", + plan.connection[connectionRef].name.in ())); + throw ::Deployment::InvalidConnection (plan.connection[connectionRef].name.in (), + "Providing component not deployed."); + } + + CORBA::Object_var facet = + facet_provider->provide_facet (endpoint.portName.in ()); + + ::Components::Cookie_var cookie = provided->connect (conn.externalReference[0].portName.in (), + facet.in ()); + + CIAO_DEBUG (5, (LM_INFO, CLINFO + "Connection_Handler::connect_facet - " + "Connection <%C> successfully established.\n", + conn.name.in ())); + + this->cookies_[conn.name.in ()] = CONNECTION_INFO (cookie, + ::Components::CCMObject::_duplicate (provided)); + } + + void + Connection_Handler::connect_receptacle (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef, + ::CORBA::ULong endpointRef, + const ::CORBA::Any & provided_reference) + { + const ::Deployment::PlanConnectionDescription &conn = + plan.connection[connectionRef]; + const ::Deployment::PlanSubcomponentPortEndpoint &endpoint = + conn.internalEndpoint[endpointRef]; + + CIAO_DEBUG (6, (LM_DEBUG, CLINFO + "Connection_Handler::connect_receptacle - " + "Connecting connection <%C> on instance <%C>\n", + conn.name.in (), + plan.instance[endpoint.instanceRef].name.in ())); + + if (this->is_local_facet (conn)) + { + CORBA::ULong other_endpointRef = (endpointRef + 1) % 2; + if (conn.internalEndpoint.length () == 2 && + (conn.internalEndpoint[other_endpointRef].kind == ::Deployment::Facet)) + { + const ::Deployment::PlanSubcomponentPortEndpoint &other_endpoint = + conn.internalEndpoint[other_endpointRef]; + this->connect_local_port (plan.instance[other_endpoint.instanceRef].name.in (), + other_endpoint.portName.in (), + plan.instance[endpoint.instanceRef].name.in (), + endpoint.portName.in ()); + return; + } + else + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Connection_Handler::connect_receptacle - " + "Error: Wrong number of internal endpoints for local receptacle connection\n")); + throw ::Deployment::InvalidConnection (conn.name.in (), + "Local receptacle connections require exactly 2 internalEndpoints"); + } + } + + ::CORBA::Object_var provided; + + if (!(provided_reference >>= CORBA::Any::to_object (provided))) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Connection_Handler::connect_facet - " + "Unable to extract provided reference to CORBA::Object\n", + plan.connection[connectionRef].name.in ())); + throw ::Deployment::InvalidConnection (plan.connection[connectionRef].name.in (), + "Unable to extract provided reference to CORBA Object."); + } + + if (conn.externalReference.length () != 0) + { + ::Components::CCMObject_var facet_provider = + ::Components::CCMObject::_narrow (provided.in ()); + + if (CORBA::is_nil (facet_provider.in ())) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Connection_Handler::connect_facet - " + "Unable to narrow provided external reference " + "to CCMObject in connection <%C>\n", + conn.name.in ())); + throw ::Deployment::InvalidConnection (conn.name.in (), + "Unable to narrow external reference to CCMObject\n"); + } + + provided = + facet_provider->provide_facet (conn.externalReference[0].portName.in ()); + } + + ::Components::CCMObject_var receptacle = + DEPLOYMENT_STATE::instance ()->fetch_component (plan.instance[endpoint.instanceRef].name.in ()); + + if (CORBA::is_nil (receptacle)) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Connection_Handler::connect_receptacle - " + "While connecting <%C>:" + "Receptacle component <%C> not deployed.\n", + plan.connection[connectionRef].name.in (), + plan.instance[endpoint.instanceRef].name.in ())); + throw ::Deployment::InvalidConnection (plan.connection[connectionRef].name.in (), + "Receptacle component not deployed."); + } + + ::Components::Cookie_var cookie = receptacle->connect (endpoint.portName.in (), + provided.in ()); + CIAO_DEBUG (5, (LM_INFO, CLINFO + "Connection_Handler::connect_receptacle - " + "Connection <%C> successfully established.\n", + conn.name.in ())); + + this->cookies_[conn.name.in ()] = CONNECTION_INFO (cookie, + ::Components::CCMObject::_duplicate (receptacle.in ())); + } + + void + Connection_Handler::connect_publisher (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef, + ::CORBA::ULong endpointRef, + const ::CORBA::Any & provided_reference) + { + CIAO_TRACE ("Connection_Handler::connect_publisher"); + + const ::Deployment::PlanConnectionDescription &conn = + plan.connection[connectionRef]; + const ::Deployment::PlanSubcomponentPortEndpoint &endpoint = + conn.internalEndpoint[endpointRef]; + + CIAO_DEBUG (6, (LM_DEBUG, CLINFO + "Connection_Handler::connect_publisher - " + "Connecting connection <%C> on instance <%C>\n", + conn.name.in (), + plan.instance[endpoint.instanceRef].name.in ())); + + ::CORBA::Object_var consumer; + + if (!(provided_reference >>= CORBA::Any::to_object (consumer)) || + CORBA::is_nil (consumer.in ())) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Connection_Handler::connect_publisher - " + "Unable to extract provided reference to CORBA::Object\n", + plan.connection[connectionRef].name.in ())); + throw ::Deployment::InvalidConnection (plan.connection[connectionRef].name.in (), + "Unable to extract provided reference to CORBA Object."); + } + + Components::EventConsumerBase_var event = + Components::EventConsumerBase::_unchecked_narrow (consumer); + + ::Components::CCMObject_var publisher = + DEPLOYMENT_STATE::instance ()->fetch_component (plan.instance[endpoint.instanceRef].name.in ()); + + if (CORBA::is_nil (publisher)) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Connection_Handler::connect_publisher - " + "While connecting <%C>:" + "Publishing component not deployed.", + plan.connection[connectionRef].name.in ())); + throw ::Deployment::InvalidConnection (conn.name.in (), + "Publisher component not deployed."); + } + + Components::Cookie_var cookie = publisher->subscribe (endpoint.portName.in (), + event.in ()); + + CIAO_DEBUG (5, (LM_INFO, CLINFO + "Connection_Handler::connect_publisher - " + "Connection <%C> successfully established.\n", + conn.name.in ())); + + this->cookies_[conn.name.in ()] = CONNECTION_INFO (cookie, + ::Components::CCMObject::_duplicate (publisher.in ())); + } + + void + Connection_Handler::connect_consumer (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef, + ::CORBA::ULong endpointRef, + const ::CORBA::Any &) + { + CIAO_TRACE ("Connection_Handler::connect_subscriber"); + + const ::Deployment::PlanConnectionDescription &conn = + plan.connection[connectionRef]; + const ::Deployment::PlanSubcomponentPortEndpoint &endpoint = + conn.internalEndpoint[endpointRef]; + + CIAO_DEBUG (6, (LM_DEBUG, CLINFO + "Connection_Handler::connect_consumer - " + "Connecting connection <%C> on instance <%C>\n", + conn.name.in (), + plan.instance[endpoint.instanceRef].name.in ())); + + throw ::Deployment::InvalidConnection (conn.name.in (), + "ExternalReference connection of consumers " + "currently unsupported.\n"); + } + + void + Connection_Handler::connect_emitter (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef, + ::CORBA::ULong endpointRef, + const ::CORBA::Any & provided_reference) + { + CIAO_TRACE ("Connection_Handler::connect_emitter"); + + const ::Deployment::PlanConnectionDescription &conn = + plan.connection[connectionRef]; + const ::Deployment::PlanSubcomponentPortEndpoint &endpoint = + conn.internalEndpoint[endpointRef]; + + CIAO_DEBUG (6, (LM_DEBUG, CLINFO + "Connection_Handler::connect_emitter - " + "Connecting connection <%C> on instance <%C>\n", + conn.name.in (), + plan.instance[endpoint.instanceRef].name.in ())); + + ::CORBA::Object_var consumer; + + if (!(provided_reference >>= CORBA::Any::to_object (consumer)) || + CORBA::is_nil (consumer.in ())) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Connection_Handler::connect_emitter - " + "Unable to extract provided reference to CORBA::Object\n", + plan.connection[connectionRef].name.in ())); + throw ::Deployment::InvalidConnection (plan.connection[connectionRef].name.in (), + "Unable to extract provided reference to CORBA Object."); + } + + Components::EventConsumerBase_var event = + Components::EventConsumerBase::_unchecked_narrow (consumer); + + ::Components::CCMObject_var emitter = + DEPLOYMENT_STATE::instance ()->fetch_component (plan.instance[endpoint.instanceRef].name.in ()); + + if (CORBA::is_nil (emitter)) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Connection_Handler::connect_emitter - " + "While connecting <%C>:" + "Emitting component not deployed.", + plan.connection[connectionRef].name.in ())); + throw ::Deployment::InvalidConnection (conn.name.in (), + "Emitting component not deployed."); + } + + emitter->subscribe (endpoint.portName.in (), + event.in ()); + + CIAO_DEBUG (5, (LM_INFO, CLINFO + "Connection_Handler::connect_emitter - " + "Connection <%C> successfully established.\n", + conn.name.in ())); + + ::Components::Cookie_var nil_cookie; + + this->cookies_[conn.name.in ()] = CONNECTION_INFO (nil_cookie, + ::Components::CCMObject::_duplicate (emitter.in ())); + } + + void + Connection_Handler::disconnect_facet (const ::Deployment::DeploymentPlan &, + ::CORBA::ULong) + + { + CIAO_TRACE ("Connection_Handler::disconnect_facet"); + } + + void + Connection_Handler::disconnect_receptacle (const ::Deployment::DeploymentPlan &, + ::CORBA::ULong) + + { + CIAO_TRACE ("Connection_Handler::disconnect_receptacle"); + } + + void + Connection_Handler::disconnect_publisher (const ::Deployment::DeploymentPlan &, + ::CORBA::ULong) + + { + CIAO_TRACE ("Connection_Handler::disconnect_publisher"); + } + + void + Connection_Handler::disconnect_subscriber (const ::Deployment::DeploymentPlan &, + ::CORBA::ULong) + + { + CIAO_TRACE ("Connection_Handler::disconnect_subscriber"); + } + + void + Connection_Handler::connect_local_port (const char *facet_id, + const char *facet_port, + const char *receptacle_id, + const char *receptacle_port) + { + CIAO_TRACE ("Connection_Handler::connect_local_port"); + + const char *facet_cont = + DEPLOYMENT_STATE::instance ()->instance_to_container (facet_id); + const char *recep_cont = + DEPLOYMENT_STATE::instance ()->instance_to_container (receptacle_id); + + if (ACE_OS::strcmp (facet_cont, recep_cont) != 0) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Connection_Handler::connect_local_port - " + "Ports <%C> and <%C> participate in local facet/receptacle connection, " + "but are installed in differing containers <%C> and <%C>\n", + facet_id, + receptacle_id, + facet_cont, + recep_cont)); + throw ::Deployment::InvalidConnection (facet_id, + "Component instance participates in a local connection with " + "a non-local entity."); + } + + CIAO::Container_var cont = + DEPLOYMENT_STATE::instance ()->fetch_container (facet_cont); + + Components::CCMObject_var + facet = DEPLOYMENT_STATE::instance ()->fetch_component (facet_id), + receptacle = DEPLOYMENT_STATE::instance ()->fetch_component (receptacle_id); + + cont->connect_local_facet (facet, + facet_port, + receptacle, + receptacle_port); + CIAO_DEBUG (5, (LM_INFO, CLINFO + "Connection_Handler::connect_local_port - " + "Connected local port <%C>:<%C> to <%C>:<%C>\n", + facet_id, facet_port, + receptacle_id, receptacle_port)); + } + + bool + Connection_Handler::is_local_facet (const ::Deployment::PlanConnectionDescription &conn) + { + CIAO_TRACE ("Connection_Handler::is_local_facet"); + Deployment::Requirements const& deploy_req = conn.deployRequirement; + for (CORBA::ULong i = 0; i < deploy_req.length (); i++) + { + if (ACE_OS::strcmp (deploy_req[i].name, "edu.dre.vanderbilt.DAnCE.ConnectionType") == 0 && + ACE_OS::strcmp (deploy_req[i].resourceType, "Local_Interface") == 0) + { + return true; + } + } + return false; + } +} diff --git a/modules/CIAO/ciao/Deployment/Handlers/Connection_Handler.h b/modules/CIAO/ciao/Deployment/Handlers/Connection_Handler.h new file mode 100644 index 00000000000..b3b8e0fae11 --- /dev/null +++ b/modules/CIAO/ciao/Deployment/Handlers/Connection_Handler.h @@ -0,0 +1,89 @@ +/** + * @file Connection_Handler.h + * @author William R. Otte <wotte@dre.vanderbilt.edu> + * $Id$ + * + * Common connection handling logic for components. + */ + +#ifndef CONNECTION_HANDLER_H +#define CONNECTION_HANDLER_H + +#include "Deployment/Deployment_DeploymentPlanC.h" +#include "ccm/CCM_ObjectC.h" + +#include <map> +#include <string> + +namespace CIAO +{ + class Connection_Handler + { + public: + void + provide_endpoint_reference (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef, + ::CORBA::Any_out endpoint_reference); + + void connect_instance (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef, + const ::CORBA::Any & provided_reference); + + void disconnect_instance (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef); + + private: + void connect_facet (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef, + ::CORBA::ULong endpoint, + const ::CORBA::Any & provided_reference); + + void connect_receptacle (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef, + ::CORBA::ULong endpoint, + const ::CORBA::Any & provided_reference); + + void connect_publisher (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef, + ::CORBA::ULong endpoint, + const ::CORBA::Any & provided_reference); + + void connect_emitter (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef, + ::CORBA::ULong endpoint, + const ::CORBA::Any & provided_reference); + + void connect_consumer (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef, + ::CORBA::ULong endpoint, + const ::CORBA::Any & provided_reference); + + void disconnect_facet (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef); + + + void disconnect_receptacle (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef); + + void disconnect_publisher (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef); + + void disconnect_subscriber (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef); + + void connect_local_port (const char *facet_id, + const char *facet_port, + const char *receptacle_id, + const char *receptacle_port); + + bool is_local_facet (const ::Deployment::PlanConnectionDescription &conn); + + typedef std::pair < ::Components::Cookie_var, + ::Components::CCMObject_var> CONNECTION_INFO; + typedef std::map <std::string, + CONNECTION_INFO> COOKIES; + + COOKIES cookies_; + }; +} +#endif diff --git a/modules/CIAO/ciao/Deployment/Handlers/Container_Handler.cpp b/modules/CIAO/ciao/Deployment/Handlers/Container_Handler.cpp new file mode 100644 index 00000000000..d27dab97c65 --- /dev/null +++ b/modules/CIAO/ciao/Deployment/Handlers/Container_Handler.cpp @@ -0,0 +1,206 @@ +// $Id$ + +#include "Container_Handler.h" +#include "ciao/Logger/Log_Macros.h" +#include "ciao/Containers/Session/Session_Container.h" +#include "ciao/ComponentServer/Server_init.h" + +#include "CIAO_State.h" + +namespace CIAO +{ + Container_Handler_i::Container_Handler_i (const DAnCE::Utility::PROPERTY_MAP &, + CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa) + : orb_ (CORBA::ORB::_duplicate (orb)), + poa_ (PortableServer::POA::_duplicate (poa)) + + { + CIAO_TRACE ("Container_Handler_i::Container_Handler_i"); + CIAO::Server_init (orb_); + + // For the time being, we are going to go ahead and construct a container. + ::Deployment::DeploymentPlan plan; + plan.instance.length (1); + plan.instance[0].name = ""; + + ::CORBA::Any_var any; + this->install_instance (plan, 0, any.out ()); + } + + // Destructor + Container_Handler_i::~Container_Handler_i (void) + { + CIAO_TRACE ("Container_Handler_i::~Container_Handler_i"); + + try + { + // For the time being, we are going to go ahead and delete the default container + ::Deployment::DeploymentPlan plan; + plan.instance.length (1); + plan.instance[0].name = ""; + + CORBA::Any any; + this->remove_instance (plan, 0, any); + } + catch (...) + { //swallow + } + } + + + char * + Container_Handler_i::instance_type (void) + { + CIAO_TRACE ("Container_Handler_i::instance_type"); + return CORBA::string_dup ("edu.dre.vanderbilt.dre.DAnCE.CCM.Container"); + } + + + void + Container_Handler_i::install_instance (const ::Deployment::DeploymentPlan &plan, + ::CORBA::ULong instanceRef, + ::CORBA::Any_out instance_reference) + { + CIAO_TRACE ("Container_Handler_i::install_instance"); + + CIAO::Session_Container *cont (0); + const char *name (plan.instance[instanceRef].name.in ()); + CORBA::PolicyList policies (0); + + CIAO_DEBUG (6, (LM_DEBUG, CLINFO + "Container_Handler_i::install_instance - " + "Creating container with id %C\n", + name)); + ACE_NEW_THROW_EX (cont, + CIAO::Session_Container (this->orb_, + this->poa_, + 0 /* not needed */, + false /* we're always dynanic for the moment */, + 0, /*always dynanic */ + name, + 0 /* no additional policies at this moment */), + CORBA::NO_MEMORY ()); + + CIAO_DEBUG (8, (LM_DEBUG, CLINFO + "Container_Handler_i::install_instance - " + "Container <%C> successfully created\n", + name)); + + CIAO::Container_var container_ref (cont); + + DEPLOYMENT_STATE::instance ()->add_container (name, + cont); + + ::CORBA::Any_ptr outref; + ACE_NEW_THROW_EX (outref, + ::CORBA::Any (), + CORBA::NO_MEMORY ()); + + (*outref) <<= container_ref; + + instance_reference = outref; + } + + void + Container_Handler_i::activate_instance (const ::Deployment::DeploymentPlan & , + ::CORBA::ULong , + const ::CORBA::Any &) + { + CIAO_TRACE ("Container_Handler_i::activate_instance"); + // no activation needed. + } + + void + Container_Handler_i::passivate_instance (const ::Deployment::DeploymentPlan & , + ::CORBA::ULong , + const ::CORBA::Any &) + { + CIAO_TRACE ("Container_Handler_i::passivate_instance"); + // no passivation needed. + } + + void + Container_Handler_i::provide_endpoint_reference (const ::Deployment::DeploymentPlan &, + ::CORBA::ULong, + ::CORBA::Any_out) + { + CIAO_TRACE ("Container_Handler_i::provide_endpoint_reference"); + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Container_Handler_i::provide_endpoint_reference - " + "Unable to provide any endpoints.\n")); + throw CORBA::NO_IMPLEMENT (); + } + + void + Container_Handler_i::remove_instance (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong instanceRef, + const ::CORBA::Any &) + { + CIAO_TRACE ("Container_Handler_i::remove_instance"); + + const char *name = plan.instance[instanceRef].name.in (); + + ::CIAO::Container_var cont = + DEPLOYMENT_STATE::instance ()->fetch_container (name); + + if (!cont) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO, + "Container_Handler_i::remove_instance - " + "Error, no contianer with id <%C>", + name)); + throw ::Deployment::StopError (name, + "No container with ID"); + } + + + CIAO_DEBUG (8, (LM_TRACE, CLINFO + "Container_Handler_i::remove_instance - " + "Removing container with Id <%C>\n", + name)); + + DEPLOYMENT_STATE::instance ()->remove_container (name); + + CIAO_DEBUG (5, (LM_TRACE, CLINFO + "Container_Handler_i::remove_instance - " + "Container with Id <%C> removed.\n", + name)); + } + + + void + Container_Handler_i::connect_instance (const ::Deployment::DeploymentPlan &, + ::CORBA::ULong, + const ::CORBA::Any &) + { + CIAO_TRACE ("Container_Handler_i::connect_instance"); + + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Container_Handler_i::connect_instance - ", + "No connections allowed for containers.\n")); + throw CORBA::NO_IMPLEMENT (); + } + + + void + Container_Handler_i::disconnect_instance (const ::Deployment::DeploymentPlan &, + ::CORBA::ULong) + { + CIAO_TRACE ("Container_Handler_i::disconnect_instance"); + + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Container_Handler_i::disconnect_instance - ", + "No connections allowed for containers.\n")); + throw CORBA::NO_IMPLEMENT (); + } + + void + Container_Handler_i::instance_configured (const ::Deployment::DeploymentPlan &, + ::CORBA::ULong) + { + CIAO_TRACE ("Container_Handler_i::instance_configured"); + // nothing to be done + } +} + diff --git a/modules/CIAO/ciao/Deployment/Handlers/Container_Handler.h b/modules/CIAO/ciao/Deployment/Handlers/Container_Handler.h new file mode 100644 index 00000000000..c0ea9e940ff --- /dev/null +++ b/modules/CIAO/ciao/Deployment/Handlers/Container_Handler.h @@ -0,0 +1,87 @@ + +// -*- C++ -*- +// $Id$ + +/** + * @file Locality_Manager_Handler_Impl.h + * @author William R. Otte <wotte@dre.vanderbilt.edu> + * + * Installation handler implementation for spawning LocalityManagers. + */ + +#ifndef CIAO_CONTAINER_HANDLER_H +#define CIAO_CONTAINER_HANDLER_H + +#include "tao/ORB.h" +#include "tao/PortableServer/POAC.h" +#include "DAnCE/DAnCE_LocalityManagerS.h" +#include "DAnCE/DAnCE_Utility.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +#pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ciao/Deployment/Handlers/CIAO_Locality_Handler_Export.h" +#include "tao/LocalObject.h" +#include <set> +namespace CIAO +{ + class CIAO_LocalityActivator_i; + + class CIAO_Locality_Handler_Export Container_Handler_i + : public virtual DAnCE::InstanceDeploymentHandler, + public virtual ::CORBA::LocalObject + { + public: + // Constructor + Container_Handler_i (const DAnCE::Utility::PROPERTY_MAP &props, + CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa); + + // Destructor + virtual ~Container_Handler_i (void); + + virtual + char * instance_type (void); + + virtual + void install_instance (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong instanceRef, + ::CORBA::Any_out instance_reference); + + virtual + void activate_instance (const ::Deployment::DeploymentPlan & , + ::CORBA::ULong , + const ::CORBA::Any &); + virtual + void passivate_instance (const ::Deployment::DeploymentPlan & , + ::CORBA::ULong , + const ::CORBA::Any &); + + virtual + void remove_instance (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong instanceRef, + const ::CORBA::Any & instance_reference); + + virtual + void provide_endpoint_reference (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef, + ::CORBA::Any_out endpoint_reference); + virtual + void connect_instance (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef, + const ::CORBA::Any & provided_reference); + + virtual + void disconnect_instance (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef); + + virtual + void instance_configured (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong instanceRef); + private: + CORBA::ORB_var orb_; + PortableServer::POA_var poa_; + }; +} +#endif diff --git a/modules/CIAO/ciao/Deployment/Handlers/Home_Handler.cpp b/modules/CIAO/ciao/Deployment/Handlers/Home_Handler.cpp new file mode 100644 index 00000000000..877b88a137b --- /dev/null +++ b/modules/CIAO/ciao/Deployment/Handlers/Home_Handler.cpp @@ -0,0 +1,377 @@ +// $Id$ + +#include "Home_Handler.h" +#include "ciao/Logger/Log_Macros.h" +#include "ciao/ComponentServer/CIAO_PropertiesC.h" +#include "ciao/Containers/Container_BaseC.h" +#include "CIAO_State.h" + +namespace CIAO +{ + Home_Handler_i::Home_Handler_i (void) + { + CIAO_TRACE ("Home_Handler_i::Home_Handler_i"); + } + + // Destructor + Home_Handler_i::~Home_Handler_i (void) + { + CIAO_TRACE ("Home_Handler_i::~Home_Handler_i"); + } + + + char * + Home_Handler_i::instance_type (void) + { + CIAO_TRACE ("Home_Handler_i::instance_type"); + return CORBA::string_dup ("edu.dre.vanderbilt.dre.CCM.Home"); + } + + + void + Home_Handler_i::install_instance (const ::Deployment::DeploymentPlan &plan, + ::CORBA::ULong instanceRef, + ::CORBA::Any_out instance_reference) + { + CIAO_TRACE ("Home_Handler_i::install_instance"); + + const ::Deployment::InstanceDeploymentDescription &idd (plan.instance[instanceRef]); + const ::Deployment::MonolithicDeploymentDescription &mdd (plan.implementation[idd.implementationRef]); + + DAnCE::Utility::PROPERTY_MAP *pmap; + + ACE_NEW_THROW_EX (pmap, + DAnCE::Utility::PROPERTY_MAP (idd.configProperty.length () + + mdd.execParameter.length ()), + CORBA::NO_MEMORY ()); + + Deployment_Common::Instance_Info info; + info.name = idd.name.in (); + info.pmap.reset (pmap); + + + DAnCE::Utility::build_property_map (*pmap, + mdd.execParameter); + DAnCE::Utility::build_property_map (*pmap, + idd.configProperty); + + CORBA::String_var exec_art, exec_entry, svnt_art, svnt_entry, cont_id; + + using namespace CIAO::Deployment; + CORBA::Any val; + const char *tmp; + + if ((pmap->find (SVNT_ENTRYPT, val)) == 0) + { + val >>= tmp; + svnt_entry = tmp; + CIAO_DEBUG (9, (LM_TRACE, CLINFO + "Home_Handler_i::install_instance - " + "Found Servant entrypoint %C\n", svnt_entry.in ())); + } + else + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Home_Handler_i::install_instance - " + "Error: No Servant entrypoint (%C) provided, aborting installation\n", + SVNT_ENTRYPT)); + throw ::Deployment::InvalidComponentExecParameter (idd.name.in (), + "No servant entrypoint identified."); + } + + if (pmap->find (SVNT_ARTIFACT, val) == 0) + { + val >>= tmp; + CIAO_DEBUG (9, (LM_TRACE, CLINFO + "Home_Handler_i::install_instance - " + "Found Servant artifact %C\n", tmp)); + svnt_art = Deployment_Common::get_implementation (tmp, plan); + } + else + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Home_Handler_i::install_instance - " + "Error: No Servant artifact provided, aborting installation\n")); + throw ::Deployment::InvalidComponentExecParameter (idd.name.in (), + "No servant artifact identified."); + } + + + if (pmap->find (EXEC_ARTIFACT, val) == 0) + { + val >>= tmp; + exec_art = Deployment_Common::get_implementation (tmp, plan); + CIAO_DEBUG (9, (LM_TRACE, CLINFO + "Home_Handler_i::install_instance - " + "Found executor artifact: %C\n", exec_art.in ())); + } + else + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Home_Handler_i::install_instance - " + "Error: No Executor artifact provided, aborting installation\n")); + throw ::Deployment::InvalidComponentExecParameter (idd.name.in (), + "No executory artifact identified.\n"); + } + + if (pmap->find (HOME_FACTORY, val) == 0) + { + val >>= tmp; + exec_entry = tmp; + CIAO_DEBUG (9, (LM_TRACE, CLINFO + "Home_Handler_i::install_instance - " + "Found executor entrypoint: %C\n", exec_entry.in ())); + } + else + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Home_Handler_i::install_instance - " + "Error: No Executor artifact provided, aborting installation\n")); + throw ::Deployment::InvalidComponentExecParameter (idd.name.in (), + "No executor entrypoint provided\n"); + } + + if (pmap->find (CONTAINER_ID, val) == 0) + { + val >>= tmp; + cont_id = tmp; + CIAO_DEBUG (9, (LM_TRACE, CLINFO + "Home_Handler_i::install_instance - " + "Found executor entrypoint: %C\n", exec_entry.in ())); + } + else + { + CIAO_ERROR (4, (LM_INFO, CLINFO + "Home_Handler_i::install_instance - " + "No container provided, using default container for instance <%C>\n", + idd.name.in ())); + cont_id = ""; + } + + ::CIAO::Container_var container = DEPLOYMENT_STATE::instance ()->fetch_container (cont_id); + + if (CORBA::is_nil (container)) + { + CIAO_ERROR (1, (LM_INFO, CLINFO + "Home_Handler_i::install_instance - " + "Container with Id <%C> not installed, aborting.\n", + cont_id.in ())); + throw ::Deployment::InvalidComponentExecParameter (idd.name.in (), + "Invalid container\n"); + } + + Components::CCMHome_var home_ref; + + try + { + home_ref = container->install_home (exec_art, + exec_entry, + svnt_art, + svnt_entry, + idd.name.in ()); + } + catch (::CORBA::Exception &ex) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Home_Handler_i::install_instance - " + "Caught CORBA exception <%C>\n", + ex._info ().c_str ())); + throw ::Deployment::StartError (idd.name.in (), + ex._info ().c_str ()); + } + catch (...) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Home_Handler_i::install_instance - " + "Caught unknown C++ exception\n")); + throw ::Deployment::StartError (idd.name.in (), + "Unknown C++ exception\n"); + } + + if (CORBA::is_nil (home_ref)) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Home_Handler_i::install_instance - " + "Container provided nil object reference for home.\n")); + throw ::Deployment::StartError (idd.name.in (), + "Container provided nil object reference"); + } + + this->instances_[idd.name.in ()] = info; + + DEPLOYMENT_STATE::instance ()->add_home (idd.name.in (), cont_id, home_ref.in ()); + + CORBA::Any *retval; + ACE_NEW_THROW_EX (retval, + CORBA::Any (), + CORBA::NO_MEMORY ()); + + (*retval) <<= home_ref; + instance_reference = retval; + } + + + void + Home_Handler_i::activate_instance (const ::Deployment::DeploymentPlan & , + ::CORBA::ULong , + const ::CORBA::Any &) + { + CIAO_TRACE ("Home_Handler_i::activate_instance"); + // no activation needed. + } + + void + Home_Handler_i::passivate_instance (const ::Deployment::DeploymentPlan & , + ::CORBA::ULong , + const ::CORBA::Any &) + { + CIAO_TRACE ("Home_Handler_i::passivate_instance"); + // no passivation needed. + } + + void + Home_Handler_i::remove_instance (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong instanceRef, + const ::CORBA::Any & instance_reference) + { + CIAO_TRACE ("Home_Handler_i::remove_instance"); + + const char *name = plan.instance[instanceRef].name.in (); + Deployment_Common::INSTANCES::iterator instance + = this->instances_.find (name); + + if (instance == this->instances_.end ()) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Home_Handler_i::remove_instance - " + "Instructed to remove unknown home instance <%C>\n", + name)); + throw ::Deployment::StopError (name, + "Wrong instance handler for home instance\n"); + } + + CIAO_DEBUG (8, (LM_DEBUG, CLINFO + "Home_Handler_i::remove_instance - " + "Attempting removal of home instance <%C>\n", + name)); + + Components::CCMHome_var ref; + + if (!(instance_reference >>= ref) || + CORBA::is_nil (ref)) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Home_Handler_i::remove_instance - " + "Unable to convert provided instance reference to CCMHome " + "while removing instance <%C>\n", + name)); + throw ::Deployment::StopError (name, + "Unable to narrow reference to CCMHome"); + } + + CORBA::Any val; + const char *cont_id; + + if (instance->second.pmap->find (Deployment::CONTAINER_ID, val) == 0) + { + val >>= cont_id; + CIAO_DEBUG (9, (LM_TRACE, CLINFO + "Home_Handler_i::remove_instance - " + "Found home container: %C\n", cont_id)); + } + else + { + CIAO_ERROR (4, (LM_INFO, CLINFO + "Home_Handler_i::remove_instance - " + "No container provided, using default container for instance <%C>\n", + name)); + cont_id = ""; + } + + ::CIAO::Container_var container = DEPLOYMENT_STATE::instance ()->fetch_container (cont_id); + + if (CORBA::is_nil (container)) + { + CIAO_ERROR (1, (LM_INFO, CLINFO + "Home_Handler_i::remove_instance - " + "Container with Id <%C> not installed, aborting.\n", + cont_id)); + throw ::Deployment::StopError (name, + "Invalid container\n"); + } + + try + { + container->uninstall_home (ref); + } + catch (CORBA::Exception &ex) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Home_Handler_i::remove_instance - " + "Caught CORBA exception <%C>\n", + ex._info ().c_str ())); + throw ::Deployment::StopError (name, + ex._info ().c_str ()); + } + catch (...) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Home_Handler_i::remove_instance - " + "Caught unknown C++ exception\n")); + throw ::Deployment::StopError (name, + "Unknown C++ exception\n"); + } + + this->instances_.erase (instance); + + CIAO_DEBUG (4, (LM_INFO, CLINFO + "Home_Handler_i::remove_instance - " + "Instance <%C> successfully removed\n", + name)); + } + + void + Home_Handler_i::provide_endpoint_reference (const ::Deployment::DeploymentPlan &, + ::CORBA::ULong, + ::CORBA::Any_out) + { + CIAO_TRACE ("Home_Handler_i::provide_endpoint_reference"); + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Home_Handler_i::provide_endpoint_reference - " + "Unable to provide any endpoints.\n")); + throw CORBA::NO_IMPLEMENT (); + } + + void + Home_Handler_i::connect_instance (const ::Deployment::DeploymentPlan &, + ::CORBA::ULong, + const ::CORBA::Any &) + { + CIAO_TRACE ("Home_Handler_i::connect_instance"); + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Home_Handler_i::connect_instance - ", + "No connections allowed for homes.\n")); + throw CORBA::NO_IMPLEMENT (); + } + + + void + Home_Handler_i::disconnect_instance (const ::Deployment::DeploymentPlan &, + ::CORBA::ULong) + { + CIAO_TRACE ("Home_Handler_i::disconnect_instance"); + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Home_Handler_i::disconnect_instance - ", + "No connections allowed for homes.\n")); + throw CORBA::NO_IMPLEMENT (); + } + + + void + Home_Handler_i::instance_configured (const ::Deployment::DeploymentPlan &, + ::CORBA::ULong) + { + CIAO_TRACE ("Home_Handler_i::instance_configured"); + // nothing to be done + } +} diff --git a/modules/CIAO/ciao/Deployment/Handlers/Home_Handler.h b/modules/CIAO/ciao/Deployment/Handlers/Home_Handler.h new file mode 100644 index 00000000000..38bd716bc3b --- /dev/null +++ b/modules/CIAO/ciao/Deployment/Handlers/Home_Handler.h @@ -0,0 +1,83 @@ + +// -*- C++ -*- +// $Id$ + +/** + * @file Locality_Manager_Handler_Impl.h + * @author William R. Otte <wotte@dre.vanderbilt.edu> + * + * Installation handler implementation for spawning LocalityManagers. + */ + +#ifndef CIAO_HOME_HANDLER_H +#define CIAO_HOME_HANDLER_H + +#include "DAnCE/DAnCE_LocalityManagerS.h" +#include "DAnCE/DAnCE_Utility.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +#pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ciao/Deployment/Handlers/CIAO_Locality_Handler_Export.h" +#include "tao/LocalObject.h" + +#include "ciao/Deployment/Handlers/CIAO_Handler_Common.h" + +namespace CIAO +{ + class CIAO_Locality_Handler_Export Home_Handler_i + : public virtual DAnCE::InstanceDeploymentHandler, + public virtual ::CORBA::LocalObject + { + public: + // Constructor + Home_Handler_i (void); + + // Destructor + virtual ~Home_Handler_i (void); + + virtual + char * instance_type (void); + + virtual + void install_instance (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong instanceRef, + ::CORBA::Any_out instance_reference); + + virtual + void activate_instance (const ::Deployment::DeploymentPlan & , + ::CORBA::ULong , + const ::CORBA::Any &); + virtual + void passivate_instance (const ::Deployment::DeploymentPlan & , + ::CORBA::ULong , + const ::CORBA::Any &); + + virtual + void remove_instance (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong instanceRef, + const ::CORBA::Any & instance_reference); + + virtual + void provide_endpoint_reference (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef, + ::CORBA::Any_out endpoint_reference); + + virtual + void connect_instance (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef, + const ::CORBA::Any & provided_reference); + + virtual + void disconnect_instance (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef); + + virtual + void instance_configured (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong instanceRef); + private: + Deployment_Common::INSTANCES instances_; + }; +} +#endif diff --git a/modules/CIAO/ciao/Deployment/Handlers/Homed_Component_Handler.cpp b/modules/CIAO/ciao/Deployment/Handlers/Homed_Component_Handler.cpp new file mode 100644 index 00000000000..2f127234d18 --- /dev/null +++ b/modules/CIAO/ciao/Deployment/Handlers/Homed_Component_Handler.cpp @@ -0,0 +1,392 @@ +// $Id$ + +#include "Homed_Component_Handler.h" +#include "ccm/CCM_KeylessCCMHomeC.h" +#include "ciao/Logger/Log_Macros.h" +#include "ciao/ComponentServer/CIAO_PropertiesC.h" +#include "DAnCE/Deployment/Deployment_StartErrorC.h" +#include "CIAO_Handler_Common.h" +#include "CIAO_State.h" + +namespace CIAO +{ + Homed_Component_Handler_i::Homed_Component_Handler_i () + { + CIAO_TRACE ("Homed_Component_Handler_i::Homed_Component_Handler_i"); + } + + // Destructor + Homed_Component_Handler_i::~Homed_Component_Handler_i (void) + { + CIAO_TRACE ("Homed_Component_Handler_i::~Homed_Component_Handler_i"); + } + + + char * + Homed_Component_Handler_i::instance_type (void) + { + CIAO_TRACE ("Homed_Component_Handler_i::instance_type"); + return CORBA::string_dup ("edu.vanderbilt.dre.CCM.HomedComponent"); + } + + + void + Homed_Component_Handler_i::install_instance (const ::Deployment::DeploymentPlan &plan, + ::CORBA::ULong instanceRef, + ::CORBA::Any_out instance_reference) + { + CIAO_TRACE ("Homed_Component_Handler_i::install_instance"); + + const ::Deployment::InstanceDeploymentDescription &idd (plan.instance[instanceRef]); + const ::Deployment::MonolithicDeploymentDescription &mdd (plan.implementation[idd.implementationRef]); + + DAnCE::Utility::PROPERTY_MAP *pmap; + + ACE_NEW_THROW_EX (pmap, + DAnCE::Utility::PROPERTY_MAP (idd.configProperty.length () + + mdd.execParameter.length ()), + CORBA::NO_MEMORY ()); + + Deployment_Common::Instance_Info info; + info.name = idd.name.in (); + info.pmap.reset (pmap); + + + DAnCE::Utility::build_property_map (*pmap, + mdd.execParameter); + DAnCE::Utility::build_property_map (*pmap, + idd.configProperty); + + + using namespace CIAO::Deployment; + CORBA::Any val; + const char *tmp; + + if (pmap->find (COMPONENT_HOME, val) == 0) + { + val >>= tmp; + CIAO_DEBUG (9, (LM_TRACE, CLINFO + "Homed_Component_Handler_i::install_instance - " + "Found component home ID %C\n", tmp)); + } + else + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Homed_Component_Handler_i::install_instance - " + "Error: No home ID provided, aborting installation\n")); + throw ::Deployment::PlanError (idd.name.in (), + "No Home identified."); + } + + Components::CCMHome_var tmp_home = DEPLOYMENT_STATE::instance ()->fetch_home (tmp); + + Components::KeylessCCMHome_var home = Components::KeylessCCMHome::_narrow (tmp_home); + if (CORBA::is_nil (home)) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Homed_Component_Handler_i::install_instance - " + "Object reference for Home <%C> is not available for component <%C>\n", + tmp, idd.name.in ())); + throw ::Deployment::StartError (idd.name.in (), + "Home ID is not available"); + } + + Components::CCMObject_var ref; + try + { + ref = home->create_component (); + } + catch (const CORBA::Exception &ex) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Homed_Component_Handler_i::install_instance - " + "Caught CORBA exception while installing component <%C>: %C\n", + idd.name.in (), + ex._info ().c_str ())); + throw ::Deployment::StartError (idd.name.in (), + ex._info ().c_str ()); + } + catch (...) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Homed_Component_Handler_i::install_instance - " + "Caught C++ exception while installing component <%C>\n", + idd.name.in ())); + throw ::Deployment::StartError (idd.name.in (), + "Unknown C++ exception"); + } + + if (CORBA::is_nil (ref.in ())) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Homed_Component_Handler_i::install_instance - " + "Received nil object reference from create on Home <%C> " + "while creating component <%C>\n", + tmp, + idd.name.in ())); + throw ::Deployment::StartError (idd.name.in (), + "Nil reference from home on create"); + } + + + CIAO_DEBUG (4, (LM_ERROR, CLINFO + "Homed_Component_Handler_i::install_instance - " + "Successfully created component <%C>\n", + idd.name.in ())); + + this->instances_[idd.name.in ()] = info; + + const char *cont_id = + DEPLOYMENT_STATE::instance ()->instance_to_container (tmp); + + DEPLOYMENT_STATE::instance ()->add_component (idd.name.in (), + cont_id, + ref.in ()); + + CORBA::Any *any; + ACE_NEW_THROW_EX (any, + CORBA::Any (), + CORBA::NO_MEMORY ()); + + (*any) <<= ref; + + instance_reference = any; + } + + + void + Homed_Component_Handler_i::activate_instance (const ::Deployment::DeploymentPlan &plan, + ::CORBA::ULong instanceRef, + const ::CORBA::Any &) + { + CIAO_TRACE ("Homed_Component_Handler_i::activate_instance"); + + const char *name = plan.instance[instanceRef].name.in (); + + const char *container = + DEPLOYMENT_STATE::instance ()->instance_to_container (name); + + CIAO::Container_var cont = + DEPLOYMENT_STATE::instance ()->fetch_container (container); + + Components::CCMObject_var comp = + DEPLOYMENT_STATE::instance ()->fetch_component (name); + + try + { + cont->activate_component (comp.in ()); + } + catch (CORBA::Exception &ex) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Homed_Component_Handler_i::activate_instance - " + "Caught CORBA Exception while activating instance <%C>: %C\n", + name, + ex._info ().c_str ())); + throw ::Deployment::StartError (name, + ex._info ().c_str ()); + } + catch (...) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Homed_Component_Handler_i::activate_instance - " + "Caught C++ Exception while activating instance <%C>\n", + name)); + throw ::Deployment::StartError (name, + "Unknown C++ exception during activation"); + } + } + + void + Homed_Component_Handler_i::passivate_instance (const ::Deployment::DeploymentPlan &plan, + ::CORBA::ULong instanceRef, + const ::CORBA::Any &) + { + CIAO_TRACE ("Homed_Component_Handler_i::passivate_instance"); + + const char *name = plan.instance[instanceRef].name.in (); + + const char *container = + DEPLOYMENT_STATE::instance ()->instance_to_container (name); + + CIAO::Container_var cont = + DEPLOYMENT_STATE::instance ()->fetch_container (container); + + Components::CCMObject_var comp = + DEPLOYMENT_STATE::instance ()->fetch_component (name); + + try + { + cont->passivate_component (comp.in ()); + } + catch (CORBA::Exception &ex) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Homed_Component_Handler_i::passivate_instance - " + "Caught CORBA Exception while passivating instance <%C>: %C\n", + name, + ex._info ().c_str ())); + throw ::Deployment::StopError (name, + ex._info ().c_str ()); + } + catch (...) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Homed_Component_Handler_i::passivate_instance - " + "Caught C++ Exception while passivating instance <%C>\n", + name)); + throw ::Deployment::StartError (name, + "Unknown C++ exception during passivation"); + } + } + + void + Homed_Component_Handler_i::remove_instance (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong instanceRef, + const ::CORBA::Any & instance_reference) + { + CIAO_TRACE ("Homed_Component_Handler_i::remove_instance"); + + const char *name = plan.instance[instanceRef].name.in (); + Deployment_Common::INSTANCES::iterator instance + = this->instances_.find (name); + + if (instance == this->instances_.end ()) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Homed_Component_Handler_i::remove_instance - " + "Instructed to remove unknown homed component instance <%C>\n", + name)); + throw ::Deployment::StopError (name, + "Wrong instance handler for homed component instance\n"); + } + + CIAO_DEBUG (8, (LM_DEBUG, CLINFO + "Homed_Component_Handler_i::remove_instance - " + "Attempting removal of homed component instance <%C>\n", + name)); + + Components::CCMObject_var ref; + if (!(instance_reference >>= ref) || + CORBA::is_nil (ref)) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Homed_Component_Handler_i::remove_instance - " + "Unable to convert provided instance reference to CCMObject " + "while removing instance <%C>\n", + name)); + throw ::Deployment::StopError (name, + "Unable to narrow reference to CCMObject"); + } + + using namespace CIAO::Deployment; + CORBA::Any val; + const char *tmp; + + if (instance->second.pmap->find (COMPONENT_HOME, val) == 0) + { + val >>= tmp; + CIAO_DEBUG (9, (LM_TRACE, CLINFO + "Homed_Component_Handler_i::remove_instance - " + "Found component home ID %C\n", tmp)); + } + else + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Homed_Component_Handler_i::remove_instance - " + "Error: No home ID provided, aborting removal\n")); + throw ::Deployment::StopError (name, + "No Home identified."); + } + + Components::CCMHome_var home = DEPLOYMENT_STATE::instance ()->fetch_home (tmp); + + if (CORBA::is_nil (home)) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Homed_Component_Handler_i::remove_instance - " + "Object reference for Home <%C> is not available for component <%C>\n", + tmp, name)); + throw ::Deployment::StopError (name, + "Home ID is not available"); + } + + try + { + home->remove_component (ref.in ()); + } + catch (const CORBA::Exception &ex) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Homed_Component_Handler_i::remove_instance - " + "Caught CORBA exception while removing component <%C>: %C\n", + name, + ex._info ().c_str ())); + throw ::Deployment::StopError (name, + ex._info ().c_str ()); + } + catch (...) + { + CIAO_ERROR (1, (LM_ERROR, CLINFO + "Homed_Component_Handler_i::remove_instance - " + "Caught C++ exception while removing component <%C>\n", + name)); + throw ::Deployment::StopError (name, + "Unknown C++ exception"); + } + + CIAO_DEBUG (4, (LM_INFO, CLINFO + "Homed_Component_Handler_i::remove_instance - " + "Component <%C> successfully removed\n")); + + this->instances_.erase (instance); + + DEPLOYMENT_STATE::instance ()->remove_component (name); + } + + void + Homed_Component_Handler_i::provide_endpoint_reference (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef, + ::CORBA::Any_out endpoint_reference) + { + CIAO_TRACE ("Homed_Component_Handler_i::provide_endpoint_reference"); + + DEPLOYMENT_STATE::instance ()->connection_handler.provide_endpoint_reference (plan, + connectionRef, + endpoint_reference); + } + + void + Homed_Component_Handler_i::connect_instance (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef, + const ::CORBA::Any & provided_reference) + { + CIAO_TRACE ("Homed_Component_Handler_i::connect_instance"); + + DEPLOYMENT_STATE::instance ()->connection_handler.connect_instance (plan, + connectionRef, + provided_reference); + } + + + void + Homed_Component_Handler_i::disconnect_instance (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef) + { + CIAO_TRACE ("Homed_Component_Handler_i::disconnect_instance"); + DEPLOYMENT_STATE::instance ()->connection_handler.disconnect_instance (plan, + connectionRef); + } + + void + Homed_Component_Handler_i::instance_configured (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong instanceRef) + { + CIAO_TRACE ("Homed_Component_Handler_i::instance_configured"); + + Components::CCMObject_var ref = + DEPLOYMENT_STATE::instance ()->fetch_component (plan.instance[instanceRef].name.in ()); + + ref->configuration_complete (); + } +} diff --git a/modules/CIAO/ciao/Deployment/Handlers/Homed_Component_Handler.h b/modules/CIAO/ciao/Deployment/Handlers/Homed_Component_Handler.h new file mode 100644 index 00000000000..99f9d081b95 --- /dev/null +++ b/modules/CIAO/ciao/Deployment/Handlers/Homed_Component_Handler.h @@ -0,0 +1,84 @@ + +// -*- C++ -*- +// $Id$ + +/** + * @file Locality_Manager_Handler_Impl.h + * @author William R. Otte <wotte@dre.vanderbilt.edu> + * + * Installation handler implementation for spawning LocalityManagers. + */ + +#ifndef CIAO_HOMED_COMPONENT_HANDLER_H +#define CIAO_HOMED_COMPONENT_HANDLER_H + +#include "DAnCE/DAnCE_LocalityManagerS.h" +#include "DAnCE/DAnCE_Utility.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +#pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ciao/Deployment/Handlers/CIAO_Locality_Handler_Export.h" +#include "tao/LocalObject.h" +#include "ciao/Deployment/Handlers/CIAO_Handler_Common.h" + +namespace CIAO +{ + class CIAO_LocalityActivator_i; + + class CIAO_Locality_Handler_Export Homed_Component_Handler_i + : public virtual DAnCE::InstanceDeploymentHandler, + public virtual ::CORBA::LocalObject + { + public: + // Constructor + Homed_Component_Handler_i (); + + // Destructor + virtual ~Homed_Component_Handler_i (void); + + virtual + char * instance_type (void); + + virtual + void install_instance (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong instanceRef, + ::CORBA::Any_out instance_reference); + + virtual + void activate_instance (const ::Deployment::DeploymentPlan & , + ::CORBA::ULong , + const ::CORBA::Any &); + virtual + void passivate_instance (const ::Deployment::DeploymentPlan & , + ::CORBA::ULong , + const ::CORBA::Any &); + + virtual + void remove_instance (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong instanceRef, + const ::CORBA::Any & instance_reference); + + virtual + void provide_endpoint_reference (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef, + ::CORBA::Any_out endpoint_reference); + + virtual + void connect_instance (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef, + const ::CORBA::Any & provided_reference); + + virtual + void disconnect_instance (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong connectionRef); + + virtual + void instance_configured (const ::Deployment::DeploymentPlan & plan, + ::CORBA::ULong instanceRef); + private: + Deployment_Common::INSTANCES instances_; + }; +} +#endif |