2 //=============================================================================
6 * Visitor generating code for Homes in the servant header.
10 //=============================================================================
14 be_visitor_home_svh::be_visitor_home_svh (be_visitor_context
*ctx
)
15 : be_visitor_scope (ctx
),
18 os_ (*ctx
->stream ()),
19 export_macro_ (be_global
->svnt_export_macro ())
21 /// All existing CIAO examples set the servant export values in the CIDL
22 /// compiler to equal the IDL compiler's skel export values. Below is a
23 /// partial effort to decouple them, should be completely decoupled
24 /// sometime. See comment in codegen.cpp, line 1173.
25 if (export_macro_
== "")
27 export_macro_
= be_global
->skel_export_macro ();
31 be_visitor_home_svh::~be_visitor_home_svh (void)
36 be_visitor_home_svh::visit_home (be_home
*node
)
38 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_svh::")
56 ACE_TEXT ("visit_home - ")
57 ACE_TEXT ("gen_servant_class() failed\n")),
61 this->gen_entrypoint ();
70 be_visitor_home_svh::visit_operation (be_operation
*node
)
72 be_visitor_operation_ch
v (this->ctx_
);
73 return v
.visit_operation (node
);
77 be_visitor_home_svh::visit_attribute (be_attribute
*node
)
79 be_visitor_attribute
v (this->ctx_
);
80 return v
.visit_attribute (node
);
84 be_visitor_home_svh::visit_factory (be_factory
*node
)
86 // An inherited factory/finder needs to return the managed
87 // component of the home where it is defined.
89 dynamic_cast<be_home
*> (node
->defined_in ());
91 AST_Component
*c
= h
->managed_component ();
94 << "virtual ::" << c
->name () << "_ptr" << be_nl
95 << node
->local_name ();
97 // We can reuse this visitor.
98 be_visitor_valuetype_init_arglist_ch
v (this->ctx_
);
100 if (v
.visit_factory (node
) != 0)
102 ACE_ERROR_RETURN ((LM_ERROR
,
103 ACE_TEXT ("be_visitor_home_svh::")
104 ACE_TEXT ("visit_factory - ")
105 ACE_TEXT ("codegen for argument ")
106 ACE_TEXT ("list failed\n")),
116 be_visitor_home_svh::visit_finder (be_finder
*node
)
118 return this->visit_factory (node
);
122 be_visitor_home_svh::gen_servant_class (void)
124 AST_Decl
*scope
= ScopeAsDecl (node_
->defined_in ());
125 ACE_CString
sname_str (scope
->full_name ());
126 const char *sname
= sname_str
.c_str ();
128 // No '_cxx_' prefix.
130 node_
->original_local_name ()->get_string ();
132 const char *clname
= comp_
->local_name ()->get_string ();
133 const char *global
= (sname_str
== "" ? "" : "::");
136 << "class " << export_macro_
.c_str () << " " << lname
137 << "_Servant" << be_idt_nl
138 << ": public virtual" << be_idt
<< be_idt_nl
140 << "Home_Servant_Impl<" << be_idt_nl
141 << "::" << node_
->full_skel_name () << "," << be_nl
142 << global
<< sname
<< "::CCM_" << lname
<< "," << be_nl
143 << clname
<< "_Servant," << be_nl
144 << "::CIAO::" << be_global
->ciao_container_type () << "_Container>"
145 << be_uidt
<< be_uidt
<< be_uidt
<< be_uidt_nl
147 << "public:" << be_idt_nl
;
149 os_
<< lname
<< "_Servant (" << be_idt_nl
150 << global
<< sname
<< "::CCM_" << lname
<< "_ptr exe," << be_nl
151 << "const char * ins_name," << be_nl
152 << "::CIAO::" << be_global
->ciao_container_type ()
153 << "_Container_ptr c);" << be_uidt
;
156 << "virtual ~" << lname
<< "_Servant (void);";
158 if (this->node_
->has_rw_attributes ())
161 << "virtual void" << be_nl
162 << "set_attributes (const "
163 << "::Components::ConfigValues & descr);";
166 AST_Type
*pk
= node_
->primary_key ();
171 << "// Implicit home primary key operations - not supported.";
174 << "virtual ::" << comp_
->name () << "_ptr" << be_nl
175 << "create (" << be_idt_nl
176 << "::" << pk
->name () << " * key);" << be_uidt
;
178 if (!be_global
->gen_lwccm ())
181 << "virtual ::" << comp_
->name () << "_ptr" << be_nl
182 << "find_by_primary_key (" << be_idt_nl
183 << "::" << pk
->name () << " * key);" << be_uidt
;
187 << "virtual void" << be_nl
188 << "remove (" << be_idt_nl
189 << "::" << pk
->name () << " * key);" << be_uidt
;
191 if (!be_global
->gen_lwccm ())
194 << "virtual ::" << pk
->name () << " *" << be_nl
195 << "get_primary_key (" << be_idt_nl
196 << "::" << comp_
->name () << "_ptr comp);" << be_uidt
;
204 if (this->visit_scope (h
) != 0)
206 ACE_ERROR_RETURN ((LM_ERROR
,
207 ACE_TEXT ("be_visitor_home_svh::")
208 ACE_TEXT ("gen_servant_class - ")
209 ACE_TEXT ("visit_scope() failed\n")),
213 for (long i
= 0; i
< h
->n_inherits (); ++i
)
215 // A closure of all the supported interfaces is stored
216 // in the base class 'pd_inherits_flat' member.
218 dynamic_cast<be_interface
*> (h
->inherits ()[i
]);
221 bi
->traverse_inheritance_graph (
222 be_visitor_home_svh::op_attr_decl_helper
,
227 ACE_ERROR_RETURN ((LM_ERROR
,
228 ACE_TEXT ("be_visitor_home_svh::")
229 ACE_TEXT ("gen_servant_class - ")
230 ACE_TEXT ("traverse_inheritance_graph() ")
231 ACE_TEXT ("failed for %s\n"),
237 h
= dynamic_cast<be_home
*> (h
->base_home ());
247 be_visitor_home_svh::gen_entrypoint (void)
250 << "extern \"C\" " << export_macro_
.c_str ()
251 << " ::PortableServer::Servant" << be_nl
252 << "create_" << node_
->flat_name ()
253 << "_Servant (" << be_idt_nl
254 << "::Components::HomeExecutorBase_ptr p," << be_nl
255 << "::CIAO::" << be_global
->ciao_container_type ()
256 << "_Container_ptr c," << be_nl
257 << "const char * ins_name);" << be_uidt
;
261 be_visitor_home_svh::op_attr_decl_helper (be_interface
* /* derived */,
262 be_interface
*ancestor
,
265 /// We're in a static method, so we have to instantiate a temporary
266 /// visitor and context.
267 be_visitor_context ctx
;
268 ctx
.state (TAO_CodeGen::TAO_ROOT_SVH
);
270 be_visitor_home_svh
visitor (&ctx
);
272 /// Since this visitor overriddes only visit_operation() and
273 /// visit_attribute(), we can get away with this for the declarations.
274 return visitor
.visit_scope (ancestor
);