diff options
Diffstat (limited to 'modules/CIAO/ciao/Servants')
31 files changed, 3335 insertions, 0 deletions
diff --git a/modules/CIAO/ciao/Servants/CIAO_Port_Activator.idl b/modules/CIAO/ciao/Servants/CIAO_Port_Activator.idl new file mode 100644 index 00000000000..593a9b33ce0 --- /dev/null +++ b/modules/CIAO/ciao/Servants/CIAO_Port_Activator.idl @@ -0,0 +1,37 @@ +/** + * @file CIAO_Port_Activator.idl + * @author Wiliam R. Otte <wotte@dre.vanderbilt.edu + * $Id$ + * Local interface describing servant activators for component ports. + */ + +#ifndef CIAO_PORT_ACTIVATOR_IDL_ +#define CIAO_PORT_ACTIVATOR_IDL_ + +#include "tao/PortableServer/ServantActivator.pidl" + +module CIAO +{ + module Port_Activator_Types + { + enum Type + { + FACET, + SINK + }; + }; + + local interface Port_Activator + { + // OID of port this activator encapsulates + attribute string oid; + // name of the port + readonly attribute string name; + + PortableServer::Servant activate (in PortableServer::ObjectId oid); + + void deactivate (in PortableServer::Servant servant); + }; +}; + +#endif diff --git a/modules/CIAO/ciao/Servants/CIAO_Port_Activator_export.h b/modules/CIAO/ciao/Servants/CIAO_Port_Activator_export.h new file mode 100644 index 00000000000..7da2bf79f70 --- /dev/null +++ b/modules/CIAO/ciao/Servants/CIAO_Port_Activator_export.h @@ -0,0 +1,58 @@ + +// -*- C++ -*- +// $Id$ +// Definition for Win32 Export directives. +// This file is generated automatically by generate_export_file.pl CIAO_Port_Activator +// ------------------------------ +#ifndef CIAO_PORT_ACTIVATOR_EXPORT_H +#define CIAO_PORT_ACTIVATOR_EXPORT_H + +#include "ace/config-all.h" + +#if defined (ACE_AS_STATIC_LIBS) && !defined (CIAO_PORT_ACTIVATOR_HAS_DLL) +# define CIAO_PORT_ACTIVATOR_HAS_DLL 0 +#endif /* ACE_AS_STATIC_LIBS && CIAO_PORT_ACTIVATOR_HAS_DLL */ + +#if !defined (CIAO_PORT_ACTIVATOR_HAS_DLL) +# define CIAO_PORT_ACTIVATOR_HAS_DLL 1 +#endif /* ! CIAO_PORT_ACTIVATOR_HAS_DLL */ + +#if defined (CIAO_PORT_ACTIVATOR_HAS_DLL) && (CIAO_PORT_ACTIVATOR_HAS_DLL == 1) +# if defined (CIAO_PORT_ACTIVATOR_BUILD_DLL) +# define CIAO_Port_Activator_Export ACE_Proper_Export_Flag +# define CIAO_PORT_ACTIVATOR_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) +# define CIAO_PORT_ACTIVATOR_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# else /* CIAO_PORT_ACTIVATOR_BUILD_DLL */ +# define CIAO_Port_Activator_Export ACE_Proper_Import_Flag +# define CIAO_PORT_ACTIVATOR_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) +# define CIAO_PORT_ACTIVATOR_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# endif /* CIAO_PORT_ACTIVATOR_BUILD_DLL */ +#else /* CIAO_PORT_ACTIVATOR_HAS_DLL == 1 */ +# define CIAO_Port_Activator_Export +# define CIAO_PORT_ACTIVATOR_SINGLETON_DECLARATION(T) +# define CIAO_PORT_ACTIVATOR_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +#endif /* CIAO_PORT_ACTIVATOR_HAS_DLL == 1 */ + +// Set CIAO_PORT_ACTIVATOR_NTRACE = 0 to turn on library specific tracing even if +// tracing is turned off for ACE. +#if !defined (CIAO_PORT_ACTIVATOR_NTRACE) +# if (ACE_NTRACE == 1) +# define CIAO_PORT_ACTIVATOR_NTRACE 1 +# else /* (ACE_NTRACE == 1) */ +# define CIAO_PORT_ACTIVATOR_NTRACE 0 +# endif /* (ACE_NTRACE == 1) */ +#endif /* !CIAO_PORT_ACTIVATOR_NTRACE */ + +#if (CIAO_PORT_ACTIVATOR_NTRACE == 1) +# define CIAO_PORT_ACTIVATOR_TRACE(X) +#else /* (CIAO_PORT_ACTIVATOR_NTRACE == 1) */ +# if !defined (ACE_HAS_TRACE) +# define ACE_HAS_TRACE +# endif /* ACE_HAS_TRACE */ +# define CIAO_PORT_ACTIVATOR_TRACE(X) ACE_TRACE_IMPL(X) +# include "ace/Trace.h" +#endif /* (CIAO_PORT_ACTIVATOR_NTRACE == 1) */ + +#endif /* CIAO_PORT_ACTIVATOR_EXPORT_H */ + +// End of auto generated file. diff --git a/modules/CIAO/ciao/Servants/CIAO_Servant_Impl_export.h b/modules/CIAO/ciao/Servants/CIAO_Servant_Impl_export.h new file mode 100644 index 00000000000..c624a706b48 --- /dev/null +++ b/modules/CIAO/ciao/Servants/CIAO_Servant_Impl_export.h @@ -0,0 +1,58 @@ + +// -*- C++ -*- +// $Id$ +// Definition for Win32 Export directives. +// This file is generated automatically by generate_export_file.pl CIAO_Servant_Impl +// ------------------------------ +#ifndef CIAO_SERVANT_IMPL_EXPORT_H +#define CIAO_SERVANT_IMPL_EXPORT_H + +#include "ace/config-all.h" + +#if defined (ACE_AS_STATIC_LIBS) && !defined (CIAO_SERVANT_IMPL_HAS_DLL) +# define CIAO_SERVANT_IMPL_HAS_DLL 0 +#endif /* ACE_AS_STATIC_LIBS && CIAO_SERVANT_IMPL_HAS_DLL */ + +#if !defined (CIAO_SERVANT_IMPL_HAS_DLL) +# define CIAO_SERVANT_IMPL_HAS_DLL 1 +#endif /* ! CIAO_SERVANT_IMPL_HAS_DLL */ + +#if defined (CIAO_SERVANT_IMPL_HAS_DLL) && (CIAO_SERVANT_IMPL_HAS_DLL == 1) +# if defined (CIAO_SERVANT_IMPL_BUILD_DLL) +# define CIAO_Servant_Impl_Export ACE_Proper_Export_Flag +# define CIAO_SERVANT_IMPL_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) +# define CIAO_SERVANT_IMPL_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# else /* CIAO_SERVANT_IMPL_BUILD_DLL */ +# define CIAO_Servant_Impl_Export ACE_Proper_Import_Flag +# define CIAO_SERVANT_IMPL_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) +# define CIAO_SERVANT_IMPL_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# endif /* CIAO_SERVANT_IMPL_BUILD_DLL */ +#else /* CIAO_SERVANT_IMPL_HAS_DLL == 1 */ +# define CIAO_Servant_Impl_Export +# define CIAO_SERVANT_IMPL_SINGLETON_DECLARATION(T) +# define CIAO_SERVANT_IMPL_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +#endif /* CIAO_SERVANT_IMPL_HAS_DLL == 1 */ + +// Set CIAO_SERVANT_IMPL_NTRACE = 0 to turn on library specific tracing even if +// tracing is turned off for ACE. +#if !defined (CIAO_SERVANT_IMPL_NTRACE) +# if (ACE_NTRACE == 1) +# define CIAO_SERVANT_IMPL_NTRACE 1 +# else /* (ACE_NTRACE == 1) */ +# define CIAO_SERVANT_IMPL_NTRACE 0 +# endif /* (ACE_NTRACE == 1) */ +#endif /* !CIAO_SERVANT_IMPL_NTRACE */ + +#if (CIAO_SERVANT_IMPL_NTRACE == 1) +# define CIAO_SERVANT_IMPL_TRACE(X) +#else /* (CIAO_SERVANT_IMPL_NTRACE == 1) */ +# if !defined (ACE_HAS_TRACE) +# define ACE_HAS_TRACE +# endif /* ACE_HAS_TRACE */ +# define CIAO_SERVANT_IMPL_TRACE(X) ACE_TRACE_IMPL(X) +# include "ace/Trace.h" +#endif /* (CIAO_SERVANT_IMPL_NTRACE == 1) */ + +#endif /* CIAO_SERVANT_IMPL_EXPORT_H */ + +// End of auto generated file. diff --git a/modules/CIAO/ciao/Servants/Home_Servant_Impl_Base.cpp b/modules/CIAO/ciao/Servants/Home_Servant_Impl_Base.cpp new file mode 100644 index 00000000000..eeeedb34d59 --- /dev/null +++ b/modules/CIAO/ciao/Servants/Home_Servant_Impl_Base.cpp @@ -0,0 +1,31 @@ +// $Id$ + +#include "Home_Servant_Impl_Base.h" +#include "ciao/Containers/Container_Base.h" + +namespace CIAO +{ + Home_Servant_Impl_Base::Home_Servant_Impl_Base (Container_ptr c) + : container_ (Container::_duplicate(c)) + { + } + + Home_Servant_Impl_Base::~Home_Servant_Impl_Base (void) + { + } + + // Operations for CCMHome interface. + + CORBA::IRObject_ptr + Home_Servant_Impl_Base::get_component_def (void) + { + throw CORBA::NO_IMPLEMENT (); + } + + CORBA::IRObject_ptr + Home_Servant_Impl_Base::get_home_def (void) + { + throw CORBA::NO_IMPLEMENT (); + } + +} diff --git a/modules/CIAO/ciao/Servants/Home_Servant_Impl_Base.h b/modules/CIAO/ciao/Servants/Home_Servant_Impl_Base.h new file mode 100644 index 00000000000..f1c6de82b60 --- /dev/null +++ b/modules/CIAO/ciao/Servants/Home_Servant_Impl_Base.h @@ -0,0 +1,67 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Home_Servant_Impl_Base.h + * + * $Id$ + * + * This file contains the non-template declaration of a base class for + * the template mixin for the generated home servant class. + * + * @author Jeff Parsons <j.parsons@vanderbilt.edu> + */ +//============================================================================= + +#ifndef CIAO_HOME_SERVANT_IMPL_BASE_H +#define CIAO_HOME_SERVANT_IMPL_BASE_H + +#include /**/ "ace/pre.h" + +#include "CIAO_Servant_Impl_export.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ccm/CCM_HomeS.h" +#include "ciao/Containers/Container_BaseC.h" + +namespace CIAO +{ + /** + * @class Home_Servant_Impl_Base + * + * @brief Non-template base class for Home_Servant_Impl. + * + * Holds the non-template parts of its child class + * Home_Servant_Impl. + */ + class CIAO_Servant_Impl_Export Home_Servant_Impl_Base + : public virtual POA_Components::CCMHome + { + public: + Home_Servant_Impl_Base (Container_ptr c); + + virtual ~Home_Servant_Impl_Base (void); + + // Operations for CCMHome interface. + + virtual ::CORBA::IRObject_ptr get_component_def (void); + + virtual ::CORBA::IRObject_ptr get_home_def (void); + + virtual void update_component_map (PortableServer::ObjectId &oid) = 0; + + protected: + Container_var container_; + + private: + /// Not to be used + Home_Servant_Impl_Base (void); + }; +} + +#include /**/ "ace/post.h" + +#endif /* CIAO_HOME_SERVANT_IMPL_BASE_H */ diff --git a/modules/CIAO/ciao/Servants/Home_Servant_Impl_T.cpp b/modules/CIAO/ciao/Servants/Home_Servant_Impl_T.cpp new file mode 100644 index 00000000000..f6a58a6707a --- /dev/null +++ b/modules/CIAO/ciao/Servants/Home_Servant_Impl_T.cpp @@ -0,0 +1,226 @@ +// $Id$ + +#ifndef CIAO_HOME_SERVANT_IMPL_T_C +#define CIAO_HOME_SERVANT_IMPL_T_C + +#include "Home_Servant_Impl_T.h" +#include "ccm/CCM_ObjectC.h" +#include "ccm/CCM_EnterpriseComponentC.h" +#include "ciao/Containers/Container_BaseC.h" +#include "ciao/CIAO_common.h" + + +namespace CIAO +{ + template <typename BASE_SKEL, + typename EXEC, + typename COMP_SVNT> + Home_Servant_Impl<BASE_SKEL, + EXEC, + COMP_SVNT>::Home_Servant_Impl ( + typename EXEC::_ptr_type exe, + Container_ptr c, + const char *ins_name + ) + : Home_Servant_Impl_Base (c), + ins_name_ (ins_name), + executor_ (EXEC::_duplicate (exe)), + serial_number_ (0) + { + CIAO_DEBUG ((LM_TRACE, CLINFO "Home_Servant_Impl<>::Home_Servant_Impl - " + "Creating servant for home with ID %C\n", + ins_name)); + } + + template <typename BASE_SKEL, + typename EXEC, + typename COMP_SVNT> + Home_Servant_Impl<BASE_SKEL, + EXEC, + COMP_SVNT>::~Home_Servant_Impl (void) + { + CIAO_TRACE ("Home_Servant_Impl<>::destructor"); + + OBJ_ITERATOR const end = this->objref_map_.end (); + + for (OBJ_ITERATOR iter = this->objref_map_.begin (); + iter != end; + ++iter) + { + this->remove_component (((*iter).int_id_).in ()); + } + } + + // Operations for CCMHome interface. + + template <typename BASE_SKEL, + typename EXEC, + typename COMP_SVNT> + void + Home_Servant_Impl<BASE_SKEL, + EXEC, + COMP_SVNT>::remove_component ( + ::Components::CCMObject_ptr comp) + { + CIAO_TRACE ("Home_Servant_Impl<>::remove_component"); + + PortableServer::ObjectId_var oid = + this->container_->the_POA ()->reference_to_id (comp); + + Components::CCMObject_var ccm_obj_var = Components::CCMObject::_nil (); + if (objref_map_.find (oid.in (), ccm_obj_var) != 0) + { + CIAO_ERROR ((LM_WARNING, CLINFO "Home_Servant_Impl<>::remove_component - Invalid component object reference\n")); + throw Components::RemoveFailure (); + } + + typedef typename COMP_SVNT::_stub_type stub_type; + typename COMP_SVNT::_stub_var_type _ciao_comp = + stub_type::_narrow (ccm_obj_var.in ()); + + if (CORBA::is_nil (_ciao_comp.in ())) + { + throw Components::RemoveFailure (); + } + + _ciao_comp->remove (); + + CIAO_DEBUG ((LM_INFO, CLINFO "Home_Servant_Impl<>::remove_component - Removed the component\n")); + } + + template <typename BASE_SKEL, + typename EXEC, + typename COMP_SVNT> + void + Home_Servant_Impl<BASE_SKEL, + EXEC, + COMP_SVNT>::update_component_map ( + PortableServer::ObjectId &oid) + { + CIAO_TRACE ("Home_Servant_Impl<>::update_component_map"); + + Components::CCMObject_var ccm_obj_ptr; + if (objref_map_.unbind (oid, ccm_obj_ptr) != 0) + { + CIAO_ERROR ((LM_ERROR, CLINFO "Home_Servant_Impl<>::update_component_map - " + "Invalid component object reference\n")); + return; + } + + return; + } + + // Operations for keyless home interface. + + template <typename BASE_SKEL, + typename EXEC, + typename COMP_SVNT> + Components::CCMObject_ptr + Home_Servant_Impl<BASE_SKEL, + EXEC, + COMP_SVNT>::create_component (void) + { + CIAO_TRACE ("Home_Servant_Impl<>::create_component"); + + return this->create (); + } + + // Operations for implicit home interface. + + template <typename BASE_SKEL, + typename EXEC, + typename COMP_SVNT> + typename COMP_SVNT::_stub_ptr_type + Home_Servant_Impl<BASE_SKEL, + EXEC, + COMP_SVNT>::create (void) + { + CIAO_TRACE ("Home_Servant_Impl<>::create"); + + if (this->executor_.in () == 0) + { + CIAO_ERROR ((LM_ERROR, CLINFO "Home_Servant_Impl<>:create - nil executor reference\n")); + throw CORBA::INTERNAL (); + } + + ::Components::EnterpriseComponent_var _ciao_ec = + this->executor_->create (); + + typedef typename COMP_SVNT::_exec_type exec_type; + typename COMP_SVNT::_exec_type::_var_type _ciao_comp = + exec_type::_narrow (_ciao_ec.in ()); + + return this->_ciao_activate_component (_ciao_comp.in ()); + } + + // CIAO-specific operations. + + template <typename BASE_SKEL, + typename EXEC, + typename COMP_SVNT> + typename COMP_SVNT::_stub_ptr_type + Home_Servant_Impl<BASE_SKEL, + EXEC, + COMP_SVNT>::_ciao_activate_component ( + typename COMP_SVNT::_exec_type::_ptr_type exe) + { + CIAO_TRACE ("Home_Servant_Impl<>::_ciao_activate_component"); + + CORBA::Object_var hobj = this->container_->get_objref (this); + + Components::CCMHome_var home = + Components::CCMHome::_narrow (hobj.in ()); + + char buffer[256]; + unsigned long serial = this->serial_number_++; + ACE_OS::sprintf (buffer, + "%ld", + serial); + + typedef typename COMP_SVNT::_stub_type stub_type; + COMP_SVNT *svt = 0; + ACE_NEW_THROW_EX (svt, + COMP_SVNT (exe, + home.in (), + (this->ins_name_ + buffer).c_str (), + this, + this->container_), + CORBA::NO_MEMORY ()); + + PortableServer::ServantBase_var safe (svt); + PortableServer::ObjectId_var oid; + + CORBA::Object_var objref = + this->container_->install_servant (svt, + Container_Types::COMPONENT_t, + oid.out ()); + + typedef typename COMP_SVNT::_stub_type stub_type; + typename COMP_SVNT::_stub_var_type ho = stub_type::_narrow (objref.in ()); + + Components::CCMObject_var ccmobjref = + Components::CCMObject::_narrow (objref.in ()); + + this->objref_map_.bind ( + oid.in (), + Components::CCMObject::_duplicate (ccmobjref.in ())); + + return ho._retn (); + } + + template <typename BASE_SKEL, + typename EXEC, + typename COMP_SVNT> + void + Home_Servant_Impl<BASE_SKEL, + EXEC, + COMP_SVNT>::_ciao_passivate_component ( + typename COMP_SVNT::_stub_ptr_type comp) + { + CIAO_TRACE ("Home_Servant_Impl<>::_ciao_passivate_component"); + + this->container_->uninstall_component (comp); + } +} + +#endif /* CIAO_HOME_SERVANT_IMPL_T_C */ diff --git a/modules/CIAO/ciao/Servants/Home_Servant_Impl_T.h b/modules/CIAO/ciao/Servants/Home_Servant_Impl_T.h new file mode 100644 index 00000000000..199c3e83026 --- /dev/null +++ b/modules/CIAO/ciao/Servants/Home_Servant_Impl_T.h @@ -0,0 +1,112 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Home_Servant_Impl_T.h + * + * $Id$ + * + * This file contains the declaration of a mixin base class for + * the generated home servant class. + * + * @authors Jeff Parsons <j.parsons@vanderbilt.edu> + */ +//============================================================================= + + +#ifndef CIAO_HOME_SERVANT_IMPL_T_H +#define CIAO_HOME_SERVANT_IMPL_T_H + +#include /**/ "ace/pre.h" + +#include "Home_Servant_Impl_Base.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" + +namespace CIAO +{ + class Container; + typedef Container *Container_ptr; + + + /** + * @class Home_Servant_Impl + * + * @brief Mixin base class for generated home servant. + * + * This class implements operations + * common to all generated home servants. + */ + template <typename BASE_SKEL, + typename EXEC, + typename COMP_SVNT> + class Home_Servant_Impl + : public virtual BASE_SKEL, + public virtual Home_Servant_Impl_Base + { + public: + Home_Servant_Impl (typename EXEC::_ptr_type exe, + Container_ptr c, + const char *ins_name); + + virtual ~Home_Servant_Impl (void); + + // Operations for CCMHome interface. + + virtual void remove_component (Components::CCMObject_ptr comp); + + // Operations for keyless home interface. + + virtual ::Components::CCMObject_ptr create_component (); + + // Operations for implicit home interface. + + virtual typename COMP_SVNT::_stub_ptr_type create (); + + virtual void + update_component_map (PortableServer::ObjectId &oid); + + protected: + // CIAO-specific operations. + + typename COMP_SVNT::_stub_ptr_type + _ciao_activate_component (typename COMP_SVNT::_exec_type::_ptr_type exe); + + void + _ciao_passivate_component (typename COMP_SVNT::_stub_ptr_type comp); + + protected: + ACE_CString ins_name_; + typename EXEC::_var_type executor_; + + typedef ACE_Hash_Map_Manager_Ex<PortableServer::ObjectId, + Components::CCMObject_var, + TAO_ObjectId_Hash, + ACE_Equal_To<PortableServer::ObjectId>, + TAO_SYNCH_MUTEX> + OBJREF_MAP; + + typedef OBJREF_MAP::iterator OBJ_ITERATOR; + + OBJREF_MAP objref_map_; + + ACE_Atomic_Op <TAO_SYNCH_MUTEX, unsigned long> serial_number_; + }; +} + +#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) +#include "Home_Servant_Impl_T.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) +#pragma implementation ("Home_Servant_Impl_T.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + +#include /**/ "ace/post.h" + +#endif /* CIAO_HOME_SERVANT_IMPL_T_H */ diff --git a/modules/CIAO/ciao/Servants/Port_Activator.cpp b/modules/CIAO/ciao/Servants/Port_Activator.cpp new file mode 100644 index 00000000000..35f7b3981d0 --- /dev/null +++ b/modules/CIAO/ciao/Servants/Port_Activator.cpp @@ -0,0 +1,25 @@ +#include "Port_Activator.h" + +ACE_RCSID (ciao, + Servant_Activator, + "$Id$") + +#if !defined (__ACE_INLINE__) +# include "Port_Activator.inl" +#endif /* __ACE_INLINE__ */ + +namespace CIAO +{ + Port_Activator_i::Port_Activator_i (const char *oid, + const char *name, + Port_Activator_Types::Type t) + : oid_ (oid), + name_ (name), + t_ (t) + { + } + + Port_Activator_i::~Port_Activator_i (void) + { + } +} diff --git a/modules/CIAO/ciao/Servants/Port_Activator.h b/modules/CIAO/ciao/Servants/Port_Activator.h new file mode 100644 index 00000000000..994ac418991 --- /dev/null +++ b/modules/CIAO/ciao/Servants/Port_Activator.h @@ -0,0 +1,86 @@ +// -*- C++ -*- +//============================================================================= +/** + * @file Port_Activator.h + * + * $Id$ + * + * @authors Bala Natarajan <bala@dre.vanderbilt.edu> + */ +//============================================================================= + +#ifndef CIAO_PORT_ACTIVATOR_H +#define CIAO_PORT_ACTIVATOR_H + +#include /**/ "ace/pre.h" + +#include "CIAO_Servant_Impl_export.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/PortableServer/PortableServer.h" +#include "ciao/Servants/CIAO_Port_ActivatorC.h" + +namespace CIAO +{ + /** + * @class Port_Activator_i + * + * @brief Base class for port activations + * + * This is a ABC for the Port_Activator_T <> template class where + * the bulk of the work is done. This class is simply a place holder + * so that we could use the pointer to this class to achieve + * polymorphism for facet and consumer servant activations. + * + */ + class CIAO_Servant_Impl_Export Port_Activator_i : + public virtual Port_Activator + { + public: + Port_Activator_i (const char *oid, const char *name, Port_Activator_Types::Type t); + + virtual ~Port_Activator_i (void); + + /// Return the oid of port that this activator encapulates. + virtual char* oid (void); + + /// Set the oid + virtual void oid (const char* oid); + + /// Return the oid of port that this activator encapulates. + virtual char* name (void); + + /// Activate the servant reponsible for this port. + /** + * There are intentionally no throw specifications. It is the + * caller's responsibility to handle CORBA and C++ + * specifications. + */ + virtual PortableServer::Servant activate ( + const PortableServer::ObjectId &oid) = 0; + + virtual void deactivate (::PortableServer::Servant servant) = 0; + + protected: + /// The object ID that is used to activate the servant within the + /// POA. + CORBA::String_var oid_; + + /// Name of the port + CORBA::String_var name_; + + /// What type of port is it, a consumer or facet. + Port_Activator_Types::Type const t_; + }; +} + +#if defined (__ACE_INLINE__) +# include "Port_Activator.inl" +#endif /* __ACE_INLINE__ */ + +#include /**/ "ace/post.h" + +#endif /*CIAO_PORT_ACTIVATOR_H*/ diff --git a/modules/CIAO/ciao/Servants/Port_Activator.inl b/modules/CIAO/ciao/Servants/Port_Activator.inl new file mode 100644 index 00000000000..65ef76d56d9 --- /dev/null +++ b/modules/CIAO/ciao/Servants/Port_Activator.inl @@ -0,0 +1,22 @@ +// $Id$ + +namespace CIAO +{ + ACE_INLINE char* + Port_Activator_i::oid (void) + { + return CORBA::string_dup(this->oid_.in ()); + } + + ACE_INLINE void + Port_Activator_i::oid (const char* oid) + { + this->oid_ = oid; + } + + ACE_INLINE char* + Port_Activator_i::name (void) + { + return CORBA::string_dup(this->name_.in ()); + } +} diff --git a/modules/CIAO/ciao/Servants/Port_Activator_T.cpp b/modules/CIAO/ciao/Servants/Port_Activator_T.cpp new file mode 100644 index 00000000000..6b8b69b2e24 --- /dev/null +++ b/modules/CIAO/ciao/Servants/Port_Activator_T.cpp @@ -0,0 +1,79 @@ +// $Id$ + +#ifndef CIAO_PORT_ACTIVATOR_T_CPP +#define CIAO_PORT_ACTIVATOR_T_CPP + +#include "Port_Activator_T.h" +#include "tao/CORBA_String.h" + +#include "ace/OS_NS_string.h" + +namespace CIAO +{ + template <typename SERV, + typename EXEC, + typename CONTEXT, + typename COMP_SERV> + Port_Activator_T<SERV, EXEC, CONTEXT, COMP_SERV>::Port_Activator_T ( + const char *oid, + const char *name, + Port_Activator_Types::Type t, + EXEC *e, + CONTEXT *c, + COMP_SERV *cc) + : Port_Activator_i (oid, name, t) + , executor_ (e) + , context_ (c) + , comp_serv_ (cc) + { + } + + template <typename SERV, + typename EXEC, + typename CONTEXT, + typename COMP_SERV> + void + Port_Activator_T<SERV, EXEC, CONTEXT, COMP_SERV>::deactivate ( + PortableServer::Servant servant) + { + SERVANT *s = dynamic_cast<SERVANT *> (servant); + s->_remove_ref (); + } + + template <typename SERV, + typename EXEC, + typename CONTEXT, + typename COMP_SERV> + PortableServer::Servant + Port_Activator_T<SERV, EXEC, CONTEXT, COMP_SERV>::activate ( + const PortableServer::ObjectId &oid) + { + CORBA::String_var str = + PortableServer::ObjectId_to_string (oid); + + // An additional check, may not be necessary. Being on the safe + // side. + if (ACE_OS::strcmp (this->oid_.in (), str.in ()) == 0) + { + if (this->executor_ == 0 && this->t_ == Port_Activator_Types::FACET) + { + CORBA::Object_var tmp = + this->comp_serv_->get_facet_executor (this->name_.in ()); + + this->executor_ = EXEC::_narrow (tmp.in ()); + } + + SERVANT *s = 0; + + ACE_NEW_THROW_EX (s, + SERVANT (this->executor_, + this->context_), + CORBA::NO_MEMORY ()); + return s; + } + + throw CORBA::OBJECT_NOT_EXIST (); + } +} + +#endif /*SERVANT_ACTIVATOR_T_CPP*/ diff --git a/modules/CIAO/ciao/Servants/Port_Activator_T.h b/modules/CIAO/ciao/Servants/Port_Activator_T.h new file mode 100644 index 00000000000..4e40d895e8e --- /dev/null +++ b/modules/CIAO/ciao/Servants/Port_Activator_T.h @@ -0,0 +1,80 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Port_Activator_T.h + * + * $Id$ + * + * @authors Bala Natarajan <bala@dre.vanderbilt.edu> + */ +//============================================================================= + +#ifndef CIAO_PORT_ACTIVATOR_T_H +#define CIAO_PORT_ACTIVATOR_T_H +#include /**/ "ace/pre.h" + +#include "ciao/Servants/Port_Activator.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + + +namespace CIAO +{ + /** + * @class Port_Activator_T + * + * @brief Concrete class that implements the strategy for creating + * the right type of servant for the ports in question. + * + * This class is parametrized by the servant type for the port, the + * executor type for the port, the context for the component and the + * component servant which instantiated this class within the + * container. + */ + template <typename SERV, + typename EXEC, + typename CONTEXT, + typename COMP_SERV> + class Port_Activator_T : public virtual Port_Activator_i + { + public: + typedef SERV SERVANT; + + Port_Activator_T (const char *oid, + const char *name, + Port_Activator_Types::Type t, + EXEC *e, + CONTEXT *c, + COMP_SERV *cs); + + /// Template method from the base class, please see the base class + /// documentation for details. + virtual PortableServer::Servant activate (const PortableServer::ObjectId &oid); + + virtual void deactivate (PortableServer::Servant servant); + + private: + /// The executor + EXEC *executor_; + + /// Context classes + CONTEXT *context_; + + /// Component servant which created <this> + COMP_SERV *comp_serv_; + }; +} + +#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) +#include "Port_Activator_T.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) +#pragma implementation ("Port_Activator_T.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + +#include /**/ "ace/post.h" +#endif /*CIAO_SERVANT_ACTIVATOR_T_H*/ diff --git a/modules/CIAO/ciao/Servants/Servant_Impl_Base.cpp b/modules/CIAO/ciao/Servants/Servant_Impl_Base.cpp new file mode 100644 index 00000000000..c763cbc94c9 --- /dev/null +++ b/modules/CIAO/ciao/Servants/Servant_Impl_Base.cpp @@ -0,0 +1,759 @@ +// $Id$ + +#include "Servant_Impl_Base.h" + +#include "StandardConfigurator_Impl.h" +#include "ciao/CIAO_common.h" +#include "ciao/Containers/Container_BaseC.h" + + +namespace CIAO +{ + Servant_Impl_Base::Servant_Impl_Base (Components::CCMHome_ptr home, + Home_Servant_Impl_Base *home_servant, + Container_ptr c) + : home_ (Components::CCMHome::_duplicate (home)), + home_servant_ (home_servant), + container_ (Container::_duplicate (c)) + { + } + + Servant_Impl_Base::~Servant_Impl_Base (void) + { + } + + // Operations for CCMObject interface. + + ::Components::PrimaryKeyBase * + Servant_Impl_Base::get_primary_key (void) + { + CIAO_TRACE("Servant_Impl_Base::get_primary_key"); + throw ::Components::NoKeyAvailable (); + } + + CORBA::IRObject_ptr + Servant_Impl_Base::get_component_def (void) + { + CIAO_TRACE("Servant_Impl_Base::get_component_def"); + throw ::CORBA::NO_IMPLEMENT (); + } + + void + Servant_Impl_Base::configuration_complete (void) + { + CIAO_TRACE("Servant_Impl_Base::configuration_complete (void)"); + // CIAO to-do + } + + void + Servant_Impl_Base::remove (void) + { + CIAO_TRACE("Servant_Impl_Base::remove (void)"); + try + { + // Removing Facets + Components::FacetDescriptions_var facets = this->get_all_facets (); + + CORBA::ULong const facet_len = facets->length (); + + for (CORBA::ULong i = 0; i < facet_len; ++i) + { + PortableServer::ObjectId_var facet_id = + this->container_->the_port_POA ()->reference_to_id ( + facets[i]->facet_ref ()); + + this->container_->the_port_POA ()->deactivate_object ( + facet_id); + + CIAO::Servant_Activator_var sa = + this->container_->ports_servant_activator (); + + if (!CORBA::is_nil (sa.in ())) + { + sa->update_port_activator (facet_id.in ()); + } + } + + // Removed Facets + + // Removing Consumers + Components::ConsumerDescriptions_var consumers = + this->get_all_consumers (); + + CORBA::ULong const consumer_len = consumers->length (); + + for (CORBA::ULong j = 0; j < consumer_len; ++j) + { + PortableServer::ObjectId_var cons_id = + this->container_->the_port_POA ()->reference_to_id ( + consumers[j]->consumer ()); + + this->container_->the_port_POA ()->deactivate_object ( + cons_id); + + CIAO::Servant_Activator_var sa = + this->container_->ports_servant_activator (); + + if (!CORBA::is_nil (sa.in ())) + { + sa->update_port_activator (cons_id.in ()); + } + } + + Components::SessionComponent_var temp = this->get_executor (); + temp->ccm_remove (); + + CORBA::Object_var objref = this->container_->get_objref (this); + + Components::CCMObject_var ccmobjref = + Components::CCMObject::_narrow (objref.in ()); + + PortableServer::ObjectId_var oid; + + this->container_->uninstall_servant (this, + Container_Types::COMPONENT_t, + oid.out ()); + + if (this->home_servant_) + this->home_servant_->update_component_map (oid); + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Port not active\n"); + } + } + + ::Components::ConnectionDescriptions * + Servant_Impl_Base::get_connections (const char * /* name */) + { + CIAO_TRACE("Servant_Impl_Base::get_connections (const char * /* name */)"); + throw CORBA::NO_IMPLEMENT (); + } + + ::Components::ComponentPortDescription * + Servant_Impl_Base::get_all_ports (void) + { + CIAO_TRACE("Servant_Impl_Base::get_all_ports (void)"); + OBV_Components::ComponentPortDescription *cps = 0; + ACE_NEW_THROW_EX (cps, + OBV_Components::ComponentPortDescription, + CORBA::NO_MEMORY ()); + ::Components::ComponentPortDescription_var retv = cps; + + ::Components::FacetDescriptions_var facets_desc = + this->get_all_facets (); + + ::Components::ReceptacleDescriptions_var receptacle_desc = + this->get_all_receptacles (); + + ::Components::ConsumerDescriptions_var consumer_desc = + this->get_all_consumers (); + + ::Components::EmitterDescriptions_var emitter_desc = + this->get_all_emitters (); + + ::Components::PublisherDescriptions_var publisher_desc = + this->get_all_publishers (); + + retv->facets (facets_desc.in ()); + retv->receptacles (receptacle_desc.in ()); + retv->consumers (consumer_desc.in ()); + retv->emitters (emitter_desc.in ()); + retv->publishers (publisher_desc.in ()); + + return retv._retn (); + } + + ::CORBA::Object_ptr + Servant_Impl_Base::provide_facet (const char *name) + { + CIAO_TRACE("Servant_Impl_Base::provide_facet (const char *name)"); + if (0 == name) + { + throw Components::InvalidName (); + } + + CORBA::Object_ptr retval = this->lookup_facet (name); + + if ( ::CORBA::is_nil (retval)) + { + throw Components::InvalidName (); + } + + return retval; + } + + Components::FacetDescriptions * + Servant_Impl_Base::get_named_facets ( + const ::Components::NameList & names) + { + CIAO_TRACE("Servant_Impl_Base::get_named_facets"); + Components::FacetDescriptions *retval = 0; + ACE_NEW_THROW_EX (retval, + ::Components::FacetDescriptions, + CORBA::NO_MEMORY ()); + Components::FacetDescriptions_var safe_retval = retval; + CORBA::ULong const len = names.length (); + safe_retval->length (len); + + for (CORBA::ULong i = 0; i < len; ++i) + { + ::Components::FacetDescription *tmp = + this->lookup_facet_description (names[i]); + + if (0 == tmp) + { + throw Components::InvalidName (); + } + + safe_retval[i] = tmp; + } + + return safe_retval._retn (); + } + + ::Components::FacetDescriptions * + Servant_Impl_Base::get_all_facets (void) + { + CIAO_TRACE ("Servant_Impl_Base::get_all_facets (void)"); + ::Components::FacetDescriptions *tmp = 0; + ACE_NEW_THROW_EX (tmp, + ::Components::FacetDescriptions, + CORBA::NO_MEMORY ()); + + ::Components::FacetDescriptions_var retval = tmp; + + retval->length (this->facet_table_.size ()); + CORBA::ULong i = 0UL; + + for (FacetTable::const_iterator iter = this->facet_table_.begin (); + iter != this->facet_table_.end (); + ++iter, ++i) + { + retval[i] = iter->second; + } + + return retval._retn (); + } + + + ::Components::ConsumerDescriptions * + Servant_Impl_Base::get_all_consumers (void) + { + CIAO_TRACE("Servant_Impl_Base::get_all_consumers (void)"); + ::Components::ConsumerDescriptions *tmp = 0; + ACE_NEW_THROW_EX (tmp, + ::Components::ConsumerDescriptions ( + this->consumer_table_.size ()), + CORBA::NO_MEMORY ()); + + ::Components::ConsumerDescriptions_var retval = tmp; + + retval->length (this->consumer_table_.size ()); + CORBA::ULong i = 0UL; + + for (ConsumerTable::const_iterator iter = this->consumer_table_.begin (); + iter != this->consumer_table_.end (); + ++iter, ++i) + { + retval[i] = iter->second; + } + + return retval._retn (); + } + + + ::Components::EventConsumerBase_ptr + Servant_Impl_Base::get_consumer (const char *sink_name) + { + CIAO_TRACE("Servant_Impl_Base::get_consumer (const char *sink_name)"); + if (0 == sink_name) + { + throw Components::InvalidName (); + } + + Components::EventConsumerBase_ptr retval = + this->lookup_consumer (sink_name); + + if (CORBA::is_nil (retval)) + { + throw Components::InvalidName (); + } + + return retval; + } + + ::Components::ConsumerDescriptions * + Servant_Impl_Base::get_named_consumers ( + const ::Components::NameList & names) + { + CIAO_TRACE("Servant_Impl_Base::get_named_consumers"); + Components::ConsumerDescriptions *retval = 0; + ACE_NEW_THROW_EX (retval, + ::Components::ConsumerDescriptions, + CORBA::NO_MEMORY ()); + Components::ConsumerDescriptions_var safe_retval = retval; + CORBA::ULong const len = names.length (); + safe_retval->length (len); + + for (CORBA::ULong i = 0; i < len; ++i) + { + ::Components::ConsumerDescription *tmp = + this->lookup_consumer_description (names[i]); + + if (0 == tmp) + { + throw Components::InvalidName (); + } + + safe_retval[i] = tmp; + } + + return safe_retval._retn (); + } + + ::Components::EmitterDescriptions * + Servant_Impl_Base::get_named_emitters ( + const ::Components::NameList & /* names */) + { + CIAO_TRACE("Servant_Impl_Base::get_named_emitters"); + throw CORBA::NO_IMPLEMENT (); + } + + ::Components::ReceptacleDescriptions * + Servant_Impl_Base::get_all_receptacles (void) + { + CIAO_TRACE(" Servant_Impl_Base::get_all_receptacles (void)"); + CIAO_DEBUG ((LM_TRACE, CLINFO "Servant_Impl_Base::get_all_receptacles\n")); + + ::Components::ReceptacleDescriptions *tmp = 0; + ACE_NEW_THROW_EX (tmp, + ::Components::ReceptacleDescriptions, + CORBA::NO_MEMORY ()); + + ::Components::ReceptacleDescriptions_var retval = tmp; + + retval->length (this->receptacle_table_.current_size ()); + CORBA::ULong i = 0; + + CIAO_DEBUG ((LM_DEBUG, CLINFO + "Servant_Impl_Base::get_all_receptacles - Building sequence of length %d\n", + retval->length())); + + for (ReceptacleTable::iterator iter = this->receptacle_table_.begin (); + iter != this->receptacle_table_.end (); + ++iter, ++i) + { + CIAO_DEBUG ((LM_TRACE, CLINFO + "Servant_Impl_Base::get_all_receptacles - Starting loop iteration...\n", + retval->length())); + + ReceptacleTable::ENTRY & entry = *iter; + retval[i] = entry.int_id_; + } + + CIAO_DEBUG ((LM_TRACE, CLINFO "Servant_Impl_Base::get_all_receptacles - Escaped loop.\n")); + return retval._retn (); + } + + ::Components::ReceptacleDescriptions * + Servant_Impl_Base::get_named_receptacles ( + const ::Components::NameList & /* names */) + { + CIAO_TRACE("Servant_Impl_Base::get_named_receptacles"); + throw ::CORBA::NO_IMPLEMENT (); + } + + ::Components::PublisherDescriptions * + Servant_Impl_Base::get_named_publishers ( + const ::Components::NameList & /* names */) + { + CIAO_TRACE("Servant_Impl_Base::get_named_publishers"); + throw ::CORBA::NO_IMPLEMENT (); + } + + /// Protected operations. + void + Servant_Impl_Base::add_facet (const char *port_name, + ::CORBA::Object_ptr port_ref) + { + CIAO_TRACE("Servant_Impl_Base::add_facet"); + if (0 == port_name || ::CORBA::is_nil (port_ref)) + { + throw ::CORBA::BAD_PARAM (); + } + + ::Components::FacetDescription *fd = 0; + ACE_NEW_THROW_EX (fd, + ::OBV_Components::FacetDescription (port_name, + port_ref->_interface_repository_id (), + port_ref), + CORBA::NO_MEMORY ()); + ::Components::FacetDescription_var safe = fd; + + FacetTable::value_type entry; + entry.first = port_name; + entry.second = safe._retn (); + + { + ACE_WRITE_GUARD_THROW_EX (TAO_SYNCH_MUTEX, mon, this->lock_, + CORBA::NO_RESOURCES ()); + + (void) this->facet_table_.insert (entry); + } + } + + CORBA::Object_ptr + Servant_Impl_Base::lookup_facet (const char *port_name) + { + CIAO_TRACE("Servant_Impl_Base::lookup_facet"); + if (0 == port_name) + { + return CORBA::Object::_nil (); + } + + ACE_READ_GUARD_THROW_EX (TAO_SYNCH_MUTEX, + mon, + this->lock_, + CORBA::NO_RESOURCES ()); + + FacetTable::const_iterator iter = + this->facet_table_.find (port_name); + + if (iter == this->facet_table_.end ()) + { + return CORBA::Object::_nil (); + } + + return CORBA::Object::_duplicate (iter->second->facet_ref ()); + } + + ::Components::FacetDescription * + Servant_Impl_Base::lookup_facet_description (const char *port_name) + { + CIAO_TRACE("Servant_Impl_Base::lookup_facet_description"); + if (0 == port_name) + { + /// Calling function will throw InvalidName after getting this. + return 0; + } + + ::Components::FacetDescription_var fd; + + { + ACE_READ_GUARD_RETURN (TAO_SYNCH_MUTEX, + mon, + this->lock_, + 0); + FacetTable::const_iterator iter = + this->facet_table_.find (port_name); + + if (iter != this->facet_table_.end ()) + { + fd = iter->second; + } + } + + return fd._retn (); + } + + void + Servant_Impl_Base::add_receptacle (const char *receptacle_name, + CORBA::Object_ptr recept_ref, + ::Components::Cookie * cookie) + { + CIAO_TRACE("Servant_Impl_Base::add_receptacle"); + CIAO_DEBUG ((LM_INFO, CLINFO + "Servant_Impl_Base::add_receptacle - attempting to add new connection to receptacle (%C)\n", + receptacle_name)); + + ::Components::ReceptacleDescription_var safe; + ::Components::ReceptacleDescription *rd = 0; + + if (this->receptacle_table_.find (receptacle_name, + safe) == -1) + { + CIAO_DEBUG ((LM_DEBUG, CLINFO + "Servant_Impl_Base::add_receptacle - Found no receptacle named (%C), creating it...\n", + receptacle_name)); + + ACE_NEW_THROW_EX (rd, + OBV_Components::ReceptacleDescription, + CORBA::NO_MEMORY ()); + safe = rd; + + rd->name (receptacle_name); + rd->type_id (); + // The receptacle is a multiplex receptacle if and only if a + // cookie was given. + rd->is_multiple (cookie != 0); + + ::Components::ConnectionDescription *cd = 0; + ACE_NEW_THROW_EX (cd, + OBV_Components::ConnectionDescription (cookie, + recept_ref), + CORBA::NO_MEMORY ()); + ::Components::ConnectionDescription_var cd_safe = cd; + ::Components::ConnectionDescriptions cds (1); + + cds.length (1); + cds[0] = cd_safe; + rd->connections (cds); + } + else + { + CIAO_DEBUG ((LM_DEBUG, CLINFO + "Servant_Impl_Base::add_receptacle - Found a receptacle named (%C)\n", + receptacle_name)); + rd = safe.inout (); + + ::Components::ConnectionDescription *cd = 0; + ACE_NEW_THROW_EX (cd, + OBV_Components::ConnectionDescription (cookie, + recept_ref), + CORBA::NO_MEMORY ()); + ::Components::ConnectionDescription_var cd_safe = cd; + ::Components::ConnectionDescriptions & cds = rd->connections (); + CORBA::ULong old_length = cds.length (); + cds.length (old_length + 1); + cds [old_length] = cd_safe; + + CIAO_DEBUG ((LM_DEBUG, CLINFO + "Servant_Impl_Base::add_receptacle - Added new connection to " + "existing receptacle named (%C)\n", + receptacle_name)); + } + + if (this->receptacle_table_.bind (receptacle_name, safe) == 0) + { + CIAO_DEBUG ((LM_INFO, CLINFO + "Servant_Impl_Base::add_receptacle - Successfully added new receptacle named (%C)\n", + receptacle_name)); + } + } + + void + Servant_Impl_Base::add_consumer (const char *port_name, + ::Components::EventConsumerBase_ptr port_ref) + { + CIAO_TRACE("Servant_Impl_Base::add_consumer"); + if (0 == port_name || ::CORBA::is_nil (port_ref)) + { + CIAO_ERROR ((LM_ERROR, CLINFO "Servant_Impl_Base::add_consumer - Bad port name [%C] or bad objref\n", + port_name)); + throw ::CORBA::BAD_PARAM (); + return; + } + + ::Components::ConsumerDescription *cd = 0; + ACE_NEW_THROW_EX (cd, + ::OBV_Components::ConsumerDescription, + CORBA::NO_MEMORY ()); + + ::Components::ConsumerDescription_var safe = cd; + + cd->name (port_name); + cd->type_id (port_ref->_interface_repository_id ()); + cd->consumer (port_ref); + + ConsumerTable::value_type entry; + entry.first = port_name; + entry.second = safe._retn (); + + ACE_WRITE_GUARD_THROW_EX (TAO_SYNCH_MUTEX, mon, this->lock_, + CORBA::NO_RESOURCES ()); + + (void) this->consumer_table_.insert (entry); + } + + ::Components::EventConsumerBase_ptr + Servant_Impl_Base::lookup_consumer (const char *port_name) + { + CIAO_TRACE("Servant_Impl_Base::lookup_consumer"); + if (0 == port_name) + { + return ::Components::EventConsumerBase::_nil (); + } + + ACE_READ_GUARD_THROW_EX (TAO_SYNCH_MUTEX, + mon, + this->lock_, + CORBA::NO_RESOURCES ()); + + ConsumerTable::const_iterator iter = + this->consumer_table_.find (port_name); + + if (iter == this->consumer_table_.end ()) + { + return ::Components::EventConsumerBase::_nil (); + } + + return + ::Components::EventConsumerBase::_duplicate ( + iter->second->consumer ()); + } + + ::Components::ConsumerDescription * + Servant_Impl_Base::lookup_consumer_description ( + const char *port_name) + { + CIAO_TRACE("Servant_Impl_Base::lookup_consumer_description"); + if (0 == port_name) + { + /// Calling function will throw InvalidName after getting this. + return 0; + } + + ::Components::ConsumerDescription_var cd; + ConsumerTable::const_iterator iter; + + { + ACE_READ_GUARD_THROW_EX (TAO_SYNCH_MUTEX, + mon, + this->lock_, + CORBA::NO_RESOURCES ()); + + iter = this->consumer_table_.find (port_name); + + if (iter != this->consumer_table_.end ()) + { + cd = iter->second; + } + } + + return cd._retn (); + } + + ::Components::StandardConfigurator_ptr + Servant_Impl_Base::get_standard_configurator (void) + { + CIAO_TRACE("Servant_Impl_Base::get_standard_configurator (void)"); + // Create the configurator servant. + StandardConfigurator_Impl *config_impl = 0; + + ACE_NEW_THROW_EX (config_impl, + StandardConfigurator_Impl (this), + CORBA::NO_MEMORY ()); + + + Components::StandardConfigurator_var configurator = + config_impl->_this (); + + return configurator._retn (); + } + + void + Servant_Impl_Base::activate_component (void) + { + CIAO_TRACE ("Servant_Impl_Base::activate_component"); + throw CORBA::NO_IMPLEMENT (); + } + + + void + Servant_Impl_Base::passivate_component (void) + { + CIAO_TRACE ("Servant_Impl_Base::passivate_component"); + throw CORBA::NO_IMPLEMENT (); + } + + Components::SessionComponent_ptr + Servant_Impl_Base::get_executor (void) + { + CIAO_TRACE ("Servant_Impl_Base::get_executor"); + throw CORBA::NO_IMPLEMENT (); + } + + void + Servant_Impl_Base::set_attributes (const Components::ConfigValues &/*descr*/) + { + CIAO_TRACE ("Servant_Impl_Base::set_attributes"); + throw CORBA::NO_IMPLEMENT (); + } + + ::Components::CCMHome_ptr + Servant_Impl_Base::get_ccm_home (void) + { + CIAO_TRACE ("Servant_Impl_Base::get_ccm_home"); + throw CORBA::NO_IMPLEMENT (); + } + + PortableServer::POA_ptr + Servant_Impl_Base::_default_POA (void) + { + CIAO_TRACE("Servant_Impl_Base::_default_POA (void)"); + return + PortableServer::POA::_duplicate (container_->the_POA ()); + } + + ::Components::Cookie * + Servant_Impl_Base::subscribe (const char *, + ::Components::EventConsumerBase_ptr) + { + CIAO_TRACE ("Servant_Impl_Base::subscribe"); + throw CORBA::NO_IMPLEMENT (); + } + + + ::Components::EventConsumerBase_ptr + Servant_Impl_Base::unsubscribe (const char *, + ::Components::Cookie *) + { + CIAO_TRACE ("Servant_Impl_Base::unsubscribe"); + throw CORBA::NO_IMPLEMENT (); + } + + void + Servant_Impl_Base::connect_consumer (const char *, + ::Components::EventConsumerBase_ptr) + { + CIAO_TRACE ("Servant_Impl_Base::connect_consumer"); + throw CORBA::NO_IMPLEMENT (); + } + + ::Components::EventConsumerBase_ptr + Servant_Impl_Base::disconnect_consumer (const char *) + { + CIAO_TRACE ("Servant_Impl_Base::disconnect_consumer"); + throw CORBA::NO_IMPLEMENT (); + } + + ::Components::EmitterDescriptions * + Servant_Impl_Base::get_all_emitters (void) + { + CIAO_TRACE ("Servant_Impl_Base::get_all_emitters"); + throw CORBA::NO_IMPLEMENT (); + } + + ::Components::PublisherDescriptions * + Servant_Impl_Base::get_all_publishers (void) + { + CIAO_TRACE ("Servant_Impl_Base::get_all_publishers"); + throw CORBA::NO_IMPLEMENT (); + } + + ::CORBA::Boolean + Servant_Impl_Base::same_component (::CORBA::Object_ptr) + { + CIAO_TRACE ("Servant_Impl_Base::same_component"); + throw CORBA::NO_IMPLEMENT (); + } + + + ::Components::Cookie * + Servant_Impl_Base::connect (const char *, + ::CORBA::Object_ptr) + { + CIAO_TRACE ("Servant_Impl_Base::connect"); + throw CORBA::NO_IMPLEMENT (); + } + + ::CORBA::Object_ptr + Servant_Impl_Base::disconnect (const char *, + ::Components::Cookie *) + { + CIAO_TRACE ("Servant_Impl_Base::disconnect"); + throw CORBA::NO_IMPLEMENT (); + } +} + diff --git a/modules/CIAO/ciao/Servants/Servant_Impl_Base.h b/modules/CIAO/ciao/Servants/Servant_Impl_Base.h new file mode 100644 index 00000000000..ef6a1c47aa5 --- /dev/null +++ b/modules/CIAO/ciao/Servants/Servant_Impl_Base.h @@ -0,0 +1,247 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Servant_Impl_Base.h + * + * $Id$ + * + * This file contains the non-template declaration of a base class for + * the template mixin for the generated servant class. + * + * @author Jeff Parsons <j.parsons@vanderbilt.edu> + */ +//============================================================================= + +#ifndef CIAO_SERVANT_IMPL_BASE_H +#define CIAO_SERVANT_IMPL_BASE_H + +#include /**/ "ace/pre.h" + +#include "CIAO_Servant_Impl_export.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "Home_Servant_Impl_Base.h" +#include "ciao/Containers/CIAO_Servant_ActivatorC.h" + +#include "ace/Hash_Map_Manager_T.h" +#include "ace/Array_Map.h" +#include "ccm/CCM_ContainerC.h" +#include "ccm/CCM_ObjectS.h" +#include "ccm/CCM_StandardConfiguratorC.h" + + + +namespace CIAO +{ + class Container; + typedef Container *Container_ptr; + typedef TAO_Objref_Var_T<Container> Container_var; + + namespace Servant { + template<typename T_var> + void describe_simplex_receptacle ( + const char *port_name, + const char *port_type_repo_id, + T_var &connection, + ::Components::ReceptacleDescriptions_var &descriptions, + CORBA::ULong slot); + + template<typename T_var> + void describe_multiplex_receptacle ( + const char *port_name, + const char *port_type_repo_id, + ACE_Array_Map<ptrdiff_t, T_var> &objrefs, + ::Components::ReceptacleDescriptions_var &descriptions, + CORBA::ULong slot); + + template<typename T_var> + void describe_pub_event_source ( + const char *port_name, + const char *port_type_repo_id, + ACE_Array_Map<ptrdiff_t, T_var> &consumers, + ::Components::PublisherDescriptions_var &descriptions, + CORBA::ULong slot); + + template<typename T_var> + void describe_emit_event_source ( + const char *port_name, + const char *port_type_repo_id, + T_var &consumer_ref, + ::Components::EmitterDescriptions_var &descriptions, + CORBA::ULong slot); + } /* Servant */ + + /** + * @class Servant_Impl_Base + * + * @brief Non-template base class for Servant_Impl. + * + * Holds the non-template parts of its child class + * Servant_Impl. + */ + class CIAO_Servant_Impl_Export Servant_Impl_Base + : public virtual POA_Components::CCMObject + { + protected: + Servant_Impl_Base (Components::CCMHome_ptr home, + Home_Servant_Impl_Base *home_servant, + Container_ptr c); + + public: + virtual ~Servant_Impl_Base (void); + + /// Operations for CCMObject interface. + + virtual ::Components::PrimaryKeyBase * get_primary_key (void); + + virtual CORBA::IRObject_ptr get_component_def (void); + + virtual Components::SessionComponent_ptr get_executor (void); + + virtual void configuration_complete (void); + + virtual void activate_component (void); + + virtual void passivate_component (void); + + virtual ::Components::CCMHome_ptr get_ccm_home (void); + + virtual void remove (void); + + virtual ::Components::ConnectionDescriptions * + get_connections (const char *name); + + virtual ::Components::ComponentPortDescription * get_all_ports (void); + + virtual CORBA::Object_ptr provide_facet (const char *name); + + virtual ::Components::FacetDescriptions * + get_named_facets (const ::Components::NameList & names); + + virtual ::Components::FacetDescriptions * get_all_facets (void); + + virtual ::Components::ConsumerDescriptions * get_all_consumers (void); + + virtual ::Components::EventConsumerBase_ptr + get_consumer (const char *sink_name); + + virtual ::Components::ConsumerDescriptions * + get_named_consumers (const ::Components::NameList & names); + + virtual ::Components::EmitterDescriptions * + get_named_emitters (const ::Components::NameList & names); + + virtual ::Components::ReceptacleDescriptions * + get_named_receptacles (const ::Components::NameList & names); + + virtual ::Components::ReceptacleDescriptions * + get_all_receptacles (void); + + virtual ::Components::PublisherDescriptions * + get_named_publishers (const ::Components::NameList & names); + + /// Operation to set attributes on the component. + virtual void set_attributes (const Components::ConfigValues &descr); + + // Creates and returns the StandardConfigurator for the component. + virtual ::Components::StandardConfigurator_ptr + get_standard_configurator (void); + + /// Override that returns the (passed-in) default POA of our member + /// component's container, to ensure that we get registered + /// to that POA when _this() is called. + virtual PortableServer::POA_ptr _default_POA (void); + + virtual ::Components::Cookie * subscribe (const char * publisher_name, + ::Components::EventConsumerBase_ptr subscriber); + + virtual ::Components::EventConsumerBase_ptr unsubscribe (const char * publisher_name, + ::Components::Cookie * ck); + + virtual void connect_consumer (const char * emitter_name, + ::Components::EventConsumerBase_ptr consumer); + + virtual ::Components::EventConsumerBase_ptr disconnect_consumer (const char * source_name); + + virtual ::Components::EmitterDescriptions * get_all_emitters (void); + + virtual ::Components::PublisherDescriptions * get_all_publishers (void); + + virtual ::CORBA::Boolean same_component (::CORBA::Object_ptr object_ref); + + virtual ::Components::Cookie * connect (const char * name, + ::CORBA::Object_ptr connection); + + virtual ::CORBA::Object_ptr disconnect (const char * name, + ::Components::Cookie * ck); + + + protected: + void add_facet (const char *port_name, + ::CORBA::Object_ptr port_ref); + + CORBA::Object_ptr lookup_facet (const char *port_name); + + ::Components::FacetDescription *lookup_facet_description ( + const char *port_name); + + void add_receptacle (const char *receptacle_name, + CORBA::Object_ptr recept_ref, + ::Components::Cookie * cookie); + + void add_consumer (const char *port_name, + ::Components::EventConsumerBase_ptr port_ref); + + ::Components::EventConsumerBase_ptr lookup_consumer ( + const char *port_name); + + ::Components::ConsumerDescription *lookup_consumer_description ( + const char *port_name); + + /// Called from generated servant class to help with + /// get_all_*() methods. + + protected: + typedef ACE_Array_Map<ACE_CString, + ::Components::FacetDescription_var> + FacetTable; + + typedef ACE_Array_Map<ACE_CString, + ::Components::ConsumerDescription_var> + ConsumerTable; + + typedef ACE_Hash_Map_Manager_Ex<const char *, + ::Components::ReceptacleDescription_var, + ACE_Hash<const char *>, + ACE_Equal_To<const char *>, + ACE_Null_Mutex> + ReceptacleTable; + + FacetTable facet_table_; + ConsumerTable consumer_table_; + ReceptacleTable receptacle_table_; + Components::CCMHome_var home_; + Home_Servant_Impl_Base *home_servant_; + Container_var container_; + + private: + /// For internal locking of table reads and writes. + TAO_SYNCH_MUTEX lock_; + }; +} + +#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) +#include "Servant_Impl_Utils_T.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) +#pragma implementation ("Servant_Impl_Utils_T.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + +#include /**/ "ace/post.h" + +#endif /* CIAO_SERVANT_IMPL_T_H */ diff --git a/modules/CIAO/ciao/Servants/Servant_Impl_T.cpp b/modules/CIAO/ciao/Servants/Servant_Impl_T.cpp new file mode 100644 index 00000000000..8c3b00a09d0 --- /dev/null +++ b/modules/CIAO/ciao/Servants/Servant_Impl_T.cpp @@ -0,0 +1,239 @@ +// $Id$ + +#ifndef CIAO_SERVANT_IMPL_T_C +#define CIAO_SERVANT_IMPL_T_C + +#include "Servant_Impl_T.h" +#include <ccm/CCM_EntityContextC.h> + +namespace CIAO +{ + template <typename BASE_SKEL, + typename EXEC, + typename CONTEXT> + Servant_Impl<BASE_SKEL, EXEC, CONTEXT>::Servant_Impl ( + EXEC * exe, + Components::CCMHome_ptr home, + Home_Servant_Impl_Base *home_servant, + Container_ptr c + ) + : Servant_Impl_Base (home, home_servant, c), + activated_ (false), + configuration_completed_ (false), + executor_ (EXEC::_duplicate (exe)) + { + } + + template <typename BASE_SKEL, + typename EXEC, + typename CONTEXT> + Servant_Impl<BASE_SKEL, EXEC, CONTEXT>::~Servant_Impl (void) + { + CIAO_DEBUG ((LM_INFO, "Servant_Impl_T::~Servant_Impl - " + "Executor object reference count is %u\n", + this->executor_->_refcount_value ())); + + // ********************************************************************** + /* + try + { + ::Components::SessionComponent_var scom = + ::Components::SessionComponent::_narrow ( + this->executor_.in () + ); + + if (! ::CORBA::is_nil (scom.in ())) + { + scom->ccm_remove (); + } + } + catch (const CORBA::Exception& ex) + { + } + */ + // ********************************************************************* + + this->context_->_remove_ref (); + } + + // Operations for CCMObject interface. + + template <typename BASE_SKEL, + typename EXEC, + typename CONTEXT> + CORBA::Boolean + Servant_Impl<BASE_SKEL, EXEC, CONTEXT>::same_component ( + CORBA::Object_ptr object_ref + ) + { + if (::CORBA::is_nil (object_ref)) + { + throw ::CORBA::BAD_PARAM (); + } + + ::CORBA::Object_var the_other = + object_ref->_get_component (); + + ::CORBA::Object_var me = + this->context_->get_CCM_object (); + + return me->_is_equivalent (the_other.in ()); + + } + + template <typename BASE_SKEL, + typename EXEC, + typename CONTEXT> + ::Components::CCMHome_ptr + Servant_Impl<BASE_SKEL, EXEC, CONTEXT>::get_ccm_home ( + ) + { + return this->context_->get_CCM_home (); + } + + template <typename BASE_SKEL, + typename EXEC, + typename CONTEXT> + Components::SessionComponent_ptr + Servant_Impl<BASE_SKEL, EXEC, CONTEXT>::get_executor ( + ) + { + ::Components::SessionComponent_var temp = + ::Components::SessionComponent::_narrow ( + this->executor_.in () + ); + return temp._retn (); + } + + template <typename BASE_SKEL, + typename EXEC, + typename CONTEXT> + CORBA::Object_ptr + Servant_Impl<BASE_SKEL, EXEC, CONTEXT>::_get_component ( + ) + { + ::Components::SessionContext_var sc = + ::Components::SessionContext::_narrow ( + this->context_ + ); + + if (! ::CORBA::is_nil (sc.in ())) + { + return sc->get_CCM_object (); + } + + ::Components::EntityContext_var ec = + ::Components::EntityContext::_narrow ( + this->context_ + ); + + if (! ::CORBA::is_nil (ec.in ())) + { + return ec->get_CCM_object (); + } + + throw CORBA::INTERNAL (); + } + + // CIAO-specific operations. + + template <typename BASE_SKEL, + typename EXEC, + typename CONTEXT> + void + Servant_Impl<BASE_SKEL, EXEC, CONTEXT>::activate_component ( + ) + { + if (this->configuration_completed_ == 1) + { + this->ciao_activate (); + } + } + + template <typename BASE_SKEL, + typename EXEC, + typename CONTEXT> + void + Servant_Impl<BASE_SKEL, EXEC, CONTEXT>::passivate_component ( + ) + { + if (this->activated_ == 1) + { + this->ciao_passivate (); + } + } + + template <typename BASE_SKEL, + typename EXEC, + typename CONTEXT> + void + Servant_Impl<BASE_SKEL, EXEC, CONTEXT>::configuration_complete ( + ) + { + ::Components::SessionComponent_var temp = + ::Components::SessionComponent::_narrow ( + this->executor_.in () + ); + + if (! ::CORBA::is_nil (temp.in ())) + { + if (this->configuration_completed_ == 0) + { + this->configuration_completed_ = 1; + temp->configuration_complete (); + } + } + } + + template <typename BASE_SKEL, + typename EXEC, + typename CONTEXT> + void + Servant_Impl<BASE_SKEL, EXEC, CONTEXT>::ciao_activate () + { + ::Components::SessionComponent_var temp = + ::Components::SessionComponent::_narrow ( + this->executor_.in () + ); + + if (! ::CORBA::is_nil (temp.in ())) + { + if (this->activated_ == 0) + { + this->activated_ = 1; + temp->ccm_activate (); + } + } + } + + template <typename BASE_SKEL, + typename EXEC, + typename CONTEXT> + CORBA::Boolean + Servant_Impl<BASE_SKEL, EXEC, CONTEXT>::is_activated ( + ) + { + return this->activated_; + } + + template <typename BASE_SKEL, + typename EXEC, + typename CONTEXT> + void + Servant_Impl<BASE_SKEL, EXEC, CONTEXT>::ciao_passivate ( + ) + { + // @@ Jai, could you please see why this is required? + ::Components::SessionComponent_var temp = + ::Components::SessionComponent::_narrow ( + this->executor_.in () + ); + + if (! ::CORBA::is_nil (temp.in ())) + temp->ccm_passivate (); + + this->activated_ = 0; + } +} + +#endif /* CIAO_SERVANT_IMPL_T_C */ diff --git a/modules/CIAO/ciao/Servants/Servant_Impl_T.h b/modules/CIAO/ciao/Servants/Servant_Impl_T.h new file mode 100644 index 00000000000..10c25af865b --- /dev/null +++ b/modules/CIAO/ciao/Servants/Servant_Impl_T.h @@ -0,0 +1,111 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Servant_Impl_T.h + * + * $Id$ + * + * This file contains the declaration of a mixin base class for + * the generated servant class. + * + * @authors Boris Kolpackov <boris@dre.vanderbilt.edu> + * Jeff Parsons <j.parsons@vanderbilt.edu> + */ +//============================================================================= + + +#ifndef CIAO_SERVANT_IMPL_T_H +#define CIAO_SERVANT_IMPL_T_H + +#include /**/ "ace/pre.h" + +#include "Servant_Impl_Base.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +namespace CIAO +{ + /** + * @class Servant_Impl + * + * @brief Mixin base class for generated servant. + * + * This class implements navigation and other operations + * common to all generated servants. + */ + template <typename BASE_SKEL, + typename EXEC, + typename CONTEXT> + class Servant_Impl : public virtual BASE_SKEL, + public virtual Servant_Impl_Base + { + public: + Servant_Impl (EXEC * exe, + Components::CCMHome_ptr home, + Home_Servant_Impl_Base *home_servant, + Container_ptr c); + + virtual ~Servant_Impl (void); + + // Operations for CCMObject interface. + + virtual CORBA::Boolean + same_component (CORBA::Object_ptr object_ref); + + virtual ::Components::CCMHome_ptr + get_ccm_home (); + + virtual CORBA::Object_ptr + _get_component (); + + virtual Components::SessionComponent_ptr + get_executor (); + + // CIAO-specific operations. + + void + configuration_complete (); + + void + ciao_activate (); + + /// @@NOTE: The busted operation. + void + ciao_passivate (); + + CORBA::Boolean + is_activated (); + + virtual void + activate_component (); + + virtual void + passivate_component (); + + protected: + + CORBA::Boolean activated_; + CORBA::Boolean configuration_completed_; + + /// Initialized in this constructor. + typename EXEC::_var_type executor_; + + /// Initialized in the derived, generated servant constructor. + CONTEXT * context_; + }; +} + +#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) +#include "Servant_Impl_T.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) +#pragma implementation ("Servant_Impl_T.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + +#include /**/ "ace/post.h" + +#endif /* CIAO_SERVANT_IMPL_T_H */ diff --git a/modules/CIAO/ciao/Servants/Servant_Impl_Utils_T.cpp b/modules/CIAO/ciao/Servants/Servant_Impl_Utils_T.cpp new file mode 100644 index 00000000000..e84a1faa0bc --- /dev/null +++ b/modules/CIAO/ciao/Servants/Servant_Impl_Utils_T.cpp @@ -0,0 +1,182 @@ +// $Id$ + +#ifndef CIAO_SERVANT_IMPL_UTILS_T_C +#define CIAO_SERVANT_IMPL_UTILS_T_C + +#include "ciao/Servants/Servant_Impl_Base.h" +#include "ciao/Valuetype_Factories/Cookies.h" +#include "ciao/CIAO_common.h" + +namespace CIAO +{ + template<typename T_var> + void + Servant::describe_simplex_receptacle ( + const char *port_name, + const char *port_type_repo_id, + T_var &connection, + ::Components::ReceptacleDescriptions_var &descriptions, + CORBA::ULong slot) + { + CIAO_TRACE ("Servant::describe_simplex_receptacle"); + + ::Components::ReceptacleDescription *elem = 0; + ACE_NEW_THROW_EX (elem, + ::OBV_Components::ReceptacleDescription, + CORBA::NO_MEMORY ()); + + ::Components::ReceptacleDescription_var safe_elem = elem; + + elem->name (port_name); + elem->type_id (port_type_repo_id); + elem->is_multiple (false); + elem->connections ().length (1UL); + + ::Components::ConnectionDescription *conn = 0; + ACE_NEW (conn, ::OBV_Components::ConnectionDescription); + ::Components::ConnectionDescription_var safe_conn = conn; + + conn->ck (0); + conn->objref (connection.in ()); + + elem->connections ()[0UL] = safe_conn._retn (); + descriptions[slot] = safe_elem._retn (); + } + + template<typename T_var> + void + Servant::describe_multiplex_receptacle ( + const char *port_name, + const char *port_type_repo_id, + ACE_Array_Map<ptrdiff_t, T_var> &objrefs, + ::Components::ReceptacleDescriptions_var &descriptions, + CORBA::ULong slot + ) + { + CIAO_TRACE ("Servant::describe_multiplex_receptacle"); + + ::Components::ReceptacleDescription *elem = 0; + ACE_NEW_THROW_EX (elem, + ::OBV_Components::ReceptacleDescription, + CORBA::NO_MEMORY ()); + + ::Components::ReceptacleDescription_var safe_elem = elem; + + elem->name (port_name); + elem->type_id (port_type_repo_id); + elem->is_multiple (true); + elem->connections ().length (objrefs.size ()); + + CORBA::ULong seq_slot = 0UL; + ::Components::ConnectionDescription *conn = 0; + + typedef typename ACE_Array_Map<ptrdiff_t, T_var>::const_iterator + CONST_ITERATOR; + + for (CONST_ITERATOR iter = objrefs.begin (); + iter != objrefs.end (); + ++iter, ++seq_slot) + { + ACE_NEW_THROW_EX (conn, + ::OBV_Components::ConnectionDescription, + CORBA::NO_MEMORY ()); + ::Components::ConnectionDescription_var safe_conn = conn; + + ::Components::Cookie *key_cookie = 0; + ACE_NEW_THROW_EX (key_cookie, + CIAO::Cookie_Impl (iter->first), + CORBA::NO_MEMORY ()); + + // Valuetype member set operation calls add_ref. + conn->ck (key_cookie); + CORBA::remove_ref (key_cookie); + + conn->objref (iter->second.in ()); + + elem->connections ()[seq_slot] = safe_conn._retn (); + } + + descriptions[slot] = safe_elem._retn (); + } + + template<typename T_var> + void + Servant::describe_pub_event_source ( + const char *port_name, + const char *port_type_repo_id, + ACE_Array_Map<ptrdiff_t, T_var> &consumers, + ::Components::PublisherDescriptions_var &descriptions, + CORBA::ULong slot + ) + { + CIAO_TRACE ("Servant::describe_pub_event_source"); + + ::Components::PublisherDescription *elem = 0; + ACE_NEW_THROW_EX (elem, + ::OBV_Components::PublisherDescription, + CORBA::NO_MEMORY ()); + + ::Components::PublisherDescription_var safe_elem = elem; + + elem->name (port_name); + elem->type_id (port_type_repo_id); + elem->consumers ().length (consumers.size ()); + + ptrdiff_t map_slot = 0UL; + ::Components::SubscriberDescription *sub = 0; + + typedef typename ACE_Array_Map<ptrdiff_t, T_var>::const_iterator + CONST_ITERATOR; + + for (CONST_ITERATOR iter = consumers.begin (); + iter != consumers.end (); + ++iter, ++map_slot) + { + ACE_NEW_THROW_EX (sub, + ::OBV_Components::SubscriberDescription, + CORBA::NO_MEMORY ()); + ::Components::SubscriberDescription_var safe_sub = sub; + + ::Components::Cookie *key_cookie = 0; + ACE_NEW (key_cookie, + CIAO::Cookie_Impl (iter->first)); + + // Valuetype member set operation calls add_ref. + sub->ck (key_cookie); + CORBA::remove_ref (key_cookie); + + sub->consumer (iter->second.in ()); + + elem->consumers ()[map_slot] = safe_sub._retn (); + } + + descriptions[slot] = safe_elem._retn (); + } + + template<typename T_var> + void + Servant::describe_emit_event_source ( + const char *port_name, + const char *port_type_repo_id, + T_var &consumer_ref, + ::Components::EmitterDescriptions_var &descriptions, + CORBA::ULong slot) + { + CIAO_TRACE ("Servant::describe_emit_event_source"); + ::Components::EmitterDescription *elem = 0; + ACE_NEW_THROW_EX (elem, + ::OBV_Components::EmitterDescription, + CORBA::NO_MEMORY ()); + ::Components::EmitterDescription_var safe_elem = elem; + + elem->name (port_name); + elem->type_id (port_type_repo_id); + + // Valuetype 'set' call increments the reference count. + elem->consumer (consumer_ref.in ()); + + descriptions[slot] = safe_elem._retn (); + } +} + +#endif /* CIAO_SERVANT_IMPL_T_C */ diff --git a/modules/CIAO/ciao/Servants/Servants.mpc b/modules/CIAO/ciao/Servants/Servants.mpc new file mode 100644 index 00000000000..11934238bf8 --- /dev/null +++ b/modules/CIAO/ciao/Servants/Servants.mpc @@ -0,0 +1,52 @@ +// $Id$ +project(CIAO_Port_Activator_stub) : portableserver, ciaoidldefaults, ciao_lib { + dynamicflags = CIAO_PORT_ACTIVATOR_BUILD_DLL + idlflags += -Wb,stub_export_include=CIAO_Port_Activator_export.h + idlflags += -Wb,stub_export_macro=CIAO_Port_Activator_Export + idlflags += -SS + IDL_Files { + CIAO_Port_Activator.idl + } + + Source_Files { + CIAO_Port_ActivatorC.cpp + } + + Header_Files { + } +} + +project(CIAO_Servant_Impl) : ciao_servant_activator, ciao_port_activator_stub, ciao_container_base, ccm_svnt, ciao_output { + dynamicflags = CIAO_SERVANT_IMPL_BUILD_DLL + IDL_Files { + } + + Source_Files { + Home_Servant_Impl_Base.cpp + Home_Servant_Impl_T.cpp + Servant_Impl_Base.cpp + Servant_Impl_T.cpp + StandardConfigurator_Impl.cpp + Port_Activator.cpp + } + + Template_Files { + Servant_Impl_Utils_T.cpp + Port_Activator_T.cpp + } + + Header_Files { + CIAO_Servant_Impl_export.h + Home_Servant_Impl_Base.h + Home_Servant_Impl_T.h + Servant_Impl_Base.h + Servant_Impl_T.h + StandardConfigurator_Impl.h + Port_Activator.h + Port_Activator_T.h + } + + Inline_Files { + Port_Activator.inl + } +} diff --git a/modules/CIAO/ciao/Servants/StandardConfigurator_Impl.cpp b/modules/CIAO/ciao/Servants/StandardConfigurator_Impl.cpp new file mode 100644 index 00000000000..59b683fb82b --- /dev/null +++ b/modules/CIAO/ciao/Servants/StandardConfigurator_Impl.cpp @@ -0,0 +1,33 @@ +// StandardConfigurator.cpp,v 1.0 2004/14/04 08:47:46 white Exp + +#include "StandardConfigurator_Impl.h" +#include "Servant_Impl_Base.h" + +ACE_RCSID (ciao, + StandardConfigurator_Impl, + "$Id$") + +namespace CIAO +{ + StandardConfigurator_Impl::StandardConfigurator_Impl ( + Servant_Impl_Base* servant) + : component_ (servant) + { + } + + StandardConfigurator_Impl::~StandardConfigurator_Impl (void) + { + } + + void + StandardConfigurator_Impl::set_configuration ( + const Components::ConfigValues &descr) + { + this->component_->set_attributes (descr); + } + + void + StandardConfigurator_Impl::configure (Components::CCMObject_ptr) + { + } +} diff --git a/modules/CIAO/ciao/Servants/StandardConfigurator_Impl.h b/modules/CIAO/ciao/Servants/StandardConfigurator_Impl.h new file mode 100644 index 00000000000..4f49e216b88 --- /dev/null +++ b/modules/CIAO/ciao/Servants/StandardConfigurator_Impl.h @@ -0,0 +1,73 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file StandardConfigurator_Impl.h + * + * $Id$ + * + * This file contains implementation for the servant of + * Components::StandardConfigurator interface. + * + * @author Jules White <jules@dre.vanderbilt.edu> + */ +//============================================================================= + +#ifndef CIAO_STANDARDCONFIGURATOR_IMPL_H +#define CIAO_STANDARDCONFIGURATOR_IMPL_H + +# include /**/ "ace/pre.h" + +#include "CIAO_Servant_Impl_export.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ccm/CCM_StandardConfiguratorS.h" + +namespace CIAO +{ + class Servant_Impl_Base; +} + +namespace CIAO +{ + /** + * @class StandardConfigurator_Impl + * + * @brief Servant implementation for Components::StandardConfigurator + * + * This class implements the Components::StandardConfigurator + * interface as defined by the CCM spcification. This class aids + * in setting the initial values of component attributes that are + * defined in the meta data. + */ + class CIAO_Servant_Impl_Export StandardConfigurator_Impl + : public virtual POA_Components::StandardConfigurator + { + public: + /// Constructor + StandardConfigurator_Impl (Servant_Impl_Base* toconfigure); + + /// Destructor + virtual ~StandardConfigurator_Impl (void); + + /// This method will call set_attributes on the component that is + /// being configured, i.e, the template method from + /// StandardConfigurator interface. + virtual void set_configuration (const Components::ConfigValues & descr); + + void configure (Components::CCMObject_ptr comp); + + private: + /// The component whose attributes are going to be configured via + /// set_attributes + Servant_Impl_Base* const component_; + }; + +} + +#include /**/ "ace/post.h" + +#endif /* CIAO_STANDARDCONFIGURATOR_IMPL_H */ diff --git a/modules/CIAO/ciao/Servants/Swapping/CIAO_SwapExec.idl b/modules/CIAO/ciao/Servants/Swapping/CIAO_SwapExec.idl new file mode 100644 index 00000000000..b52f7db782a --- /dev/null +++ b/modules/CIAO/ciao/Servants/Swapping/CIAO_SwapExec.idl @@ -0,0 +1,12 @@ +// $Id$ + +#include "ccm/CCM_EnterpriseComponent.idl" + +module CIAO +{ + local interface Swap_Exec : ::Components::EnterpriseComponent + { + Components::EnterpriseComponent incarnate (); + Components::EnterpriseComponent etherealize (); + }; +}; diff --git a/modules/CIAO/ciao/Servants/Swapping/CIAO_Swapping_Servant_export.h b/modules/CIAO/ciao/Servants/Swapping/CIAO_Swapping_Servant_export.h new file mode 100644 index 00000000000..672c412e343 --- /dev/null +++ b/modules/CIAO/ciao/Servants/Swapping/CIAO_Swapping_Servant_export.h @@ -0,0 +1,58 @@ + +// -*- C++ -*- +// $Id$ +// Definition for Win32 Export directives. +// This file is generated automatically by generate_export_file.pl CIAO_Swapping_Servant +// ------------------------------ +#ifndef CIAO_SWAPPING_SERVANT_EXPORT_H +#define CIAO_SWAPPING_SERVANT_EXPORT_H + +#include "ace/config-all.h" + +#if defined (ACE_AS_STATIC_LIBS) && !defined (CIAO_SWAPPING_SERVANT_HAS_DLL) +# define CIAO_SWAPPING_SERVANT_HAS_DLL 0 +#endif /* ACE_AS_STATIC_LIBS && CIAO_SWAPPING_SERVANT_HAS_DLL */ + +#if !defined (CIAO_SWAPPING_SERVANT_HAS_DLL) +# define CIAO_SWAPPING_SERVANT_HAS_DLL 1 +#endif /* ! CIAO_SWAPPING_SERVANT_HAS_DLL */ + +#if defined (CIAO_SWAPPING_SERVANT_HAS_DLL) && (CIAO_SWAPPING_SERVANT_HAS_DLL == 1) +# if defined (CIAO_SWAPPING_SERVANT_BUILD_DLL) +# define CIAO_Swapping_Servant_Export ACE_Proper_Export_Flag +# define CIAO_SWAPPING_SERVANT_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) +# define CIAO_SWAPPING_SERVANT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# else /* CIAO_SWAPPING_SERVANT_BUILD_DLL */ +# define CIAO_Swapping_Servant_Export ACE_Proper_Import_Flag +# define CIAO_SWAPPING_SERVANT_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) +# define CIAO_SWAPPING_SERVANT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# endif /* CIAO_SWAPPING_SERVANT_BUILD_DLL */ +#else /* CIAO_SWAPPING_SERVANT_HAS_DLL == 1 */ +# define CIAO_Swapping_Servant_Export +# define CIAO_SWAPPING_SERVANT_SINGLETON_DECLARATION(T) +# define CIAO_SWAPPING_SERVANT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +#endif /* CIAO_SWAPPING_SERVANT_HAS_DLL == 1 */ + +// Set CIAO_SWAPPING_SERVANT_NTRACE = 0 to turn on library specific tracing even if +// tracing is turned off for ACE. +#if !defined (CIAO_SWAPPING_SERVANT_NTRACE) +# if (ACE_NTRACE == 1) +# define CIAO_SWAPPING_SERVANT_NTRACE 1 +# else /* (ACE_NTRACE == 1) */ +# define CIAO_SWAPPING_SERVANT_NTRACE 0 +# endif /* (ACE_NTRACE == 1) */ +#endif /* !CIAO_SWAPPING_SERVANT_NTRACE */ + +#if (CIAO_SWAPPING_SERVANT_NTRACE == 1) +# define CIAO_SWAPPING_SERVANT_TRACE(X) +#else /* (CIAO_SWAPPING_SERVANT_NTRACE == 1) */ +# if !defined (ACE_HAS_TRACE) +# define ACE_HAS_TRACE +# endif /* ACE_HAS_TRACE */ +# define CIAO_SWAPPING_SERVANT_TRACE(X) ACE_TRACE_IMPL(X) +# include "ace/Trace.h" +#endif /* (CIAO_SWAPPING_SERVANT_NTRACE == 1) */ + +#endif /* CIAO_SWAPPING_SERVANT_EXPORT_H */ + +// End of auto generated file. diff --git a/modules/CIAO/ciao/Servants/Swapping/Dynamic_Component_Servant_Base.cpp b/modules/CIAO/ciao/Servants/Swapping/Dynamic_Component_Servant_Base.cpp new file mode 100644 index 00000000000..5127e369f92 --- /dev/null +++ b/modules/CIAO/ciao/Servants/Swapping/Dynamic_Component_Servant_Base.cpp @@ -0,0 +1,28 @@ +#include "ciao/Servants/Swapping/Dynamic_Component_Servant_Base.h" + +ACE_RCSID (ciao, + Dynamic_Component_Servant_Base, + "$Id$") + +namespace CIAO +{ + Dynamic_Component_Servant_Base::Dynamic_Component_Servant_Base (void) + : container_ (0) + { + // This constructor is here to keep MSVC happy and should + // not be used at all. This constructor should be removed + // in the future. Until then, we have the ACE_ASSERT + // below to detect a runtime call to this constructor. + ACE_ASSERT (0); + } + + Dynamic_Component_Servant_Base::Dynamic_Component_Servant_Base + (Session_Container * c) + : container_ (c) + { + } + + Dynamic_Component_Servant_Base::~Dynamic_Component_Servant_Base (void) + { + } +} diff --git a/modules/CIAO/ciao/Servants/Swapping/Dynamic_Component_Servant_Base.h b/modules/CIAO/ciao/Servants/Swapping/Dynamic_Component_Servant_Base.h new file mode 100644 index 00000000000..75f32819036 --- /dev/null +++ b/modules/CIAO/ciao/Servants/Swapping/Dynamic_Component_Servant_Base.h @@ -0,0 +1,54 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Dynamic_Component_Servant_Base.h + * + * $Id$ + * + */ +//============================================================================= + +#ifndef CIAO_DYNAMIC_COMPONENT_SERVANT_BASE__H +#define CIAO_DYNAMIC_COMPONENT_SERVANT_BASE__H + +#include /**/ "ace/pre.h" + +#include "ciao/Servants/Swapping/CIAO_Swapping_Servant_export.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/PortableServer/PortableServer.h" + +namespace CIAO +{ + class Session_Container; + + class CIAO_Swapping_Servant_Export Dynamic_Component_Servant_Base + { + public: + /// @todo Not to be used, no idea why this should be public, have to check this + Dynamic_Component_Servant_Base (void); + + explicit Dynamic_Component_Servant_Base (Session_Container *c); + + virtual ~Dynamic_Component_Servant_Base (void); + + virtual PortableServer::Servant + create (PortableServer::ObjectId &oid) = 0; + + virtual void destroy (PortableServer::ObjectId &oid) = 0; + + virtual void update_destroy_count () = 0; + + protected: + Session_Container *container_; + }; + +} + +#include /**/ "ace/post.h" + +#endif /* CIAO_DYNAMIC_COMPONENT_SERVANT_BASE__H */ diff --git a/modules/CIAO/ciao/Servants/Swapping/Dynamic_Component_Servant_T.cpp b/modules/CIAO/ciao/Servants/Swapping/Dynamic_Component_Servant_T.cpp new file mode 100644 index 00000000000..a23f8559c89 --- /dev/null +++ b/modules/CIAO/ciao/Servants/Swapping/Dynamic_Component_Servant_T.cpp @@ -0,0 +1,87 @@ +// $Id$ + +#ifndef CIAO_DYNAMIC_COMPONENT_SERVANT_T_C +#define CIAO_DYNAMIC_COMPONENT_SERVANT_T_C + +#include "Dynamic_Component_Servant_T.h" + +namespace CIAO +{ + template <typename COMP_SVNT> + Dynamic_Component_Servant<COMP_SVNT>::Dynamic_Component_Servant ( + Components::EnterpriseComponent_ptr ec, + Components::CCMHome_ptr home, + const char* ins_name, + Home_Servant_Impl_Base *home_servant, + Session_Container *c) + : Dynamic_Component_Servant_Base (c) + , executor_ (Components::EnterpriseComponent::_duplicate (ec)) + , ins_name_ (ins_name) + , home_servant_ (home_servant) + , home_ (Components::CCMHome::_duplicate (home)) + , component_removed_ (false) + { + } + + template <typename COMP_SVNT> + void Dynamic_Component_Servant<COMP_SVNT>::update_destroy_count (void) + { + component_removed_ = true; + } + + template <typename COMP_SVNT> + Dynamic_Component_Servant<COMP_SVNT>::~Dynamic_Component_Servant (void) + { + } + + template <typename COMP_SVNT> + void Dynamic_Component_Servant<COMP_SVNT>::destroy ( + PortableServer::ObjectId &oid) + { + // @@Jai, here is a logical problem. You find a servant from a map + // having a list of servants and you turn on a bit. What is the + // granularity of the bit? Looks like its too coarse. Do you see + // what I am saying? + COMP_SVNT *servant = 0; + + if (0 == this->servant_map_.find (oid, servant)) + { + servant->remove (); + component_removed_ = true; + } + } + + template <typename COMP_SVNT> + PortableServer::Servant Dynamic_Component_Servant<COMP_SVNT>::create ( + PortableServer::ObjectId &oid) + { + CIAO::Swap_Exec_var swap_exec = + CIAO::Swap_Exec::_narrow (this->executor_.in ()); + + ::Components::EnterpriseComponent_var ciao_ec = + swap_exec->incarnate (); + + typedef typename COMP_SVNT::_exec_type exec_type; + typename COMP_SVNT::_exec_type::_var_type ciao_comp = + exec_type::_narrow (ciao_ec.in ()); + + /// @@ Jai, should you be using ACE_NEW_THROW_EX here? + COMP_SVNT *svt = new COMP_SVNT (ciao_comp.in (), + this->home_.in (), + this->ins_name_.in (), + this->home_servant_, + this->container_); + + // @@Jai, see the problem with a coarse grained stuff here. + if (component_removed_ == true) + { + component_removed_ = false; + } + + PortableServer::ServantBase_var safe (svt); + this->servant_map_.bind (oid, svt); + return safe._retn (); + } +} + +#endif /* CIAO_DYNAMIC_COMPONENT_SERVANT_T_C */ diff --git a/modules/CIAO/ciao/Servants/Swapping/Dynamic_Component_Servant_T.h b/modules/CIAO/ciao/Servants/Swapping/Dynamic_Component_Servant_T.h new file mode 100644 index 00000000000..244a51b1891 --- /dev/null +++ b/modules/CIAO/ciao/Servants/Swapping/Dynamic_Component_Servant_T.h @@ -0,0 +1,85 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Dynamic_Component_Servant_T.h + * + * $Id$ + * + * This file contains the declaration of a mixin base class for + * the generated home servant class. + * + */ +//============================================================================= + + +#ifndef CIAO_DYNAMIC_COMPONENT_SERVANT_T_H +#define CIAO_DYNAMIC_COMPONENT_SERVANT_T_H + +#include /**/ "ace/pre.h" + +#include "Dynamic_Component_Servant_Base.h" +#include "CIAO_SwapExecC.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/PortableServer/Key_Adapters.h" +#include "ace/Hash_Map_Manager_T.h" + +namespace CIAO +{ + template <typename COMP_SVNT> + class Dynamic_Component_Servant + : public virtual Dynamic_Component_Servant_Base + { + public: + // @@Jai, please add documentation for these methods. + Dynamic_Component_Servant (Components::EnterpriseComponent_ptr ec, + Components::CCMHome_ptr home, + const char* ins_name, + Home_Servant_Impl_Base *home_servant, + Session_Container *c); + + virtual ~Dynamic_Component_Servant (void); + + virtual PortableServer::Servant create (PortableServer::ObjectId &oid); + + virtual void destroy (PortableServer::ObjectId &oid); + + virtual void update_destroy_count (void); + + protected: + Components::EnterpriseComponent_var executor_; + + CORBA::String_var ins_name_; + + Home_Servant_Impl_Base *home_servant_; + + Components::CCMHome_var home_; + + // @@ Jai, please document why this is there. + ACE_Hash_Map_Manager_Ex<PortableServer::ObjectId, + COMP_SVNT *, + TAO_ObjectId_Hash, + ACE_Equal_To<PortableServer::ObjectId>, + TAO_SYNCH_MUTEX> + servant_map_; + + // @@ Jai, please explain what this flag means? + bool component_removed_; + }; +} + +#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) +#include "Dynamic_Component_Servant_T.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) +#pragma implementation ("Dynamic_Component_Servant_T.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + +#include /**/ "ace/post.h" + +#endif /* CIAO_DYNAMIC_COMPONENT_SERVANT_T_H */ diff --git a/modules/CIAO/ciao/Servants/Swapping/Swapping_Servant_Home_Impl_Base.cpp b/modules/CIAO/ciao/Servants/Swapping/Swapping_Servant_Home_Impl_Base.cpp new file mode 100644 index 00000000000..d33d197ee7e --- /dev/null +++ b/modules/CIAO/ciao/Servants/Swapping/Swapping_Servant_Home_Impl_Base.cpp @@ -0,0 +1,31 @@ +// $Id$ + +#include "Swapping_Servant_Home_Impl_Base.h" + +namespace CIAO +{ + Swapping_Home_Servant_Impl_Base::Swapping_Home_Servant_Impl_Base ( + Swapping_Container * c) + : container_ (c) + { + } + + Swapping_Home_Servant_Impl_Base::~Swapping_Home_Servant_Impl_Base (void) + { + } + + // Operations for CCMHome interface. + + CORBA::IRObject_ptr + Swapping_Home_Servant_Impl_Base::get_component_def (void) + { + throw CORBA::NO_IMPLEMENT (); + } + + CORBA::IRObject_ptr + Swapping_Home_Servant_Impl_Base::get_home_def (void) + { + throw CORBA::NO_IMPLEMENT (); + } + +} diff --git a/modules/CIAO/ciao/Servants/Swapping/Swapping_Servant_Home_Impl_Base.h b/modules/CIAO/ciao/Servants/Swapping/Swapping_Servant_Home_Impl_Base.h new file mode 100644 index 00000000000..749eefe4ce7 --- /dev/null +++ b/modules/CIAO/ciao/Servants/Swapping/Swapping_Servant_Home_Impl_Base.h @@ -0,0 +1,63 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Swapping_Servant_Home_Impl_Base.h + * + * $Id$ + * + */ +//============================================================================= + +#ifndef CIAO_SWAPPING_SERVANT_HOME_IMPL_BASE_H +#define CIAO_SWAPPING_SERVANT_HOME_IMPL_BASE_H + +#include /**/ "ace/pre.h" + +#include "ciao/Servants/Swapping/CIAO_Swapping_Servant_export.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "CCM_HomeS.h" + +namespace CIAO +{ + class Swapping_Container; + + /** + * @class Swapping_Home_Servant_Impl_Base + * + */ + // @@ Jai, why are you inheriting from "home" here? What is the + // point? + // @@ JAI, probably my class naming convention was the problem. + // This is a home implementation and that is why inheriting from + // "home". + // + class CIAO_Swapping_Servant_Export Swapping_Home_Servant_Impl_Base + : public virtual POA_Components::CCMHome + { + public: + Swapping_Home_Servant_Impl_Base (Swapping_Container * c); + + virtual ~Swapping_Home_Servant_Impl_Base (void); + + // Operations for CCMHome interface. + virtual ::CORBA::IRObject_ptr get_component_def (void); + + virtual ::CORBA::IRObject_ptr get_home_def (void); + + protected: + Swapping_Container *container_; + + private: + /// Not to be used + Swapping_Home_Servant_Impl_Base (void); + }; +} + +#include /**/ "ace/post.h" + +#endif /* CIAO_SWAPPING_SERVANT_HOME_IMPL_BASE_H */ diff --git a/modules/CIAO/ciao/Servants/Swapping/Swapping_Servant_Home_Impl_T.cpp b/modules/CIAO/ciao/Servants/Swapping/Swapping_Servant_Home_Impl_T.cpp new file mode 100644 index 00000000000..fbc804ca1aa --- /dev/null +++ b/modules/CIAO/ciao/Servants/Swapping/Swapping_Servant_Home_Impl_T.cpp @@ -0,0 +1,213 @@ +// $Id$ + +#ifndef CIAO_SWAPPING_SERVANT_IMPL_T_C +#define CIAO_SWAPPING_SERVANT_IMPL_T_C + +#include "ciao/Swapping_Servant_Home_Impl_T.h" +#include "ciao/Dynamic_Component_Servant_T.h" + +namespace CIAO +{ + template <typename BASE_SKEL, + typename EXEC, + typename COMP_SVNT> + Swapping_Home_Servant_Impl<BASE_SKEL, + EXEC, + COMP_SVNT>::Swapping_Home_Servant_Impl ( + typename EXEC::_ptr_type exe, + Session_Container * c, + const char* ins_name, + const char* obj_id, + const char* repo_id) + : Home_Servant_Impl_Base (c), + executor_ (EXEC::_duplicate (exe)), + ins_name_ (ins_name), + obj_id_ (obj_id), + repo_id_ (repo_id) + { + } + + template <typename BASE_SKEL, + typename EXEC, + typename COMP_SVNT> + Swapping_Home_Servant_Impl<BASE_SKEL, + EXEC, + COMP_SVNT>::~Swapping_Home_Servant_Impl () + { + const DYNAMIC_SERVANT_MAP_ITERATOR end = + this->dynamic_servant_map_.end (); + + PortableServer::ObjectId_var oid = + PortableServer::string_to_ObjectId (this->obj_id_); + + try + { + this->container_->delete_servant_from_map (oid); + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("~Swapping_Home_Servant_Impl\t\n"); + } + + for (DYNAMIC_SERVANT_MAP_ITERATOR iter = + this->dynamic_servant_map_.begin (); + iter != end; ++iter) + { + (*iter).int_id_->destroy (oid); + } + } + + // Operations for CCMHome interface. + + template <typename BASE_SKEL, + typename EXEC, + typename COMP_SVNT> + void + Swapping_Home_Servant_Impl<BASE_SKEL, + EXEC, + COMP_SVNT>::remove_component ( + ::Components::CCMObject_ptr + ) + { + PortableServer::ObjectId_var oid = + PortableServer::string_to_ObjectId (this->obj_id_); + + Dynamic_Component_Servant_Base *servant = 0; + + if (this->dynamic_servant_map_.find (oid.in (), servant) == 0) + { + servant->destroy (oid); + } + } + + // Operations for keyless home interface. + + template <typename BASE_SKEL, + typename EXEC, + typename COMP_SVNT> + Components::CCMObject_ptr + Swapping_Home_Servant_Impl<BASE_SKEL, + EXEC, + COMP_SVNT>::create_component ( + ) + { + return this->create (); + } + + // Operations for implicit home interface. + + template <typename BASE_SKEL, + typename EXEC, + typename COMP_SVNT> + typename COMP_SVNT::_stub_ptr_type + Swapping_Home_Servant_Impl<BASE_SKEL, + EXEC, + COMP_SVNT>::create ( + ) + { + if (this->executor_.in () == 0) + { + throw CORBA::INTERNAL (); + } + + + ::Components::EnterpriseComponent_var _ciao_ec = + this->executor_->create (); + + return this->_ciao_activate_component (_ciao_ec.in ()); + } + + // CIAO-specific operations. + + template <typename BASE_SKEL, + typename EXEC, + typename COMP_SVNT> + typename COMP_SVNT::_stub_ptr_type + Swapping_Home_Servant_Impl<BASE_SKEL, + EXEC, + COMP_SVNT>::_ciao_activate_component ( + ::Components::EnterpriseComponent_ptr ec + ) + { + CORBA::Object_var hobj = + this->container_->get_home_objref (this); + + Components::CCMHome_var home = + Components::CCMHome::_narrow (hobj.in ()); + + PortableServer::ObjectId_var oid = + PortableServer::string_to_ObjectId (this->obj_id_); + + CORBA::Object_var objref = + this->container_->generate_reference ( + this->obj_id_, + this->repo_id_, + Container::Component); + + Dynamic_Component_Servant_Base *svt = + new Dynamic_Component_Servant<COMP_SVNT> (ec, + home.in (), + this->ins_name_, + this, + this->container_); + + this->container_->add_servant_to_map (oid, svt); + + this->dynamic_servant_map_.bind (oid.in (), svt); + + typedef typename COMP_SVNT::_stub_type stub_type; + typename COMP_SVNT::_stub_var_type ho = + stub_type::_narrow (objref.in ()); + + return ho._retn (); + } + + template <typename BASE_SKEL, + typename EXEC, + typename COMP_SVNT> + void + Swapping_Home_Servant_Impl<BASE_SKEL, + EXEC, + COMP_SVNT>::update_component_map ( + PortableServer::ObjectId &oid) + { + Dynamic_Component_Servant_Base *servant = 0; + + if (this->dynamic_servant_map_.find (oid, servant) == 0) + { + servant->update_destroy_count (); + this->dynamic_servant_map_.unbind (oid); + } + + return; + } + + template <typename BASE_SKEL, + typename EXEC, + typename COMP_SVNT> + void + Swapping_Home_Servant_Impl<BASE_SKEL, + EXEC, + COMP_SVNT>::_ciao_passivate_component ( + typename COMP_SVNT::_stub_ptr_type comp + ) + { + PortableServer::ObjectId_var oid; + + this->container_->uninstall_component (comp, + oid.out ()); + + COMP_SVNT *servant = 0; + + if (this->component_map_.find (oid.in (), servant) == 0) + { + PortableServer::ServantBase_var safe (servant); + + servant->ciao_passivate (); + + this->component_map_.unbind (oid.in ()); + } + } +} + +#endif /* CIAO_SWAPPING_SERVANT_IMPL_T_C */ diff --git a/modules/CIAO/ciao/Servants/Swapping/Swapping_Servant_Home_Impl_T.h b/modules/CIAO/ciao/Servants/Swapping/Swapping_Servant_Home_Impl_T.h new file mode 100644 index 00000000000..e6c59a6f37d --- /dev/null +++ b/modules/CIAO/ciao/Servants/Swapping/Swapping_Servant_Home_Impl_T.h @@ -0,0 +1,121 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Swapping_Servant_Home_Impl_T.h + * + * $Id$ + * + * This file contains the declaration of a mixin base class for + * the generated home servant class. + * + */ +//============================================================================= + + +#ifndef CIAO_SWAPPING_SERVANT_HOME_IMPL_T_H +#define CIAO_SWAPPING_SERVANT_HOME_IMPL_T_H + +#include /**/ "ace/pre.h" + +#include "ciao/Home_Servant_Impl_Base.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ciao/Dynamic_Component_Servant_Base.h" + +#include "tao/PortableServer/Key_Adapters.h" + +#include "ace/Hash_Map_Manager_T.h" + +namespace CIAO +{ + class Session_Container; + + /** + * @class Swapping_Servant_Impl + * + * @brief Mixin base class for generated home servant. + * + * This class implements operations + * common to all generated home servants. + */ + template <typename BASE_SKEL, + typename EXEC, + typename COMP_SVNT> + class Swapping_Home_Servant_Impl + : public virtual BASE_SKEL, + public virtual Home_Servant_Impl_Base + { + public: + Swapping_Home_Servant_Impl (typename EXEC::_ptr_type exe, + Session_Container * c, + const char* ins_name, + const char* obj_id, + const char* repo_id); + + virtual ~Swapping_Home_Servant_Impl (void); + + // Operations for CCMHome interface. + + virtual void + remove_component (Components::CCMObject_ptr comp); + + // Operations for keyless home interface. + + virtual ::Components::CCMObject_ptr create_component (); + + // Operations for implicit home interface. + + virtual typename COMP_SVNT::_stub_ptr_type create (); + + virtual void + update_component_map (PortableServer::ObjectId &oid); + + protected: + // CIAO-specific operations. + + typename COMP_SVNT::_stub_ptr_type + _ciao_activate_component (::Components::EnterpriseComponent_ptr ec); + + void + _ciao_passivate_component (typename COMP_SVNT::_stub_ptr_type comp); + + protected: + typename EXEC::_var_type executor_; + + ACE_Hash_Map_Manager_Ex<PortableServer::ObjectId, + COMP_SVNT *, + TAO_ObjectId_Hash, + ACE_Equal_To<PortableServer::ObjectId>, + TAO_SYNCH_MUTEX> + component_map_; + + typedef ACE_Hash_Map_Manager_Ex<PortableServer::ObjectId, + Dynamic_Component_Servant_Base *, + TAO_ObjectId_Hash, + ACE_Equal_To<PortableServer::ObjectId>, + TAO_SYNCH_MUTEX> DYNAMIC_SERVANT_MAP; + + typedef DYNAMIC_SERVANT_MAP::iterator DYNAMIC_SERVANT_MAP_ITERATOR; + DYNAMIC_SERVANT_MAP dynamic_servant_map_; + + const char* ins_name_; + const char* obj_id_; + const char* repo_id_; + }; +} + +#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) +#include "Swapping_Servant_Home_Impl_T.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) +#pragma implementation ("Swapping_Servant_Home_Impl_T.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + +#include /**/ "ace/post.h" + +#endif /* CIAO_SWAPPING_SERVANT_HOME_IMPL_T_H */ diff --git a/modules/CIAO/ciao/Servants/Swapping/Swapping_Servants.mpc b/modules/CIAO/ciao/Servants/Swapping/Swapping_Servants.mpc new file mode 100644 index 00000000000..0815af50445 --- /dev/null +++ b/modules/CIAO/ciao/Servants/Swapping/Swapping_Servants.mpc @@ -0,0 +1,6 @@ +// $Id$ + +project(CIAO_Swapping_Servants) : ciao_lib, ciao_container_base, utils, \ + ccm_componentserver_stub, ciao_servant_activator, ciao_session_container { + dynamicflags = CIAO_SWAPPING_SERVANT_BUILD_DLL +} |