1 //=============================================================================
5 * Specialized interface visitor for AMH.
7 * @author Darrell Brunsch <brunsch@cs.wustl.edu>
9 //=============================================================================
11 #include "interface.h"
13 be_visitor_amh_interface_ss::be_visitor_amh_interface_ss (
14 be_visitor_context
*ctx
)
15 : be_visitor_interface_ss (ctx
)
19 be_visitor_amh_interface_ss::~be_visitor_amh_interface_ss ()
24 be_visitor_amh_interface_ss::visit_operation (be_operation
*node
)
26 be_visitor_amh_operation_ss
visitor (this->ctx_
);
27 return visitor
.visit_operation (node
);
31 be_visitor_amh_interface_ss::visit_attribute (be_attribute
*node
)
33 be_visitor_amh_operation_ss
visitor (this->ctx_
);
34 return visitor
.visit_attribute (node
);
38 be_visitor_amh_interface_ss::visit_interface (be_interface
*node
)
40 // Do not generate AMH classes for any sort of implied IDL.
41 if (node
->original_interface () != nullptr)
46 return be_visitor_interface_ss::visit_interface (node
);
50 be_visitor_amh_interface_ss::this_method (be_interface
*node
)
52 TAO_OutStream
*os
= this->ctx_
->stream ();
54 // the _this () operation
55 //const char *non_amh_name = node->full_name () + 4;
56 ACE_CString non_amh_name
= "";
57 non_amh_name
+= node
->client_enclosing_scope ();
58 non_amh_name
+= node
->local_name ();
60 ACE_CString full_skel_name_holder
=
61 this->generate_full_skel_name (node
);
62 const char *full_skel_name
= full_skel_name_holder
.c_str ();
64 TAO_INSERT_COMMENT (os
);
66 *os
<< non_amh_name
.c_str () << "*" << be_nl
68 << "::_this ()" << be_nl
70 << "TAO_Stub_Auto_Ptr stub (this->_create_stub ());" << be_nl
;
72 *os
<< "::CORBA::Boolean _tao_opt_colloc = "
73 << "stub->servant_orb_var ()->orb_core ()->"
74 << "optimize_collocation_objects ();" << be_nl
75 << "::CORBA::Object_var obj = "
76 << "new (std::nothrow) ::CORBA::Object (stub.get (), _tao_opt_colloc, this);" << be_nl
77 << "if (obj.ptr ())" << be_idt_nl
80 *os
<< "(void) stub.release ();" << be_nl
;
82 if (!node
->is_abstract ())
84 *os
<< "return TAO::Narrow_Utils<::" << node
->name () << ">::unchecked_narrow (";
88 *os
<< "return TAO::AbstractBase_Narrow_Utils<::" << node
->name () << ">::unchecked_narrow (";
90 *os
<< "obj.in ());" << be_nl
;
94 << be_uidt_nl
<< "return {};" << be_uidt_nl
<< "}";
98 be_visitor_amh_interface_ss::dispatch_method (be_interface
*node
)
100 TAO_OutStream
*os
= this->ctx_
->stream ();
102 ACE_CString full_skel_name_holder
=
103 this->generate_full_skel_name (node
);
104 const char *full_skel_name
= full_skel_name_holder
.c_str ();
106 TAO_INSERT_COMMENT (os
);
108 *os
<< "void" << be_nl
109 << full_skel_name
<< "::_dispatch (" << be_idt
<< be_idt_nl
110 << "TAO_ServerRequest &req," << be_nl
111 << "TAO::Portable_Server::Servant_Upcall *context)" << be_uidt
114 << "this->asynchronous_upcall_dispatch ("
118 << ");" << be_uidt_nl
123 be_visitor_amh_interface_ss::generate_amh_classes (be_interface
*)
125 // No AMH classes for the AMH classes... :-)
130 be_visitor_amh_interface_ss::generate_proxy_classes (be_interface
*)
132 // No Proxy or ProxyBrokers for the AMH classes
136 // ****************************************************************
138 class TAO_IDL_Downcast_Implementation_Worker
139 : public TAO_IDL_Inheritance_Hierarchy_Worker
142 TAO_IDL_Downcast_Implementation_Worker ();
144 virtual int emit (be_interface
*base
,
146 be_interface
*derived
);
149 TAO_IDL_Downcast_Implementation_Worker::
150 TAO_IDL_Downcast_Implementation_Worker ()
155 TAO_IDL_Downcast_Implementation_Worker::
156 emit (be_interface
* /* derived */,
160 // @@ This whole thing would be more efficient if we could pass the
161 // ACE_CString to compute_full_name, after all it uses that
163 ACE_CString
amh_name ("POA_");
165 // @@ The following code is *NOT* exception-safe.
167 base
->compute_full_name ("AMH_", "", buf
);
169 // buf was allocated using ACE_OS::strdup, so we must use free instead
173 *os
<< "if (ACE_OS::strcmp (logical_type_id, \""
174 << base
->repoID () << "\") == 0)" << be_idt_nl
175 << "return static_cast<"
176 << amh_name
.c_str () << "*> (this);" << be_uidt_nl
;
181 // ****************************************************************
183 class TAO_IDL_Copy_Ctor_Worker
184 : public TAO_IDL_Inheritance_Hierarchy_Worker
187 TAO_IDL_Copy_Ctor_Worker ();
189 virtual int emit (be_interface
*base
,
191 be_interface
*derived
);
194 TAO_IDL_Copy_Ctor_Worker::TAO_IDL_Copy_Ctor_Worker ()
199 TAO_IDL_Copy_Ctor_Worker::emit (be_interface
*derived
,
203 if (derived
== base
|| derived
->nmembers () > 0)
208 *os
<< "," << be_idt_nl
;
210 if (base
->is_nested ())
212 be_decl
*scope
= nullptr;
213 scope
= dynamic_cast<be_scope
*> (base
->defined_in ())->decl ();
215 *os
<< "POA_" << scope
->name () << "::AMH_"
216 << base
->local_name () << " (rhs)";
220 // @@ This whole thing would be more efficient if we could pass the
221 // ACE_CString to compute_full_name, after all it uses that
223 ACE_CString
amh_name ("POA_");
225 // @@ The following code is *NOT* exception-safe.
227 base
->compute_full_name ("AMH_", "", buf
);
229 // buf was allocated by ACE_OS::strdup, so we need to use free
230 // instead of delete.
233 *os
<< amh_name
.c_str () << " (rhs)";
242 be_visitor_amh_interface_ss::generate_copy_ctor (be_interface
*node
,
245 // Make sure the queues are empty.
246 node
->get_insert_queue ().reset ();
247 node
->get_del_queue ().reset ();
249 // Insert ourselves in the queue.
250 if (node
->get_insert_queue ().enqueue_tail (node
) == -1)
252 ACE_ERROR_RETURN ((LM_ERROR
,
253 "(%N:%l) be_interface::generate_copy_ctor - "
254 "error generating entries\n"),
258 TAO_IDL_Copy_Ctor_Worker worker
;
259 return node
->traverse_inheritance_graph (worker
, os
);
262 // ****************************************************************
265 be_visitor_amh_interface_ss::generate_flat_name (be_interface
*node
)
267 // @@ The following code is *NOT* exception-safe.
269 node
->compute_flat_name ("AMH_", "", buf
);
271 // @@ This whole thing would be more efficient if we could pass the
272 // ACE_CString to compute_flat_name, after all it uses that
274 ACE_CString
result (buf
);
275 // buf was allocated using ACE_OS::strdup, so we must use free instead
283 be_visitor_amh_interface_ss::generate_local_name (be_interface
*node
)
285 ACE_CString local_name
= "AMH_";
286 local_name
+= node
->local_name ();
291 be_visitor_amh_interface_ss::generate_full_skel_name (be_interface
*node
)
293 // @@ This whole thing would be more efficient if we could pass the
294 // ACE_CString to compute_full_name, after all it uses that
296 ACE_CString
result ("POA_");
298 // @@ The following code is *NOT* exception-safe.
300 node
->compute_full_name ("AMH_", "", buf
);
302 // buf was allocated using ACE_OS::strdup, so we must use free instead