summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/be/be_visitor_component/context_svth.cpp
blob: 8ea4e15f4b2f4957456f0b2715beddc348df3ea9 (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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310

//=============================================================================
/**
 *  @file    context_svh.cpp
 *
 *  $Id$
 *
 *  Visitor generating code for a context class in the
 *  servant header.
 *
 *
 *  @author Jeff Parsons
 */
//=============================================================================
#include <be_helper.h>

be_visitor_context_svth::be_visitor_context_svth (be_visitor_context *ctx)
  : be_visitor_component_scope (ctx)
{
}

be_visitor_context_svth::~be_visitor_context_svth (void)
{
}

int
be_visitor_context_svth::visit_component (be_component *node)
{
  // This visitor is spawned by be_visitor_component_svh,
  // which already does a check for imported node, so none
  // is needed here.
  node_ = node;

  AST_Decl *scope = ScopeAsDecl (node->defined_in ());
  ACE_CString sname_str (scope->full_name ());
  const char *sname = sname_str.c_str ();

  // No '_cxx_' prefix.
  const char *lname =
    node->original_local_name ()->get_string ();

  const char *global = (sname_str == "" ? "" : "::");

  os_ << be_nl
      << "class " << lname << "_Servant;"
      << be_nl_2;


  os_ << "template <typename CONTAINER_TYPE, typename BASE>" << be_nl;

  os_ << "class " << export_macro_.c_str () << " " << lname
      << "_Context_T" << be_idt_nl;
  // Spec: no multiple inheritance allowed for components.
  AST_Component * base = node->base_component ();
  if (base)
    {
      AST_Decl *base_scope = ScopeAsDecl (base->defined_in ());
      ACE_CString sbase_name_str (scope->full_name ());
      const char *sbase_name = sbase_name_str.c_str ();
      const char *lbase_name =
        base->original_local_name ()->get_string ();

      os_ << ": public " << global << "CIAO_" << base->flat_name ()
          << "_Impl::" << lbase_name << "_Context_T<CONTAINER_TYPE, BASE>";
    }
  else
    {
      os_ << ": public virtual BASE";
    }


  os_ << be_uidt_nl
      << "{" << be_nl
      << "public:" << be_idt_nl;

  os_ << "/// Allow the servant to access our state." << be_nl
      << "friend class " << lname << "_Servant;"
      << be_nl_2;

//   os_ << "/// Some useful typedefs." << be_nl
//       << "typedef" << be_nl
//       << "::CIAO::" << be_global->ciao_container_type ()
//       << "_Context_Impl_T<" << be_idt << be_idt_nl
//       << global << sname << "::CCM_"
//       << lname << "_Context," << be_nl
//       << "::" << node->name () << ">" << be_uidt_nl
//       << "base_type;" << be_uidt_nl << be_nl;
//
//   os_ << "typedef base_type::context_type context_type;" << be_nl
//       << "typedef base_type::component_type component_type;"
//       << be_nl;

  AST_Decl::NodeType nt = this->node_->node_type ();
  bool const is_connector = (nt == AST_Decl::NT_connector);
  bool no_events = false;

  if (!is_connector)
    {
      no_events =
        (node->n_consumes () == 0UL
         && node->n_emits () == 0UL
         && node->n_publishes () == 0UL);
    }

  bool const de_facto = (is_connector || no_events);

  os_ << "typedef ::CIAO::"
      << (de_facto ? "Connector_" : "")
      << "Servant_Impl_Base svnt_base_type;" << be_nl_2;

  os_ << lname << "_Context_T (" << be_idt_nl
      << "::Components::CCMHome_ptr h," << be_nl
      << "typename CONTAINER_TYPE::_ptr_type c," << be_nl
      << "PortableServer::Servant sv," << be_nl
      << "const char *id);" << be_uidt_nl << be_nl;

  os_ << "virtual ~" << lname << "_Context_T (void);";

  os_ << be_nl_2
      << "/** @name Operations and members for " << lname
      << " receptacles and event sources,"
      << be_nl
      << " * defined in " << global << sname
      << "::CCM_" << lname << "_Context." << be_nl << " */"
      << be_nl
      << "//@{";

  if (this->visit_component_scope (node) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("be_visitor_context_svth")
                         ACE_TEXT ("::visit_component - ")
                         ACE_TEXT ("visit_component_scope() ")
                         ACE_TEXT ("failed\n")),
                        -1);
    }

  os_ << be_nl
      << "//@}"
      << be_uidt_nl
      << "};";

  return 0;
}

int
be_visitor_context_svth::visit_connector (be_connector *node)
{
  return this->visit_component (node);
}

int
be_visitor_context_svth::visit_uses (be_uses *node)
{
  if (node->imported ())
    {
      return 0;
    }

  ACE_CString prefix (this->ctx_->port_prefix ());
  prefix += node->local_name ()->get_string ();
  const char *port_name = prefix.c_str ();

  const char *obj_name = node->uses_type ()->full_name ();
  bool const is_multiple = node->is_multiple ();

  os_ << be_uidt_nl << be_nl
      << "public:" << be_idt_nl
      << "virtual ";

  if (is_multiple)
    {
      os_ << "::" << node_->full_name () << "::"
          << port_name << "Connections *" << be_nl
          << "get_connections_" << port_name << " (void);";
    }
  else
    {
      os_ << "::" << obj_name << "_ptr" << be_nl
          << "get_connection_" << port_name << " (void);";
    }

  os_ << be_nl << be_uidt_nl
      << "protected:" << be_idt_nl
      << "virtual "
      << (is_multiple ? "::Components::Cookie *" : "void")
      << be_nl
      << "connect_" << port_name << " ("
      << "::" << obj_name << "_ptr);"
      << be_nl_2;

  os_ << "virtual ::" << obj_name << "_ptr" << be_nl
      << "disconnect_" << port_name << " (";

  if (is_multiple)
    {
      os_ << "::Components::Cookie * ck);";
    }
  else
    {
      os_ << "void);";
    }

  os_ << be_uidt_nl << be_nl
      << "private:" << be_idt_nl;

  if (is_multiple)
    {
      os_ << "/// Multiplex " << port_name << " connection." << be_nl
          << "typedef std::map<ptrdiff_t," << be_nl
          << "                 ::"
          << obj_name << "_var>" << be_idt_nl
          << tao_cg->upcase (port_name)
          << "_TABLE;" << be_uidt_nl
          << tao_cg->upcase (port_name) << "_TABLE "
          << "ciao_uses_" << port_name << "_;" << be_nl
          << "TAO_SYNCH_MUTEX " << port_name << "_lock_;";
    }
  else
    {
      os_ << "/// Simplex " << port_name << " connection." << be_nl
          << "::" << obj_name << "_var" << be_nl
          << "ciao_uses_" << port_name << "_;";
    }

  return 0;
}

int
be_visitor_context_svth::visit_publishes (be_publishes *node)
{
  if (node->imported ())
    {
      return 0;
    }

  const char *obj_name = node->publishes_type ()->full_name ();
  const char *port_name = node->local_name ()->get_string ();

  os_ << be_uidt_nl << be_nl
      << "public:" << be_idt_nl
      << "virtual void" << be_nl
      << "push_" << port_name << " (" << be_idt_nl
      << "::" << obj_name << " * ev);" << be_uidt_nl;

  os_ << be_uidt_nl
      << "protected:" << be_idt_nl;

  os_ << "virtual ::Components::Cookie *" << be_nl
      << "subscribe_" << port_name << " (" << be_idt_nl
      << "::" << obj_name << "Consumer_ptr c);" << be_uidt_nl;

  os_ << be_nl
      << "virtual ::" << obj_name << "Consumer_ptr" << be_nl
      << "unsubscribe_" << port_name << " (" << be_idt_nl
      << "::Components::Cookie * ck);" << be_uidt;

  os_ << be_uidt_nl << be_nl
      << "private:" << be_idt_nl;

  os_ << "typedef std::map<ptrdiff_t," << be_nl
      << "                 ::" << obj_name
      << "Consumer_var>" << be_idt_nl
      << tao_cg->upcase (port_name) << "_TABLE;" << be_uidt_nl
      << tao_cg->upcase (port_name) << "_TABLE ciao_publishes_"
      << port_name << "_;" << be_nl
      << "TAO_SYNCH_MUTEX " << port_name << "_lock_;"
      << be_nl_2;

  return 0;
}

int
be_visitor_context_svth::visit_emits (be_emits *node)
{
  if (node->imported ())
    {
      return 0;
    }

  const char *obj_name = node->emits_type ()->full_name ();
  const char *port_name = node->local_name ()->get_string ();

  os_ << be_uidt_nl << be_nl
      << "public:" << be_idt_nl;

  os_ << "virtual void" << be_nl
      << "push_" << port_name << " (" << be_idt_nl
      << "::" << obj_name << " * ev);" << be_uidt;

  os_ << be_uidt_nl << be_nl
          << "protected:" << be_idt_nl;

  os_ << "virtual void" << be_nl
      << "connect_" << port_name << " (" << be_idt_nl
      << "::" << obj_name << "Consumer_ptr c);" << be_uidt;

  os_ << be_nl_2
      << "virtual ::" << obj_name << "Consumer_ptr" << be_nl
      << "disconnect_" << port_name << " (void);";

  os_ << be_uidt_nl << be_nl
      << "protected:" << be_idt_nl
      << "::" << obj_name << "Consumer_var" << be_nl
      << "ciao_emits_" << port_name << "_consumer_;";

  return 0;
}