00001 // $Id: Control_Registry.h 84286 2009-01-31 08:50:42Z johnnyw $ 00002 00003 #ifndef CONTROL_REGISTRY_H 00004 #define CONTROL_REGISTRY_H 00005 00006 #include /**/ "ace/pre.h" 00007 00008 #include "tao/TAO_Singleton.h" 00009 00010 #include "tao/Monitor/Monitor.h" 00011 00012 #include "orbsvcs/orbsvcs/Notify/MonitorControl/Control.h" 00013 00014 #include "ace/Hash_Map_Manager_T.h" 00015 00016 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00017 00018 class TAO_Notify_MC_Export TAO_Control_Registry 00019 { 00020 public: 00021 /// Reusing NameList that comes from the TAO Monitor library. 00022 typedef Monitor::NameList NameList; 00023 00024 /// Exception thrown in the event that something goes wrong 00025 /// when adding to the registry 00026 class TAO_Notify_MC_Export Map_Error 00027 { 00028 public: 00029 enum ErrorReason 00030 { 00031 MAP_ERROR_BIND_FAILURE, 00032 MAP_ERROR_INVALID_VALUE 00033 }; 00034 00035 ErrorReason why_; 00036 00037 Map_Error (ErrorReason why) 00038 : why_ (why) 00039 { 00040 } 00041 }; 00042 00043 /// Return the singleton instance of the registry 00044 static TAO_Control_Registry* instance (void); 00045 00046 /// Empty out the map of objects 00047 ~TAO_Control_Registry (void); 00048 00049 /// Adds an object to the map. 00050 /// Throws Map_Error if the object is null or if there 00051 /// is a fatal error adding it to the map. 00052 /// Returns true if the object is successfully added to the map. 00053 /// Returns false otherwise. 00054 bool add (TAO_NS_Control* type); 00055 00056 /// Removes an object from the map. 00057 /// Returns true if the object is successfully removed from the map. 00058 /// Returns false otherwise. 00059 bool remove (const ACE_CString& name); 00060 00061 /// Returns a list of names stored in the registry 00062 const NameList& names (void); 00063 00064 /// Gets an object from the map 00065 /// Returns the object if it is successfully located. 00066 /// Returns null otherwise. 00067 TAO_NS_Control* get (const ACE_CString& name) const; 00068 00069 private: 00070 typedef ACE_Hash_Map_Manager<ACE_CString, 00071 TAO_NS_Control*, 00072 ACE_SYNCH_NULL_MUTEX> 00073 Map; 00074 00075 mutable TAO_SYNCH_RW_MUTEX mutex_; 00076 Map map_; 00077 NameList name_cache_; 00078 }; 00079 00080 TAO_END_VERSIONED_NAMESPACE_DECL 00081 00082 #include /**/ "ace/post.h" 00083 00084 #endif /* CONTROL_REGISTRY_H */