summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Event_Utilities.cpp
blob: 29b41b32d450f2f97bb1b1731bdcc5cba2bfc740 (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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// $Id$

#include "orbsvcs/orbsvcs/Event_Utilities.h"
#include "ace/Log_Msg.h"
#include "ace/OS_NS_stdio.h"
#include "ace/OS_NS_string.h"

#if !defined (__ACE_INLINE__)
#include "orbsvcs/orbsvcs/Event_Utilities.i"
#endif /* __ACE_INLINE__ */

ACE_RCSID (orbsvcs, 
           Event_Utilities, 
           "$Id$")

ACE_ConsumerQOS_Factory::
    ACE_ConsumerQOS_Factory (TAO_EC_Event_Initializer initializer)
  : designator_set_ (0),
    event_initializer_ (initializer)
{
  qos_.is_gateway = 0;
}

ACE_ConsumerQOS_Factory::~ACE_ConsumerQOS_Factory (void)
{
}

int
ACE_ConsumerQOS_Factory::start_conjunction_group (int nchildren)
{
  int l = qos_.dependencies.length ();
  qos_.dependencies.length (l + 1);
  if (this->event_initializer_ != 0)
    (*this->event_initializer_) (qos_.dependencies[l].event);
  qos_.dependencies[l].event.header.type = ACE_ES_CONJUNCTION_DESIGNATOR;
  qos_.dependencies[l].event.header.source = nchildren;
  qos_.dependencies[l].rt_info = 0;
  this->designator_set_ = 1;
  return 0;
}

int
ACE_ConsumerQOS_Factory::start_disjunction_group (int nchildren)
{
  int l = qos_.dependencies.length ();
  qos_.dependencies.length (l + 1);
  if (this->event_initializer_ != 0)
    (*this->event_initializer_) (qos_.dependencies[l].event);
  qos_.dependencies[l].event.header.type = ACE_ES_DISJUNCTION_DESIGNATOR;
  qos_.dependencies[l].event.header.source = nchildren;
  qos_.dependencies[l].rt_info = 0;
  this->designator_set_ = 1;
  return 0;
}

int
ACE_ConsumerQOS_Factory::start_logical_and_group (int nchildren)
{
  int l = qos_.dependencies.length ();
  qos_.dependencies.length (l + 1);
  if (this->event_initializer_ != 0)
    (*this->event_initializer_) (qos_.dependencies[l].event);
  qos_.dependencies[l].event.header.type = ACE_ES_LOGICAL_AND_DESIGNATOR;
  qos_.dependencies[l].event.header.source = nchildren;
  qos_.dependencies[l].rt_info = 0;
  this->designator_set_ = 1;
  return 0;
}

int
ACE_ConsumerQOS_Factory::start_negation (void)
{
  int l = qos_.dependencies.length ();
  qos_.dependencies.length (l + 1);
  if (this->event_initializer_ != 0)
    (*this->event_initializer_) (qos_.dependencies[l].event);
  qos_.dependencies[l].event.header.type = ACE_ES_NEGATION_DESIGNATOR;
  qos_.dependencies[l].rt_info = 0;
  this->designator_set_ = 1;
  return 0;
}

int
ACE_ConsumerQOS_Factory::start_bitmask (CORBA::ULong source_mask,
                                        CORBA::ULong type_mask)
{
  int l = qos_.dependencies.length ();
  qos_.dependencies.length (l + 2);
  if (this->event_initializer_ != 0)
    {
      (*this->event_initializer_) (qos_.dependencies[l].event);
      (*this->event_initializer_) (qos_.dependencies[l + 1].event);
    }
  qos_.dependencies[l].event.header.type = ACE_ES_BITMASK_DESIGNATOR;
  qos_.dependencies[l].rt_info = 0;

  qos_.dependencies[l+1].event.header.source = source_mask;
  qos_.dependencies[l+1].event.header.type = type_mask;
  qos_.dependencies[l+1].rt_info = 0;

  this->designator_set_ = 1;
  return 0;
}

int
ACE_ConsumerQOS_Factory::insert (const RtecEventChannelAdmin::Dependency &subscribe)
{
  // Make sure that a designator is first.
  if (designator_set_ == 0)
    {
      int l = qos_.dependencies.length ();
      qos_.dependencies.length (l + 1);
      if (this->event_initializer_ != 0)
        (*this->event_initializer_) (qos_.dependencies[l].event);
      qos_.dependencies[l].rt_info = 0;
      qos_.dependencies[l].event.header.type = ACE_ES_GLOBAL_DESIGNATOR;

      this->designator_set_ = 1;
    }

  int l = qos_.dependencies.length ();
  qos_.dependencies.length (l + 1);
  qos_.dependencies[l] = subscribe;
  return 0;
}

void event_debug (const char* p,
                  const RtecEventComm::Event& event)
{
  size_t l = ACE_OS::strlen (p);
  ACE_DEBUG ((LM_DEBUG,
              "%*.*s - event.source: %d (0x%x)\n"
              "%*.*s   event.type: %d (0x%x)\n",
              l, l, p, event.header.source, event.header.source,
              l, l, p, event.header.type, event.header.type));
}

void
ACE_ConsumerQOS_Factory::debug (const RtecEventChannelAdmin::ConsumerQOS& qos)
{
  ACE_DEBUG ((LM_DEBUG, "ConsumerQOS { \n"));
  ACE_DEBUG ((LM_DEBUG, "  is_gateway: %d\n", qos.is_gateway));

  for (u_int i = 0; i < qos.dependencies.length (); ++i)
    {
      char buf[128];
      ACE_OS::sprintf (buf, " dep[%d]", i);
      event_debug (buf, qos.dependencies[i].event);
      ACE_DEBUG ((LM_DEBUG, "%s  rt_info: %d\n",
                  buf, qos.dependencies[i].rt_info));
    }
  ACE_DEBUG ((LM_DEBUG, "}\n"));
}

// ************************************************************
ACE_SupplierQOS_Factory::
    ACE_SupplierQOS_Factory (TAO_EC_Event_Initializer initializer,
                             int qos_max_len)
  : event_initializer_ (initializer)
{
  qos_.is_gateway = 0;

  // Allocate the space requested by the application....
  qos_.publications.length (qos_max_len);

  // ... now reset the length, we do not want to use any elements in
  // the sequence that have not been initialized....
  qos_.publications.length (0);
}

int
ACE_SupplierQOS_Factory::insert (RtecEventComm::EventSourceID sid,
                                 RtecEventComm::EventType type,
                                 RtecBase::handle_t rt_info,
                                 u_int ncalls)
{
  CORBA::ULong l = this->qos_.publications.length ();
  if (l >= this->qos_.publications.maximum ())
    {
      // There is not enough space for the next element, grow the
      // buffer.
      this->qos_.publications.length (l + 1);

      // @@ TODO We may want to consider more efficient growing
      // strategies here, for example, duplicating the size of the
      // buffer, or growing in fixed sized chunks...
    }

  if (this->event_initializer_ != 0)
    (*this->event_initializer_) (qos_.publications[l].event);
  this->qos_.publications[l].event.header.source = sid;
  this->qos_.publications[l].event.header.type = type;
  // TODO: IDL union this->qos_.publications[l].event.data_.lval (0);
  this->qos_.publications[l].dependency_info.rt_info = rt_info;
  this->qos_.publications[l].dependency_info.number_of_calls = ncalls;
  return 0;
}

void ACE_SupplierQOS_Factory::debug (const RtecEventChannelAdmin::SupplierQOS& qos)
{
  ACE_DEBUG ((LM_DEBUG, "SupplierQOS { \n"));
  ACE_DEBUG ((LM_DEBUG, "  is_gateway: %d\n", qos.is_gateway));

  for (u_int i = 0; i < qos.publications.length (); ++i)
    {
      char buf[128];
      ACE_OS::sprintf (buf, " publications[%d]", i);
      event_debug (buf, qos.publications[i].event);
      ACE_DEBUG ((LM_DEBUG,
                  "%s   dependency_info.rt_info: %d\n"
                  "%s   dependency_info.number_of_calls: %d\n",
                  buf, qos.publications[i].dependency_info.rt_info,
                  buf, qos.publications[i].dependency_info.number_of_calls));
        }
  ACE_DEBUG ((LM_DEBUG, "}\n"));

}