2 //=============================================================================
4 * @file servant_svh.cpp
6 * Visitor generating code for a servant class in the
11 //=============================================================================
13 #include "component.h"
15 be_visitor_servant_svh::be_visitor_servant_svh (be_visitor_context
*ctx
)
16 : be_visitor_component_scope (ctx
)
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
28 AST_Decl
*scope
= ScopeAsDecl (node_
->defined_in ());
29 ACE_CString
sname_str (scope
->full_name ());
30 const char *sname
= sname_str
.c_str ();
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>
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
57 << "public:" << be_idt_nl
;
59 os_
<< "typedef " << global
<< sname
<< "::CCM_" << lname
60 << " _exec_type;" << 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
;
73 << "virtual ~" << lname
<< "_Servant"
76 if (this->node_
->has_rw_attributes ())
79 << "virtual void" << be_nl
80 << "set_attributes (const "
81 << "::Components::ConfigValues & descr);"
86 << "/// Supported operations and attributes.";
89 node_
->traverse_inheritance_graph (
90 be_interface::op_attr_decl_helper
,
97 ACE_ERROR_RETURN ((LM_ERROR
,
98 "be_visitor_servant_svh::"
100 "inheritance graph traversal failed\n"),
104 status
= this->visit_component_scope (node
);
108 ACE_ERROR_RETURN ((LM_ERROR
,
109 "be_visitor_servant_svh::"
111 "visit_component_scope() failed\n"),
115 this->gen_non_type_specific ();
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
)
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 ())
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
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
<< "_;";
185 be_visitor_servant_svh::visit_uses (be_uses
*node
)
187 if (node
->uses_type ()->is_local () || be_global
->gen_lwccm ())
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
204 os_
<< "::" << node_
->full_name () << "::"
205 << port_name
<< "Connections *" << be_nl
206 << "get_connections_" << port_name
<< " ();";
210 os_
<< "::" << obj_name
<< "_ptr" << be_nl
211 << "get_connection_" << port_name
<< " ();";
216 << (is_multiple
? "::Components::Cookie *" : "void")
218 << "connect_" << port_name
<< " ("
219 << "::" << obj_name
<< "_ptr);"
222 os_
<< "virtual ::" << obj_name
<< "_ptr" << be_nl
223 << "disconnect_" << port_name
<< " (";
227 os_
<< "::Components::Cookie * ck);";
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
;
253 << "virtual ::" << obj_name
<< "Consumer_ptr" << be_nl
254 << "unsubscribe_" << port_name
<< " (" << be_idt_nl
255 << "::Components::Cookie * ck);" << be_uidt
;
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 ();
269 << "virtual void" << be_nl
270 << "connect_" << port_name
<< " (" << be_idt_nl
271 << "::" << obj_name
<< "Consumer_ptr c);" << be_uidt
;
274 << "virtual ::" << obj_name
<< "Consumer_ptr" << be_nl
275 << "disconnect_" << port_name
<< " ();";
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
)
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"
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
331 << "virtual void" << be_nl
332 << "push_" << ev_lname
<< " (" << be_idt_nl
333 << "::" << obj_name
<< " * evt);" << be_uidt
;
336 << "/// Inherited from ::Components::EventConsumerBase." << be_nl
337 << "virtual void" << be_nl
338 << "push_event (::Components::EventBase * ev);";
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
352 << global
<< sname
<< "::CCM_"
353 << lname
<< "_Context_var" << be_nl
359 if (!be_global
->gen_lwccm ())
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
<< "_;";
382 be_visitor_servant_svh::gen_non_type_specific ()
385 << "// Base class overrides."
386 << be_uidt_nl
<< be_nl
387 << "public:" << be_idt
;
389 if (this->node_
->n_uses () > 0UL)
392 << "virtual ::Components::Cookie *" << be_nl
393 << "connect (const char * name, ::CORBA::Object_ptr connection);";
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)
403 << "virtual ::Components::ReceptacleDescriptions *"
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)
417 << "virtual ::Components::PublisherDescriptions *"
419 << "get_all_publishers ();";
422 if (this->node_
->n_emits () != 0UL)
425 << "virtual ::Components::EmitterDescriptions *"
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)
438 << "virtual ::Components::Cookie *" << be_nl
439 << "subscribe (const char * publisher_name,"
442 << "EventConsumerBase_ptr subscriber);";
445 << "virtual ::Components::EventConsumerBase_ptr"
447 << "unsubscribe (const char * publisher_name,"
449 << " ::Components::Cookie * ck);";
452 if (this->node_
->n_emits () > 0UL)
455 << "virtual void" << be_nl
456 << "connect_consumer (const char * emitter_name,"
459 << "EventConsumerBase_ptr consumer);";
462 << "virtual ::Components::EventConsumerBase_ptr"
464 << "disconnect_consumer (const char * source_name);";
468 if (this->node_
->n_provides () > 0UL)
471 << "/// CIAO-specific." << be_nl
472 << "::CORBA::Object_ptr" << be_nl
473 << "get_facet_executor (const char * name);";