PG_FactoryRegistry.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    PG_FactoryRegistry.h
00006  *
00007  *  PG_FactoryRegistry.h,v 1.12 2006/03/14 06:14:34 jtc Exp
00008  *
00009  *  This file declares the implementation of PortableGroup::FactoryRegistry.
00010  *  Eventually this should be folded into the Fault Tolerance ReplicationManager
00011  *
00012  *  @author Dale Wilson <wilson_d@ociweb.com>
00013  */
00014 //=============================================================================
00015 
00016 #ifndef TAO_PG_FACTORYREGISTRY_H_
00017 #define TAO_PG_FACTORYREGISTRY_H_
00018 #include /**/ "ace/pre.h"
00019 #include /**/ "ace/ACE.h"
00020 
00021 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00022 #pragma once
00023 #endif /* ACE_LACKS_PRAGMA_ONCE */
00024 
00025 #include "tao/Versioned_Namespace.h"
00026 
00027 /////////////////////////////////
00028 // Includes needed by this header
00029 #include "orbsvcs/PortableGroup/portablegroup_export.h"
00030 #include "orbsvcs/PortableGroupS.h"
00031 #include "ace/Hash_Map_Manager.h"
00032 #include "ace/SString.h"
00033 #include "ace/Null_Mutex.h"
00034 
00035 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00036 
00037 //////////////////////////////////
00038 // Classes declared in this header
00039 namespace TAO
00040 {
00041   class PG_FactoryRegistry;
00042 }
00043 
00044 /////////////////////
00045 // Forward references
00046 
00047 namespace TAO
00048 {
00049   /**
00050    * Implement the PortableGroup::FactoryRegistry interface
00051    * Note FactoryRegistry is not part of the OMG standard.  It was added
00052    * as part of the TAO implementation of Fault Tolerant CORBA
00053    */
00054   class TAO_PortableGroup_Export PG_FactoryRegistry
00055     : public virtual POA_PortableGroup::FactoryRegistry
00056   {
00057     struct RoleInfo
00058     {
00059       ACE_CString type_id_;
00060       PortableGroup::FactoryInfos infos_;
00061 
00062       RoleInfo(size_t estimated_number_entries = 5);
00063     };
00064     typedef ACE_Null_Mutex MapMutex;
00065     typedef ACE_Hash_Map_Manager <ACE_CString, RoleInfo *, MapMutex>  RegistryType;
00066     typedef ACE_Hash_Map_Entry <ACE_CString, RoleInfo *> RegistryType_Entry;
00067     typedef ACE_Hash_Map_Iterator <ACE_CString, RoleInfo *, MapMutex> RegistryType_Iterator;
00068 
00069     //////////////////////
00070     // non-CORBA interface
00071   public:
00072     /// Constructor
00073     PG_FactoryRegistry (const char * name = "FactoryRegistry");
00074 
00075     /// virtual Destructor
00076     virtual ~PG_FactoryRegistry (void);
00077 
00078     /**
00079      * Parse command line arguments.
00080      * @param argc traditional C argc
00081      * @param argv traditional C argv
00082      * @return zero for success; nonzero is process return code for failure.
00083      */
00084     int parse_args (int argc, char * argv[]);
00085 
00086     /**
00087      * Initialize this object.
00088      * @param orbManager our ORB -- we keep var to it.
00089      * @return zero for success; nonzero is process return code for failure.
00090      */
00091     int init (CORBA::ORB_ptr orb  ACE_ENV_ARG_DECL);
00092 
00093     /**
00094      * alternative init using designated poa
00095      */
00096     void init (CORBA::ORB_ptr orb, PortableServer::POA_ptr poa ACE_ENV_ARG_DECL);
00097 
00098     /**
00099      * Prepare to exit.
00100      * @return zero for success; nonzero is process return code for failure.
00101      */
00102     int fini (ACE_ENV_SINGLE_ARG_DECL);
00103 
00104     /**
00105      * Processing to happen when the ORB's event loop is idle.
00106      * @param result is a place to return status to be returned by the process
00107      * @returns 0 to continue.  1 to quit.
00108      */
00109     int idle(int & result ACE_ENV_ARG_DECL);
00110 
00111     /**
00112      * Identify this object.
00113      * @return a string to identify this object for logging/console message purposes.
00114      */
00115     const char * identity () const;
00116 
00117     /**
00118      * An object reference to the this object.
00119      * Duplicated by the call so it may (and probably should) be assigned to a _var..
00120      */
00121     ::PortableGroup::FactoryRegistry_ptr reference();
00122 
00123     ////////////////////////////////
00124     // override servant base methods
00125     virtual void _remove_ref (ACE_ENV_SINGLE_ARG_DECL);
00126 
00127     //////////////////
00128     // CORBA interface
00129     // See IDL for documentation
00130 
00131     virtual void register_factory (
00132         const char * role,
00133         const char * type_id,
00134         const PortableGroup::FactoryInfo & factory_info
00135         ACE_ENV_ARG_DECL
00136       )
00137       ACE_THROW_SPEC ((
00138         CORBA::SystemException
00139         , PortableGroup::MemberAlreadyPresent
00140         , PortableGroup::TypeConflict));
00141 
00142     virtual void unregister_factory (
00143         const char * role,
00144         const PortableGroup::Location & location
00145       ACE_ENV_ARG_DECL
00146     )
00147     ACE_THROW_SPEC ((CORBA::SystemException, PortableGroup::MemberNotFound));
00148 
00149     virtual void unregister_factory_by_role (
00150         const char * role
00151         ACE_ENV_ARG_DECL
00152       )
00153       ACE_THROW_SPEC ((CORBA::SystemException));
00154 
00155 
00156     virtual void unregister_factory_by_location (
00157       const PortableGroup::Location & location
00158       ACE_ENV_ARG_DECL
00159     )
00160     ACE_THROW_SPEC ((CORBA::SystemException));
00161 
00162     virtual ::PortableGroup::FactoryInfos * list_factories_by_role (
00163         const char * role,
00164         CORBA::String_out type_id
00165         ACE_ENV_ARG_DECL
00166       )
00167       ACE_THROW_SPEC ((CORBA::SystemException));
00168 
00169     virtual ::PortableGroup::FactoryInfos * list_factories_by_location (
00170       const PortableGroup::Location & location
00171       ACE_ENV_ARG_DECL
00172     )
00173     ACE_THROW_SPEC ((CORBA::SystemException));
00174 
00175     /////////////////////////
00176     // Implementation methods
00177   private:
00178     /**
00179      * Write this factory's IOR to a file
00180      */
00181     int write_ior_file (const char * outputFile, const char * ior);
00182 
00183     ///////////////
00184     // Data Members
00185   private:
00186 
00187     /**
00188      * A human-readable string to distinguish this from other Notifiers.
00189      */
00190     ACE_CString identity_;
00191 
00192     /**
00193      * Protect internal state.
00194      * Mutex should be locked by corba methods, or by
00195      * external (public) methods before calling implementation
00196      * methods.
00197      * Implementation methods should assume the mutex is
00198      * locked if necessary.
00199      */
00200     TAO_SYNCH_MUTEX internals_;
00201     typedef ACE_Guard<TAO_SYNCH_MUTEX> InternalGuard;
00202 
00203     /**
00204      * The orb
00205      */
00206     CORBA::ORB_var orb_;
00207 
00208     /**
00209      * The POA used to activate this object.
00210      */
00211     PortableServer::POA_var poa_;
00212 
00213     /**
00214      * The CORBA object id assigned to this object.
00215      */
00216     PortableServer::ObjectId_var object_id_;
00217 
00218     /**
00219      * This objects identity as a CORBA object.
00220      */
00221     CORBA::Object_var this_obj_;
00222 
00223     /**
00224      * IOR of this object as assigned by poa.
00225      */
00226     CORBA::String_var ior_;
00227 
00228     /**
00229      * A file to which the factory's IOR should be written.
00230      */
00231     const char * ior_output_file_;
00232 
00233     /**
00234      * A name to be used to register the factory with the name service.
00235      */
00236     const char * ns_name_;
00237 
00238     CosNaming::NamingContext_var naming_context_;
00239 
00240     CosNaming::Name this_name_;
00241 
00242     /**
00243      * Quit on idle flag.
00244      */
00245     int quit_on_idle_;
00246 
00247     /**
00248      * State of the quit process
00249      */
00250     enum {LIVE, DEACTIVATED, GONE} quit_state_;
00251 
00252     int linger_;
00253 
00254     RegistryType registry_;
00255 
00256   };
00257 } // namespace TAO
00258 
00259 TAO_END_VERSIONED_NAMESPACE_DECL
00260 
00261 #include /**/ "ace/post.h"
00262 
00263 #endif // TAO_PG_FACTORYREGISTRY_H_

Generated on Thu Nov 9 14:03:33 2006 for TAO_PortableGroup by doxygen 1.3.6