Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / TAO_IDL / be / be_visitor_dds_ts_idl.cpp
blobf7374989670f9f6aecf0919e6a523564f451709c
2 //=============================================================================
3 /**
4 * @file be_visitor_dds_ts_idl.cpp
6 * Visitor generating code for DDS type support IDL files.
8 * @author Jeff Parsons
9 */
10 //=============================================================================
12 // ********************************
13 // Visitor for DDS type support IDL
14 // ********************************
16 #include "be_visitor_dds_ts_idl.h"
17 #include "be_visitor_context.h"
18 #include "be_root.h"
19 #include "be_structure.h"
20 #include "be_union.h"
21 #include "be_valuetype.h"
22 #include "be_extern.h"
23 #include "be_util.h"
25 #include "utl_string.h"
26 #include "utl_identifier.h"
28 be_visitor_dds_ts_idl::be_visitor_dds_ts_idl (
29 be_visitor_context *ctx)
30 : be_visitor_scope (ctx),
31 os_ptr_ (0)
35 be_visitor_dds_ts_idl::~be_visitor_dds_ts_idl (void)
39 int
40 be_visitor_dds_ts_idl::visit_root (be_root *node)
42 if (this->init_file () == -1)
44 ACE_ERROR_RETURN ((LM_ERROR,
45 ACE_TEXT ("be_visitor_dds_ts_idl")
46 ACE_TEXT ("::visit_root - ")
47 ACE_TEXT ("failed to initialize\n")),
48 -1);
51 if (this->visit_scope (node) == -1)
53 ACE_ERROR_RETURN ((LM_ERROR,
54 ACE_TEXT ("be_visitor_dds_ts_idl")
55 ACE_TEXT ("::visit_root - ")
56 ACE_TEXT ("codegen for scope failed\n")),
57 -1);
60 this->fini_file ();
62 return 0;
65 int
66 be_visitor_dds_ts_idl::visit_module (be_module *node)
68 if (this->visit_scope (node) == -1)
70 ACE_ERROR_RETURN ((LM_ERROR,
71 ACE_TEXT ("be_visitor_dds_ts_idl")
72 ACE_TEXT ("::visit_module - ")
73 ACE_TEXT ("codegen for scope failed\n")),
74 -1);
77 return 0;
80 int
81 be_visitor_dds_ts_idl::visit_structure (be_structure *node)
83 return this->process_node (node);
86 int
87 be_visitor_dds_ts_idl::visit_union (be_union *node)
89 return this->process_node (node);
92 int
93 be_visitor_dds_ts_idl::visit_valuetype (be_valuetype *node)
95 return this->process_node (node);
98 int
99 be_visitor_dds_ts_idl::process_node (be_type *node)
101 be_util::gen_nesting_open (*this->os_ptr_, node);
103 this->gen_datawriter (node);
104 this->gen_datareader (node);
106 be_util::gen_nesting_close (*this->os_ptr_, node);
108 return 0;
111 void
112 be_visitor_dds_ts_idl::gen_datawriter (be_type *node)
114 TAO_OutStream &los (*this->os_ptr_);
115 const char *lname = node->local_name ()->get_string ();
117 los << be_nl
118 << "local interface " << lname
119 << "IDLDataWriter : ::DDS::DataWriter" << be_nl
120 << "{" << be_idt;
122 los << be_nl
123 << "DDS::InstanceHandle_t register_instance (" << be_idt_nl
124 << "in " << lname << " instance_data);" << be_uidt;
126 los << be_nl_2
127 << "DDS::InstanceHandle_t register_instance_w_timestamp ("
128 << be_idt_nl
129 << "in " << lname << " instance_data," << be_nl
130 << "in DDS::Time_t source_timestamp);" << be_uidt;
132 los << be_nl_2
133 << "DDS::ReturnCode_t unregister_instance (" << be_idt_nl
134 << "in " << lname << " instance_data," << be_nl
135 << "in DDS::InstanceHandle_t handle);" << be_uidt;
137 los << be_nl_2
138 << "DDS::ReturnCode_t unregister_instance_w_timestamp ("
139 << be_idt_nl
140 << "in " << lname << " instance_data," << be_nl
141 << "in DDS::InstanceHandle_t handle," << be_nl
142 << "in DDS::Time_t source_timestamp);" << be_uidt;
144 los << be_nl_2
145 << "DDS::ReturnCode_t write (" << be_idt_nl
146 << "in " << lname << " instance_data," << be_nl
147 << "in DDS::InstanceHandle_t handle);" << be_uidt;
149 los << be_nl_2
150 << "DDS::ReturnCode_t write_w_timestamp (" << be_idt_nl
151 << "in " << lname << " instance_data," << be_nl
152 << "in DDS::InstanceHandle_t handle," << be_nl
153 << "in DDS::Time_t source_timestamp);" << be_uidt;
155 los << be_nl_2
156 << "DDS::ReturnCode_t dispose (" << be_idt_nl
157 << "in " << lname << " instance_data," << be_nl
158 << "in DDS::InstanceHandle_t instance_handle);"
159 << be_uidt;
161 los << be_nl_2
162 << "DDS::ReturnCode_t dispose_w_timestamp ("
163 << be_idt_nl
164 << "in " << lname << " instance_data," << be_nl
165 << "in DDS::InstanceHandle_t instance_handle," << be_nl
166 << "in DDS::Time_t source_timestamp);" << be_uidt;
168 los << be_nl_2
169 << "DDS::ReturnCode_t get_key_value (" << be_idt_nl
170 << "inout " << lname << " key_holder," << be_nl
171 << "in DDS::InstanceHandle_t handle);" << be_uidt;
173 los << be_nl_2
174 << "DDS::InstanceHandle_t lookup_instance ("
175 << be_idt_nl
176 << "in " << lname << " instance_data);" << be_uidt;
178 los << be_uidt_nl
179 << "};";
182 void
183 be_visitor_dds_ts_idl::gen_datareader (be_type *node)
185 TAO_OutStream &los (*this->os_ptr_);
186 const char *lname = node->local_name ()->get_string ();
188 los << be_nl_2
189 << "local interface " << lname
190 << "IDLDataReader : ::DDS::DataReader" << be_nl
191 << "{" << be_idt;
193 los << be_nl
194 << "DDS::ReturnCode_t read (" << be_idt_nl
195 << "inout " << lname << "Seq data_values," << be_nl
196 << "inout DDS::SampleInfoSeq sample_infos," << be_nl
197 << "in long max_samples," << be_nl
198 << "in DDS::SampleStateMask sample_states," << be_nl
199 << "in DDS::ViewStateMask view_states," << be_nl
200 << "in DDS::InstanceStateMask instance_states);"
201 << be_uidt;
203 los << be_nl_2
204 << "DDS::ReturnCode_t take (" << be_idt_nl
205 << "inout " << lname << "Seq data_values," << be_nl
206 << "inout DDS::SampleInfoSeq sample_infos," << be_nl
207 << "in long max_samples," << be_nl
208 << "in DDS::SampleStateMask sample_states," << be_nl
209 << "in DDS::ViewStateMask view_states," << be_nl
210 << "in DDS::InstanceStateMask instance_states);"
211 << be_uidt;
213 los << be_nl_2
214 << "DDS::ReturnCode_t read_w_condition (" << be_idt_nl
215 << "inout " << lname << "Seq data_values," << be_nl
216 << "inout DDS::SampleInfoSeq sample_infos," << be_nl
217 << "in long max_samples," << be_nl
218 << "in DDS::ReadCondition a_condition);" << be_uidt;
220 los << be_nl_2
221 << "DDS::ReturnCode_t take_w_condition (" << be_idt_nl
222 << "inout " << lname << "Seq data_values," << be_nl
223 << "inout DDS::SampleInfoSeq sample_infos," << be_nl
224 << "in long max_samples," << be_nl
225 << "in DDS::ReadCondition a_condition);" << be_uidt;
227 los << be_nl_2
228 << "DDS::ReturnCode_t read_next_sample (" << be_idt_nl
229 << "inout " << lname << " data_values," << be_nl
230 << "inout DDS::SampleInfo sample_info);" << be_uidt;
232 los << be_nl_2
233 << "DDS::ReturnCode_t take_next_sample (" << be_idt_nl
234 << "inout " << lname << " data_values," << be_nl
235 << "inout DDS::SampleInfo sample_info);" << be_uidt;
237 los << be_nl_2
238 << "DDS::ReturnCode_t read_instance (" << be_idt_nl
239 << "inout " << lname << "Seq data_values," << be_nl
240 << "inout DDS::SampleInfoSeq sample_infos," << be_nl
241 << "in long max_samples," << be_nl
242 << "in DDS::InstanceHandle_t a_handle," << be_nl
243 << "in DDS::SampleStateMask sample_states," << be_nl
244 << "in DDS::ViewStateMask view_states," << be_nl
245 << "in DDS::InstanceStateMask instance_states);"
246 << be_uidt;
248 los << be_nl_2
249 << "DDS::ReturnCode_t take_instance (" << be_idt_nl
250 << "inout " << lname << "Seq data_values," << be_nl
251 << "inout DDS::SampleInfoSeq sample_infos," << be_nl
252 << "in long max_samples," << be_nl
253 << "in DDS::InstanceHandle_t a_handle," << be_nl
254 << "in DDS::SampleStateMask sample_states," << be_nl
255 << "in DDS::ViewStateMask view_states," << be_nl
256 << "in DDS::InstanceStateMask instance_states);"
257 << be_uidt;
259 los << be_nl_2
260 << "DDS::ReturnCode_t read_next_instance (" << be_idt_nl
261 << "inout " << lname << "Seq data_values," << be_nl
262 << "inout DDS::SampleInfoSeq sample_infos," << be_nl
263 << "in long max_samples," << be_nl
264 << "in DDS::InstanceHandle_t previous_handle," << be_nl
265 << "in DDS::SampleStateMask sample_states," << be_nl
266 << "in DDS::ViewStateMask view_states," << be_nl
267 << "in DDS::InstanceStateMask instance_states);"
268 << be_uidt;
270 los << be_nl_2
271 << "DDS::ReturnCode_t take_next_instance (" << be_idt_nl
272 << "inout " << lname << "Seq data_values," << be_nl
273 << "inout DDS::SampleInfoSeq sample_infos," << be_nl
274 << "in long max_samples," << be_nl
275 << "in DDS::InstanceHandle_t previous_handle," << be_nl
276 << "in DDS::SampleStateMask sample_states," << be_nl
277 << "in DDS::ViewStateMask view_states," << be_nl
278 << "in DDS::InstanceStateMask instance_states);"
279 << be_uidt;
281 los << be_nl_2
282 << "DDS::ReturnCode_t read_next_instance_w_condition ("
283 << be_idt_nl
284 << "inout " << lname << "Seq data_values," << be_nl
285 << "inout DDS::SampleInfoSeq sample_infos," << be_nl
286 << "in long max_samples," << be_nl
287 << "in DDS::InstanceHandle_t previous_handle," << be_nl
288 << "in DDS::ReadCondition a_condition);" << be_uidt;
290 los << be_nl_2
291 << "DDS::ReturnCode_t take_next_instance_w_condition ("
292 << be_idt_nl
293 << "inout " << lname << "Seq data_values," << be_nl
294 << "inout DDS::SampleInfoSeq sample_infos," << be_nl
295 << "in long max_samples," << be_nl
296 << "in DDS::InstanceHandle_t previous_handle," << be_nl
297 << "in DDS::ReadCondition a_condition);" << be_uidt;
299 los << be_nl_2
300 << "DDS::ReturnCode_t return_loan (" << be_idt_nl
301 << "inout " << lname << "Seq data_values," << be_nl
302 << "inout DDS::SampleInfoSeq sample_infos);"
303 << be_uidt;
305 los << be_nl_2
306 << "DDS::ReturnCode_t get_key_value (" << be_idt_nl
307 << "inout " << lname << " key_holder," << be_nl
308 << "in DDS::InstanceHandle_t handle);" << be_uidt;
310 los << be_nl_2
311 << "DDS::InstanceHandle_t lookup_instance ("
312 << be_idt_nl
313 << "in " << lname << " instance_data);" << be_uidt;
315 los << be_uidt_nl
316 << "};";
320 be_visitor_dds_ts_idl::init_file (void)
322 /// Open an IDL file for writing.
323 ACE_CString orig (
324 idl_global->stripped_filename ()->get_string ());
326 ACE_CString fname_noext (orig.substr (0, orig.rfind ('.')));
327 fname_noext += "TypeSupport";
329 ACE_CString fname (fname_noext);
330 fname += ".idl";
332 ACE_NEW_RETURN (this->os_ptr_,
333 TAO_OutStream,
334 -1);
336 int status = this->os_ptr_->open (fname.c_str ());
338 if (status == -1)
340 ACE_ERROR_RETURN ((LM_ERROR,
341 ACE_TEXT ("be_visitor_root_ts_idl::init - ")
342 ACE_TEXT ("Error opening DDS type support ")
343 ACE_TEXT ("IDL file\n")),
344 -1);
347 this->os_ptr_->gen_ifdef_macro (fname_noext.c_str (),
348 "IDL",
349 false);
351 *this->os_ptr_ << be_nl_2
352 << "#include <dds_rtf2_dcps.idl>" << be_nl_2
353 << "#include \""
354 << idl_global->filename ()->get_string ()
355 << "\"";
357 return 0;
360 void
361 be_visitor_dds_ts_idl::fini_file (void)
363 *this->os_ptr_ << be_nl_2
364 << "#endif /* ifndef */\n"
365 << "\n";
367 delete this->os_ptr_;
368 this->os_ptr_ = 0;