Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / TAO_IDL / be / be_visitor_component / servant_svh.cpp
blob4dd9b33267b70486c9fc172f0b68e09de4f4d6e4
2 //=============================================================================
3 /**
4 * @file servant_svh.cpp
6 * Visitor generating code for a servant class in the
7 * servant header.
9 * @author Jeff Parsons
11 //=============================================================================
13 #include "component.h"
15 be_visitor_servant_svh::be_visitor_servant_svh (be_visitor_context *ctx)
16 : be_visitor_component_scope (ctx)
20 int
21 be_visitor_servant_svh::visit_component (be_component *node)
23 // This visitor is spawned by be_visitor_component_svh,
24 // which already does a check for imported node, so none
25 // is needed here.
26 node_ = node;
28 AST_Decl *scope = ScopeAsDecl (node_->defined_in ());
29 ACE_CString sname_str (scope->full_name ());
30 const char *sname = sname_str.c_str ();
32 // No '_cxx_' prefix.
33 const char *lname =
34 node_->original_local_name ()->get_string ();
36 const char *global = (sname_str == "" ? "" : "::");
38 // ::CIAO::Session_Context_Impl<
39 // ::Inherited::CCM_Base_comp_Context,
40 // ::Inherited::Base_comp>
42 os_ << be_nl_2
43 << "class " << export_macro_.c_str () << " " << lname
44 << "_Servant" << be_idt_nl
45 << ": public virtual" << be_idt << be_idt_nl
46 << "::CIAO::" << be_global->ciao_container_type ()
47 << "_Servant_Impl_T<" << be_idt_nl
48 << "::" << node_->full_skel_name () << "," << be_nl
49 << global << sname << "::CCM_" << lname << "," << be_nl
50 << lname << "_Context_T< " << be_idt_nl
51 << "::CIAO::" << be_global->ciao_container_type ()
52 << "_Container, ::CIAO::" << be_global->ciao_container_type () << "_Context_Impl_T< "
53 << be_idt_nl << global << sname << "::CCM_" << lname << "_Context, " << be_nl
54 << global << sname << "::" << lname << "> > >"
55 << be_uidt << be_uidt << be_uidt << be_uidt << be_uidt << be_uidt_nl
56 << "{" << be_nl
57 << "public:" << be_idt_nl;
59 os_ << "typedef " << global << sname << "::CCM_" << lname
60 << " _exec_type;" << be_nl;
62 os_ << be_nl
63 << lname << "_Servant (" << be_idt_nl
64 << global << sname << "::CCM_"
65 << lname << "_ptr executor," << be_nl
66 << "::Components::CCMHome_ptr h," << be_nl
67 << "const char * ins_name," << be_nl
68 << "::CIAO::Home_Servant_Impl_Base *hs," << be_nl
69 << "::CIAO::" << be_global->ciao_container_type ()
70 << "_Container_ptr c);" << be_uidt_nl;
72 os_ << be_nl
73 << "virtual ~" << lname << "_Servant"
74 << " ();" << be_nl;
76 if (this->node_->has_rw_attributes ())
78 os_ << be_nl
79 << "virtual void" << be_nl
80 << "set_attributes (const "
81 << "::Components::ConfigValues & descr);"
82 << be_nl;
85 os_ << be_nl
86 << "/// Supported operations and attributes.";
88 int status =
89 node_->traverse_inheritance_graph (
90 be_interface::op_attr_decl_helper,
91 &os_,
92 false,
93 false);
95 if (status == -1)
97 ACE_ERROR_RETURN ((LM_ERROR,
98 "be_visitor_servant_svh::"
99 "visit_component - "
100 "inheritance graph traversal failed\n"),
101 -1);
104 status = this->visit_component_scope (node);
106 if (status == -1)
108 ACE_ERROR_RETURN ((LM_ERROR,
109 "be_visitor_servant_svh::"
110 "visit_component - "
111 "visit_component_scope() failed\n"),
112 -1);
115 this->gen_non_type_specific ();
117 os_ << be_uidt_nl
118 << "};";
120 return 0;
124 be_visitor_servant_svh::visit_connector (be_connector *node)
126 return this->visit_component (node);
130 be_visitor_servant_svh::visit_attribute (be_attribute *node)
132 AST_Decl::NodeType nt = this->node_->node_type ();
134 // Executor attribute code generated for porttype attributes
135 // always in connectors and only for mirrorports in components.
136 if (this->in_ext_port_ && nt == AST_Decl::NT_component)
138 return 0;
141 this->ctx_->interface (this->node_);
142 be_visitor_attribute v (this->ctx_);
143 return v.visit_attribute (node);
148 be_visitor_servant_svh::visit_provides (be_provides *node)
150 if (node->provides_type ()->is_local ()) // @TODO || be_global->gen_lwccm ())
152 return 0;
155 ACE_CString prefix (this->ctx_->port_prefix ());
156 prefix += node->local_name ()->get_string ();
157 const char *port_name = prefix.c_str ();
158 const char *obj_name = node->provides_type ()->full_name ();
160 if (!be_global->gen_lwccm ())
162 os_ << be_uidt_nl << be_nl
163 << "public:" << be_idt_nl
164 << "virtual ::" << obj_name << "_ptr" << be_nl
165 << "provide_" << port_name << " ();";
168 os_ << be_uidt_nl << be_nl
169 << "private:" << be_idt_nl
170 << "void" << be_nl
171 << "setup_" << port_name << "_i ();";
173 if (!be_global->gen_lwccm ())
175 os_ << be_uidt_nl << be_nl
176 << "private:" << be_idt_nl
177 << "::" << obj_name << "_var" << be_nl
178 << "provide_" << port_name << "_;";
181 return 0;
185 be_visitor_servant_svh::visit_uses (be_uses *node)
187 if (node->uses_type ()->is_local () || be_global->gen_lwccm ())
189 return 0;
192 ACE_CString prefix (this->ctx_->port_prefix ());
193 prefix +=node->local_name ()->get_string ();
194 const char *port_name = prefix.c_str ();
195 const char *obj_name = node->uses_type ()->full_name ();
196 bool const is_multiple = node->is_multiple ();
198 os_ << be_uidt_nl << be_nl
199 << "public:" << be_idt_nl
200 << "virtual ";
202 if (is_multiple)
204 os_ << "::" << node_->full_name () << "::"
205 << port_name << "Connections *" << be_nl
206 << "get_connections_" << port_name << " ();";
208 else
210 os_ << "::" << obj_name << "_ptr" << be_nl
211 << "get_connection_" << port_name << " ();";
214 os_ << be_nl_2
215 << "virtual "
216 << (is_multiple ? "::Components::Cookie *" : "void")
217 << be_nl
218 << "connect_" << port_name << " ("
219 << "::" << obj_name << "_ptr);"
220 << be_nl_2;
222 os_ << "virtual ::" << obj_name << "_ptr" << be_nl
223 << "disconnect_" << port_name << " (";
225 if (is_multiple)
227 os_ << "::Components::Cookie * ck);";
229 else
231 os_ << ");";
234 return 0;
238 be_visitor_servant_svh::visit_publishes (be_publishes *node)
240 if(!be_global->gen_noeventccm () && !be_global->gen_lwccm ())
242 const char *obj_name = node->publishes_type ()->full_name ();
243 const char *port_name = node->local_name ()->get_string ();
245 os_ << be_uidt_nl << be_nl
246 << "public:" << be_idt_nl;
248 os_ << "virtual ::Components::Cookie *" << be_nl
249 << "subscribe_" << port_name << " (" << be_idt_nl
250 << "::" << obj_name << "Consumer_ptr c);" << be_uidt_nl;
252 os_ << be_nl
253 << "virtual ::" << obj_name << "Consumer_ptr" << be_nl
254 << "unsubscribe_" << port_name << " (" << be_idt_nl
255 << "::Components::Cookie * ck);" << be_uidt;
257 return 0;
261 be_visitor_servant_svh::visit_emits (be_emits *node)
263 if(!be_global->gen_noeventccm () && !be_global->gen_lwccm ())
265 const char *obj_name = node->emits_type ()->full_name ();
266 const char *port_name = node->local_name ()->get_string ();
268 os_ << be_nl_2
269 << "virtual void" << be_nl
270 << "connect_" << port_name << " (" << be_idt_nl
271 << "::" << obj_name << "Consumer_ptr c);" << be_uidt;
273 os_ << be_nl_2
274 << "virtual ::" << obj_name << "Consumer_ptr" << be_nl
275 << "disconnect_" << port_name << " ();";
277 return 0;
281 be_visitor_servant_svh::visit_consumes (be_consumes *node)
283 if(!be_global->gen_noeventccm ())
285 const char *obj_name = node->consumes_type ()->full_name ();
286 const char *port_name = node->local_name ()->get_string ();
288 ACE_CString holder (obj_name);
289 ACE_CString::size_type pos = holder.rfind (':');
290 const char *ev_lname = nullptr;
292 if (pos == ACE_CString::npos)
294 ev_lname = obj_name;
296 else
298 holder = holder.substr (pos + 1);
299 ev_lname = holder.c_str ();
302 os_ << be_uidt_nl << be_nl
303 << "public:" << be_idt_nl;
305 os_ << "// Servant class for the " << port_name
306 << " consumer." << be_nl
307 << "class " << export_macro_.c_str () << " " << ev_lname
308 << "Consumer_" << port_name << "_Servant" << be_idt_nl
309 << ": public virtual ::POA_" << obj_name << "Consumer"
310 << be_uidt_nl
311 << "{" << be_nl
312 << "public:" << be_idt_nl;
314 ACE_CString sname_str (
315 ScopeAsDecl (node_->defined_in ())->full_name ());
316 const char *sname = sname_str.c_str ();
317 const char *lname = node_->local_name ();
318 const char *global = (sname_str == "" ? "" : "::");
320 os_ << ev_lname << "Consumer_" << port_name
321 << "_Servant (" << be_idt_nl
322 << global << sname << "::CCM_" << lname
323 << "_ptr executor," << be_nl
324 << global << sname << "::CCM_" << lname
325 << "_Context_ptr c);" << be_uidt_nl << be_nl;
327 os_ << "virtual ~" << ev_lname << "Consumer_" << port_name
328 << "_Servant ();";
330 os_ << be_nl_2
331 << "virtual void" << be_nl
332 << "push_" << ev_lname << " (" << be_idt_nl
333 << "::" << obj_name << " * evt);" << be_uidt;
335 os_ << be_nl_2
336 << "/// Inherited from ::Components::EventConsumerBase." << be_nl
337 << "virtual void" << be_nl
338 << "push_event (::Components::EventBase * ev);";
340 os_ << be_nl_2
341 << "/// Get component implementation." << be_nl
342 << "virtual ::CORBA::Object_ptr" << be_nl
343 << "_get_component ();";
345 os_ << be_uidt_nl << be_nl
346 << "protected:" << be_idt_nl;
348 os_ << global << sname << "::CCM_" << lname << "_var" << be_nl
349 << "executor_;";
351 os_ << be_nl_2
352 << global << sname << "::CCM_"
353 << lname << "_Context_var" << be_nl
354 << "ctx_;";
356 os_ << be_uidt_nl
357 << "};";
359 if (!be_global->gen_lwccm ())
361 os_ << be_nl_2
362 << "virtual ::" << obj_name << "Consumer_ptr" << be_nl
363 << "get_consumer_" << port_name << " ();";
366 os_ << be_uidt_nl << be_nl
367 << "private:" << be_idt_nl;
369 os_ << "void" << be_nl
370 << "setup_consumer_" << port_name << "_i ();";
372 os_ << be_uidt_nl << be_nl
373 << "private:" << be_idt_nl;
375 os_ << "::" << obj_name << "Consumer_var" << be_nl
376 << "consumes_" << port_name << "_;";
378 return 0;
381 void
382 be_visitor_servant_svh::gen_non_type_specific ()
384 os_ << be_nl_2
385 << "// Base class overrides."
386 << be_uidt_nl << be_nl
387 << "public:" << be_idt;
389 if (this->node_->n_uses () > 0UL)
391 os_ << be_nl
392 << "virtual ::Components::Cookie *" << be_nl
393 << "connect (const char * name, ::CORBA::Object_ptr connection);";
395 os_ << be_nl_2
396 << "virtual ::CORBA::Object_ptr" << be_nl
397 << "disconnect (const char * name, ::Components::Cookie * ck);";
400 if (!be_global->gen_lwccm () && this->node_->n_uses () != 0)
402 os_ << be_nl_2
403 << "virtual ::Components::ReceptacleDescriptions *"
404 << be_nl
405 << "get_all_receptacles ();";
408 AST_Decl::NodeType nt = this->node_->node_type ();
409 bool is_connector = (nt == AST_Decl::NT_connector);
411 if (!be_global->gen_lwccm () && !is_connector &&
412 !be_global->gen_noeventccm ())
414 if (this->node_->n_publishes () != 0UL)
416 os_ << be_nl_2
417 << "virtual ::Components::PublisherDescriptions *"
418 << be_nl
419 << "get_all_publishers ();";
422 if (this->node_->n_emits () != 0UL)
424 os_ << be_nl_2
425 << "virtual ::Components::EmitterDescriptions *"
426 << be_nl
427 << "get_all_emitters ();";
431 /// If the node is a connector or the events must be disabled, event sources
432 /// and sinks cannot be declared.
433 if ((!is_connector) || (!be_global->gen_noeventccm ()))
435 if (this->node_->n_publishes () > 0UL)
437 os_ << be_nl_2
438 << "virtual ::Components::Cookie *" << be_nl
439 << "subscribe (const char * publisher_name,"
440 << be_nl
441 << " ::Components::"
442 << "EventConsumerBase_ptr subscriber);";
444 os_ << be_nl_2
445 << "virtual ::Components::EventConsumerBase_ptr"
446 << be_nl
447 << "unsubscribe (const char * publisher_name,"
448 << be_nl
449 << " ::Components::Cookie * ck);";
452 if (this->node_->n_emits () > 0UL)
454 os_ << be_nl_2
455 << "virtual void" << be_nl
456 << "connect_consumer (const char * emitter_name,"
457 << be_nl
458 << " ::Components::"
459 << "EventConsumerBase_ptr consumer);";
461 os_ << be_nl_2
462 << "virtual ::Components::EventConsumerBase_ptr"
463 << be_nl
464 << "disconnect_consumer (const char * source_name);";
468 if (this->node_->n_provides () > 0UL)
470 os_ << be_nl_2
471 << "/// CIAO-specific." << be_nl
472 << "::CORBA::Object_ptr" << be_nl
473 << "get_facet_executor (const char * name);";