2 //=============================================================================
4 * @file be_visitor_dds_ts_idl.cpp
6 * Visitor generating code for DDS type support IDL files.
10 //=============================================================================
12 // ********************************
13 // Visitor for DDS type support IDL
14 // ********************************
16 #include "be_visitor_dds_ts_idl.h"
17 #include "be_visitor_context.h"
19 #include "be_structure.h"
21 #include "be_valuetype.h"
22 #include "be_extern.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
),
35 be_visitor_dds_ts_idl::~be_visitor_dds_ts_idl (void)
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")),
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")),
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")),
81 be_visitor_dds_ts_idl::visit_structure (be_structure
*node
)
83 return this->process_node (node
);
87 be_visitor_dds_ts_idl::visit_union (be_union
*node
)
89 return this->process_node (node
);
93 be_visitor_dds_ts_idl::visit_valuetype (be_valuetype
*node
)
95 return this->process_node (node
);
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
);
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 ();
118 << "local interface " << lname
119 << "IDLDataWriter : ::DDS::DataWriter" << be_nl
123 << "DDS::InstanceHandle_t register_instance (" << be_idt_nl
124 << "in " << lname
<< " instance_data);" << be_uidt
;
127 << "DDS::InstanceHandle_t register_instance_w_timestamp ("
129 << "in " << lname
<< " instance_data," << be_nl
130 << "in DDS::Time_t source_timestamp);" << be_uidt
;
133 << "DDS::ReturnCode_t unregister_instance (" << be_idt_nl
134 << "in " << lname
<< " instance_data," << be_nl
135 << "in DDS::InstanceHandle_t handle);" << be_uidt
;
138 << "DDS::ReturnCode_t unregister_instance_w_timestamp ("
140 << "in " << lname
<< " instance_data," << be_nl
141 << "in DDS::InstanceHandle_t handle," << be_nl
142 << "in DDS::Time_t source_timestamp);" << be_uidt
;
145 << "DDS::ReturnCode_t write (" << be_idt_nl
146 << "in " << lname
<< " instance_data," << be_nl
147 << "in DDS::InstanceHandle_t handle);" << be_uidt
;
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
;
156 << "DDS::ReturnCode_t dispose (" << be_idt_nl
157 << "in " << lname
<< " instance_data," << be_nl
158 << "in DDS::InstanceHandle_t instance_handle);"
162 << "DDS::ReturnCode_t dispose_w_timestamp ("
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
;
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
;
174 << "DDS::InstanceHandle_t lookup_instance ("
176 << "in " << lname
<< " instance_data);" << be_uidt
;
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 ();
189 << "local interface " << lname
190 << "IDLDataReader : ::DDS::DataReader" << 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);"
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);"
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
;
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
;
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
;
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
;
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);"
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);"
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);"
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);"
282 << "DDS::ReturnCode_t read_next_instance_w_condition ("
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
;
291 << "DDS::ReturnCode_t take_next_instance_w_condition ("
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
;
300 << "DDS::ReturnCode_t return_loan (" << be_idt_nl
301 << "inout " << lname
<< "Seq data_values," << be_nl
302 << "inout DDS::SampleInfoSeq sample_infos);"
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
;
311 << "DDS::InstanceHandle_t lookup_instance ("
313 << "in " << lname
<< " instance_data);" << be_uidt
;
320 be_visitor_dds_ts_idl::init_file (void)
322 /// Open an IDL file for writing.
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
);
332 ACE_NEW_RETURN (this->os_ptr_
,
336 int status
= this->os_ptr_
->open (fname
.c_str ());
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")),
347 this->os_ptr_
->gen_ifdef_macro (fname_noext
.c_str (),
351 *this->os_ptr_
<< be_nl_2
352 << "#include <dds_rtf2_dcps.idl>" << be_nl_2
354 << idl_global
->filename ()->get_string ()
361 be_visitor_dds_ts_idl::fini_file (void)
363 *this->os_ptr_
<< be_nl_2
364 << "#endif /* ifndef */\n"
367 delete this->os_ptr_
;