Use =default for skeleton copy constructor
[ACE_TAO.git] / TAO / TAO_IDL / be / be_visitor_interface / amh_ss.cpp
blob0db6a99e3bbd562db599807abd73e99a5b0c1cf8
1 //=============================================================================
2 /**
3 * @file amh_ss.cpp
5 * Specialized interface visitor for AMH.
7 * @author Darrell Brunsch <brunsch@cs.wustl.edu>
8 */
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 ()
23 int
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);
30 int
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);
37 int
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)
43 return 0;
46 return be_visitor_interface_ss::visit_interface (node);
49 void
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
67 << full_skel_name
68 << "::_this ()" << be_nl
69 << "{" << be_idt_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
78 << "{" << 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 (";
86 else
88 *os << "return TAO::AbstractBase_Narrow_Utils<::" << node->name () << ">::unchecked_narrow (";
90 *os << "obj.in ());" << be_nl;
92 *os << be_uidt_nl
93 << "}"
94 << be_uidt_nl << "return {};" << be_uidt_nl << "}";
97 void
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
112 << be_uidt_nl
113 << "{" << be_idt_nl
114 << "this->asynchronous_upcall_dispatch ("
115 << "req,"
116 << "context,"
117 << "this"
118 << ");" << be_uidt_nl
119 << "}";
123 be_visitor_amh_interface_ss::generate_amh_classes (be_interface *)
125 // No AMH classes for the AMH classes... :-)
126 return 0;
130 be_visitor_amh_interface_ss::generate_proxy_classes (be_interface *)
132 // No Proxy or ProxyBrokers for the AMH classes
133 return 0;
136 // ****************************************************************
138 class TAO_IDL_Downcast_Implementation_Worker
139 : public TAO_IDL_Inheritance_Hierarchy_Worker
141 public:
142 TAO_IDL_Downcast_Implementation_Worker ();
144 virtual int emit (be_interface *base,
145 TAO_OutStream *os,
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 */,
157 TAO_OutStream *os,
158 be_interface *base)
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
162 // internally.
163 ACE_CString amh_name ("POA_");
165 // @@ The following code is *NOT* exception-safe.
166 char *buf = nullptr;
167 base->compute_full_name ("AMH_", "", buf);
168 amh_name += buf;
169 // buf was allocated using ACE_OS::strdup, so we must use free instead
170 // of delete.
171 ACE_OS::free (buf);
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;
178 return 0;
181 // ****************************************************************
183 class TAO_IDL_Copy_Ctor_Worker
184 : public TAO_IDL_Inheritance_Hierarchy_Worker
186 public:
187 TAO_IDL_Copy_Ctor_Worker ();
189 virtual int emit (be_interface *base,
190 TAO_OutStream *os,
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,
200 TAO_OutStream *os,
201 be_interface *base)
203 if (derived == base || derived->nmembers () > 0)
205 return 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)";
218 else
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
222 // internally.
223 ACE_CString amh_name ("POA_");
225 // @@ The following code is *NOT* exception-safe.
226 char *buf = nullptr;
227 base->compute_full_name ("AMH_", "", buf);
228 amh_name += buf;
229 // buf was allocated by ACE_OS::strdup, so we need to use free
230 // instead of delete.
231 ACE_OS::free (buf);
233 *os << amh_name.c_str () << " (rhs)";
236 *os << be_uidt;
238 return 0;
242 be_visitor_amh_interface_ss::generate_copy_ctor (be_interface *node,
243 TAO_OutStream *os)
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"),
255 -1);
258 TAO_IDL_Copy_Ctor_Worker worker;
259 return node->traverse_inheritance_graph (worker, os);
262 // ****************************************************************
264 ACE_CString
265 be_visitor_amh_interface_ss::generate_flat_name (be_interface *node)
267 // @@ The following code is *NOT* exception-safe.
268 char *buf = nullptr;
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
273 // internally.
274 ACE_CString result (buf);
275 // buf was allocated using ACE_OS::strdup, so we must use free instead
276 // of delete.
277 ACE_OS::free (buf);
279 return result;
282 ACE_CString
283 be_visitor_amh_interface_ss::generate_local_name (be_interface *node)
285 ACE_CString local_name = "AMH_";
286 local_name += node->local_name ();
287 return local_name;
290 ACE_CString
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
295 // internally.
296 ACE_CString result ("POA_");
298 // @@ The following code is *NOT* exception-safe.
299 char *buf = nullptr;
300 node->compute_full_name ("AMH_", "", buf);
301 result += buf;
302 // buf was allocated using ACE_OS::strdup, so we must use free instead
303 // of delete.
304 ACE_OS::free (buf);
306 return result;