PG_FactoryRegistry.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    PG_FactoryRegistry.h
00006  *
00007  *  $Id: PG_FactoryRegistry.h 80273 2007-12-16 19:55:49Z johnnyw $
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 orb 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);
00092 
00093     /**
00094      * alternative init using designated poa
00095      */
00096     void init (CORBA::ORB_ptr orb, PortableServer::POA_ptr poa);
00097 
00098     /**
00099      * Prepare to exit.
00100      * @return zero for success; nonzero is process return code for failure.
00101      */
00102     int fini (void);
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);
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 (void);
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       );
00136 
00137     virtual void unregister_factory (
00138         const char * role,
00139         const PortableGroup::Location & location
00140     );
00141 
00142     virtual void unregister_factory_by_role (
00143         const char * role
00144       );
00145 
00146 
00147     virtual void unregister_factory_by_location (
00148       const PortableGroup::Location & location
00149     );
00150 
00151     virtual ::PortableGroup::FactoryInfos * list_factories_by_role (
00152         const char * role,
00153         CORBA::String_out type_id
00154       );
00155 
00156     virtual ::PortableGroup::FactoryInfos * list_factories_by_location (
00157       const PortableGroup::Location & location
00158     );
00159 
00160     /////////////////////////
00161     // Implementation methods
00162   private:
00163     /**
00164      * Write this factory's IOR to a file
00165      */
00166     int write_ior_file (const char * outputFile, const char * ior);
00167 
00168     ///////////////
00169     // Data Members
00170   private:
00171 
00172     /**
00173      * A human-readable string to distinguish this from other Notifiers.
00174      */
00175     ACE_CString identity_;
00176 
00177     /**
00178      * Protect internal state.
00179      * Mutex should be locked by corba methods, or by
00180      * external (public) methods before calling implementation
00181      * methods.
00182      * Implementation methods should assume the mutex is
00183      * locked if necessary.
00184      */
00185     TAO_SYNCH_MUTEX internals_;
00186     typedef ACE_Guard<TAO_SYNCH_MUTEX> InternalGuard;
00187 
00188     /**
00189      * The orb
00190      */
00191     CORBA::ORB_var orb_;
00192 
00193     /**
00194      * The POA used to activate this object.
00195      */
00196     PortableServer::POA_var poa_;
00197 
00198     /**
00199      * The CORBA object id assigned to this object.
00200      */
00201     PortableServer::ObjectId_var object_id_;
00202 
00203     /**
00204      * This objects identity as a CORBA object.
00205      */
00206     CORBA::Object_var this_obj_;
00207 
00208     /**
00209      * IOR of this object as assigned by poa.
00210      */
00211     CORBA::String_var ior_;
00212 
00213     /**
00214      * A file to which the factory's IOR should be written.
00215      */
00216     const char * ior_output_file_;
00217 
00218     /**
00219      * A name to be used to register the factory with the name service.
00220      */
00221     const char * ns_name_;
00222 
00223     CosNaming::NamingContext_var naming_context_;
00224 
00225     CosNaming::Name this_name_;
00226 
00227     /**
00228      * Quit on idle flag.
00229      */
00230     int quit_on_idle_;
00231 
00232     /**
00233      * State of the quit process
00234      */
00235     enum {LIVE, DEACTIVATED, GONE} quit_state_;
00236 
00237     int linger_;
00238 
00239     RegistryType registry_;
00240 
00241   };
00242 } // namespace TAO
00243 
00244 TAO_END_VERSIONED_NAMESPACE_DECL
00245 
00246 #include /**/ "ace/post.h"
00247 
00248 #endif // TAO_PG_FACTORYREGISTRY_H_

Generated on Tue Feb 2 17:49:50 2010 for TAO_PortableGroup by  doxygen 1.4.7