summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Notify/EventType.cpp
blob: 3ad1b7d988c8385f6bd2bfa0edbb40dc9b945abe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// $Id$

#include "orbsvcs/Notify/EventType.h"

#include "ace/ACE.h"
#include "ace/Log_Msg.h"
#include "ace/OS_NS_string.h"

#if ! defined (__ACE_INLINE__)
#include "orbsvcs/Notify/EventType.inl"
#endif /* __ACE_INLINE__ */

#include "orbsvcs/Notify/Topology_Saver.h"

ACE_RCSID (Notify,
           TAO_Notify_EventType,
           "$Id$")

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

TAO_Notify_EventType
TAO_Notify_EventType::special (void)
{
  return TAO_Notify_EventType ("*", "%ALL");
}

TAO_Notify_EventType::TAO_Notify_EventType (void)
{
}

void
TAO_Notify_EventType::init_i (const char* domain_name, const char* type_name)
{
  this->event_type_.domain_name = domain_name;
  this->event_type_.type_name = type_name;

  if (this->is_special () == 1)
    {
      this->event_type_.domain_name = (const char* )"*";
      this->event_type_.type_name = (const char* )"%ALL";
    }

  this->recompute_hash ();
}

TAO_Notify_EventType::TAO_Notify_EventType (const char* domain_name,
                                            const char* type_name)
{
  this->init_i (domain_name, type_name);
}

TAO_Notify_EventType::TAO_Notify_EventType (
    const CosNotification::EventType& event_type
  )
{
  this->init_i (event_type.domain_name.in (), event_type.type_name.in ());
}

TAO_Notify_EventType::~TAO_Notify_EventType ()
{
}

void
TAO_Notify_EventType::recompute_hash (void)
{
  // @@ Pradeep: this code is bound to crash someday if the strings
  // are too long....  See if the hash_pjw () function can be modified
  // to take accumulate multiple strings, as in:
  //   hash = ACE::hash_pjw_accummulate (0, str1);
  //   hash = ACE::hash_pjw_accummulate (hash, str2);
  //
  // @@ Or use grow the buffer when needed, or just add the two hash
  // values or something, but fix this code!
  //
  char buffer[BUFSIZ];
  ACE_OS::strcpy (buffer, this->event_type_.domain_name.in ());
  ACE_OS::strcat (buffer, this->event_type_.type_name.in ());

  this->hash_value_ =  ACE::hash_pjw (buffer);
}

TAO_Notify_EventType&
TAO_Notify_EventType::operator=(const CosNotification::EventType& event_type)
{
  this->init_i (event_type.domain_name.in (),event_type.type_name.in ());

  return *this;
}

TAO_Notify_EventType&
TAO_Notify_EventType::operator=(const TAO_Notify_EventType& event_type)
{
  if (this == &event_type)
    return *this;

  this->init_i (event_type.event_type_.domain_name.in (),event_type.event_type_.type_name.in ());

  return *this;
}

bool
TAO_Notify_EventType::operator==(const TAO_Notify_EventType& event_type) const
{
  if (this->hash () != event_type.hash ())
    return false;
  else // compare the strings
    return (ACE_OS::strcmp (this->event_type_.type_name.in(), event_type.event_type_.type_name.in()) == 0  &&
            ACE_OS::strcmp (this->event_type_.domain_name.in(), event_type.event_type_.domain_name.in()) == 0
           );
}

bool
TAO_Notify_EventType::operator!=(const TAO_Notify_EventType& event_type) const
{
  if (this->hash () != event_type.hash ())
    return true;
  else // compare the strings
    return (ACE_OS::strcmp (this->event_type_.type_name.in(), event_type.event_type_.type_name.in()) != 0  ||
            ACE_OS::strcmp (this->event_type_.domain_name.in(), event_type.event_type_.domain_name.in()) != 0
           );
}

CORBA::Boolean
TAO_Notify_EventType::is_special (void) const
{
  if ((this->event_type_.domain_name == 0 ||
             ACE_OS::strcmp (this->event_type_.domain_name.in(), "") == 0 ||
             ACE_OS::strcmp (this->event_type_.domain_name.in(), "*") == 0) &&
      (this->event_type_.type_name == 0 ||
             ACE_OS::strcmp (this->event_type_.type_name.in(), "") == 0 ||
             ACE_OS::strcmp (this->event_type_.type_name.in(), "*") == 0 ||
             ACE_OS::strcmp (this->event_type_.type_name.in(), "%ALL") == 0))
    return 1;
  else
    return 0;
}

void
TAO_Notify_EventType::dump (void) const
{
  ACE_DEBUG ((LM_DEBUG,
              "(%s,%s)",
              this->event_type_.domain_name.in (),
              this->event_type_.type_name.in ()));
}

/// Initialize from an NVPList, return false on failure
bool TAO_Notify_EventType::init(const TAO_Notify::NVPList& attrs)
{
  bool result = false;

  ACE_CString domain;
  ACE_CString type;
  if (attrs.load("Domain", domain) && attrs.load("Type", type))
  {
    this->init_i(domain.c_str(), type.c_str());
    result = true;
  }
  return result;

}

  // TAO_Notify::Topology_Object

void
TAO_Notify_EventType::save_persistent (TAO_Notify::Topology_Saver& saver ACE_ENV_ARG_DECL)
{
  TAO_Notify::NVPList attrs;
  bool changed = true;

  attrs.push_back(TAO_Notify::NVP("Domain", this->event_type_.domain_name.in()));
  attrs.push_back(TAO_Notify::NVP("Type", this->event_type_.type_name.in()));
  saver.begin_object(0, "subscription", attrs, changed ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;

  saver.end_object(0, "subscription" ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;
}

TAO_END_VERSIONED_NAMESPACE_DECL