1 //=============================================================================
3 * @file servant_svs.cpp
5 * Visitor generating code for a servant class in the
10 //=============================================================================
12 #include "component.h"
14 be_visitor_servant_svs::be_visitor_servant_svs (be_visitor_context
*ctx
)
15 : be_visitor_component_scope (ctx
),
21 be_visitor_servant_svs::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
28 AST_Decl
*scope
= ScopeAsDecl (node_
->defined_in ());
29 ACE_CString
sname_str (scope
->full_name ());
30 const char *sname
= sname_str
.c_str ();
31 const char *lname
= node
->local_name ();
32 const char *global
= (sname_str
== "" ? "" : "::");
33 AST_Decl::NodeType nt
= this->node_
->node_type ();
35 bool const is_connector
= (nt
== AST_Decl::NT_connector
);
36 bool no_events
= false;
41 (node
->n_consumes () == 0UL
42 && node
->n_emits () == 0UL
43 && node
->n_publishes () == 0UL);
46 bool const de_facto
= (is_connector
|| no_events
);
48 const char *opt_conn
=
49 (de_facto
? "Connector_" : "");
52 << lname
<< "_Servant::"
53 << lname
<< "_Servant (" << be_idt
<< be_idt
<< be_idt_nl
54 << global
<< sname
<< "::CCM_" << lname
55 << "_ptr exe," << be_nl
56 << "::Components::CCMHome_ptr h," << be_nl
57 << "const char * ins_name," << be_nl
58 << "::CIAO::Home_Servant_Impl_Base * hs," << be_nl
59 << "::CIAO::" << be_global
->ciao_container_type ()
60 << "_Container_ptr c)" << be_uidt
<< be_uidt_nl
61 << ": ::CIAO::" << opt_conn
62 << "Servant_Impl_Base (h, hs, c)," << be_idt_nl
63 << "::CIAO::" << be_global
->ciao_container_type ()
64 << "_Servant_Impl_T<" << be_idt_nl
65 << "::" << node_
->full_skel_name ()
67 << global
<< sname
<< "::CCM_"
68 << lname
<< "," << be_nl
69 << lname
<< "_Context_T< " << be_idt_nl
70 << "::CIAO::" << be_global
->ciao_container_type ()
71 << "_Container, ::CIAO::" << be_global
->ciao_container_type () << "_Context_Impl_T< "
72 << be_idt_nl
<< global
<< sname
<< "::CCM_" << lname
<< "_Context, " << be_nl
73 << global
<< sname
<< "::" << lname
<< "> > > (exe, h, ins_name, hs, c)"
74 << be_uidt
<< be_uidt
<< be_uidt
<< be_uidt
<< be_uidt_nl
77 be_visitor_obv_factory_reg
ofr_visitor (this->ctx_
);
79 if (ofr_visitor
.visit_component_scope (node
) == -1)
81 ACE_ERROR_RETURN ((LM_ERROR
,
82 "be_visitor_servant_svs::"
84 "OBV factory registration failed\n"),
88 /// If a component has neither facets nor event sinks, the
89 /// setup methods aren't generated.
90 if (this->node_
->n_remote_provides () > 0UL
91 || this->node_
->n_consumes () > 0UL)
93 be_visitor_populate_port_tables
ppt_visitor (this->ctx_
);
95 if (ppt_visitor
.visit_component_scope (node
) == -1)
97 ACE_ERROR_RETURN ((LM_ERROR
,
98 "be_visitor_servant_svs::"
100 "populate port tables visitor failed\n"),
105 os_
<< be_uidt_nl
<< "}";
108 << lname
<< "_Servant::~"
109 << lname
<< "_Servant ()" << be_nl
113 if (this->node_
->has_rw_attributes ())
117 << lname
<< "_Servant::set_attributes (" << be_idt_nl
118 << "const ::Components::ConfigValues & descr)"
122 os_
<< "for (::CORBA::ULong i = 0; i < descr.length (); ++i)"
125 << "const char * descr_name = descr[i]->name ();"
127 << "::CORBA::Any & descr_value = descr[i]->value ();";
129 be_visitor_attr_set
as_visitor (this->ctx_
);
131 /// This will get assigned to the visitor's interface_
132 /// member later so it can catch and skip porttype
133 /// attributes in a component.
134 as_visitor
.node (this->node_
);
136 if (as_visitor
.visit_component_scope (node
) == -1)
138 ACE_ERROR_RETURN ((LM_ERROR
,
141 "attr init visitor failed\n"),
146 << "}" << be_uidt
<< be_uidt_nl
151 << "/// Supported operations and attributes.";
153 this->op_scope_
= node
;
155 /// This overload of traverse_inheritance_graph() used here
156 /// doesn't automatically prime the queues.
157 this->node_
->get_insert_queue ().reset ();
158 this->node_
->get_del_queue ().reset ();
159 this->node_
->get_insert_queue ().enqueue_tail (node
);
161 Component_Op_Attr_Generator
op_attr_gen (this);
164 this->node_
->traverse_inheritance_graph (op_attr_gen
,
171 ACE_ERROR_RETURN ((LM_ERROR
,
172 "be_visitor_servant_svs::"
174 "inheritance graph traversal failed\n"),
179 << "/// All ports and component attributes.";
181 /// Port operations that require scope traversal to get all the
182 /// possible string name matches.
184 this->gen_provides_top ();
185 this->gen_uses_top ();
187 /// If we are visiting a connector we can skip these.
188 if (this->node_
->node_type () == AST_Decl::NT_component
)
190 this->gen_publishes_top ();
191 this->gen_emits_top ();
194 /// This call will generate all other operations and attributes,
195 /// including inherited ones.
196 if (this->visit_component_scope (node
) == -1)
198 ACE_ERROR_RETURN ((LM_ERROR
,
199 "be_visitor_servant_svs::"
201 "visit_component_scope() failed\n"),
209 be_visitor_servant_svs::visit_connector (be_connector
*node
)
211 return this->visit_component (node
);
215 be_visitor_servant_svs::visit_operation (be_operation
*node
)
217 AST_Decl::NodeType nt
=
218 ScopeAsDecl (node
->defined_in ())->node_type ();
220 // Components have implied IDL operations added to the AST, but
221 // we are interested only in supported interface operations.
222 if (nt
== AST_Decl::NT_component
|| nt
== AST_Decl::NT_connector
)
227 be_visitor_operation_svs
v (this->ctx_
);
228 v
.scope (this->op_scope_
);
230 return v
.visit_operation (node
);
234 be_visitor_servant_svs::visit_attribute (be_attribute
*node
)
236 AST_Decl::NodeType nt
= this->node_
->node_type ();
238 // Executor attribute code generated for porttype attributes
239 // always in connectors and only for mirrorports in components.
240 if (this->in_ext_port_
&& nt
== AST_Decl::NT_component
)
245 this->ctx_
->interface (this->node_
);
246 be_visitor_attribute
v (this->ctx_
);
248 v
.for_facets (false);
249 v
.op_scope (this->op_scope_
);
251 return v
.visit_attribute (node
);
255 be_visitor_servant_svs::visit_provides (be_provides
*node
)
257 if (node
->provides_type ()->is_local ()) // @TODO || be_global->gen_lwccm ())
262 ACE_CString
prefix (this->ctx_
->port_prefix ());
263 prefix
+= node
->local_name ()->get_string ();
264 const char *port_name
= prefix
.c_str ();
266 AST_Type
*obj
= node
->provides_type ();
267 const char *obj_name
= obj
->full_name ();
268 AST_Decl
*scope
= ScopeAsDecl (obj
->defined_in ());
269 ACE_CString
sname_str (scope
->full_name ());
270 const char *sname
= sname_str
.c_str ();
272 // Avoid '_cxx_' prefix.
274 obj
->original_local_name ()->get_string ();
276 const char *global
= (sname_str
== "" ? "" : "::");
277 const char *prefix_connector
= (sname_str
== "" ? "" : "_");
279 if (!be_global
->gen_lwccm ())
282 << "::" << obj_name
<< "_ptr" << be_nl
283 << node_
->local_name () << "_Servant::provide_"
284 << port_name
<< " ()" << be_nl
287 os_
<< "return" << be_idt_nl
288 << "::" << obj_name
<< "::_duplicate (this->provide_"
289 << port_name
<< "_.in ());" << be_uidt
<< be_uidt_nl
295 << node_
->local_name () << "_Servant::setup_"
296 << port_name
<< "_i ()" << be_nl
298 << "ACE_CString obj_id (this->ins_name_);" << be_nl
299 << "obj_id += \"_" << port_name
<< "\";" << be_nl_2
300 << "::CIAO::Container_var cnt_safe =" << be_idt_nl
301 << "::CIAO::Container::_duplicate ("
302 << "this->container_.in ());" << be_uidt_nl
<< be_nl
303 << "if (::CORBA::is_nil (cnt_safe.in ()))" << be_idt_nl
304 << "{" << be_idt_nl
<< "throw ::CORBA::INV_OBJREF ();" << be_uidt_nl
305 << "}" << be_uidt_nl
<< be_nl
306 << "PortableServer::POA_var POA = cnt_safe->the_port_POA ();" << be_nl
307 << "::CORBA::Object_var tmp =" << be_idt_nl
308 << "this->get_facet_executor (\"" << port_name
<< "\");"<< be_uidt_nl
<< be_nl
309 << global
<< sname
<< "::CCM_" << lname
<< "_var tmp_var = " << be_idt_nl
310 << global
<< sname
<<"::CCM_" << lname
311 << "::_narrow (tmp.in());" << be_uidt_nl
<< be_nl
312 << "typedef " << global
<< "CIAO_FACET" << prefix_connector
313 << scope
->flat_name () << "::" << obj
->local_name () << "_Servant_T <" << be_idt_nl
314 << "POA_" << sname
<< global
<< obj
->local_name ()
315 << "," << be_nl
<< global
<< sname
<<"::CCM_" << lname
<< "," << be_nl
316 << global
<< "Components::" << be_global
->ciao_container_type ()
317 << "Context>" << be_idt_nl
<< lname
318 << "_type;" << be_uidt_nl
<< be_uidt_nl
319 << lname
<< "_type *" << port_name
<< "_servant_impl = 0;" << be_nl
320 << "ACE_NEW_THROW_EX (" << be_idt_nl
321 << port_name
<< "_servant_impl," << be_nl
322 << lname
<< "_type (" << be_idt_nl
323 << "tmp_var.in(), " << be_nl
324 << "this->context_)," << be_uidt_nl
325 << "CORBA::NO_MEMORY ());" << be_uidt_nl
<< be_nl
326 << "PortableServer::ServantBase_var safe_base_servant ("
327 << port_name
<< "_servant_impl);" << be_nl
<< be_nl
328 << "PortableServer::ObjectId_var " << port_name
<< "_servant_oid =" << be_idt_nl
329 << "PortableServer::string_to_ObjectId (obj_id.c_str());" << be_uidt_nl
<< be_nl
330 << "POA->activate_object_with_id(" << port_name
<< "_servant_oid.in(),"
331 << port_name
<< "_servant_impl);" << be_nl
332 << "::CORBA::Object_var " << port_name
<< "_servant_impl_obj = " << be_idt_nl
333 << "cnt_safe->generate_reference ( " << be_idt_nl
334 << "obj_id.c_str ()," << be_nl
335 << "\"" << obj
->repoID () << "\"," << be_nl
336 << "::CIAO::Container_Types::FACET_CONSUMER_t);"
337 << be_uidt_nl
<< be_uidt_nl
338 << "this->add_facet (\"" << port_name
<< "\", " << port_name
<< "_servant_impl_obj.in ());"
346 be_visitor_servant_svs::visit_uses (be_uses
*node
)
348 if (node
->uses_type ()->is_local () || be_global
->gen_lwccm ())
353 ACE_CString
prefix (this->ctx_
->port_prefix ());
354 prefix
+= node
->local_name ()->get_string ();
355 const char *port_name
= prefix
.c_str ();
357 const char *obj_name
= node
->uses_type ()->full_name ();
358 bool const is_multiple
= node
->is_multiple ();
361 << (is_multiple
? "::Components::Cookie *" : "void")
363 << node_
->local_name () << "_Servant::connect_"
364 << port_name
<< " (" << be_idt_nl
365 << "::" << obj_name
<< "_ptr c)" << be_uidt_nl
373 os_
<< "this->context_->connect_" << port_name
374 << " (c);" << be_uidt_nl
378 << "::" << obj_name
<< "_ptr" << be_nl
379 << node_
->local_name () << "_Servant::disconnect_"
380 << port_name
<< " (";
385 << "::Components::Cookie * ck" << be_uidt
;
394 << "return this->context_->disconnect_"
395 << port_name
<< " (" << (is_multiple
? "ck" : "")
396 << ");" << be_uidt_nl
404 os_
<< node_
->full_name () << "::" << port_name
409 os_
<< obj_name
<< "_ptr";
413 << node_
->local_name () << "_Servant::get_connection"
414 << (is_multiple
? "s" : "") << "_"
415 << port_name
<< " ()" << be_nl
417 << "return this->context_->get_connection"
418 << (is_multiple
? "s" : "") << "_"
419 << port_name
<< " ();" << be_uidt_nl
426 be_visitor_servant_svs::visit_publishes (be_publishes
*node
)
428 if (be_global
->gen_lwccm ())
433 const char *obj_name
= node
->publishes_type ()->full_name ();
434 const char *port_name
= node
->local_name ()->get_string ();
437 << "::Components::Cookie *" << be_nl
438 << node_
->local_name () << "_Servant::subscribe_"
439 << port_name
<< " (" << be_idt_nl
440 << "::" << obj_name
<< "Consumer_ptr c)" << be_uidt_nl
443 os_
<< "return this->context_->subscribe_" << port_name
444 << " (c);" << be_uidt_nl
448 << "::" << obj_name
<< "Consumer_ptr" << be_nl
449 << node_
->local_name () << "_Servant::unsubscribe_"
450 << port_name
<< " (" << be_idt_nl
451 << "::Components::Cookie * ck)" << be_uidt_nl
454 os_
<< "return this->context_->unsubscribe_" << port_name
455 << " (ck);" << be_uidt_nl
462 be_visitor_servant_svs::visit_emits (be_emits
*node
)
464 if (be_global
->gen_lwccm ())
469 const char *obj_name
= node
->emits_type ()->full_name ();
470 const char *port_name
= node
->local_name ()->get_string ();
474 << node_
->local_name () << "_Servant::connect_"
475 << port_name
<< " (" << be_idt_nl
476 << "::" << obj_name
<< "Consumer_ptr c)" << be_uidt_nl
478 << "this->context_->connect_" << port_name
479 << " (c);" << be_uidt_nl
483 << "::" << obj_name
<< "Consumer_ptr" << be_nl
484 << node_
->local_name () << "_Servant::disconnect_"
485 << port_name
<< " ()" << be_nl
487 << "return this->context_->disconnect_"
488 << port_name
<< " ();" << be_uidt_nl
495 be_visitor_servant_svs::visit_consumes (be_consumes
*node
)
497 AST_Type
*obj
= node
->consumes_type ();
498 const char *port_name
= node
->local_name ()->get_string ();
500 const char *comp_lname
= node_
->local_name ();
501 ACE_CString
comp_sname_str (
502 ScopeAsDecl (node_
->defined_in ())->full_name ());
503 const char *comp_sname
= comp_sname_str
.c_str ();
504 const char *global
= (comp_sname_str
== "" ? "" : "::");
506 const char *lname
= obj
->local_name ()->get_string ();
507 const char *fname
= obj
->full_name ();
510 << comp_lname
<< "_Servant::" << lname
<< "Consumer_"
511 << port_name
<< "_Servant::" << lname
<< "Consumer_"
512 << port_name
<< "_Servant (" << be_idt
<< be_idt_nl
513 << global
<< comp_sname
<< "::CCM_" << comp_lname
514 << "_ptr executor," << be_nl
515 << global
<< comp_sname
<< "::CCM_" << comp_lname
516 << "_Context_ptr c)" << be_uidt_nl
517 << ": executor_ ( " << global
<< comp_sname
<< "::CCM_"
518 << comp_lname
<< "::_duplicate (executor))," << be_idt_nl
519 << "ctx_ ( " << global
<< comp_sname
520 << "::CCM_" << comp_lname
521 << "_Context::_duplicate (c))" << be_uidt
<< be_uidt_nl
526 << comp_lname
<< "_Servant::" << lname
<< "Consumer_"
527 << port_name
<< "_Servant::~" << lname
<< "Consumer_"
528 << port_name
<< "_Servant ()" << be_nl
533 << "::CORBA::Object_ptr" << be_nl
534 << comp_lname
<< "_Servant::" << lname
<< "Consumer_"
535 << port_name
<< "_Servant::_get_component ()" << be_nl
538 if (ACE_OS::strcmp (be_global
->ciao_container_type (), "Session") == 0)
540 os_
<< "return this->ctx_->get_CCM_object ();";
544 os_
<< "return ::CORBA::Object::_nil ();";
547 os_
<< be_uidt_nl
<< "}";
551 << comp_lname
<< "_Servant::" << lname
<< "Consumer_"
552 << port_name
<< "_Servant::push_" << lname
554 << "::" << fname
<< " * evt)" << be_uidt_nl
556 << "this->executor_->push_" << port_name
557 << " (evt);" << be_uidt_nl
561 << "/// Inherited from ::Components::EventConsumerBase."
564 << comp_lname
<< "_Servant::" << lname
<< "Consumer_"
565 << port_name
<< "_Servant::push_event (" << be_idt_nl
566 << "::Components::EventBase * ev)" << be_uidt_nl
568 << "::" << fname
<< " * ev_type =" << be_idt_nl
569 << "::" << fname
<< "::_downcast (ev);"
570 << be_uidt_nl
<< be_nl
571 << "if (ev_type != 0)" << be_idt_nl
573 << "this->push_" << lname
<< " (ev_type);" << be_nl
574 << "return;" << be_uidt_nl
575 << "}" << be_uidt_nl
<< be_nl
576 << "throw ::Components::BadEventType ();" << be_uidt_nl
579 if (!be_global
->gen_lwccm ())
582 << "::" << fname
<< "Consumer_ptr" << be_nl
583 << node_
->local_name () << "_Servant::get_consumer_"
584 << port_name
<< " ()" << be_nl
586 << "return" << be_idt_nl
587 << "::" << fname
<< "Consumer::_duplicate (" << be_idt_nl
588 << "this->consumes_" << port_name
<< "_.in ());"
589 << be_uidt
<< be_uidt
<< be_uidt_nl
595 << node_
->local_name () << "_Servant::setup_consumer_"
596 << port_name
<< "_i ()" << be_nl
598 << "ACE_CString obj_id (this->ins_name_);" << be_nl
599 << "obj_id += \"_" << port_name
<< "\";" << be_nl_2
600 << "::CIAO::Container_var cnt_safe =" << be_idt_nl
601 << "::CIAO::Container::_duplicate ("
602 << "this->container_.in ());" << be_uidt_nl
<< be_nl
603 << "if (::CORBA::is_nil (cnt_safe.in ()))" << be_idt_nl
604 << "{" << be_idt_nl
<< "throw ::CORBA::INV_OBJREF ();" << be_uidt_nl
605 << "}" << be_uidt_nl
<< be_nl
606 << "PortableServer::POA_var POA = cnt_safe->the_port_POA ();" << be_nl
607 << node_
->local_name () << "_Servant::" << lname
608 << "Consumer_" << port_name
<< "_Servant *"
609 << port_name
<< "_servant_impl = " << be_idt_nl
610 << "new " << node_
->local_name () << "_Servant::" << lname
611 << "Consumer_" << port_name
<< "_Servant (" << be_idt_nl
612 << " this->executor_, this->context_);" << be_uidt_nl
<< be_uidt_nl
<< be_nl
613 << "PortableServer::ServantBase_var safe_base_servant ("
614 << port_name
<< "_servant_impl);" << be_nl
615 << "PortableServer::ObjectId_var " << port_name
<< "_servant_oid =" << be_idt_nl
616 << "PortableServer::string_to_ObjectId (obj_id.c_str());" << be_uidt_nl
<< be_nl
617 << "POA->activate_object_with_id(" << be_idt_nl
618 << port_name
<< "_servant_oid.in()," << be_nl
619 << port_name
<< "_servant_impl);" << be_uidt_nl
<< be_nl
621 << "::CORBA::Object_var " << port_name
<< "_servant_impl_obj = " << be_idt_nl
622 << "cnt_safe->generate_reference ( " << be_idt_nl
623 << "obj_id.c_str ()," << be_nl
626 ACE_CString
work (obj
->repoID ());
627 ACE_CString
result (work
.substr (0, work
.rfind (':')));
628 result
+= "Consumer:1.0";
630 os_
<< result
.c_str ();
632 os_
<< "\"," << be_nl
633 << "::CIAO::Container_Types::FACET_CONSUMER_t);"
634 << be_uidt_nl
<< be_uidt_nl
635 << "::Components::EventConsumerBase_var ecb =" << be_idt_nl
636 << "::Components::EventConsumerBase::_narrow ("
637 << port_name
<< "_servant_impl_obj.in ());"
638 << be_uidt_nl
<< be_nl
639 << "this->add_consumer (\"" << port_name
<< "\", ecb.in ());"
647 be_visitor_servant_svs::gen_provides_top ()
649 if (this->node_
->n_provides () == 0UL)
654 ACE_CString
comp_sname_str (
655 ScopeAsDecl (node_
->defined_in ())->full_name ());
656 const char *global
= (comp_sname_str
== "" ? "" : "::");
657 ACE_CString
sname_str (ScopeAsDecl (node_
->defined_in ())->full_name ());
660 << "/// CIAO-specific." << be_nl
661 << "::CORBA::Object_ptr" << be_nl
662 << node_
->local_name ()
663 << "_Servant::get_facet_executor (" << be_idt_nl
664 << "const char * name)" << be_uidt_nl
667 os_
<< "if (!name)" << be_idt_nl
669 << "throw ::CORBA::BAD_PARAM ();" << be_uidt_nl
670 << "}" << be_uidt
<< be_nl_2
;
672 os_
<< "::" << sname_str
<< global
<< "CCM_" << node_
->original_local_name ()
673 << "_var executor = " << be_idt_nl
674 << "::" << sname_str
<< global
<< "CCM_" << node_
->original_local_name ()
675 << "::_duplicate (this->executor_.in ());" << be_uidt
<< be_nl_2
;
677 os_
<< "if (::CORBA::is_nil (executor.in ()))"
680 << "throw ::CORBA::INV_OBJREF ();" << be_uidt_nl
683 be_visitor_facet_executor_block
feb_visitor (this->ctx_
);
685 if (feb_visitor
.visit_component_scope (node_
) == -1)
687 ACE_ERROR ((LM_ERROR
,
688 "be_visitor_servant_svs::"
689 "gen_provides_top - "
690 "facet executor block visitor failed\n"));
696 << "throw ::Components::InvalidName ();" << be_uidt_nl
701 be_visitor_servant_svs::gen_publishes_top ()
703 ACE_CDR::ULong npubs
= this->node_
->n_publishes ();
708 << "::Components::Cookie *" << be_nl
709 << node_
->local_name () << "_Servant::subscribe ("
711 << "const char * publisher_name," << be_nl
712 << "::Components::EventConsumerBase_ptr subscribe)"
716 os_
<< "if (!publisher_name)" << be_idt_nl
718 << "throw ::CORBA::BAD_PARAM ();" << be_uidt_nl
721 be_visitor_subscribe_block
sb_visitor (this->ctx_
);
723 if (sb_visitor
.visit_component_scope (node_
) == -1)
725 ACE_ERROR ((LM_ERROR
,
726 "be_visitor_servant_svs::"
727 "gen_publishes_top - "
728 "subscribe block visitor failed\n"));
734 << "throw ::Components::InvalidName ();" << be_uidt_nl
738 << "::Components::EventConsumerBase_ptr" << be_nl
739 << node_
->local_name () << "_Servant::unsubscribe ("
741 << "const char * publisher_name," << be_nl
742 << "::Components::Cookie * ck)" << be_uidt_nl
745 os_
<< "if (!publisher_name)" << be_idt_nl
747 << "throw ::CORBA::BAD_PARAM ();" << be_uidt_nl
750 be_visitor_unsubscribe_block
ub_visitor (this->ctx_
);
752 if (ub_visitor
.visit_component_scope (node_
) == -1)
754 ACE_ERROR ((LM_ERROR
,
755 "be_visitor_servant_svs::"
756 "gen_publishes_top - "
757 "unsubscribe block visitor failed\n"));
763 << "throw ::Components::InvalidName ();" << be_uidt_nl
767 if (!be_global
->gen_lwccm () && !be_global
->gen_noeventccm () && this->node_
->n_publishes () != 0)
770 << "::Components::PublisherDescriptions *" << be_nl
771 << node_
->local_name ()
772 << "_Servant::get_all_publishers ()" << be_nl
774 << "::Components::PublisherDescriptions *retval {};"
776 << "ACE_NEW_THROW_EX (retval," << be_nl
777 << " ::Components::PublisherDescriptions,"
779 << " ::CORBA::NO_MEMORY ());" << be_nl_2
780 << "::Components::PublisherDescriptions_var "
781 << "safe_retval = retval;" << be_nl
782 << "safe_retval->length (" << this->node_
->n_publishes ()
787 be_visitor_event_source_desc
esd_visitor (this->ctx_
);
789 if (esd_visitor
.visit_component_scope (node_
) == -1)
791 ACE_ERROR ((LM_ERROR
,
792 ACE_TEXT ("be_visitor_servant_svs::")
793 ACE_TEXT ("gen_publishes_top - ")
794 ACE_TEXT ("event source description ")
795 ACE_TEXT ("visitor failed\n")));
802 << "return safe_retval._retn ();" << be_uidt_nl
808 be_visitor_servant_svs::gen_uses_top ()
810 ACE_CDR::ULong nuses
= this->node_
->n_uses ();
815 << "::Components::Cookie *" << be_nl
816 << node_
->local_name () << "_Servant::connect ("
818 << "const char * name," << be_nl
819 << "::CORBA::Object_ptr connection)" << be_uidt_nl
822 os_
<< "if (!name)" << be_idt_nl
824 << "throw ::CORBA::BAD_PARAM ();" << be_uidt_nl
827 be_visitor_connect_block
cb_visitor (this->ctx_
);
829 if (cb_visitor
.visit_component_scope (node_
) == -1)
831 ACE_ERROR ((LM_ERROR
,
832 ACE_TEXT ("be_visitor_servant_svs::")
833 ACE_TEXT ("gen_uses_top - ")
834 ACE_TEXT ("connect block visitor failed\n")));
840 << "throw ::Components::InvalidName ();" << be_uidt_nl
844 << "::CORBA::Object_ptr" << be_nl
845 << node_
->local_name () << "_Servant::disconnect ("
847 << "const char * name," << be_nl
848 << "::Components::Cookie * "
849 << (this->node_
->has_uses_multiple () ? "ck" : "/* ck */")
852 << "if (!name)" << be_idt_nl
854 << "throw ::CORBA::BAD_PARAM ();" << be_uidt_nl
857 be_visitor_disconnect_block
db_visitor (this->ctx_
);
859 if (db_visitor
.visit_component_scope (node_
) == -1)
861 ACE_ERROR ((LM_ERROR
,
862 "be_visitor_servant_svs::"
864 "disconnect block visitor failed\n"));
870 << "throw ::Components::InvalidName ();" << be_uidt_nl
874 if (!be_global
->gen_lwccm () && nuses
> 0)
877 << "::Components::ReceptacleDescriptions *" << be_nl
878 << node_
->local_name ()
879 << "_Servant::get_all_receptacles ()" << be_nl
881 << "::Components::ReceptacleDescriptions * retval {};"
883 << "ACE_NEW_THROW_EX (retval," << be_nl
884 << " ::Components::ReceptacleDescriptions,"
886 << " ::CORBA::NO_MEMORY ());" << be_nl_2
887 << "::Components::ReceptacleDescriptions_var "
888 << "safe_retval = retval;" << be_nl
889 << "safe_retval->length (" << nuses
894 be_visitor_receptacle_desc
rd_visitor (this->ctx_
, this->node_
);
896 if (rd_visitor
.visit_component_scope (node_
) == -1)
898 ACE_ERROR ((LM_ERROR
,
899 ACE_TEXT ("be_visitor_servant_svs::")
900 ACE_TEXT ("gen_uses_top - ")
901 ACE_TEXT ("receptacle description ")
902 ACE_TEXT ("visitor failed\n")));
909 << "return safe_retval._retn ();" << be_uidt_nl
915 be_visitor_servant_svs::gen_emits_top ()
917 /// Generated whether the component has emits ports
918 /// or not, except if we are generating a LwCCM
919 /// profile, in which case this call returns
920 /// immediately, and the base class method
921 /// (returning a null pointer to a sequence of
922 /// emitter descriptions) is seen instead.
923 this->gen_get_all_emitters ();
925 if (this->node_
->n_emits () == 0UL)
932 << node_
->local_name () << "_Servant::connect_consumer ("
934 << "const char * emitter_name," << be_nl
935 << "::Components::EventConsumerBase_ptr consumer)"
939 os_
<< "if (!emitter_name)" << be_idt_nl
941 << "throw ::CORBA::BAD_PARAM ();" << be_uidt_nl
944 be_visitor_connect_consumer_block
ccb_visitor (this->ctx_
);
946 if (ccb_visitor
.visit_component_scope (node_
) == -1)
948 ACE_ERROR ((LM_ERROR
,
949 "be_visitor_servant_svs::"
951 "connect consumer block visitor failed\n"));
957 << "throw ::Components::InvalidName ();" << be_uidt_nl
961 << "::Components::EventConsumerBase_ptr" << be_nl
962 << node_
->local_name ()
963 << "_Servant::disconnect_consumer (" << be_idt_nl
964 << "const char * source_name)" << be_uidt_nl
967 os_
<< "if (!source_name)" << be_idt_nl
969 << "throw ::CORBA::BAD_PARAM ();" << be_uidt_nl
972 be_visitor_disconnect_consumer_block
dcb_visitor (this->ctx_
);
974 if (dcb_visitor
.visit_component_scope (node_
) == -1)
976 ACE_ERROR ((LM_ERROR
,
977 "be_visitor_servant_svs::"
979 "disconnect consumer block visitor failed\n"));
985 << "throw ::Components::InvalidName ();" << be_uidt_nl
990 be_visitor_servant_svs::gen_get_all_emitters ()
992 if (be_global
->gen_lwccm () || be_global
->gen_noeventccm () || this->node_
->n_emits () == 0UL)
998 << "::Components::EmitterDescriptions *" << be_nl
999 << node_
->local_name ()
1000 << "_Servant::get_all_emitters ()" << be_nl
1002 << "::Components::EmitterDescriptions *retval {};"
1004 << "ACE_NEW_THROW_EX (retval," << be_nl
1005 << " ::Components::EmitterDescriptions,"
1007 << " ::CORBA::NO_MEMORY ());" << be_nl_2
1008 << "::Components::EmitterDescriptions_var "
1009 << "safe_retval = retval;" << be_nl
1010 << "safe_retval->length (" << this->node_
->n_emits ()
1013 be_visitor_emitter_desc
ed_visitor (this->ctx_
);
1015 if (ed_visitor
.visit_component_scope (node_
) == -1)
1017 ACE_ERROR ((LM_ERROR
,
1018 "be_visitor_servant_svs::"
1020 "emitter description visitor failed\n"));
1026 << "return safe_retval._retn ();" << be_uidt_nl
1030 // ==========================================================
1032 be_visitor_obv_factory_reg::be_visitor_obv_factory_reg (
1033 be_visitor_context
*ctx
)
1034 : be_visitor_component_scope (ctx
)
1038 be_visitor_obv_factory_reg::~be_visitor_obv_factory_reg ()
1043 be_visitor_obv_factory_reg::visit_publishes (be_publishes
*node
)
1045 this->gen_obv_factory_registration (node
->field_type ());
1051 be_visitor_obv_factory_reg::visit_emits (be_emits
*node
)
1053 this->gen_obv_factory_registration (node
->field_type ());
1059 be_visitor_obv_factory_reg::visit_consumes (be_consumes
*node
)
1061 this->gen_obv_factory_registration (node
->field_type ());
1067 be_visitor_obv_factory_reg::gen_obv_factory_registration (AST_Type
*t
)
1069 if (be_global
->gen_ciao_valuefactory_reg ())
1071 const char *fname
= t
->full_name ();
1073 os_
<< "TAO_OBV_REGISTER_FACTORY (" << be_idt_nl
1074 << "::" << fname
<< "_init," << be_nl
1075 << "::" << fname
<< ");" << be_uidt_nl
;
1079 // ==========================================================
1081 be_visitor_attr_set::be_visitor_attr_set (be_visitor_context
*ctx
)
1082 : be_visitor_component_scope (ctx
)
1086 be_visitor_attr_set::~be_visitor_attr_set ()
1091 be_visitor_attr_set::visit_attribute (be_attribute
*node
)
1093 be_visitor_attribute_ccm_init
v (this->ctx_
);
1095 if (v
.visit_attribute (node
) == -1)
1097 ACE_ERROR_RETURN ((LM_ERROR
,
1098 ACE_TEXT ("be_visitor_attr_set")
1099 ACE_TEXT ("::visit_attribute - ")
1100 ACE_TEXT ("ccm attr init visitor ")
1101 ACE_TEXT ("failed\n")),
1109 be_visitor_attr_set::visit_component_scope (be_component
*node
)
1111 if (node
== nullptr)
1116 this->ctx_
->interface (node
);
1118 if (this->visit_scope (node
) == -1)
1120 ACE_ERROR_RETURN ((LM_ERROR
,
1121 ACE_TEXT ("be_visitor_attr_set")
1122 ACE_TEXT ("::visit_component_scope - ")
1123 ACE_TEXT ("visit_scope() failed\n")),
1127 /// This overload of traverse_inheritance_graph() used here
1128 /// doesn't automatically prime the queues.
1129 node
->get_insert_queue ().reset ();
1130 node
->get_del_queue ().reset ();
1131 node
->get_insert_queue ().enqueue_tail (node
);
1133 Component_Op_Attr_Generator
component_inher (this);
1136 node
->traverse_inheritance_graph (component_inher
,
1142 ACE_ERROR_RETURN ((LM_ERROR
,
1143 ACE_TEXT ("be_visitor_attr_set")
1144 ACE_TEXT ("::visit_component_scope - ")
1145 ACE_TEXT ("traverse_inheritance_graph() ")
1146 ACE_TEXT ("failed\n")),
1150 // Recurse to the base class method for the base component(s)
1151 // so traverse_inheritance_graph() will not be called again,
1152 // which would output assignments for the attributes inherited
1153 // from the base componnent's supported interfaces multiple times.
1155 this->be_visitor_component_scope::visit_component_scope (node
->base_component ());
1158 // ==========================================================
1160 be_visitor_facet_executor_block::be_visitor_facet_executor_block (
1161 be_visitor_context
*ctx
)
1162 : be_visitor_component_scope (ctx
)
1166 be_visitor_facet_executor_block::~be_visitor_facet_executor_block (
1172 be_visitor_facet_executor_block::visit_provides (
1175 ACE_CString
prefix (this->ctx_
->port_prefix ());
1176 prefix
+= node
->local_name ()->get_string ();
1177 const char *port_name
= prefix
.c_str ();
1180 << "if (ACE_OS::strcmp (name, \"" << port_name
1181 << "\") == 0)" << be_idt_nl
1183 << "return executor->get_" << port_name
1184 << " ();" << be_uidt_nl
1190 // ======================================================
1192 be_visitor_connect_block::be_visitor_connect_block (
1193 be_visitor_context
*ctx
)
1194 : be_visitor_component_scope (ctx
)
1198 be_visitor_connect_block::~be_visitor_connect_block ()
1203 be_visitor_connect_block::visit_uses (be_uses
*node
)
1205 ACE_CString
prefix (this->ctx_
->port_prefix ());
1206 prefix
+= node
->local_name ()->get_string ();
1207 const char *port_name
= prefix
.c_str ();
1209 const char *obj_name
= node
->uses_type ()->full_name ();
1210 bool const is_multiple
= node
->is_multiple ();
1213 << "if (ACE_OS::strcmp (name, \"" << port_name
1214 << "\") == 0)" << be_idt_nl
1216 << "::" << obj_name
<< "_var _ciao_conn =" << be_idt_nl
1217 << "::" << obj_name
<< "::_narrow (connection);"
1218 << be_uidt_nl
<< be_nl
;
1220 os_
<< "/// " << (is_multiple
? "Multiplex" : "Simplex")
1221 << " connect." << be_nl
1222 << (is_multiple
? "return " : "") << "this->context_->connect_"
1223 << port_name
<< " (_ciao_conn.in ());";
1237 // ======================================================
1239 be_visitor_disconnect_block::be_visitor_disconnect_block (
1240 be_visitor_context
*ctx
)
1241 : be_visitor_component_scope (ctx
)
1245 be_visitor_disconnect_block::~be_visitor_disconnect_block (
1251 be_visitor_disconnect_block::visit_uses (be_uses
*node
)
1253 ACE_CString
prefix (this->ctx_
->port_prefix ());
1254 prefix
+= node
->local_name ()->get_string ();
1255 const char *port_name
= prefix
.c_str ();
1257 bool const is_multiple
= node
->is_multiple ();
1260 << "if (ACE_OS::strcmp (name, \"" << port_name
1261 << "\") == 0)" << be_idt_nl
1263 << "/// " << (is_multiple
? "Multiplex" : "Simplex")
1264 << " disconnect." << be_nl
;
1268 os_
<< "if (!ck)" << be_idt_nl
1270 << "throw ::Components::CookieRequired ();" << be_uidt_nl
1271 << "}" << be_uidt_nl
<< be_nl
;
1274 os_
<< "return this->context_->disconnect_" << port_name
1275 << " (" << (is_multiple
? "ck" : "") << ");" << be_uidt_nl
1281 // ======================================================
1283 be_visitor_receptacle_desc::be_visitor_receptacle_desc (
1284 be_visitor_context
*ctx
,
1286 : be_visitor_component_scope (ctx
),
1293 be_visitor_receptacle_desc::~be_visitor_receptacle_desc (
1299 be_visitor_receptacle_desc::visit_uses (be_uses
*node
)
1301 ACE_CString
prefix (this->ctx_
->port_prefix ());
1302 prefix
+= node
->local_name ()->get_string ();
1303 const char *port_name
= prefix
.c_str ();
1305 AST_Type
*obj
= node
->uses_type ();
1306 bool const is_multiple
= node
->is_multiple ();
1310 ACE_CString
sname_str (comp_
->full_name ());
1311 const char *sname
= sname_str
.c_str ();
1313 const char *global
= (sname_str
== "" ? "" : "::");
1317 os_
<< obj
->full_name () << "_var ciao_"
1318 << port_name
<< " = " << be_idt_nl
1319 << "this->context_->get_connection_"
1320 << port_name
<< " ();" << be_uidt_nl
;
1324 os_
<< "::" << sname
<< global
<< port_name
<< "Connections_var ciao_"
1325 << port_name
<< " = " << be_idt_nl
1326 << "this->context_->get_connections_"
1327 << port_name
<< " ();" << be_uidt_nl
;
1330 os_
<< "::CIAO::Servant::describe_"
1331 << (is_multiple
? "multiplex" : "simplex")
1332 << "_receptacle<" << be_idt_nl
;
1336 os_
<< "::" << obj
->full_name () << "> (" << be_idt_nl
;
1340 os_
<< "::" << sname
<< global
<< port_name
<< "Connections> (" << be_idt_nl
;
1343 os_
<< "\"" << port_name
<< "\"," << be_nl
1344 << "\"" << obj
->repoID () << "\"," << be_nl
;
1346 os_
<< "ciao_" << port_name
<< ".in ()," << be_nl
;
1348 os_
<< "safe_retval," << be_nl
1349 << slot_
++ << "UL);" << be_uidt
<< be_uidt
;
1354 // ======================================================
1356 be_visitor_subscribe_block::be_visitor_subscribe_block (
1357 be_visitor_context
*ctx
)
1358 : be_visitor_component_scope (ctx
)
1362 be_visitor_subscribe_block::~be_visitor_subscribe_block (
1368 be_visitor_subscribe_block::visit_publishes (
1371 const char *obj_name
=
1372 node
->publishes_type ()->full_name ();
1373 const char *port_name
=
1374 node
->local_name ()->get_string ();
1377 << "if (ACE_OS::strcmp (publisher_name, \""
1378 << port_name
<< "\") == 0)" << be_idt_nl
1380 << "::" << obj_name
<< "Consumer_var sub =" << be_idt_nl
1381 << "::" << obj_name
<< "Consumer::_narrow (subscribe);"
1382 << be_uidt_nl
<< be_nl
1383 << "return this->context_->subscribe_" << port_name
1384 << " (sub.in ());" << be_uidt_nl
1390 // ==========================================================
1392 be_visitor_unsubscribe_block::be_visitor_unsubscribe_block (
1393 be_visitor_context
*ctx
)
1394 : be_visitor_component_scope (ctx
)
1398 be_visitor_unsubscribe_block::~be_visitor_unsubscribe_block (
1404 be_visitor_unsubscribe_block::visit_publishes (
1407 const char *port_name
=
1408 node
->local_name ()->get_string ();
1411 << "if (ACE_OS::strcmp (publisher_name, \""
1412 << port_name
<< "\") == 0)" << be_idt_nl
1414 << "return this->context_->unsubscribe_" << port_name
1415 << " (ck);" << be_uidt_nl
1421 // ==========================================================
1423 be_visitor_event_source_desc::be_visitor_event_source_desc (
1424 be_visitor_context
*ctx
)
1425 : be_visitor_component_scope (ctx
),
1430 be_visitor_event_source_desc::~be_visitor_event_source_desc (
1436 be_visitor_event_source_desc::visit_publishes (
1439 AST_Type
*obj
= node
->publishes_type ();
1440 const char *port_name
=
1441 node
->local_name ()->get_string ();
1445 os_
<< "{" << be_idt_nl
1446 << "ACE_GUARD_RETURN (TAO_SYNCH_MUTEX," << be_nl
1448 << " this->context_->"
1449 << port_name
<< "_lock_," << be_nl
1450 << " 0);" << be_nl_2
;
1452 os_
<< "::CIAO::Servant::describe_pub_event_source<"
1454 << "::" << obj
->full_name () << "Consumer_var> ("
1456 << "\"" << port_name
<< "\"," << be_nl
1457 << "\"" << obj
->repoID () << "\"," << be_nl
1458 << "this->context_->ciao_publishes_"
1459 << port_name
<< "_," << be_nl
1460 << "safe_retval," << be_nl
1461 << slot_
++ << "UL);" << be_uidt
<< be_uidt
;
1469 // ======================================================
1471 be_visitor_connect_consumer_block::be_visitor_connect_consumer_block (
1472 be_visitor_context
*ctx
)
1473 : be_visitor_component_scope (ctx
)
1477 be_visitor_connect_consumer_block::~be_visitor_connect_consumer_block ()
1482 be_visitor_connect_consumer_block::visit_emits (
1485 const char *obj_name
=
1486 node
->emits_type ()->full_name ();
1487 const char *port_name
=
1488 node
->local_name ()->get_string ();
1491 << "if (ACE_OS::strcmp (emitter_name, \""
1492 << port_name
<< "\") == 0)" << be_idt_nl
1495 << "Consumer_var _ciao_consumer =" << be_idt_nl
1497 << "Consumer::_narrow (consumer);" << be_uidt_nl
<< be_nl
1498 << "this->context_->connect_" << port_name
1499 << " (_ciao_consumer.in ());" << be_nl_2
1500 << "return;" << be_uidt_nl
1506 // ======================================================
1508 be_visitor_disconnect_consumer_block::be_visitor_disconnect_consumer_block (
1509 be_visitor_context
*ctx
)
1510 : be_visitor_component_scope (ctx
)
1514 be_visitor_disconnect_consumer_block::~be_visitor_disconnect_consumer_block (
1520 be_visitor_disconnect_consumer_block::visit_emits (
1523 const char *port_name
=
1524 node
->local_name ()->get_string ();
1527 << "if (ACE_OS::strcmp (source_name, \""
1528 << port_name
<< "\") == 0)" << be_idt_nl
1530 << "return this->context_->disconnect_" << port_name
1531 << " ();" << be_uidt_nl
1537 // ======================================================
1539 be_visitor_emitter_desc::be_visitor_emitter_desc (
1540 be_visitor_context
*ctx
)
1541 : be_visitor_component_scope (ctx
),
1546 be_visitor_emitter_desc::~be_visitor_emitter_desc (
1552 be_visitor_emitter_desc::visit_emits (be_emits
*node
)
1554 AST_Type
*obj
= node
->emits_type ();
1555 const char *port_name
=
1556 node
->local_name ()->get_string ();
1559 << "::CIAO::Servant::describe_emit_event_source<"
1561 << "::" << obj
->full_name () << "Consumer_var> ("
1563 << "\"" << port_name
<< "\"," << be_nl
1564 << "\"" << obj
->repoID () << "\"," << be_nl
1565 << "this->context_->ciao_emits_" << port_name
1566 << "_consumer_," << be_nl
1567 << "safe_retval," << be_nl
1568 << slot_
++ << "UL);" << be_uidt
<< be_uidt
;
1573 // ======================================================
1575 be_visitor_populate_port_tables::be_visitor_populate_port_tables (
1576 be_visitor_context
*ctx
)
1577 : be_visitor_component_scope (ctx
)
1581 be_visitor_populate_port_tables::~be_visitor_populate_port_tables (
1587 be_visitor_populate_port_tables::visit_provides (
1590 if (node
->provides_type ()->is_local ())
1595 ACE_CString
prefix (this->ctx_
->port_prefix ());
1596 prefix
+= node
->local_name ()->get_string ();
1597 const char *port_name
= prefix
.c_str ();
1601 << port_name
<< "_i ();";
1607 be_visitor_populate_port_tables::visit_consumes (
1611 << "this->setup_consumer_"
1612 << node
->local_name ()->get_string () << "_i ();";
1617 // ======================================================
1619 Component_Op_Attr_Generator::Component_Op_Attr_Generator (
1620 be_visitor_scope
* visitor
)
1621 : visitor_ (visitor
)
1626 Component_Op_Attr_Generator::emit (be_interface
* /* derived_interface */,
1627 TAO_OutStream
* /* os */,
1628 be_interface
* base_interface
)
1630 AST_Decl::NodeType nt
= base_interface
->node_type ();
1632 if (nt
== AST_Decl::NT_component
|| nt
== AST_Decl::NT_connector
)
1637 return visitor_
->visit_scope (base_interface
);