EventType.cpp

Go to the documentation of this file.
00001 // $Id: EventType.cpp 78005 2007-04-12 19:14:05Z elliott_c $
00002 
00003 #include "orbsvcs/Notify/EventType.h"
00004 
00005 #include "ace/ACE.h"
00006 #include "ace/Log_Msg.h"
00007 #include "ace/OS_NS_string.h"
00008 
00009 #if ! defined (__ACE_INLINE__)
00010 #include "orbsvcs/Notify/EventType.inl"
00011 #endif /* __ACE_INLINE__ */
00012 
00013 #include "orbsvcs/Notify/Topology_Saver.h"
00014 
00015 ACE_RCSID (Notify,
00016            TAO_Notify_EventType,
00017            "$Id: EventType.cpp 78005 2007-04-12 19:14:05Z elliott_c $")
00018 
00019 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00020 
00021 TAO_Notify_EventType
00022 TAO_Notify_EventType::special (void)
00023 {
00024   return TAO_Notify_EventType ("*", "%ALL");
00025 }
00026 
00027 TAO_Notify_EventType::TAO_Notify_EventType (void)
00028 {
00029 }
00030 
00031 void
00032 TAO_Notify_EventType::init_i (const char* domain_name, const char* type_name)
00033 {
00034   this->event_type_.domain_name = domain_name;
00035   this->event_type_.type_name = type_name;
00036 
00037   if (this->is_special () == 1)
00038     {
00039       this->event_type_.domain_name = CORBA::string_dup ("*");
00040       this->event_type_.type_name = CORBA::string_dup ("%ALL");
00041     }
00042 
00043   this->recompute_hash ();
00044 }
00045 
00046 TAO_Notify_EventType::TAO_Notify_EventType (const char* domain_name,
00047                                             const char* type_name)
00048 {
00049   this->init_i (domain_name, type_name);
00050 }
00051 
00052 TAO_Notify_EventType::TAO_Notify_EventType (
00053     const CosNotification::EventType& event_type
00054   )
00055 {
00056   this->init_i (event_type.domain_name.in (), event_type.type_name.in ());
00057 }
00058 
00059 TAO_Notify_EventType::~TAO_Notify_EventType ()
00060 {
00061 }
00062 
00063 void
00064 TAO_Notify_EventType::recompute_hash (void)
00065 {
00066   // @@ Pradeep: this code is bound to crash someday if the strings
00067   // are too long....  See if the hash_pjw () function can be modified
00068   // to take accumulate multiple strings, as in:
00069   //   hash = ACE::hash_pjw_accummulate (0, str1);
00070   //   hash = ACE::hash_pjw_accummulate (hash, str2);
00071   //
00072   // @@ Or use grow the buffer when needed, or just add the two hash
00073   // values or something, but fix this code!
00074   //
00075   char buffer[BUFSIZ];
00076   ACE_OS::strcpy (buffer, this->event_type_.domain_name.in ());
00077   ACE_OS::strcat (buffer, this->event_type_.type_name.in ());
00078 
00079   this->hash_value_ =  ACE::hash_pjw (buffer);
00080 }
00081 
00082 TAO_Notify_EventType&
00083 TAO_Notify_EventType::operator=(const CosNotification::EventType& event_type)
00084 {
00085   this->init_i (event_type.domain_name.in (),event_type.type_name.in ());
00086 
00087   return *this;
00088 }
00089 
00090 TAO_Notify_EventType&
00091 TAO_Notify_EventType::operator=(const TAO_Notify_EventType& event_type)
00092 {
00093   if (this == &event_type)
00094     return *this;
00095 
00096   this->init_i (event_type.event_type_.domain_name.in (),event_type.event_type_.type_name.in ());
00097 
00098   return *this;
00099 }
00100 
00101 bool
00102 TAO_Notify_EventType::operator==(const TAO_Notify_EventType& event_type) const
00103 {
00104   return (ACE_OS::strcmp (this->event_type_.domain_name,
00105                           event_type.event_type_.domain_name) == 0 ||
00106           this->domain_is_wildcard (this->event_type_.domain_name) ||
00107           this->domain_is_wildcard (event_type.event_type_.type_name)) &&
00108          (ACE_OS::strcmp (this->event_type_.type_name,
00109                           event_type.event_type_.type_name) == 0 ||
00110           this->type_is_wildcard (this->event_type_.type_name)   ||
00111           this->type_is_wildcard (event_type.event_type_.type_name));
00112 }
00113 
00114 bool
00115 TAO_Notify_EventType::operator!=(const TAO_Notify_EventType& event_type) const
00116 {
00117   return !(*this == event_type);
00118 }
00119 
00120 CORBA::Boolean
00121 TAO_Notify_EventType::is_special (void) const
00122 {
00123   return (this->domain_is_wildcard (this->event_type_.domain_name) &&
00124           this->type_is_wildcard (this->event_type_.type_name));
00125 }
00126 
00127 void
00128 TAO_Notify_EventType::dump (void) const
00129 {
00130   ACE_DEBUG ((LM_DEBUG,
00131               "(%s,%s)",
00132               this->event_type_.domain_name.in (),
00133               this->event_type_.type_name.in ()));
00134 }
00135 
00136 /// Initialize from an NVPList, return false on failure
00137 bool TAO_Notify_EventType::init(const TAO_Notify::NVPList& attrs)
00138 {
00139   bool result = false;
00140 
00141   ACE_CString domain;
00142   ACE_CString type;
00143   if (attrs.load("Domain", domain) && attrs.load("Type", type))
00144   {
00145     this->init_i(domain.c_str(), type.c_str());
00146     result = true;
00147   }
00148   return result;
00149 
00150 }
00151 
00152   // TAO_Notify::Topology_Object
00153 
00154 void
00155 TAO_Notify_EventType::save_persistent (TAO_Notify::Topology_Saver& saver)
00156 {
00157   TAO_Notify::NVPList attrs;
00158   bool changed = true;
00159 
00160   attrs.push_back(TAO_Notify::NVP("Domain", this->event_type_.domain_name.in()));
00161   attrs.push_back(TAO_Notify::NVP("Type", this->event_type_.type_name.in()));
00162   saver.begin_object(0, "subscription", attrs, changed);
00163 
00164   saver.end_object(0, "subscription");
00165 }
00166 
00167 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:45:29 2010 for TAO_CosNotification by  doxygen 1.4.7