2 //=============================================================================
6 * Visitor generating code for Homes in the servant source.
10 //=============================================================================
14 be_visitor_home_svs::be_visitor_home_svs (be_visitor_context
*ctx
)
15 : be_visitor_scope (ctx
),
18 os_ (*ctx
->stream ()),
19 export_macro_ (be_global
->svnt_export_macro ()),
22 /// All existing CIAO examples set the servant export values in the CIDL
23 /// compiler to equal the IDL compiler's skel export values. Below is a
24 /// partial effort to decouple them, should be completely decoupled
25 /// sometime. See comment in codegen.cpp, line 1173.
26 if (export_macro_
== "")
28 export_macro_
= be_global
->skel_export_macro ();
32 be_visitor_home_svs::~be_visitor_home_svs (void)
37 be_visitor_home_svs::visit_home (be_home
*node
)
39 if (node
->imported ())
45 comp_
= node_
->managed_component ();
47 /// Use 'CIAO_' + component's flat name.
49 << "namespace CIAO_" << comp_
->flat_name () << "_Impl" << be_nl
52 if (this->gen_servant_class () == -1)
54 ACE_ERROR_RETURN ((LM_ERROR
,
55 ACE_TEXT ("be_visitor_home_svs::")
56 ACE_TEXT ("visit_home - ")
57 ACE_TEXT ("gen_servant_class() failed\n")),
61 this->gen_entrypoint ();
70 be_visitor_home_svs::visit_operation (be_operation
*node
)
72 be_visitor_operation_svs
v (this->ctx_
);
74 return v
.visit_operation (node
);
78 be_visitor_home_svs::visit_attribute (be_attribute
*node
)
80 be_visitor_attribute
v (this->ctx_
);
82 return v
.visit_attribute (node
);
86 be_visitor_home_svs::visit_argument (be_argument
*node
)
88 os_
<< node
->local_name ();
90 if (! this->last_node (node
))
99 be_visitor_home_svs::visit_factory (be_factory
*node
)
101 // An inherited factory/finder needs to return the managed
102 // component of the home where it is defined.
104 dynamic_cast<be_home
*> (node
->defined_in ());
106 AST_Component
*c
= h
->managed_component ();
109 << "::" << c
->name () << "_ptr" << be_nl
110 << node_
->original_local_name ()->get_string ()
111 << "_Servant::" << node
->local_name ();
113 be_visitor_operation_arglist
al_visitor (this->ctx_
);
114 al_visitor
.unused (this->for_finder_
);
116 if (al_visitor
.visit_factory (node
) == -1)
118 ACE_ERROR_RETURN ((LM_ERROR
,
119 "be_visitor_factory_svs::"
121 "codegen for argument list failed\n"),
128 if (this->for_finder_
)
130 os_
<< "throw ::CORBA::NO_IMPLEMENT (CORBA::OMGVMCID | 8,"
132 << " CORBA::COMPLETED_NO);";
136 ACE_CString
comp_sname_str (
137 ScopeAsDecl (comp_
->defined_in ())->full_name ());
138 const char *comp_sname
= comp_sname_str
.c_str ();
139 const char *comp_lname
= comp_
->local_name ()->get_string ();
140 const char *global
= (comp_sname_str
== "" ? "" : "::");
142 ACE_CString
sname_str (ScopeAsDecl (node_
->defined_in ())->full_name ());
144 os_
<< sname_str
<< global
<< "CCM_" << node_
->original_local_name ()
145 << "_var executor = " << be_idt_nl
146 << sname_str
<< global
<< "CCM_" << node_
->original_local_name ()
147 << "::_duplicate (this->executor_.in ());" << be_uidt
150 os_
<< "if ( ::CORBA::is_nil (executor.in ()))" << be_idt_nl
152 << "throw ::CORBA::INV_OBJREF ();" << be_uidt_nl
153 << "}" << be_uidt
<< be_nl_2
;
155 os_
<< "::Components::EnterpriseComponent_var _ciao_ec ="
157 << "executor->" << node
->local_name () << " (";
159 if (node
->argument_count () > 0)
163 if (this->visit_scope (node
) != 0)
165 ACE_ERROR_RETURN ((LM_ERROR
,
166 "be_visitor_factory_svs::"
168 "codegen for scope failed\n"),
175 os_
<< ");" << be_uidt
<< be_nl_2
176 << global
<< comp_sname
<< "::CCM_" << comp_lname
177 << "_var _ciao_comp =" << be_idt_nl
178 << global
<< comp_sname
<< "::CCM_" << comp_lname
179 << "::_narrow (_ciao_ec.in ());" << be_uidt
<< be_nl_2
180 << "if ( ::CORBA::is_nil (_ciao_ec.in ()))" << be_idt_nl
182 << "throw ::Components::CreateFailure ();" << be_uidt_nl
183 << "}" << be_uidt
<< be_nl_2
185 << "return this->_ciao_activate_component "
186 << "(_ciao_comp.in ());";
192 // In case it was set for the call above.
193 this->for_finder_
= false;
199 be_visitor_home_svs::visit_finder (be_finder
*node
)
201 this->for_finder_
= true;
202 return this->visit_factory (node
);
206 be_visitor_home_svs::gen_servant_class (void)
208 AST_Decl
*scope
= ScopeAsDecl (node_
->defined_in ());
209 ACE_CString
sname_str (scope
->full_name ());
210 const char *sname
= sname_str
.c_str ();
212 // Avoid '_cxx_' prefix.
214 node_
->original_local_name ()->get_string ();
216 const char *clname
= comp_
->local_name ()->get_string ();
217 const char *global
= (sname_str
== "" ? "" : "::");
220 << lname
<< "_Servant::"
221 << lname
<< "_Servant (" << be_idt
<< be_idt_nl
222 << global
<< sname
<< "::CCM_" << lname
<< "_ptr exe," << be_nl
223 << "const char * ins_name," << be_nl
224 << "::CIAO::" << be_global
->ciao_container_type ()
225 << "_Container_ptr c)" << be_uidt_nl
226 << ": ::CIAO::Home_Servant_Impl_Base ()," << be_idt_nl
228 << "Home_Servant_Impl<" << be_idt_nl
229 << "::" << node_
->full_skel_name () << "," << be_nl
230 << global
<< sname
<< "::CCM_" << lname
<< "," << be_nl
231 << clname
<< "_Servant," << be_nl
232 << "::CIAO::" << be_global
->ciao_container_type () << "_Container> (exe, c, ins_name)"
233 << be_uidt
<< be_uidt
<< be_uidt_nl
238 << lname
<< "_Servant::~" << lname
<< "_Servant (void)"
243 if (this->node_
->has_rw_attributes ())
247 << lname
<< "_Servant::set_attributes (" << be_idt_nl
248 << "const ::Components::ConfigValues & descr)"
252 os_
<< "for ( ::CORBA::ULong i = 0; i < descr.length (); ++i)"
255 << "const char * descr_name = descr[i]->name ();"
257 << "::CORBA::Any & descr_value = descr[i]->value ();";
259 be_visitor_home_attr_set
as_visitor (this->ctx_
);
261 if (as_visitor
.visit_home (node_
) == -1)
263 ACE_ERROR_RETURN ((LM_ERROR
,
265 "gen_servant_class - "
266 "attr init visitor failed\n"),
271 << "}" << be_uidt
<< be_uidt_nl
275 AST_Type
*pk
= node_
->primary_key ();
280 << "::" << comp_
->name () << "_ptr" << be_nl
281 << lname
<< "_Servant::create (" << be_idt_nl
282 << "::" << pk
->name () << " * /* key */)" << be_uidt_nl
284 << "throw ::CORBA::NO_IMPLEMENT (CORBA::OMGVMCID | 8,"
286 << " CORBA::COMPLETED_NO);"
290 if (!be_global
->gen_lwccm ())
293 << "::" << comp_
->name () << "_ptr" << be_nl
294 << lname
<< "_Servant::find_by_primary_key (" << be_idt_nl
295 << "::" << pk
->name () << " * /* key */)" << be_uidt_nl
297 << "throw ::CORBA::NO_IMPLEMENT (CORBA::OMGVMCID | 8,"
299 << " CORBA::COMPLETED_NO);"
306 << lname
<< "_Servant::remove (" << be_idt_nl
307 << "::" << pk
->name () << " * /* key */)" << be_uidt_nl
309 << "throw ::CORBA::NO_IMPLEMENT (CORBA::OMGVMCID | 8,"
311 << " CORBA::COMPLETED_NO);"
315 if (!be_global
->gen_lwccm ())
318 << "::" << pk
->name () << " *" << be_nl
319 << lname
<< "_Servant::get_primary_key (" << be_idt_nl
320 << "::" << comp_
->name () << "_ptr /* comp */)" << be_uidt_nl
322 << "throw ::CORBA::NO_IMPLEMENT (CORBA::OMGVMCID | 8,"
324 << " CORBA::COMPLETED_NO);"
334 if (this->visit_scope (h
) != 0)
336 ACE_ERROR_RETURN ((LM_ERROR
,
337 ACE_TEXT ("be_visitor_home_svs::")
338 ACE_TEXT ("gen_servant_class - ")
339 ACE_TEXT ("codegen for scope failed\n")),
343 for (long i
= 0; i
< h
->n_inherits (); ++i
)
345 // A closure of all the supported interfaces is stored
346 // in the base class 'pd_inherits_flat' member.
348 dynamic_cast<be_interface
*> (h
->inherits ()[i
]);
350 bi
->get_insert_queue ().reset ();
351 bi
->get_del_queue ().reset ();
352 bi
->get_insert_queue ().enqueue_tail (bi
);
354 Home_Op_Attr_Generator
op_attr_gen (this);
357 bi
->traverse_inheritance_graph (op_attr_gen
,
364 ACE_ERROR_RETURN ((LM_ERROR
,
365 ACE_TEXT ("be_visitor_home_svs::")
366 ACE_TEXT ("gen_servant_class - ")
367 ACE_TEXT ("traverse_inheritance_graph() ")
368 ACE_TEXT ("failed for %s\n"),
375 h
= dynamic_cast<be_home
*> (h
->base_home ());
382 be_visitor_home_svs::gen_entrypoint (void)
384 ACE_CString
sname_str (
385 ScopeAsDecl (node_
->defined_in ())->full_name ());
386 const char *sname
= sname_str
.c_str ();
388 // Avoid _cxx_ prefix.
390 node_
->original_local_name ()->get_string ();
392 const char *global
= (sname_str
== "" ? "" : "::");
395 << "extern \"C\" " << export_macro_
.c_str ()
396 << " ::PortableServer::Servant" << be_nl
397 << "create_" << node_
->flat_name ()
398 << "_Servant (" << be_idt_nl
399 << "::Components::HomeExecutorBase_ptr p," << be_nl
400 << "::CIAO::" << be_global
->ciao_container_type ()
401 << "_Container_ptr c," << be_nl
402 << "const char * ins_name)" << be_uidt_nl
404 << "::PortableServer::Servant retval = 0;" << be_nl
405 << global
<< sname
<< "::CCM_" << lname
406 << "_var x =" << be_idt_nl
407 << global
<< sname
<< "::CCM_" << lname
408 << "::_narrow (p);" << be_uidt_nl
<< be_nl
409 << "if (! ::CORBA::is_nil (x.in ()))" << be_idt_nl
411 << "ACE_NEW_NORETURN (retval," << be_nl
412 << " " << lname
<< "_Servant (" << be_idt_nl
413 << " x.in ()," << be_nl
414 << " ins_name," << be_nl
415 << " c));" << be_uidt
<< be_uidt_nl
416 << "}" << be_uidt_nl
<< be_nl
417 << "return retval;" << be_uidt_nl
421 //=======================================================
423 Home_Op_Attr_Generator::Home_Op_Attr_Generator (
424 be_visitor_scope
* visitor
)
430 Home_Op_Attr_Generator::emit (be_interface
* /* derived_interface */,
431 TAO_OutStream
* /* os */,
432 be_interface
* base_interface
)
434 return visitor_
->visit_scope (base_interface
);
437 // ==========================================================
439 be_visitor_home_attr_set::be_visitor_home_attr_set (
440 be_visitor_context
*ctx
)
441 : be_visitor_decl (ctx
)
445 be_visitor_home_attr_set::~be_visitor_home_attr_set (void)
450 be_visitor_home_attr_set::visit_home (be_home
*node
)
457 for (UTL_ScopeActiveIterator
i (node
, UTL_Scope::IK_decls
);
461 be_decl
*d
= dynamic_cast<be_decl
*> (i
.item ());
463 if (d
->accept (this) == -1)
465 ACE_ERROR_RETURN ((LM_ERROR
,
466 ACE_TEXT ("be_visitor_home_attr_set")
467 ACE_TEXT ("::visit_home - ")
468 ACE_TEXT ("accept () failed\n")),
473 be_home
*h
= dynamic_cast<be_home
*> (node
->base_home ());
475 return this->visit_home (h
);
479 be_visitor_home_attr_set::visit_attribute (be_attribute
*node
)
481 be_visitor_attribute_ccm_init
v (this->ctx_
);
483 if (v
.visit_attribute (node
) == -1)
485 ACE_ERROR_RETURN ((LM_ERROR
,
486 ACE_TEXT ("be_visitor_home_attr_set")
487 ACE_TEXT ("::visit_attribute - ")
488 ACE_TEXT ("ccm attr init visitor ")
489 ACE_TEXT ("failed\n")),