36 #include <boost/tuple/tuple.hpp>
41 using boost::tuples::make_tuple;
51 const std::map<std::string, std::string>& parsed_options,
52 const std::string& option_string)
56 std::map<std::string, std::string>::const_iterator iter;
58 iter = parsed_options.find(
"pure_enums");
59 gen_pure_enums_ = (iter != parsed_options.end());
61 iter = parsed_options.find(
"dense");
62 gen_dense_ = (iter != parsed_options.end());
64 iter = parsed_options.find(
"include_prefix");
65 use_include_prefix_ = (iter != parsed_options.end());
67 iter = parsed_options.find(
"cob_style");
68 gen_cob_style_ = (iter != parsed_options.end());
70 iter = parsed_options.find(
"no_client_completion");
71 gen_no_client_completion_ = (iter != parsed_options.end());
73 iter = parsed_options.find(
"templates");
74 gen_templates_ = (iter != parsed_options.end());
76 out_dir_base_ =
"gen-cpp";
83 void init_generator();
84 void close_generator();
86 void generate_consts(std::vector<t_const*> consts);
92 void generate_typedef(
t_typedef* ttypedef);
93 void generate_enum(
t_enum* tenum);
95 generate_cpp_struct(tstruct,
false);
98 generate_cpp_struct(txception,
true);
101 void generate_sandesh(
t_sandesh* tsandesh) {
102 generate_cpp_sandesh(tsandesh);
104 void generate_cpp_sandesh(
t_sandesh* tsandesh);
105 void generate_sandesh_definition (std::ofstream& out,
t_sandesh* tsandesh);
106 void generate_sandesh_fingerprint (std::ofstream& out,
t_sandesh* tsandesh,
bool is_definition);
107 void generate_sandesh_http_reader (std::ofstream& out,
t_sandesh* tsandesh);
108 void generate_sandesh_reader (std::ofstream& out,
t_sandesh* tsandesh);
109 void generate_sandesh_writer (std::ofstream& out,
t_sandesh* tsandesh);
110 void generate_sandesh_creator (std::ofstream& out,
t_sandesh* tsandesh);
111 void generate_sandesh_member_init_list(std::ofstream& out,
t_sandesh* tsandesh,
bool init_dval =
false);
112 void generate_sandesh_base_init (ofstream& out,
t_sandesh* tsandesh,
bool init_dval);
113 void generate_sandesh_hints (std::ofstream& out,
t_sandesh* tsandesh);
114 void generate_sandesh_request (std::ofstream& out,
t_sandesh* tsandesh);
115 void generate_sandesh_default_ctor (std::ofstream& out,
t_sandesh* tsandesh,
bool is_request);
116 void generate_sandesh_loggers (std::ofstream& out,
t_sandesh* tsandesh);
117 void generate_logger_field (std::ofstream& out,
t_field *tfield,
string prefix,
bool log_value_only,
bool no_name_log,
bool for_sandesh =
false);
118 void generate_logger_struct (std::ofstream& out,
t_struct *tstruct,
string prefix,
string name);
119 void generate_logger_container (std::ofstream& out,
t_type* ttype,
string name,
bool log_value_only);
120 void generate_logger_map_element (std::ofstream& out,
t_map* tmap,
string iter,
bool log_value_only);
121 void generate_logger_set_element (std::ofstream& out,
t_set* tset,
string iter,
bool log_value_only);
122 void generate_logger_list_element (std::ofstream& out,
t_list* tlist,
string iter,
bool log_value_only);
123 void generate_sandesh_get_size (std::ofstream& out,
t_sandesh* tsandesh);
124 void generate_get_size_field (std::ofstream& out,
t_field *tfield);
125 void generate_get_size_struct (std::ofstream& out,
t_struct *tstruct,
string name);
126 void generate_get_size_container (std::ofstream& out,
t_type* ttype,
string name);
127 void generate_get_size_map_element (std::ofstream& out,
t_map* tmap,
string name);
128 void generate_get_size_list_element(std::ofstream& out,
t_list* ttype,
string name);
129 void generate_get_size_set_element (std::ofstream& out,
t_set* ttype,
string name);
130 void generate_sandesh_trace (std::ofstream& out,
t_sandesh* tsandesh);
131 void generate_sandesh_context (std::ofstream& out,
t_sandesh* tsandesh,
string val);
132 void generate_sandesh_seqnum(std::ofstream& out,
t_sandesh* tsandesh);
133 void generate_sandesh_versionsig(std::ofstream& out,
t_sandesh* tsandesh);
134 void generate_sandesh_static_seqnum_def(std::ofstream& out,
t_sandesh* tsandesh);
135 void generate_sandesh_static_versionsig_def(std::ofstream& out,
t_sandesh* tsandesh);
136 void generate_sandesh_trace_seqnum_ctor(std::ofstream& out,
t_sandesh* tsandesh);
137 void generate_static_const_string_definition(std::ofstream& out,
t_sandesh* tsandesh);
138 std::string generate_sandesh_no_static_const_string_function(
t_sandesh *tsandesh,
bool signature,
bool autogen_darg,
bool trace =
false,
bool request =
false,
bool ctorcall =
false);
139 void generate_static_const_string_definition(std::ofstream& out, std::string name,
140 const vector<t_field*>& fields);
141 std::string generate_sandesh_async_creator(
t_sandesh *tsandesh,
bool signature,
bool expand_autogen,
bool skip_autogen,
142 std::string prefix, std::string suffix,
bool category_level_file_line_first,
143 bool autogen_category_level,
bool drop_log_reason,
bool use_sandesh_object =
false);
144 void generate_sandesh_rate_limit_fn(ofstream &out,
t_sandesh *tsandesh);
145 void generate_sandesh_async_send_fn(ofstream &out,
t_sandesh *tsandesh,
146 bool generate_sandesh_object,
bool generate_rate_limit,
bool generate_system_log);
147 void generate_sandesh_async_send_macros(ofstream &out,
t_sandesh *tsandesh,
148 bool generate_sandesh_object);
149 void generate_sandesh_static_log_fn(ofstream &out,
t_sandesh *tsandesh,
150 bool generate_sandesh_object);
151 void generate_sandesh_async_create_fn(ofstream &out,
t_sandesh *tsandesh);
152 void generate_sandesh_async_create_macro(ofstream &out,
t_sandesh *tsandesh);
153 void generate_sandesh_session_log_unrolled_fn(ofstream &out,
t_sandesh *tsandesh);
154 void generate_sandesh_session_adjust_session_end_point_objects_fn(ofstream &out,
156 void generate_sandesh_flow_send_fn(ofstream &out,
t_sandesh *tsandesh);
157 void generate_sandesh_systemlog_creators(ofstream &out,
t_sandesh *tsandesh);
158 void generate_sandesh_objectlog_creators(ofstream &out,
t_sandesh *tsandesh);
159 void generate_sandesh_flow_creators(ofstream &out,
t_sandesh *tsandesh);
160 void generate_sandesh_uve_creator(std::ofstream& out,
t_sandesh* tsandesh);
161 std::string generate_sandesh_trace_creator(
t_sandesh *tsandesh,
bool signature,
bool expand_autogen,
bool skip_autogen,
162 std::string prefix, std::string suffix);
163 void generate_sandesh_updater(ofstream& out,
t_sandesh* tsandesh);
164 void generate_isRatelimitPass(ofstream& out,
t_sandesh* tsandesh);
165 void generate_sandesh_static_rate_limit_log_def(ofstream& out,
t_sandesh* tsandesh);
166 void generate_sandesh_static_rate_limit_mutex_def(ofstream& out,
t_sandesh* tsandesh);
167 void generate_sandesh_static_rate_limit_buffer_def(ofstream& out,
t_sandesh* tsandesh);
186 DSInfo(
bool is_map,
size_t period, CacheAttribute cat,
187 string rawtype, RawMetric rmtype,
188 string resulttype,
string algo,
string annotation,
189 string compattr,
string subcompattr,
string prealgo) :
190 is_map_(is_map), period_(period), cat_(cat),
191 rawtype_(rawtype), rmtype_(rmtype),
192 resulttype_(resulttype), algo_(algo),
193 annotation_(annotation),
194 compattr_(compattr) , subcompattr_(subcompattr), prealgo_(prealgo) {}
207 void derived_stats_info(
t_struct* tstruct,
208 map<string,DSInfo>& dsmap,
210 map<
string,set<string> >& rawmap);
212 void cache_attr_info(
t_struct* tstruct, std::map<string, CacheAttribute>& attrs);
215 set<string>& inl, set<string>& never, set<string>& periodic);
218 void generate_cpp_struct(
t_struct* tstruct,
bool is_exception);
220 void generate_service(
t_service* tservice);
225 void generate_struct_definition (std::ofstream& out,
t_struct* tstruct,
bool is_exception=
false,
bool pointers=
false,
bool read=
true,
bool write=
true);
226 void generate_struct_fingerprint (std::ofstream& out,
t_struct* tstruct,
bool is_definition);
227 void generate_struct_reader (std::ofstream& out,
t_struct* tstruct,
bool pointers=
false);
228 void generate_struct_writer (std::ofstream& out,
t_struct* tstruct,
bool pointers=
false);
229 void generate_struct_result_writer (std::ofstream& out,
t_struct* tstruct,
bool pointers=
false);
231 void generate_static_const_string_definition(std::ofstream& out,
t_struct* tstruct);
232 void generate_struct_logger (ofstream& out,
const string& name,
233 const vector<t_field*>& fields);
234 void generate_struct_get_size (ofstream& out,
const string& name,
235 const vector<t_field*>& fields);
242 void generate_service_interface (
t_service* tservice,
string style);
243 void generate_service_interface_factory (
t_service* tservice,
string style);
244 void generate_service_null (
t_service* tservice,
string style);
245 void generate_service_multiface (
t_service* tservice);
246 void generate_service_helpers (
t_service* tservice);
247 void generate_service_client (
t_service* tservice,
string style);
248 void generate_service_processor (
t_service* tservice,
string style);
249 void generate_service_skeleton (
t_service* tservice);
251 string style,
bool specialized=
false);
253 void generate_service_async_skeleton (
t_service* tservice);
259 void generate_deserialize_field (std::ofstream& out,
261 std::string prefix=
"",
262 std::string suffix=
"");
264 void generate_deserialize_struct (std::ofstream& out,
266 std::string prefix=
"");
268 void generate_deserialize_container (std::ofstream& out,
270 std::string prefix=
"");
272 void generate_deserialize_set_element (std::ofstream& out,
274 std::string prefix=
"");
276 void generate_deserialize_map_element (std::ofstream& out,
278 std::string prefix=
"");
280 void generate_deserialize_list_element (std::ofstream& out,
286 void generate_serialize_field (std::ofstream& out,
288 std::string prefix=
"",
289 std::string suffix=
"");
291 void generate_serialize_struct (std::ofstream& out,
293 std::string prefix=
"");
295 void generate_serialize_container (std::ofstream& out,
297 std::string prefix=
"");
299 void generate_serialize_map_element (std::ofstream& out,
303 void generate_serialize_set_element (std::ofstream& out,
307 void generate_serialize_list_element (std::ofstream& out,
311 void generate_function_call (ostream& out,
318 void generate_serialize_sandesh (std::ofstream& out,
320 std::string prefix=
"");
328 std::string namespace_open(std::string ns);
329 std::string namespace_close(std::string ns);
330 std::string type_name(
t_type* ttype,
bool in_typedef=
false,
bool arg=
false);
333 std::string declare_field(
t_field* tfield,
bool init=
false,
bool pointer=
false,
bool constant=
false,
bool reference=
false,
bool constructor=
false);
335 std::string declare_field(
t_field* tfield,
bool init=
false,
bool pointer=
false,
bool constant=
false,
bool reference=
false);
337 std::string function_signature(
t_function* tfunction, std::string style, std::string prefix=
"",
bool name_params=
true);
338 std::string cob_function_signature(
t_function* tfunction, std::string prefix=
"",
bool name_params=
true);
339 std::string argument_list(
t_struct* tstruct,
bool name_params=
true,
bool start_comma=
false);
340 std::string type_to_enum(
t_type* ttype);
341 std::string local_reflection_name(
const char*,
t_type* ttype,
bool external=
false);
343 void generate_enum_constant_list(std::ofstream& f,
344 const vector<t_enum_value*>& constants,
347 bool include_values);
350 void generate_local_reflection(std::ofstream& out,
t_type* ttype,
bool is_definition);
351 void generate_local_reflection_pointer(std::ofstream& out,
t_type* ttype);
354 ttype = get_true_type(ttype);
361 ttype->is_sandesh() ||
368 use_include_prefix_ = use_include_prefix;
376 std::string get_include_prefix(
const t_program& program)
const;
382 void generate_common_struct_reader_body(std::ofstream& out,
384 bool pointers =
false);
390 void generate_common_struct_writer_body(std::ofstream& out,
392 bool pointers =
false);
444 std::ofstream f_request_impl_;
445 std::ofstream f_html_template_;
446 struct sandesh_logger {
453 void generate_sandesh_logger(std::ofstream& out,
t_sandesh* tsandesh,
455 void generate_sandesh_static_logger(ofstream &out,
t_sandesh *tsandesh,
456 bool generate_sandesh_object);
457 void generate_sandesh_static_drop_logger(ofstream &out,
t_sandesh *tsandesh,
458 bool generate_sandesh_object);
481 MKDIR(get_out_dir().c_str());
484 string f_types_name = get_out_dir()+program_name_+
"_types.h";
485 f_types_.open(f_types_name.c_str());
487 string f_types_impl_name = get_out_dir()+program_name_+
"_types.cpp";
488 f_types_impl_.open(f_types_impl_name.c_str());
491 string f_request_impl_name = get_out_dir()+program_name_+
"_request_skeleton.cpp";
492 f_request_impl_.open(f_request_impl_name.c_str());
494 string f_html_template_name = get_out_dir()+program_name_+
"_html_template.cpp";
495 f_html_template_.open(f_html_template_name.c_str());
498 if (gen_templates_) {
501 string f_types_tcc_name = get_out_dir()+program_name_+
"_types.tcc";
502 f_types_tcc_.open(f_types_tcc_name.c_str());
521 "#ifndef " << program_name_ <<
"_TYPES_H" << endl <<
522 "#define " << program_name_ <<
"_TYPES_H" << endl <<
525 "#ifndef " << program_name_ <<
"_TYPES_TCC" << endl <<
526 "#define " << program_name_ <<
"_TYPES_TCC" << endl <<
531 "#include <sandesh/Thrift.h>" << endl <<
533 "#include <TApplicationException.h>" << endl <<
535 "#include <tbb/atomic.h>" << endl <<
536 "#include <boost/shared_ptr.hpp>" << endl <<
537 "#include <sandesh/derived_stats.h>" << endl <<
538 "#include <sandesh/derived_stats_algo.h>" << endl <<
539 "#include <boost/pointer_cast.hpp>" << endl <<
541 "#include <base/trace.h>" << endl;
542 if (program_name_ !=
"sandesh") {
543 f_types_ <<
"#include <sandesh/sandesh_types.h>" << endl;
544 f_types_ <<
"#include <sandesh/sandesh_constants.h>" << endl;
545 if (program_name_ !=
"derived_stats_results" && program_name_ !=
"vns") {
546 f_types_ <<
"#include <sandesh/sandesh.h>" << endl;
550 "#include <sandesh/protocol/TProtocol.h>" << endl <<
551 "#include <sandesh/transport/TTransport.h>" << endl <<
555 const vector<t_program*>& includes = program_->get_includes();
556 for (
size_t i = 0; i < includes.size(); ++i) {
558 "#include \"" << get_include_prefix(*(includes[i])) <<
559 includes[i]->get_name() <<
"_types.h\"" << endl;
564 "#include \"" << get_include_prefix(*(includes[i])) <<
565 includes[i]->get_name() <<
"_types.tcc\"" << endl;
570 const vector<string>& cpp_includes = program_->get_cpp_includes();
571 for (
size_t i = 0; i < cpp_includes.size(); ++i) {
572 if (cpp_includes[i][0] ==
'<') {
574 "#include " << cpp_includes[i] << endl;
577 "#include \"" << cpp_includes[i] <<
"\"" << endl;
586 "#include <boost/date_time/posix_time/posix_time.hpp>" << endl << endl <<
587 "#include <base/logging.h>" << endl << endl <<
588 "#include <sandesh/sandesh_uve.h>" << endl <<
589 "#include <sandesh/sandesh_http.h>" << endl <<
590 "#include <sandesh/sandesh_trace.h>" << endl <<
591 "#include <curl/curl.h>" << endl <<
592 "#include <boost/foreach.hpp>" << endl <<
593 "#include <boost/assign/list_of.hpp>" << endl <<
594 "#include <boost/make_shared.hpp>" << endl << endl;
597 "#include \"" << get_include_prefix(*get_program()) << program_name_ <<
598 "_types.h\"" << endl <<
601 "#include \"" << get_include_prefix(*get_program()) << program_name_ <<
602 "_types.h\"" << endl <<
606 "#include <sandesh/sandesh_types.h>" << endl <<
607 "#include <sandesh/sandesh_constants.h>" << endl <<
608 "#include <sandesh/sandesh.h>" << endl <<
609 "#include \"" << get_include_prefix(*get_program()) << program_name_ <<
610 "_types.h\"" << endl <<
613 "#include <sandesh/sandesh_http.h>" << endl;
615 "static SandeshHttp::HtmlInfo h_info(" <<
616 program_name_ <<
"_xml," << program_name_ <<
"_xml_len);" << endl;
618 "static SandeshHttp sh(\"" << program_name_ <<
".xml\", h_info);" << endl;
619 f_html_template_ <<
"int " << program_name_ <<
"_marker = 0;" << endl;
628 "#include <TReflectionLocal.h>" << endl <<
633 ns_open_ = namespace_open(program_->get_namespace(
"cpp"));
634 ns_close_ = namespace_close(program_->get_namespace(
"cpp"));
676 if (gen_templates_) {
678 "#include \"" << get_include_prefix(*get_program()) << program_name_ <<
679 "_types.tcc\"" << endl <<
691 f_types_impl_.close();
692 f_types_tcc_.close();
694 f_request_impl_.close();
695 f_html_template_.close();
712 const vector<t_enum_value*>& constants,
715 bool include_values) {
719 vector<t_enum_value*>::const_iterator c_iter;
721 for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
728 << prefix << (*c_iter)->get_name() << suffix;
729 if (include_values && (*c_iter)->has_value()) {
730 f <<
" = " << (*c_iter)->get_value();
736 indent(f) <<
"};" << endl;
748 std::string enum_name = tenum->
get_name();
749 if (!gen_pure_enums_) {
756 indent() <<
"enum " << enum_name;
758 generate_enum_constant_list(f_types_, constants,
"",
"",
true);
760 if (!gen_pure_enums_) {
762 f_types_ <<
"};" << endl;
770 std::string prefix =
"";
771 if (!gen_pure_enums_) {
777 generate_enum_constant_list(f_types_impl_, constants, prefix.c_str(),
"",
false);
781 generate_enum_constant_list(f_types_impl_, constants,
"\"",
"\"",
false);
784 indent() <<
"extern const std::map<int, const char*> _" <<
785 tenum->
get_name() <<
"_VALUES_TO_NAMES;" << endl << endl;
788 indent() <<
"const std::map<int, const char*> _" << tenum->
get_name() <<
789 "_VALUES_TO_NAMES(::contrail::sandesh::TEnumIterator(" << constants.size() <<
790 ", _k" << tenum->
get_name() <<
"Values" <<
791 ", _k" << tenum->
get_name() <<
"Names), " <<
792 "::contrail::sandesh::TEnumIterator(-1, NULL, NULL));" << endl << endl;
794 generate_local_reflection(f_types_, tenum,
false);
795 generate_local_reflection(f_types_impl_, tenum,
true);
802 string f_consts_name = get_out_dir()+program_name_+
"_constants.h";
804 f_consts.open(f_consts_name.c_str());
806 string f_consts_impl_name = get_out_dir()+program_name_+
"_constants.cpp";
807 ofstream f_consts_impl;
808 f_consts_impl.open(f_consts_impl_name.c_str());
818 "#ifndef " << program_name_ <<
"_CONSTANTS_H" << endl <<
819 "#define " << program_name_ <<
"_CONSTANTS_H" << endl <<
821 "#include \"" << get_include_prefix(*get_program()) << program_name_ <<
822 "_types.h\"" << endl <<
829 "#include <base/trace.h>" << endl <<
830 "#include <sandesh/sandesh_types.h>" << endl <<
831 "#include <sandesh/sandesh_constants.h>" << endl <<
832 "#include <sandesh/sandesh.h>" << endl <<
833 "#include <sandesh/sandesh_trace.h>" << endl << endl;
836 "#include \"" << get_include_prefix(*get_program()) << program_name_ <<
837 "_constants.h\"" << endl <<
843 "class " << program_name_ <<
"Constants {" << endl <<
844 " public:" << endl <<
845 " " << program_name_ <<
"Constants();" << endl <<
848 vector<t_const*>::iterator c_iter;
849 for (c_iter = consts.begin(); c_iter != consts.end(); ++c_iter) {
850 string name = (*c_iter)->get_name();
860 "const " << program_name_ <<
"Constants g_" << program_name_ <<
"_constants;" << endl <<
862 program_name_ <<
"Constants::" << program_name_ <<
"Constants() {" << endl;
864 for (c_iter = consts.begin(); c_iter != consts.end(); ++c_iter) {
865 print_const_value(f_consts_impl,
866 (*c_iter)->get_name(),
867 (*c_iter)->get_type(),
868 (*c_iter)->get_value());
876 "extern const " << program_name_ <<
"Constants g_" << program_name_ <<
"_constants;" << endl <<
895 type = get_true_type(type);
897 string v2 = render_const_value(out, name, type, value);
898 indent(out) << name <<
" = " << v2 <<
";" << endl <<
904 const vector<t_field*>& fields = ((
t_struct*)type)->get_members();
905 vector<t_field*>::const_iterator f_iter;
906 const map<t_const_value*, t_const_value*>& val = value->
get_map();
907 map<t_const_value*, t_const_value*>::const_iterator v_iter;
908 for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) {
909 t_type* field_type = NULL;
910 for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
911 if ((*f_iter)->get_name() == v_iter->first->get_string()) {
912 field_type = (*f_iter)->get_type();
915 if (field_type == NULL) {
916 throw "type error: " + type->
get_name() +
" has no field " + v_iter->first->get_string();
918 string val = render_const_value(out, name, field_type, v_iter->second);
919 indent(out) << name <<
"." << v_iter->first->get_string() <<
" = " << val <<
";" << endl;
920 indent(out) << name <<
".__isset." << v_iter->first->get_string() <<
" = true;" << endl;
923 }
else if (type->
is_map()) {
926 const map<t_const_value*, t_const_value*>& val = value->
get_map();
927 map<t_const_value*, t_const_value*>::const_iterator v_iter;
928 for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) {
929 string key = render_const_value(out, name, ktype, v_iter->first);
930 string val = render_const_value(out, name, vtype, v_iter->second);
931 indent(out) << name <<
".insert(std::make_pair(" << key <<
", " << val <<
"));" << endl;
936 const vector<t_const_value*>& val = value->
get_list();
937 vector<t_const_value*>::const_iterator v_iter;
938 for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) {
939 string val = render_const_value(out, name, etype, *v_iter);
940 indent(out) << name <<
".push_back(" << val <<
");" << endl;
943 }
else if (type->
is_set()) {
945 const vector<t_const_value*>& val = value->
get_list();
946 vector<t_const_value*>::const_iterator v_iter;
947 for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) {
948 string val = render_const_value(out, name, etype, *v_iter);
949 indent(out) << name <<
".insert(" << val <<
");" << endl;
953 throw "INVALID TYPE IN print_const_value: " + type->
get_name();
962 std::ostringstream render;
969 case t_base_type::TYPE_STATIC_CONST_STRING:
970 case t_base_type::TYPE_XML:
972 render <<
'"' << get_escaped_string(value) <<
'"';
975 render << ((value->
get_integer() > 0) ?
"true" :
"false");
981 case t_base_type::TYPE_U16:
982 case t_base_type::TYPE_U32:
990 case t_base_type::TYPE_U64:
993 case t_base_type::TYPE_UUID:
994 render <<
"boost::uuids::string_generator()(\"" << value->
get_uuid() <<
"\")";
1005 case t_base_type::TYPE_IPV4:
1008 case t_base_type::TYPE_IPADDR:
1009 render <<
"boost::asio::ip::address::from_string(\"" <<
1019 string t = tmp(
"tmp");
1021 print_const_value(out, t, type, value);
1025 return render.str();
1036 generate_struct_definition(f_types_, tstruct, is_exception);
1037 generate_struct_fingerprint(f_types_impl_, tstruct,
true);
1038 generate_local_reflection(f_types_, tstruct,
false);
1039 generate_local_reflection(f_types_impl_, tstruct,
true);
1040 generate_local_reflection_pointer(f_types_impl_, tstruct);
1042 generate_static_const_string_definition(f_types_impl_, tstruct);
1045 std::ofstream& out = (gen_templates_ ? f_types_tcc_ : f_types_impl_);
1046 generate_struct_reader(out, tstruct);
1047 generate_struct_writer(out, tstruct);
1062 void t_cpp_generator::generate_cpp_sandesh(
t_sandesh* tsandesh) {
1075 generate_sandesh_definition(f_types_, tsandesh);
1076 generate_sandesh_fingerprint(f_types_impl_, tsandesh,
true);
1077 std::ofstream& out = f_types_impl_;
1078 generate_static_const_string_definition(out, tsandesh);
1079 generate_sandesh_static_versionsig_def(out, tsandesh);
1080 generate_sandesh_creator(out, tsandesh);
1081 generate_sandesh_reader(out, tsandesh);
1082 generate_sandesh_writer(out, tsandesh);
1083 generate_sandesh_loggers(out, tsandesh);
1084 generate_sandesh_get_size(out, tsandesh);
1087 generate_sandesh_static_seqnum_def(out, tsandesh);
1090 generate_sandesh_http_reader(out, tsandesh);
1092 generate_sandesh_request(f_request_impl_, tsandesh);
1094 if (is_uve || is_alarm) {
1095 generate_sandesh_updater(out,tsandesh);
1098 generate_sandesh_static_rate_limit_log_def(out, tsandesh);
1099 generate_sandesh_static_rate_limit_mutex_def(out, tsandesh);
1100 generate_sandesh_static_rate_limit_buffer_def(out, tsandesh);
1111 void t_cpp_generator::generate_sandesh_request(ofstream& out,
1113 out <<
"void " << tsandesh->
get_name() <<
"::" <<
1114 "HandleRequest() const {" << endl;
1117 indent(out) <<
"// This autogenerated skeleton file illustrates the " <<
1118 "function needed to" << endl;
1119 indent(out) <<
"// implement " << tsandesh->
get_name() <<
"." << endl;
1120 indent(out) <<
"// You should copy it to another filename to avoid " <<
1121 "overwriting it. Add the" << endl;
1122 indent(out) <<
"// HandleRequest() implementation to it, and include it " <<
1123 "in your module's" << endl;
1124 indent(out) <<
"// SConscript. Alternatively, add the implementation of " <<
1125 "HandleRequest()" << endl;
1126 indent(out) <<
"// in your module's sources." << endl;
1136 std::string t_cpp_generator::generate_sandesh_no_static_const_string_function(
1137 t_sandesh* tsandesh,
bool signature,
bool autogen_darg,
1138 bool trace,
bool request,
bool ctorcall) {
1142 vector<t_field*>::const_iterator m_iter;
1143 const vector<t_field*>& members = tsandesh->
get_members();
1145 bool init_function =
false;
1149 init_function =
true;
1151 result +=
"SandeshTraceBufferPtr trace_buf, std::string file, int32_t line";
1153 result +=
"trace_buf, file, line";
1159 init_function =
true;
1160 result +=
"uint32_t seqno";
1164 init_function =
true;
1168 result +=
"lseqnum_++";
1172 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
1173 t_type* t = get_true_type((*m_iter)->get_type());
1174 if (t->is_static_const_string()) {
1177 if ((*m_iter)->get_auto_generated() && trace) {
1184 if (!init_function) {
1186 init_function =
true;
1193 if (autogen_darg && (*m_iter)->get_auto_generated()) {
1194 result += declare_field(*m_iter,
true,
false,
false,
false,
true);
1197 result += declare_field(*m_iter,
false,
false, use_const, !t->
is_base_type() || t->
is_string(),
true);
1200 result += (*m_iter)->get_name();
1203 if (!init_function) {
1209 if (init_function) {
1212 result +=
"const std::string& context, SandeshConnection * sconn = NULL";
1214 if (init_function) {
1217 result +=
"context, sconn";
1225 std::string t_cpp_generator::generate_sandesh_async_creator(
t_sandesh* tsandesh,
bool signature,
1226 bool expand_autogen,
bool skip_autogen, std::string prefix, std::string suffix,
1227 bool category_level_file_line_first,
bool autogen_category_level,
bool
1228 drop_log_reason,
bool use_sandesh_object)
1232 string category_def = prefix +
"category" + suffix;
1233 string level_def = prefix +
"level" + suffix;
1234 string category_dec =
"std::string " + category_def;
1235 string level_dec =
"SandeshLevel::type " + level_def;
1236 string module_name =
"\"\"";
1237 string drop_reason_dec;
1238 string drop_reason_def;
1241 vector<t_field*>::const_iterator m_iter;
1242 const vector<t_field*>& members = tsandesh->
get_members();
1243 bool init_function =
false;
1244 if (drop_log_reason) {
1245 drop_reason_def = prefix +
"drop_reason" + suffix +
", ";
1246 drop_reason_dec =
"const std::string& " + drop_reason_def;
1249 if (category_level_file_line_first) {
1251 result +=
"(" + drop_reason_dec + category_dec +
", " + level_dec;
1252 if (!is_flow) result +=
", std::string file, int32_t line";
1254 if (!autogen_category_level) {
1255 result +=
"(" + drop_reason_dec + category_def +
", " + level_def;
1256 if (!is_flow) result +=
", __FILE__, __LINE__";
1258 result +=
"(" + drop_reason_dec + module_name +
", SandeshLevel::SYS_INFO";
1259 if (!is_flow) result +=
", __FILE__, __LINE__";
1262 init_function =
true;
1265 if (!autogen_category_level) {
1266 result +=
"(" + drop_reason_dec + category_dec +
", " + level_dec;
1267 init_function =
true;
1270 if (!autogen_category_level) {
1271 result +=
"(" + drop_reason_def + category_def +
", " + level_def;
1272 init_function =
true;
1276 if(use_sandesh_object) {
1277 if (!init_function) {
1279 init_function =
true;
1282 result +=
", " + tsandesh->
get_name() +
" *snh";
1288 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
1290 t_type* t = get_true_type((*m_iter)->get_type());
1291 if (t->is_static_const_string()) {
1298 bool skip = (*m_iter)->get_auto_generated() &&
1299 ((*m_iter)->get_name() ==
"file" || (*m_iter)->get_name() ==
"line") &&
1300 category_level_file_line_first;
1301 if (!init_function) {
1303 init_function =
true;
1312 if ((*m_iter)->get_auto_generated()) {
1314 result += declare_field(*m_iter,
true,
false,
false, !t->
is_base_type(),
true);
1318 result += declare_field(*m_iter,
false,
false, use_const,
1326 if ((*m_iter)->get_auto_generated()) {
1332 if (expand_autogen) {
1333 if ((*m_iter)->get_name() ==
"file") {
1335 result +=
"__FILE__";
1336 }
else if ((*m_iter)->get_name() ==
"line") {
1338 result +=
"__LINE__";
1342 result += prefix + (*m_iter)->get_name() + suffix;
1346 result += prefix + (*m_iter)->get_name() + suffix;
1351 if (!init_function) {
1358 void t_cpp_generator::generate_sandesh_async_create_fn(ofstream &out,
1360 std::string creator_func_name =
"Create";
1362 << creator_func_name <<
"(std::string file = \"\", int32_t line = 0) {"
1366 " * snh = new " << tsandesh->
get_name() <<
"(lseqnum_++, file, line);"
1368 out <<
indent() <<
"return snh;" << endl;
1370 indent(out) <<
"}" << endl << endl;
1373 void t_cpp_generator::generate_sandesh_async_create_macro(ofstream &out,
1375 std::string creator_func_name =
"Create";
1377 string creator_name = tsandesh->
get_name() + creator_func_name;
1378 string creator_name_usc = underscore(creator_name);
1379 string creator_name_uc = uppercase(creator_name_usc);
1380 out <<
indent() <<
"#define " << creator_name_uc <<
1383 out <<
indent() << tsandesh->
get_name() <<
"::" << creator_func_name <<
1384 "(__FILE__, __LINE__)" << endl;
1386 indent(out) << endl << endl;
1389 void t_cpp_generator::generate_sandesh_async_send_fn(
1390 ofstream &out,
t_sandesh *tsandesh,
bool generate_sandesh_object,
1391 bool generate_rate_limit,
bool generate_system_log) {
1392 std::string sender_func_name =
"Send";
1394 out <<
indent() <<
"static void " << sender_func_name;
1395 out << generate_sandesh_async_creator(tsandesh,
true,
false,
false,
"",
"",
1396 true,
false,
false, generate_sandesh_object);
1397 out <<
" {" << endl;
1399 if (generate_sandesh_object) {
1400 out <<
indent() <<
"snh->set_level(level);" << endl;
1401 out <<
indent() <<
"snh->set_category(category);" << endl;
1403 out <<
indent() <<
"if (HandleTest(level, category)) {" << endl;
1405 out <<
indent() <<
"Log";
1406 if (generate_sandesh_object) {
1407 out <<
"(category, level, snh);" << endl;
1408 out <<
indent() <<
"snh->Release();" << endl;
1410 out << generate_sandesh_async_creator(tsandesh,
false,
false,
false,
"",
1411 "",
false,
false,
false) <<
"; " << endl;
1413 out <<
indent() <<
"return;" << endl;
1415 if (generate_system_log) {
1416 out <<
indent() <<
"if (IsSendingAllMessagesDisabled() || " <<
1417 "IsSendingSystemLogsDisabled()) {" << endl;
1419 out <<
indent() <<
"if (IsSendingAllMessagesDisabled() || " <<
1420 "IsSendingObjectLogsDisabled()) {" << endl;
1423 out <<
indent() <<
"UpdateTxMsgFailStats(\"" << tsandesh->
get_name() <<
1424 "\", 0, SandeshTxDropReason::SendingDisabled);" << endl;
1425 out <<
indent() <<
"Log";
1426 if (generate_sandesh_object) {
1427 out <<
"(category, level, snh);" << endl;
1428 out <<
indent() <<
"snh->Release();" << endl;
1430 out << generate_sandesh_async_creator(tsandesh,
false,
false,
false,
"",
1431 "",
false,
false,
false) <<
"; " << endl;
1433 out <<
indent() <<
"return;" << endl;
1435 if (generate_rate_limit) {
1436 out <<
indent() <<
"if (!IsRatelimitPass()) {" << endl;
1438 out <<
indent() <<
"UpdateTxMsgFailStats(\"" << tsandesh->
get_name() <<
1439 "\", 0, SandeshTxDropReason::RatelimitDrop);" << endl;
1440 out <<
indent() <<
"if (do_rate_limit_drop_log_) {" << endl;
1442 out <<
indent() <<
"std::stringstream ratelimit_val;" << endl;
1443 out <<
indent() <<
" ratelimit_val << Sandesh::get_send_rate_limit();"
1445 out <<
indent() <<
"std::string drop_reason = \"SANDESH: Ratelimit"
1446 " Drop (\" + ratelimit_val.str() + std::string(\" messages"
1447 "/second): \") ;" << endl;
1448 out <<
indent() <<
"DropLog";
1449 if (generate_sandesh_object) {
1450 out <<
"(drop_reason, category, level, snh);" << endl;
1451 out <<
indent() <<
"snh->Release();" << endl;
1453 out << generate_sandesh_async_creator(tsandesh,
false,
false,
1454 false,
"",
"",
false,
false,
true) <<
"; " << endl;
1456 out <<
indent() <<
"do_rate_limit_drop_log_ = false;" << endl;
1458 out <<
indent() <<
"return;" << endl;
1461 out <<
indent() <<
"if (level >= SendingLevel()) {" << endl;
1463 out <<
indent() <<
"UpdateTxMsgFailStats(\"" << tsandesh->
get_name() <<
1464 "\", 0, SandeshTxDropReason::QueueLevel);" << endl;
1465 out <<
indent() <<
"std::string drop_reason = \"SANDESH: Queue Drop:"
1467 out <<
indent() <<
"DropLog";
1468 if (generate_sandesh_object) {
1469 out <<
"(drop_reason, category, level, snh);" << endl;
1470 out <<
indent() <<
"snh->Release();" << endl;
1472 out << generate_sandesh_async_creator(tsandesh,
false,
false,
false,
"",
1473 "",
false,
false,
true) <<
"; " << endl;
1475 out <<
indent() <<
"return;" << endl;
1477 if (!generate_sandesh_object) {
1479 " * snh = new " << tsandesh->
get_name() <<
1480 generate_sandesh_no_static_const_string_function(tsandesh,
1481 false,
false,
false,
false) <<
";" << endl;
1482 out <<
indent() <<
"snh->set_level(level);" << endl;
1483 out <<
indent() <<
"snh->set_category(category);" << endl;
1485 out <<
indent() <<
"snh->Dispatch();" << endl;
1487 indent(out) <<
"}" << endl << endl;
1490 void t_cpp_generator::generate_sandesh_async_send_macros(ofstream &out,
1491 t_sandesh *tsandesh,
bool generate_sandesh_object) {
1492 std::string sender_func_name =
"Send";
1493 std::string logger_func_name =
"Log";
1495 string creator_name = tsandesh->
get_name() + logger_func_name;
1496 if (generate_sandesh_object) {
1497 creator_name +=
"Sandesh";
1499 string creator_name_usc = underscore(creator_name);
1500 string creator_name_uc = uppercase(creator_name_usc);
1501 out <<
indent() <<
"#define " << creator_name_uc;
1502 out << generate_sandesh_async_creator(tsandesh,
false,
false,
true,
"_",
1503 "",
false,
false,
false, generate_sandesh_object);
1504 out <<
"\\" << endl;
1506 out <<
indent() << tsandesh->
get_name() <<
"::" << sender_func_name;
1507 out << generate_sandesh_async_creator(tsandesh,
false,
true,
false,
1508 "(_",
")",
true,
false,
false, generate_sandesh_object) << endl;
1510 indent(out) << endl << endl;
1513 creator_name = tsandesh->
get_name() + sender_func_name;
1514 if (generate_sandesh_object) {
1515 creator_name +=
"Sandesh";
1517 creator_name_usc = underscore(creator_name);
1518 creator_name_uc = uppercase(creator_name_usc);
1519 out <<
indent() <<
"#define " << creator_name_uc;
1520 out << generate_sandesh_async_creator(tsandesh,
false,
false,
true,
"_",
1521 "",
false,
true,
false, generate_sandesh_object);
1522 out <<
"\\" << endl;
1524 out <<
indent() << tsandesh->
get_name() <<
"::" << sender_func_name;
1525 out << generate_sandesh_async_creator(tsandesh,
false,
true,
false,
1526 "(_",
")",
true,
true,
false, generate_sandesh_object) << endl;
1528 indent(out) << endl << endl;
1531 void t_cpp_generator::generate_sandesh_rate_limit_fn(ofstream &out,
1533 out <<
indent() <<
"static bool IsRatelimitPass() {" << endl;
1535 generate_isRatelimitPass(out, tsandesh);
1537 indent(out) <<
"}" << endl << endl;
1540 void t_cpp_generator::generate_sandesh_systemlog_creators(ofstream &out,
1542 bool generate_sandesh_object =
false;
1543 bool generate_rate_limit =
true;
1544 bool generate_system_log =
true;
1546 generate_sandesh_async_send_fn(out, tsandesh, generate_sandesh_object,
1547 generate_rate_limit, generate_system_log);
1548 generate_sandesh_async_send_macros(out, tsandesh, generate_sandesh_object);
1550 generate_sandesh_static_drop_logger(out, tsandesh,
1551 generate_sandesh_object);
1553 generate_sandesh_static_logger(out, tsandesh, generate_sandesh_object);
1555 generate_sandesh_rate_limit_fn(out, tsandesh);
1558 void t_cpp_generator::generate_sandesh_objectlog_creators(ofstream &out,
1561 bool generate_sandesh_object =
false;
1562 bool generate_rate_limit =
false;
1563 bool generate_system_log =
false;
1565 generate_sandesh_async_send_fn(out, tsandesh, generate_sandesh_object,
1566 generate_rate_limit, generate_system_log);
1567 generate_sandesh_async_send_macros(out, tsandesh, generate_sandesh_object);
1569 generate_sandesh_static_drop_logger(out, tsandesh,
1570 generate_sandesh_object);
1572 generate_sandesh_static_logger(out, tsandesh, generate_sandesh_object);
1574 generate_sandesh_object =
true;
1576 generate_sandesh_async_create_fn(out, tsandesh);
1577 generate_sandesh_async_create_macro(out, tsandesh);
1579 generate_sandesh_async_send_fn(out, tsandesh, generate_sandesh_object,
1580 generate_rate_limit, generate_system_log);
1581 generate_sandesh_async_send_macros(out, tsandesh, generate_sandesh_object);
1583 generate_sandesh_static_drop_logger(out, tsandesh,
1584 generate_sandesh_object);
1586 generate_sandesh_static_logger(out, tsandesh, generate_sandesh_object);
1589 void t_cpp_generator::generate_sandesh_session_log_unrolled_fn(ofstream &out,
1592 out <<
indent() <<
"static void LogUnrolled";
1593 out << generate_sandesh_async_creator(tsandesh,
true,
false,
false,
"",
"",
1594 true,
false,
false,
false);
1598 void t_cpp_generator::generate_sandesh_session_adjust_session_end_point_objects_fn(ofstream &out,
1600 out <<
"static void adjust_session_end_point_objects(std::vector"
1601 " <SessionEndpoint> & session_data);" << endl;
1605 void t_cpp_generator::generate_sandesh_flow_send_fn(ofstream &out,
1607 std::string sender_func_name =
"Send";
1608 std::string logger_func_name =
"Log";
1610 out <<
indent() <<
"static void " << sender_func_name;
1611 out << generate_sandesh_async_creator(tsandesh,
true,
false,
false,
"",
"",
1612 true,
false,
false,
false);
1613 out <<
" {" << endl;
1615 out <<
indent() <<
"if (HandleTest(level, category)) {" << endl;
1617 out <<
indent() <<
"return;" << endl;
1619 out <<
indent() <<
"if (IsSendingAllMessagesDisabled() ||" <<
1620 " IsSendingFlowsDisabled()) {" << endl;
1622 out <<
indent() <<
"UpdateTxMsgFailStats(\"" << tsandesh->
get_name() <<
1623 "\", 0, SandeshTxDropReason::SendingDisabled);" << endl;
1624 out <<
indent() <<
"if (IsLoggingDroppedAllowed(SandeshType::FLOW))" <<
1627 out <<
indent() <<
"Log" <<
1628 generate_sandesh_async_creator(tsandesh,
false,
1629 false,
false,
"",
"",
false,
false,
false) <<
";" << endl;
1631 out <<
indent() <<
"return;" << endl;
1635 "if (is_send_slo_to_logger_enabled() || is_send_sampled_to_logger_enabled()) { " <<
1640 out <<
indent() <<
"LogUnrolled(category, level, session_data);" << endl;
1643 out <<
indent() <<
"if (level >= SendingLevel()) {" << endl;
1645 out <<
indent() <<
"UpdateTxMsgFailStats(\"" << tsandesh->
get_name() <<
1646 "\", 0, SandeshTxDropReason::QueueLevel);" << endl;
1647 out <<
indent() <<
"if (IsLoggingDroppedAllowed(SandeshType::FLOW))" <<
1650 out <<
indent() <<
"std::string drop_reason = \"SANDESH: Queue Drop:"
1652 out <<
indent() <<
"DropLog" <<
1653 generate_sandesh_async_creator(tsandesh,
false,
1654 false,
false,
"",
"",
false,
false,
true) <<
";" << endl;
1656 out <<
indent() <<
"return;" << endl;
1659 " * snh = new " << tsandesh->
get_name() <<
1660 generate_sandesh_no_static_const_string_function(tsandesh,
1661 false,
false,
false,
false) <<
";" << endl;
1663 out <<
indent() <<
"if (!is_send_sampled_to_collector_enabled() && !is_send_slo_to_collector_enabled()) {" << endl;
1665 out <<
indent() <<
"return;" << endl;
1667 out <<
indent() <<
" if (is_send_sampled_to_collector_enabled() != is_send_slo_to_collector_enabled()) {" << endl;
1669 out <<
indent() <<
"adjust_session_end_point_objects(snh->session_data);";
1673 out <<
indent() <<
"snh->set_level(level);" << endl;
1674 out <<
indent() <<
"snh->set_category(category);" << endl;
1675 out <<
indent() <<
"snh->Dispatch();" << endl;
1677 indent(out) <<
"}" << endl << endl;
1680 void t_cpp_generator::generate_sandesh_flow_creators(ofstream &out,
1682 bool generate_sandesh_object =
false;
1686 generate_sandesh_session_log_unrolled_fn(out, tsandesh);
1687 generate_sandesh_session_adjust_session_end_point_objects_fn(out, tsandesh);
1690 generate_sandesh_flow_send_fn(out, tsandesh);
1691 generate_sandesh_async_send_macros(out, tsandesh, generate_sandesh_object);
1693 generate_sandesh_static_drop_logger(out, tsandesh,
1694 generate_sandesh_object);
1696 generate_sandesh_static_logger(out, tsandesh, generate_sandesh_object);
1699 std::string t_cpp_generator::generate_sandesh_trace_creator(
t_sandesh *tsandesh,
1700 bool signature,
bool expand_autogen,
bool skip_autogen,
1701 std::string prefix, std::string suffix) {
1705 vector<t_field*>::const_iterator m_iter;
1706 const vector<t_field*>& members = tsandesh->
get_members();
1710 result +=
"SandeshTraceBufferPtr tracebuf";
1711 if (!skip_autogen) {
1712 result +=
", std::string file, int32_t line";
1715 result += prefix +
"trace_buf" + suffix;
1716 if (!skip_autogen) {
1717 if (expand_autogen) {
1718 result +=
", __FILE__, __LINE__";
1720 result +=
", " + prefix +
"file" + suffix +
", " +
1721 prefix +
"line" + suffix;
1726 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
1728 t_type* t = get_true_type((*m_iter)->get_type());
1729 if (t->is_static_const_string()) {
1732 if ((*m_iter)->get_auto_generated()) {
1739 result += declare_field(*m_iter,
false,
false, use_const,
1743 result += prefix + (*m_iter)->get_name() + suffix;
1757 void t_cpp_generator::generate_sandesh_member_init_list(ofstream& out,
1760 vector<t_field*>::const_iterator m_iter;
1761 const vector<t_field*>& members = tsandesh->
get_members();
1764 generate_sandesh_base_init(out, tsandesh, init_dval);
1766 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
1767 t_type* t = get_true_type((*m_iter)->get_type());
1772 if (t->is_static_const_string()) {
1785 }
else if (t->is_uuid()) {
1786 dval +=
"boost::uuids::nil_uuid()";
1787 }
else if (t->is_ipaddr()) {
1794 dval = render_const_value(out, (*m_iter)->get_name(), t, cv);
1797 dval = (*m_iter)->get_name();
1800 out <<
", " << (*m_iter)->get_name() <<
"(" << dval <<
")";
1811 void t_cpp_generator::generate_sandesh_seqnum(ofstream& out,
1815 indent(out) <<
"static tbb::atomic<uint32_t> lseqnum_;" << endl;
1817 indent(out) <<
"static uint32_t lseqnum_;" << endl;
1822 string generate_sandesh_base_name(
t_sandesh* tsandesh,
bool type) {
1826 return "SandeshType::REQUEST";
1828 return "SandeshRequest";
1830 }
else if (((
t_base_type *)t)->is_sandesh_response()) {
1832 return "SandeshType::RESPONSE";
1834 return "SandeshResponse";
1836 }
else if (((
t_base_type *)t)->is_sandesh_uve()) {
1838 return "SandeshType::UVE";
1840 return "SandeshUVE";
1842 }
else if (((
t_base_type *)t)->is_sandesh_alarm()) {
1844 return "SandeshType::ALARM";
1846 return "SandeshAlarm";
1848 }
else if (((
t_base_type *)t)->is_sandesh_system()) {
1850 return "SandeshType::SYSTEM";
1852 return "SandeshSystem";
1854 }
else if (((
t_base_type *)t)->is_sandesh_buffer()) {
1856 return "SandeshType::BUFFER";
1858 return "SandeshBuffer";
1860 }
else if (((
t_base_type *)t)->is_sandesh_trace() ||
1863 return "SandeshType::TRACE";
1865 return "SandeshTrace";
1867 }
else if (((
t_base_type *)t)->is_sandesh_object()) {
1869 return "SandeshType::OBJECT";
1871 return "SandeshObject";
1873 }
else if (((
t_base_type *)t)->is_sandesh_flow()) {
1876 return "SandeshType::SESSION";
1878 return "SandeshFlowSession";
1883 return "SandeshType::FLOW";
1885 return "SandeshFlow";
1899 void t_cpp_generator::generate_sandesh_versionsig(ofstream& out,
1901 indent(out) <<
"static uint32_t versionsig_;" << endl;
1904 void t_cpp_generator::generate_sandesh_base_init(
1905 ofstream& out,
t_sandesh* tsandesh,
bool init_dval) {
1906 out << generate_sandesh_base_name(tsandesh,
false);
1909 out <<
"(\"" << tsandesh->
get_name() <<
"\",lseqnum_++)";
1911 out <<
"(\"" << tsandesh->
get_name() <<
"\",seqno)";
1915 void t_cpp_generator::generate_sandesh_trace_seqnum_ctor(ofstream& out,
1917 indent(out) <<
"set_seqnum(0);" << endl;
1926 void t_cpp_generator::generate_sandesh_context(ofstream& out,
1929 indent(out) <<
"set_context(" << val <<
");" << endl;
1939 void t_cpp_generator::generate_sandesh_hints(ofstream& out,
1942 string shints =
"0";
1944 if (has_key_annotation) {
1945 shints +=
" | g_sandesh_constants.SANDESH_KEY_HINT";
1947 indent(out) <<
"set_hints(" << shints <<
");" << endl;
1956 void t_cpp_generator::generate_sandesh_default_ctor(ofstream& out,
1959 vector<t_field*>::const_iterator m_iter;
1960 const vector<t_field*>& members = tsandesh->
get_members();
1963 generate_sandesh_member_init_list(out, tsandesh,
true);
1964 out <<
" {" << endl;
1968 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
1969 t_type* t = get_true_type((*m_iter)->get_type());
1973 print_const_value(out, (*m_iter)->get_name(), t, cv);
1977 generate_sandesh_hints(out, tsandesh);
1979 generate_sandesh_context(out, tsandesh,
"\"\"");
1991 void t_cpp_generator::generate_sandesh_definition(ofstream& out,
1995 bool is_trace = ((
t_base_type *)t)->is_sandesh_trace() ||
1997 bool is_request = ((
t_base_type *)t)->is_sandesh_request();
1998 bool is_response = ((
t_base_type *)t)->is_sandesh_response();
1999 bool is_uve = ((
t_base_type *)t)->is_sandesh_uve();
2000 bool is_alarm = ((
t_base_type *)t)->is_sandesh_alarm();
2001 bool is_buffer = ((
t_base_type *)t)->is_sandesh_buffer();
2002 bool is_system = ((
t_base_type *)t)->is_sandesh_system();
2003 bool is_object = ((
t_base_type *)t)->is_sandesh_object();
2004 bool is_flow = ((
t_base_type *)t)->is_sandesh_flow();
2005 bool is_session = ((
t_base_type *)t)->is_sandesh_session();
2008 extends =
" : public SandeshRequest";
2009 }
else if (is_response) {
2010 extends =
" : public SandeshResponse";
2011 }
else if (is_uve) {
2012 extends =
" : public SandeshUVE";
2013 }
else if (is_alarm) {
2014 extends =
" : public SandeshAlarm";
2015 }
else if (is_system) {
2016 extends =
" : public SandeshSystem";
2017 }
else if (is_buffer) {
2018 extends =
" : public SandeshBuffer";
2019 }
else if (is_trace) {
2020 extends =
" : public SandeshTrace";
2021 }
else if (is_object) {
2022 extends =
" : public SandeshObject";
2023 }
else if (is_flow) {
2025 extends =
" : public SandeshFlowSession";
2027 extends =
" : public SandeshFlow";
2032 vector<t_field*>::const_iterator m_iter;
2033 const vector<t_field*>& members = tsandesh->
get_members();
2040 bool has_nonrequired_fields =
false;
2041 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
2043 has_nonrequired_fields =
true;
2046 if (has_nonrequired_fields) {
2049 indent() <<
"typedef struct _" << tsandesh->
get_name() <<
"__isset {" << endl;
2053 "_" << tsandesh->
get_name() <<
"__isset() ";
2055 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
2062 ": " << (*m_iter)->get_name() <<
"(false)";
2065 ", " << (*m_iter)->get_name() <<
"(false)";
2068 out <<
" {}" << endl;
2070 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
2073 "bool " << (*m_iter)->get_name() <<
";" << endl;
2079 "} _" << tsandesh->
get_name() <<
"__isset;" << endl;
2085 out <<
indent() <<
"class " << tsandesh->
get_name() << extends <<
" {" << endl;
2088 out <<
indent() <<
" public:" << endl;
2090 generate_sandesh_fingerprint(out, tsandesh,
false);
2094 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
2095 if (((*m_iter)->get_type())->is_static_const_string()) {
2098 out << endl <<
indent() <<
2099 "void set_" << (*m_iter)->get_name() <<
2100 "(" <<
type_name((*m_iter)->get_type(),
false,
true);
2101 out <<
" val) {" << endl <<
indent() <<
2102 indent() << (*m_iter)->get_name() <<
" = val;" << endl;
2109 (*m_iter)->get_name() <<
" = true;" << endl;
2111 out <<
indent() <<
"}" << endl;
2113 out << endl <<
indent() <<
2114 type_name((*m_iter)->get_type(),
false,
true)
2115 <<
" get_" << (*m_iter)->get_name() <<
2116 "() const {" << endl;
2118 (*m_iter)->get_name() <<
";" << endl;
2119 out <<
indent() <<
"}" << endl;
2126 indent() <<
"bool operator == (const " << tsandesh->
get_name() <<
" & " <<
2127 (members.size() > 0 ?
"rhs" :
"/* rhs */") <<
") const" << endl;
2129 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
2134 indent() <<
"if (!(" << (*m_iter)->get_name()
2135 <<
" == rhs." << (*m_iter)->get_name() <<
"))" << endl <<
2136 indent() <<
" return false;" << endl;
2139 indent() <<
"if (__isset." << (*m_iter)->get_name()
2140 <<
" != rhs.__isset." << (*m_iter)->get_name() <<
")" << endl <<
2141 indent() <<
" return false;" << endl <<
2142 indent() <<
"else if (__isset." << (*m_iter)->get_name() <<
" && !("
2143 << (*m_iter)->get_name() <<
" == rhs." << (*m_iter)->get_name()
2145 indent() <<
" return false;" << endl;
2148 indent(out) <<
"return true;" << endl;
2151 indent() <<
"bool operator != (const " << tsandesh->
get_name() <<
" &rhs) const {" << endl <<
2152 indent() <<
" return !(*this == rhs);" << endl <<
2153 indent() <<
"}" << endl << endl;
2157 out << endl <<
indent() <<
"virtual ~" <<
2158 tsandesh->
get_name() <<
"() {}" << endl << endl;
2162 if (has_nonrequired_fields) {
2164 "__isset __isset;" << endl;
2167 out <<
indent() <<
"virtual std::string ModuleName() const { " <<
2168 "return \"" << program_name_ <<
"\"; }" << endl << endl;
2173 generate_sandesh_default_ctor(out, tsandesh,
true);
2175 indent(out) <<
"SANDESH_REGISTER_DEC_TYPE(" << tsandesh->
get_name() <<
2177 out <<
indent() <<
"virtual void HandleRequest() const;" << endl;
2178 indent(out) <<
"virtual bool RequestFromHttp(" <<
2179 "const std::string& ctx, const std::string& snh_query);" << endl;
2182 out <<
indent() <<
"static void Request" <<
2183 generate_sandesh_no_static_const_string_function(tsandesh,
true,
true,
false, is_request,
true) <<
2187 " * snh = new " << tsandesh->
get_name() <<
2188 generate_sandesh_no_static_const_string_function(tsandesh,
false,
false,
false, is_request) <<
2190 out <<
indent() <<
"snh->Dispatch(sconn);" << endl;
2192 indent(out) <<
"}" << endl << endl;
2193 }
else if (is_response) {
2196 generate_sandesh_default_ctor(out, tsandesh,
false);
2198 string creator_func_name =
"Response";
2199 out <<
indent() <<
"void " << creator_func_name <<
2200 "() { Dispatch(); }" << endl;
2201 }
else if (is_uve || is_alarm) {
2202 const vector<t_field*>& fields = tsandesh->
get_members();
2203 vector<t_field*>::const_iterator f_iter = fields.begin();
2204 assert((*f_iter)->get_name() ==
"data");
2206 bool is_proxy =
false;
2207 std::map<std::string, std::string>::iterator ait;
2208 ait = ((*f_iter)->get_type())->annotations_.find(
"timeout");
2209 if (ait != ((*f_iter)->get_type())->annotations_.end()) {
2214 indent(out) <<
"static void Send(const " <<
type_name((*f_iter)->get_type()) <<
2215 "& data, std::string table = \"\", uint64_t mono_usec=0, int partition=-1);" << endl;
2216 indent(out) <<
"static void Send(const " <<
type_name((*f_iter)->get_type()) <<
2217 "& data, SandeshLevel::type Xlevel = SandeshLevel::SYS_NOTICE, " <<
2218 "std::string table = \"\", uint64_t mono_usec=0, int partition=-1);" << endl;
2219 std::map<std::string, std::string>::iterator pit;
2220 pit = ((*f_iter)->get_type())->annotations_.find(
"period");
2221 indent(out) <<
"static const uint64_t kProxyPeriod_us = " <<
2222 pit->second.c_str() <<
"000000;" << endl;
2225 indent(out) <<
"static void Send(const " <<
type_name((*f_iter)->get_type()) <<
2226 "& data, std::string table = \"\", uint64_t mono_usec=0);" << endl;
2227 indent(out) <<
"static void Send(const " <<
type_name((*f_iter)->get_type()) <<
2228 "& data, SandeshLevel::type Xlevel, " <<
2229 "std::string table = \"\", uint64_t mono_usec=0);" << endl;
2232 indent(out) <<
"static void Send(const " <<
type_name((*f_iter)->get_type()) <<
2233 "& cdata, SandeshUVE::SendType stype, uint32_t seqno," <<
2234 " uint32_t cycle, std::string ctx = \"\");" << endl;
2235 indent(out) <<
"static void Send(const " <<
type_name((*f_iter)->get_type()) <<
2236 "& cdata, SandeshLevel::type Xlevel, SandeshUVE::SendType stype, " <<
2237 "uint32_t seqno, uint32_t cycle, std::string ctx = \"\");" << endl;
2238 }
else if (is_system) {
2239 generate_sandesh_systemlog_creators(out, tsandesh);
2240 }
else if (is_flow) {
2241 generate_sandesh_flow_creators(out, tsandesh);
2242 }
else if (is_object) {
2243 generate_sandesh_objectlog_creators(out, tsandesh);
2244 }
else if (is_trace) {
2246 out <<
indent() <<
"virtual void SendTrace(" <<
2247 "const std::string& tcontext, bool more) {" << endl;
2249 indent(out) <<
"set_context(tcontext);" << endl;
2250 indent(out) <<
"set_more(more);" << endl;
2252 " * snh = new " << tsandesh->
get_name() <<
"(*this);" << endl;
2253 indent(out) <<
"snh->Dispatch();" << endl;
2255 indent(out) <<
"}" << endl << endl;
2257 string creator_func_name =
"TraceMsg";
2258 out << endl <<
indent() <<
"static void " << creator_func_name <<
2259 generate_sandesh_trace_creator(tsandesh,
true,
false,
false,
"",
"") <<
2260 ";" << endl << endl;
2261 string creator_macro_name = tsandesh->
get_name() +
"Trace";
2262 string creator_name_usc = underscore(creator_macro_name);
2263 string creator_name_uc = uppercase(creator_name_usc);
2264 out <<
indent() <<
"#define " << creator_name_uc <<
2265 generate_sandesh_trace_creator(tsandesh,
false,
false,
true,
"_",
"") <<
2268 out <<
indent() << tsandesh->
get_name() <<
"::" << creator_func_name <<
2269 generate_sandesh_trace_creator(tsandesh,
false,
true,
false,
"(_",
")") <<
2272 }
else if (is_buffer) {
2275 generate_sandesh_default_ctor(out, tsandesh,
false);
2277 indent(out) <<
"SANDESH_REGISTER_DEC_TYPE(" << tsandesh->
get_name() <<
2278 ");" << endl << endl;
2282 out <<
indent() <<
"virtual const int32_t versionsig() const { return versionsig_;}" << endl;
2283 out <<
indent() <<
"static const int32_t sversionsig() { return versionsig_;}" << endl;
2286 out <<
indent() <<
"static int32_t lseqnum() { return lseqnum_;}" << endl;
2289 if (is_uve || is_alarm) {
2290 const vector<t_field*>& fields = tsandesh->
get_members();
2291 vector<t_field*>::const_iterator f_iter = fields.begin();
2292 assert((*f_iter)->get_name() ==
"data");
2293 string dtype =
type_name((*f_iter)->get_type());
2295 "static std::map<std::string, std::string> _DSConf(void);" << endl;
2296 out <<
indent() <<
"static void _InitDerivedStats(" << dtype <<
2297 " & _data, const map<string,string> & _dsconf);" << endl;
2298 out <<
indent() <<
"static bool UpdateUVE(" << dtype <<
2299 " & _data, " << dtype <<
2300 " & tdata, uint64_t mono_usec, SandeshLevel::type Xlevel);" << endl;
2301 out <<
indent() <<
"bool LoadUVE(SendType stype, uint32_t cycle);" << endl;
2304 out <<
indent() <<
"std::string ToString() const;" << endl;
2306 out <<
indent() <<
"size_t GetSize() const;" << endl;
2310 out <<
"private:" << endl << endl;
2312 indent(out) <<
"virtual void Process(SandeshContext *context);" << endl << endl;
2313 }
else if (!((
t_base_type *)t)->is_sandesh_response()) {
2316 out << generate_sandesh_no_static_const_string_function(tsandesh,
true,
false,
false, is_request);
2317 generate_sandesh_member_init_list(out, tsandesh,
false);
2318 out <<
" {" << endl;
2322 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
2323 t_type* t = get_true_type((*m_iter)->get_type());
2327 print_const_value(out, (*m_iter)->get_name(), t, cv);
2332 generate_sandesh_trace_seqnum_ctor(out, tsandesh);
2335 generate_sandesh_context(out, tsandesh,
"context");
2336 out <<
indent() <<
"if (context == \"ctrl\") " <<
2337 "set_hints(g_sandesh_constants.SANDESH_CONTROL_HINT);" << endl;
2338 out <<
indent() <<
"else set_hints(0);" << endl;
2339 out <<
indent() <<
"(void)sconn;" << endl;
2342 generate_sandesh_hints(out, tsandesh);
2350 <<
"(uint32_t seqno," " std::string file, int32_t line) : ";
2351 generate_sandesh_base_init(out, tsandesh,
false);
2352 out <<
", file(file), line(line) {" << endl;
2354 generate_sandesh_hints(out, tsandesh);
2359 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
2360 indent(out) << declare_field(*m_iter,
false,
false,
false) << endl;
2364 generate_sandesh_seqnum(out, tsandesh);
2367 generate_sandesh_versionsig(out, tsandesh);
2369 out <<
indent() <<
"static const char *name_;" << endl;
2371 out <<
indent() <<
"void Log() const;" << endl;
2373 out <<
indent() <<
"void ForcedLog() const;" << endl;
2375 out <<
indent() <<
"int32_t Read(" <<
2376 "boost::shared_ptr<contrail::sandesh::protocol::TProtocol> iprot);" << endl;
2378 out <<
indent() <<
"int32_t Write(" <<
2379 "boost::shared_ptr<contrail::sandesh::protocol::TProtocol> oprot) const;" << endl;
2382 out <<
indent() <<
"static bool do_rate_limit_drop_log_;" << endl;
2384 out <<
indent() <<
"static boost::circular_buffer<time_t>"
2385 " rate_limit_buffer_;" << endl;
2387 out <<
indent() <<
"static tbb::mutex rate_limit_mutex_;" << endl;
2392 indent(out) <<
"};" << endl << endl;
2395 void t_cpp_generator::generate_sandesh_fingerprint(ofstream& out,
2397 bool is_definition) {
2398 string stat, nspace, comment;
2399 if (is_definition) {
2401 nspace = tsandesh->
get_name() +
"::";
2411 indent() << stat <<
"const char* " << nspace
2412 <<
"ascii_fingerprint" << comment <<
"= \"" <<
2414 indent() << stat <<
"const uint8_t " << nspace <<
2416 const char* comma =
"";
2421 out <<
"};" << endl << endl;
2425 void t_cpp_generator::cache_attr_info(
t_struct* tstruct,
2426 std::map<string, CacheAttribute> &attrs) {
2428 const vector<t_field*>& members = tstruct->
get_members();
2429 vector<t_field*>::const_iterator m_iter;
2430 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
2431 std::map<std::string, std::string>::iterator jt;
2432 jt = (*m_iter)->annotations_.find(
"hidden");
2436 assert(jt == (*m_iter)->annotations_.end());
2437 assert((*m_iter)->annotations_.find(
"stats") == (*m_iter)->annotations_.end());
2438 assert((*m_iter)->annotations_.find(
"mstats") == (*m_iter)->annotations_.end());
2439 attrs.insert(std::make_pair((*m_iter)->get_name(),
2444 if (((*m_iter)->annotations_.find(
"stats") != (*m_iter)->annotations_.end()) ||
2445 ((*m_iter)->annotations_.find(
"mstats") != (*m_iter)->annotations_.end())) {
2449 if (jt!=(*m_iter)->annotations_.end()) {
2450 attrs.insert(std::make_pair((*m_iter)->get_name(), HIDDEN));
2452 attrs.insert(std::make_pair((*m_iter)->get_name(), INLINE));
2457 void t_cpp_generator::derived_stats_info(
t_struct* tstruct,
2459 map<string,DSInfo> & dsmap,
2461 map<
string,set<string> >& rawmap) {
2462 const vector<t_field*>& members = tstruct->
get_members();
2463 vector<t_field*>::const_iterator m_iter;
2464 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
2465 std::map<std::string, std::string>::iterator jt,mt;
2466 jt = (*m_iter)->annotations_.find(
"stats");
2467 mt = (*m_iter)->annotations_.find(
"mstats");
2468 if ((jt != (*m_iter)->annotations_.end()) ||
2469 (mt != (*m_iter)->annotations_.end())) {
2472 t_type* retype = get_true_type((*m_iter)->get_type());
2475 bool is_ds_map =
false;
2477 if (mt!= (*m_iter)->annotations_.end()) {
2479 assert(jt == (*m_iter)->annotations_.end());
2481 assert(retype->is_map());
2483 restype =
type_name(get_true_type(vtype));
2485 restype =
type_name(get_true_type((*m_iter)->get_type()));
2488 const string &tstr = ((jt == (*m_iter)->annotations_.end()) ?
2489 mt->second : jt->second);
2490 size_t pos = tstr.find(
':');
2492 string residual = tstr.substr(pos+1, string::npos);
2493 size_t rpos = residual.find(
':');
2495 if (rpos == string::npos) {
2500 algo = residual.substr(0,rpos);
2501 anno = residual.substr(rpos+1, string::npos);
2505 string rawperiodattr = tstr.substr(0,pos);
2506 size_t ppos = rawperiodattr.find(
"-");
2509 if (ppos != string::npos) {
2510 string periodpre = rawperiodattr.substr(0,ppos);
2511 size_t prepos = periodpre.find(
".");
2512 if (prepos != string::npos) {
2513 period = atoi(periodpre.substr(0,prepos).c_str());
2514 prealgo = periodpre.substr(prepos+1, string::npos);
2516 period = atoi(rawperiodattr.substr(0,ppos).c_str());
2519 rawfullattr = rawperiodattr.substr(ppos+1, string::npos);
2521 rawfullattr = rawperiodattr;
2524 size_t cpos = rawfullattr.find(
'.');
2526 string compattr(
"");
2527 string subcompattr(
"");
2530 if (cpos != string::npos) {
2531 rawattr = rawfullattr.substr(0,cpos);
2532 string rescomp = rawfullattr.substr(cpos+1, string::npos);
2533 size_t upos = rescomp.find(
'.');
2534 if (upos != string::npos) {
2535 compattr = rescomp.substr(0,upos);
2536 subcompattr = rescomp.substr(upos+1, string::npos);
2541 rawattr = rawfullattr;
2545 RawMetric rmt = RM_DIAL;
2546 vector<t_field*>::const_iterator s_iter;
2547 for (s_iter = members.begin(); s_iter != members.end(); ++s_iter) {
2548 if (rawattr.compare((*s_iter)->get_name())==0) {
2549 map<string,string>::const_iterator cit =
2550 (*s_iter)->annotations_.find(
"metric");
2551 if (cit != (*s_iter)->annotations_.end()) {
2552 if (cit->second.compare(
"agg") == 0) rmt = RM_AGG;
2553 else if (cit->second.compare(
"diff") == 0) rmt = RM_DIFF;
2555 t_type* ratype = get_true_type((*s_iter)->get_type());
2558 assert(ratype->
is_map());
2559 vtype = ((
t_map*)ratype)->get_val_type();
2562 if (!compattr.empty()) {
2565 assert(vtype->is_struct());
2566 rawtype = string(
"");
2567 const vector<t_field*>& cmembers = ((
t_struct*)vtype)->get_members();
2568 vector<t_field*>::const_iterator c_iter;
2569 for (c_iter = cmembers.begin(); c_iter != cmembers.end(); ++c_iter) {
2570 if (compattr.compare((*c_iter)->get_name())==0) {
2571 t_type* catype = get_true_type((*c_iter)->get_type());
2572 if (!subcompattr.empty()) {
2575 const vector<t_field*>& umem =
2576 ((
t_struct*)catype)->get_members();
2577 vector<t_field*>::const_iterator u_iter;
2578 for (u_iter = umem.begin(); u_iter != umem.end(); ++u_iter) {
2579 if (subcompattr.compare((*u_iter)->get_name())==0) {
2580 t_type* uatype = get_true_type((*u_iter)->get_type());
2596 assert(!rawtype.empty());
2599 (*m_iter)->annotations_.find(
"hidden") != (*m_iter)->annotations_.end();
2601 CacheAttribute cat = INLINE;
2604 if (period==-1) period=1;
2606 if (period!=0) cat = HIDDEN_PER;
2609 if (period!=0) cat = PERIODIC;
2614 if (period==-1) period=0;
2622 DSInfo dsi(is_ds_map, period, cat, rawtype, rmt,
2623 restype, algo, anno, compattr, subcompattr, prealgo);
2626 dsmap.insert(make_pair((*m_iter)->get_name(), dsi));
2629 map<string,set<string> >::iterator r_iter = rawmap.find(rawattr);
2630 if (r_iter != rawmap.end()) {
2631 r_iter->second.insert((*m_iter)->get_name());
2634 dss.insert((*m_iter)->get_name());
2635 rawmap.insert(make_pair(rawattr,dss));
2653 string extends =
"";
2655 extends =
" : public ::contrail::sandesh::TException";
2659 vector<t_field*>::const_iterator m_iter;
2660 const vector<t_field*>& members = tstruct->
get_members();
2667 bool has_nonrequired_fields =
false;
2668 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
2670 has_nonrequired_fields =
true;
2673 bool del_support =
false;
2674 bool proxy_support =
false;
2675 if (has_nonrequired_fields && (!pointers || read)) {
2678 indent() <<
"typedef struct _" << tstruct->
get_name() <<
"__isset {" << endl;
2682 "_" << tstruct->
get_name() <<
"__isset() ";
2684 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
2688 t_type* t = get_true_type((*m_iter)->get_type());
2690 ((*m_iter)->get_name().compare(
"deleted") == 0)) {
2695 ((*m_iter)->get_name().compare(
"proxy") == 0)) {
2703 ": " << (*m_iter)->
get_name() <<
"(false)";
2706 ", " << (*m_iter)->get_name() <<
"(false)";
2709 out <<
" {}" << endl;
2711 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
2714 "bool " << (*m_iter)->get_name() <<
";" << endl;
2720 "} _" << tstruct->
get_name() <<
"__isset;" << endl << endl;
2728 indent() <<
"class " << tstruct->
get_name() << extends <<
" {" << endl <<
2729 indent() <<
" public:" << endl <<
2734 generate_struct_fingerprint(out, tstruct,
false);
2737 bool is_table =
false;
2739 std::map<string, CacheAttribute> cache_attrs;
2740 cache_attr_info(tstruct, cache_attrs);
2742 map<string,DSInfo> dsinfo;
2743 map<string,set<string> > rawmap;
2744 derived_stats_info(tstruct, dsinfo, rawmap);
2745 map<string,DSInfo >::iterator ds_iter;
2751 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
2752 if ((*m_iter)->get_name() ==
"name") {
2753 std::map<std::string, std::string>::iterator it;
2754 it = (*m_iter)->annotations_.find(
"key");
2755 if (it != (*m_iter)->annotations_.end()) {
2757 indent(out) << tstruct->
get_name() <<
"(std::string __tbl = \"" <<
2758 it->second <<
"\")";
2772 bool init_ctor =
false;
2774 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
2775 t_type* t = get_true_type((*m_iter)->get_type());
2777 if (t->is_static_const_string()) {
2788 }
else if (t->is_uuid()) {
2789 dval +=
"boost::uuids::nil_uuid()";
2790 }
else if (t->is_ipaddr()) {
2797 dval = render_const_value(out, (*m_iter)->get_name(), t, cv);
2802 out << (*m_iter)->get_name() <<
"(" << dval <<
")";
2804 out <<
", " << (*m_iter)->get_name() <<
"(" << dval <<
")";
2811 out <<
", table_(__tbl)";
2814 out <<
" {" << endl;
2818 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
2819 t_type* t = get_true_type((*m_iter)->get_type());
2824 print_const_value(out, (*m_iter)->get_name(), t, cv);
2834 indent() <<
"virtual ~" << tstruct->
get_name() <<
"() throw() {}" << endl << endl;
2840 "static ::contrail::sandesh::reflection::local::TypeSpec* local_reflection;" <<
2845 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
2847 declare_field(*m_iter,
false, pointers && !(*m_iter)->get_type()->is_xception(), !read) << endl;
2850 for (ds_iter = dsinfo.begin(); ds_iter != dsinfo.end(); ++ds_iter) {
2853 if ((ds_iter->second.cat_ == PERIODIC) ||
2854 (ds_iter->second.cat_ == HIDDEN_PER)) {
2855 if (ds_iter->second.prealgo_.empty()) {
2856 indent(out) <<
"boost::shared_ptr< ::contrail::sandesh::DerivedStatsPeriodicIf< ::contrail::sandesh::" <<
2857 ds_iter->second.algo_ <<
", " <<
2858 ds_iter->second.rawtype_ <<
", " <<
2859 ds_iter->second.resulttype_.substr(0, ds_iter->second.resulttype_.size() - 3) <<
", " <<
2860 ds_iter->second.resulttype_ <<
2861 "> > __dsobj_" << ds_iter->first <<
";" << endl;
2863 indent(out) <<
"boost::shared_ptr< ::contrail::sandesh::DerivedStatsPeriodicAnomalyIf< ::contrail::sandesh::" <<
2864 ds_iter->second.algo_ <<
", " <<
2865 ds_iter->second.rawtype_ <<
", ::contrail::sandesh::" <<
2866 ds_iter->second.prealgo_ <<
", " <<
2867 ds_iter->second.resulttype_ <<
2868 "> > __dsobj_" << ds_iter->first <<
";" << endl;
2871 indent(out) <<
"boost::shared_ptr< ::contrail::sandesh::DerivedStatsIf< ::contrail::sandesh::" <<
2872 ds_iter->second.algo_ <<
", " <<
2873 ds_iter->second.rawtype_ <<
", " << ds_iter->second.resulttype_ <<
2874 "> > __dsobj_" << ds_iter->first <<
";" << endl;
2879 indent(out) <<
"std::string table_;" << endl;
2885 if (has_nonrequired_fields && (!pointers || read)) {
2888 indent() <<
"_" << tstruct->
get_name() <<
"__isset __isset;" << endl;
2893 vector<string> dskeys;
2894 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
2899 if (((*m_iter)->get_type())->is_static_const_string()) {
2902 std::map<std::string, std::string>::iterator jt;
2903 jt = (*m_iter)->annotations_.find(
"aggtype");
2904 if (jt != (*m_iter)->annotations_.end()) {
2905 if (jt->second.compare(
"listkey")==0) {
2906 dskeys.push_back((*m_iter)->get_name());
2913 indent() << (dsinfo.find((*m_iter)->get_name()) == dsinfo.end() ?
2914 "void set_" :
"void __set_") << (*m_iter)->get_name() <<
2916 indent() <<
"void __set_" << (*m_iter)->get_name() <<
2918 "(" <<
type_name((*m_iter)->get_type(),
false,
true);
2919 out <<
" val) {" << endl <<
indent() <<
2920 indent() << (*m_iter)->get_name() <<
" = val;" << endl;
2928 indent() <<
"__isset." << (*m_iter)->get_name() <<
" = true;" << endl;
2934 out << endl <<
indent() <<
type_name((*m_iter)->get_type(),
false,
true)
2936 out << (*m_iter)->get_name() <<
"() const {" << endl;
2937 out <<
indent() <<
indent() <<
"return " << (*m_iter)->get_name() <<
";" << endl;
2938 out <<
indent() <<
"}" << endl;
2945 indent() <<
"bool operator == (long " <<
2946 (members.size() > 0 ?
"rhs" :
"/* rhs */") <<
") const" << endl;
2948 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
2951 t_type* type = get_true_type((*m_iter)->get_type());
2959 case t_base_type::TYPE_U16:
2960 case t_base_type::TYPE_U32:
2961 case t_base_type::TYPE_U64:
2965 indent() <<
"if (!((long)" << (*m_iter)->get_name()
2966 <<
" == rhs))" << endl <<
2967 indent() <<
" return false;" << endl;
2970 indent() <<
"if (__isset." << (*m_iter)->get_name()
2972 << (*m_iter)->get_name() <<
" == rhs))" << endl <<
2973 indent() <<
" return false;" << endl;
2977 out <<
indent() <<
"return false;" << endl;
2982 indent(out) <<
"return true;" << endl;
2987 indent() <<
"bool operator == (const " << tstruct->
get_name() <<
" & " <<
2988 (members.size() > 0 ?
"rhs" :
"/* rhs */") <<
") const" << endl;
2990 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
2995 indent() <<
"if (!(" << (*m_iter)->get_name()
2996 <<
" == rhs." << (*m_iter)->get_name() <<
"))" << endl <<
2997 indent() <<
" return false;" << endl;
3000 indent() <<
"if (__isset." << (*m_iter)->get_name()
3001 <<
" != rhs.__isset." << (*m_iter)->get_name() <<
")" << endl <<
3002 indent() <<
" return false;" << endl <<
3003 indent() <<
"else if (__isset." << (*m_iter)->get_name() <<
" && !("
3004 << (*m_iter)->get_name() <<
" == rhs." << (*m_iter)->get_name()
3006 indent() <<
" return false;" << endl;
3009 indent(out) <<
"return true;" << endl;
3012 indent() <<
"bool operator != (const " << tstruct->
get_name() <<
" &rhs) const {" << endl <<
3013 indent() <<
" return !(*this == rhs);" << endl <<
3014 indent() <<
"}" << endl << endl;
3020 indent() <<
"bool operator < (const "
3021 << tstruct->
get_name() <<
" & ) const;" << endl << endl;
3025 if (gen_templates_) {
3027 indent() <<
"template <class Protocol_>" << endl <<
3028 indent() <<
"uint32_t read(Protocol_* iprot);" << endl;
3031 indent() <<
"int32_t read(" <<
3032 "boost::shared_ptr<contrail::sandesh::protocol::TProtocol> iprot);" << endl;
3036 if (gen_templates_) {
3038 indent() <<
"template <class Protocol_>" << endl <<
3039 indent() <<
"uint32_t write(Protocol_* oprot) const;" << endl;
3042 indent() <<
"int32_t write(" <<
3043 "boost::shared_ptr<contrail::sandesh::protocol::TProtocol> oprot) const;" << endl;
3047 out <<
indent() <<
"std::string log() const;" << endl;
3051 "& right) const" << endl;
3054 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
3055 std::string nn = (*m_iter)->get_name();
3056 ds_iter = dsinfo.find((*m_iter)->get_name());
3058 if (ds_iter == dsinfo.end()) sn = std::string(
"set_");
3059 else sn = std::string(
"__set_");
3061 t_type* type = get_true_type((*m_iter)->get_type());
3070 case t_base_type::TYPE_U16:
3071 case t_base_type::TYPE_U32:
3072 case t_base_type::TYPE_U64:
3075 indent() <<
"result." << sn << nn <<
"(get_" << nn <<
3076 "() + right.get_" << nn <<
"());" << endl << endl;
3079 indent() <<
"if ((__isset." << nn <<
") && (right.__isset." <<
3080 nn <<
")) result." << sn << nn <<
"(get_" << nn <<
3081 "() + right.get_" << nn <<
"());" << endl <<
3082 indent() <<
"else if (__isset." << nn <<
") result." << sn <<
3083 nn <<
"(get_" << nn <<
"());" << endl <<
3084 indent() <<
"else if (right.__isset." << nn <<
") result." << sn <<
3085 nn <<
"(right.get_" << nn <<
"());" << endl << endl;
3092 indent(out) <<
"return result;" << endl;
3096 tstruct->
get_name() <<
" operator/(int div) const" << endl;
3099 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
3100 std::string nn = (*m_iter)->get_name();
3101 ds_iter = dsinfo.find((*m_iter)->get_name());
3103 if (ds_iter == dsinfo.end()) sn = std::string(
"set_");
3104 else sn = std::string(
"__set_");
3106 t_type* type = get_true_type((*m_iter)->get_type());
3115 case t_base_type::TYPE_U16:
3116 case t_base_type::TYPE_U32:
3117 case t_base_type::TYPE_U64:
3120 indent() <<
"result." << sn << nn <<
"(get_" << nn <<
3121 "() / div);" << endl << endl;
3124 indent() <<
"if (__isset." << nn <<
") result." << sn << nn <<
"(get_" <<
3125 nn <<
"() / div);" << endl << endl;
3132 indent(out) <<
"return result;" << endl;
3137 "& right) const" << endl;
3140 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
3141 std::string nn = (*m_iter)->get_name();
3142 ds_iter = dsinfo.find((*m_iter)->get_name());
3144 if (ds_iter == dsinfo.end()) sn = std::string(
"set_");
3145 else sn = std::string(
"__set_");
3146 t_type* type = get_true_type((*m_iter)->get_type());
3155 case t_base_type::TYPE_U16:
3156 case t_base_type::TYPE_U32:
3157 case t_base_type::TYPE_U64:
3160 indent() <<
"result." << sn << nn <<
"(get_" << nn <<
3161 "() - right.get_" << nn <<
"());" << endl << endl;
3164 indent() <<
"if ((__isset." << nn <<
") && (right.__isset." <<
3165 nn <<
")) {" << endl <<
3166 indent() <<
" result." << sn << nn <<
"(get_" << nn <<
3167 "() - right.get_" << nn <<
"()); }" << endl <<
3168 indent() <<
"else if (__isset." << nn <<
") result." << sn <<
3169 nn <<
"(get_" << nn <<
"());" << endl;
3176 indent(out) <<
"return result;" << endl;
3179 out <<
indent() <<
"size_t GetSize() const;" << endl;
3180 out <<
indent() <<
"std::string __listkey(void) {" << endl;
3181 out <<
indent() <<
" std::string __result;" << endl;
3183 vector<string>::iterator kit;
3184 for (kit = dskeys.begin(); kit != dskeys.end(); kit++) {
3186 out <<
indent() <<
" __result.append(\":\");" << endl;
3188 out <<
indent() <<
" __result += " << *kit <<
";" << endl;
3191 out <<
indent() <<
" return __result;" << endl;
3192 out <<
indent() <<
"}" << endl;
3203 indent() <<
"template <>" << endl <<
3204 indent() <<
"struct SandeshStructDeleteTrait<" <<
3205 tstruct->
get_name() <<
"> {" << endl <<
3206 indent() <<
" static bool get(const " <<
3207 tstruct->
get_name() <<
"& s) { return s.get_deleted(); }" <<
3209 indent() <<
"};" << endl;
3211 if (proxy_support) {
3213 indent() <<
"template <>" << endl <<
3214 indent() <<
"struct SandeshStructProxyTrait<" <<
3215 tstruct->
get_name() <<
"> {" << endl <<
3216 indent() <<
" static std::string get(const " <<
3217 tstruct->
get_name() <<
"& s) { return s.get_proxy(); }" <<
3219 indent() <<
"};" << endl;
3231 bool is_definition) {
3232 string stat, nspace, comment;
3233 if (is_definition) {
3235 nspace = tstruct->
get_name() +
"::";
3245 indent() << stat <<
"const char* " << nspace
3246 <<
"ascii_fingerprint" << comment <<
"= \"" <<
3248 indent() << stat <<
"const uint8_t " << nspace <<
3250 const char* comma =
"";
3255 out <<
"};" << endl << endl;
3264 bool is_definition) {
3268 ttype = get_true_type(ttype);
3272 if (!reflected_fingerprints_.insert(key).second) {
3282 generate_local_reflection(out, ((
t_list*)ttype)->get_elem_type(), is_definition);
3283 }
else if (ttype->
is_set()) {
3284 generate_local_reflection(out, ((
t_set*)ttype)->get_elem_type(), is_definition);
3285 }
else if (ttype->
is_map()) {
3286 generate_local_reflection(out, ((
t_map*)ttype)->get_key_type(), is_definition);
3287 generate_local_reflection(out, ((
t_map*)ttype)->get_val_type(), is_definition);
3294 const vector<t_field*>& members = ((
t_struct*)ttype)->get_sorted_members();
3295 vector<t_field*>::const_iterator m_iter;
3296 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
3297 generate_local_reflection(out, (**m_iter).get_type(), is_definition);
3299 generate_local_reflection(out,
g_type_void, is_definition);
3302 if (is_definition) {
3304 indent() <<
"::contrail::sandesh::reflection::local::FieldMeta" << endl <<
3305 indent() << local_reflection_name(
"metas", ttype) <<
"[] = {" << endl;
3307 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
3308 indent(out) <<
"{ " << (*m_iter)->get_key() <<
", " <<
3313 indent(out) <<
"{ 0, false }" << endl <<
"};" << endl;
3317 indent() <<
"::contrail::sandesh::reflection::local::TypeSpec*" << endl <<
3318 indent() << local_reflection_name(
"specs", ttype) <<
"[] = {" << endl;
3320 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
3322 local_reflection_name(
"typespec", (*m_iter)->get_type(),
true) <<
"," << endl;
3325 local_reflection_name(
"typespec",
g_type_void) <<
"," << endl;
3327 indent(out) <<
"};" << endl;
3333 indent() << (is_definition ?
"" :
"extern ") <<
3334 "::contrail::sandesh::reflection::local::TypeSpec" << endl <<
3335 local_reflection_name(
"typespec", ttype) <<
3336 (is_definition ?
"(" :
";") << endl;
3338 if (!is_definition) {
3346 indent(out) <<
"::contrail::sandesh::protocol::T_STOP";
3348 indent(out) << type_to_enum(ttype);
3352 out <<
"," << endl <<
3354 indent() << local_reflection_name(
"metas", ttype) <<
"," << endl <<
3355 indent() << local_reflection_name(
"specs", ttype);
3356 }
else if (ttype->
is_list()) {
3357 out <<
"," << endl <<
3358 indent() <<
"&" << local_reflection_name(
"typespec", ((
t_list*)ttype)->get_elem_type(),
true) <<
"," << endl <<
3360 }
else if (ttype->
is_set()) {
3361 out <<
"," << endl <<
3362 indent() <<
"&" << local_reflection_name(
"typespec", ((
t_set*)ttype)->get_elem_type(),
true) <<
"," << endl <<
3364 }
else if (ttype->
is_map()) {
3365 out <<
"," << endl <<
3366 indent() <<
"&" << local_reflection_name(
"typespec", ((
t_map*)ttype)->get_key_type(),
true) <<
"," << endl <<
3367 indent() <<
"&" << local_reflection_name(
"typespec", ((
t_map*)ttype)->get_val_type(),
true);
3370 out <<
");" << endl << endl;
3385 "::contrail::sandesh::reflection::local::TypeSpec* " <<
3386 ttype->
get_name() <<
"::local_reflection = " << endl <<
3387 indent() <<
" &" << local_reflection_name(
"typespec", ttype) <<
";" <<
3400 if (gen_templates_) {
3402 indent() <<
"template <class Protocol_>" << endl <<
3404 "::read(Protocol_* iprot) {" << endl;
3407 "int32_t " << tstruct->
get_name() <<
3408 "::read(boost::shared_ptr<contrail::sandesh::protocol::TProtocol> iprot) {" << endl;
3411 generate_common_struct_reader_body(out, tstruct, pointers);
3414 "}" << endl << endl;
3426 if (gen_templates_) {
3428 indent() <<
"template <class Protocol_>" << endl <<
3430 "::write(Protocol_* oprot) const {" << endl;
3433 "int32_t " << tstruct->
get_name() <<
3434 "::write(boost::shared_ptr<contrail::sandesh::protocol::TProtocol> oprot) const {" << endl;
3437 generate_common_struct_writer_body(out, tstruct, pointers);
3451 void t_cpp_generator::generate_struct_get_size(ofstream& out,
const string& name,
3452 const vector<t_field*>& fields) {
3454 indent(out) <<
"size_t " << name <<
3455 "::GetSize() const {" << endl;
3457 indent(out) <<
"size_t size = 0;" << endl;
3458 vector<t_field*>::const_iterator f_iter;
3459 for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
3460 generate_get_size_field(out, *f_iter);
3462 indent(out) <<
"return size;" << endl;
3464 indent(out) <<
"}" << endl << endl;
3473 void t_cpp_generator::generate_struct_logger(ofstream& out,
const string& name,
3474 const vector<t_field*>& fields) {
3475 indent(out) <<
"std::string " << name <<
3476 "::log() const {" << endl;
3478 out <<
indent() <<
"std::stringstream Xbuf;" << endl;
3479 vector<t_field*>::const_iterator f_iter;
3481 for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
3482 string prefix =
"\" \" << ";
3487 generate_logger_field(out, *f_iter, prefix,
false,
false);
3490 out <<
indent() <<
"return std::string();" << endl;
3492 out <<
indent() <<
"return Xbuf.str();" << endl;
3495 indent(out) <<
"}" << endl << endl;
3504 void t_cpp_generator::generate_static_const_string_definition(ofstream& out,
3506 const vector<t_field*>& fields) {
3507 vector<t_field*>::const_iterator f_iter;
3508 for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
3509 if (!((*f_iter)->get_type())->is_static_const_string()) {
3516 print_const_value(out, (*f_iter)->get_name(), (*f_iter)->get_type(), cv);
3526 void t_cpp_generator::generate_static_const_string_definition(ofstream& out,
3528 generate_static_const_string_definition(out, tsandesh->
get_name(),
3537 void t_cpp_generator::generate_static_const_string_definition(ofstream& out,
3539 generate_static_const_string_definition(out, tstruct->
get_name(),
3543 void t_cpp_generator::generate_sandesh_static_seqnum_def(ofstream& out,
3547 out <<
"tbb::atomic<uint32_t> " << tsandesh->
get_name() <<
"::lseqnum_;" << endl;
3549 out <<
"uint32_t " << tsandesh->
get_name() <<
"::lseqnum_ = 1;" << endl;
3553 void t_cpp_generator::generate_sandesh_static_versionsig_def(ofstream& out,
3555 out <<
"uint32_t " << tsandesh->
get_name() <<
"::versionsig_ = "
3559 void t_cpp_generator::generate_sandesh_static_rate_limit_buffer_def(
3561 out <<
"boost::circular_buffer<time_t> " << tsandesh->
get_name() <<
3562 "::rate_limit_buffer_(Sandesh::get_send_rate_limit());" << endl << endl;
3565 void t_cpp_generator::generate_sandesh_static_rate_limit_mutex_def(
3567 out <<
"tbb::mutex " << tsandesh->
get_name() <<
"::rate_limit_mutex_; "
3571 void t_cpp_generator::generate_sandesh_static_rate_limit_log_def(
3573 out <<
"bool " << tsandesh->
get_name() <<
"::do_rate_limit_drop_log_ = true;"
3584 void t_cpp_generator::generate_sandesh_http_reader(ofstream& out,
3586 indent(out) <<
"#include <boost/tokenizer.hpp>" << endl;
3587 indent(out) <<
"#include <base/util.h>" << endl << endl;
3588 indent(out) <<
"bool " << tsandesh->
get_name() <<
"::RequestFromHttp" <<
3589 "(const std::string& ctx, const std::string& snh_query) {" << endl;
3593 const vector<t_field*>& fields = tsandesh->
get_members();
3594 vector<t_field*>::const_iterator f_iter;
3596 indent(out) << program_name_ <<
"_marker = 0;" << endl;
3599 indent() <<
"using std::string;" << endl <<
3600 indent() <<
"boost::char_separator<char> sep(\"&\");" << endl <<
3601 indent() <<
"boost::char_separator<char> varsep(\"=\");" << endl <<
3603 indent() <<
"CURL * cr = curl_easy_init();" <<
3604 indent() <<
"boost::tokenizer<boost::char_separator<char> >" <<
3605 "tokens(snh_query, sep);" << endl <<
3606 indent() <<
"boost::tokenizer<boost::char_separator<char> >" <<
3607 "::iterator it1 = tokens.begin();" << endl << endl;
3609 indent(out) <<
"string entity_name;" << endl;
3610 indent(out) <<
"int fields_vector_size =" << fields.size() <<
";" << endl;
3614 indent(out) <<
"for(int i =0; i < fields_vector_size; i++)" << endl;
3616 indent(out) <<
"if (it1 != tokens.end())" << endl;
3618 indent(out) <<
"string tok = (*it1++).c_str();" << endl ;
3619 indent(out) <<
"boost::tokenizer<boost::char_separator<char> >" <<
3620 " var(tok, varsep);" << endl;
3621 indent(out) <<
"boost::tokenizer<boost::char_separator<char> >" <<
3622 "::iterator it2 = var.begin();" << endl << endl;
3624 indent(out) <<
"string tok_new = (*it2).c_str();" << endl;
3625 indent(out) <<
"if (it2 != var.end()&& ++it2 != var.end()) " << endl;
3629 indent(out) <<
"char *unescaped = NULL;" << endl;
3630 indent(out) <<
"unescaped = (char*) (malloc(sizeof(char)*1024));" <<endl;
3632 indent(out) <<
"std::string tmpstr;" << endl;
3634 for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter)
3636 t_type *ftype = (*f_iter)->get_type();
3640 if (btype->
is_string() || btype->is_xml())
3642 indent(out) <<
"entity_name=\"" << (*f_iter)->get_name() <<
"\";" << endl;
3643 indent(out) <<
"if((tok_new.substr(0,(entity_name.length()))).compare(entity_name) == 0)" << endl;
3645 indent(out) <<
"unescaped = curl_easy_unescape(cr, (*it2).c_str(), 0, NULL);" << endl;
3646 indent(out) <<
"tmpstr=unescaped;" << endl;
3647 indent(out) << (*f_iter)->get_name() <<
" = boost::lexical_cast<std::string>((tmpstr));" << endl;
3648 indent(out) <<
"curl_free(unescaped);" << endl;
3650 indent(out) <<
"continue;" << endl;
3653 else if (btype->is_uuid())
3655 indent(out) <<
"entity_name=\"" << (*f_iter)->get_name() <<
"\";" << endl;
3656 indent(out) <<
"if((tok_new.substr(0,(entity_name.length()))).compare(entity_name) == 0)" << endl;
3658 indent(out) <<
"std::stringstream ss;" << endl;
3659 indent(out) <<
"ss << *it2;" << endl;
3660 indent(out) <<
"ss >> " << (*f_iter)->get_name() <<
";" << endl;
3661 indent(out) <<
"continue;" << endl;
3664 else if (btype->is_ipaddr())
3666 indent(out) <<
"entity_name=\"" << (*f_iter)->get_name() <<
"\";" << endl;
3667 indent(out) <<
"if((tok_new.substr(0,(entity_name.length()))).compare(entity_name) == 0)" << endl;
3669 indent(out) <<
"boost::system::error_code ec;" << endl;
3670 indent(out) << (*f_iter)->get_name() <<
3671 " = boost::asio::ip::address::from_string((*it2), ec);" << endl;
3672 indent(out) <<
"continue;" << endl;
3677 indent(out) <<
"entity_name=\"" << (*f_iter)->get_name() <<
"\";" << endl;
3678 indent(out) <<
"if((tok_new.substr(0,(entity_name.length()))).compare(entity_name) == 0)" << endl;
3680 assert(btype->is_integer());
3681 indent(out) <<
"stringToInteger((*it2), " << (*f_iter)->get_name() <<
");" << endl;
3682 indent(out) <<
"continue;" << endl;
3689 indent(out) <<
"++it2;" << endl;
3692 vector<t_field*>::const_iterator f_iter2 = fields.begin();
3693 if (f_iter2 != fields.end())
3695 t_type *ftype = (*f_iter2)->get_type();
3699 if (btype->
is_string() || btype->is_xml())
3701 indent(out) <<
"entity_name=\"" << (*f_iter2)->get_name() <<
"\";" << endl;
3702 indent(out) <<
"unescaped = curl_easy_unescape(cr, (*it2).c_str(), 0, NULL);" << endl;
3703 indent(out) <<
"tmpstr=unescaped;" << endl;
3704 indent(out) << (*f_iter2)->get_name() <<
" = boost::lexical_cast<std::string>((tmpstr));" << endl;
3705 indent(out) <<
"curl_free(unescaped);" << endl;
3706 indent(out) <<
"continue;" << endl;
3709 else if (btype->is_uuid())
3711 indent(out) <<
"entity_name=\"" << (*f_iter2)->get_name() <<
"\";" << endl;
3712 indent(out) <<
"std::stringstream ss;" << endl;
3713 indent(out) <<
"ss << *it2;" << endl;
3714 indent(out) <<
"ss >> " << (*f_iter2)->get_name() <<
";" << endl;
3715 indent(out) <<
"continue;" << endl;
3717 else if (btype->is_ipaddr())
3719 indent(out) <<
"entity_name=\"" << (*f_iter2)->get_name() <<
"\";" << endl;
3720 indent(out) <<
"boost::system::error_code ec;" << endl;
3721 indent(out) << (*f_iter2)->get_name() <<
3722 " = boost::asio::ip::address::from_string((*it2), ec);" << endl;
3723 indent(out) <<
"continue;" << endl;
3727 indent(out) <<
"entity_name=\"" << (*f_iter2)->get_name() <<
"\";" << endl;
3728 assert(btype->is_integer());
3729 indent(out) <<
"stringToInteger((*it2), " << (*f_iter2)->get_name() <<
");" << endl;
3730 indent(out) <<
"continue;" << endl;
3734 indent(out) <<
"free(unescaped);" << endl;
3740 indent(out) <<
"set_context(ctx);" << endl;
3741 indent(out) <<
"curl_easy_cleanup(cr);" << endl;
3742 indent(out) <<
"return true;" << endl;
3744 indent(out) <<
"}" << endl << endl;
3754 void t_cpp_generator::generate_sandesh_updater(ofstream& out,
3757 const vector<t_field*>& fields = tsandesh->
get_members();
3758 vector<t_field*>::const_iterator f_iter = fields.begin();
3759 assert((*f_iter)->get_name() ==
"data");
3761 bool periodic_ustruct =
false;
3763 std::map<std::string, std::string>::iterator ait;
3764 ait = ((*f_iter)->get_type())->annotations_.find(
"period");
3765 if (ait != ((*f_iter)->get_type())->annotations_.end()) periodic_ustruct =
true;
3767 string dtype =
type_name((*f_iter)->get_type());
3768 t_type* t = get_true_type((*f_iter)->get_type());
3769 assert(t->is_struct());
3773 map<string,DSInfo> dsinfo;
3774 map<string,set<string> > rawmap;
3775 derived_stats_info(ts, dsinfo, rawmap);
3777 std::map<string, CacheAttribute> cache_attrs;
3778 cache_attr_info(ts, cache_attrs);
3780 const vector<t_field*>& sfields = ts->get_members();
3781 vector<t_field*>::const_iterator s_iter;
3784 "::LoadUVE(SendType stype, uint32_t cycle) {" << endl;
3786 indent(out) <<
"(void)cycle;" << endl;
3787 indent(out) <<
"bool is_periodic_attr = false;" << endl << endl;
3789 for (s_iter = sfields.begin(); s_iter != sfields.end(); ++s_iter) {
3790 string snm = (*s_iter)->get_name();
3791 if (snm ==
"deleted")
continue;
3795 map<string,DSInfo>::const_iterator ds_iter = dsinfo.find(snm);
3796 if (ds_iter == dsinfo.end()) {
3798 CacheAttribute cat = (cache_attrs.find(snm))->second;
3799 if (cat == MANDATORY)
continue;
3801 indent(out) <<
"if (data.__isset." << snm <<
") {" << endl;
3803 if (cat == HIDDEN) {
3804 indent(out) <<
"if (stype != ST_INTROSPECT) data.__isset." <<
3805 snm <<
" = false;" << endl;
3806 }
else if (cat == INLINE) {
3807 indent(out) <<
"if (stype == ST_PERIODIC) " <<
3808 "data.__isset." << snm <<
" = false;" << endl;
3811 indent(out) <<
"}" << endl << endl;
3813 indent(out) <<
"if (data.__dsobj_" << snm <<
"->IsResult()) {" << endl;
3815 CacheAttribute cat = ds_iter->second.cat_;
3816 if (cat == HIDDEN) {
3817 indent(out) <<
"if (stype != ST_INTROSPECT) data.__isset." <<
3818 snm <<
" = false;" << endl;
3819 }
else if (cat == HIDDEN_PER) {
3820 indent(out) <<
"if (stype == ST_PERIODIC) {" << endl;
3822 indent(out) <<
"if (cycle % " << ds_iter->second.period_ <<
3823 " == 0) data.__dsobj_" << snm <<
"->Flush(data." <<
3824 snm <<
");" << endl;
3825 indent(out) <<
"data.__isset." << snm <<
" = false;" << endl;
3827 indent(out) <<
"} else if (stype == ST_SYNC) data.__isset." <<
3828 snm <<
" = false;" << endl;
3829 }
else if (cat == INLINE) {
3830 indent(out) <<
"if (stype == ST_PERIODIC) " <<
3831 "data.__isset." << snm <<
" = false;" << endl;
3832 }
else if (cat == PERIODIC) {
3833 indent(out) <<
"if (stype == ST_PERIODIC) {" << endl;
3836 indent(out) <<
"if (cycle % " << ds_iter->second.period_ <<
3840 indent(out) <<
"data.__dsobj_" << snm <<
"->Flush(data." <<
3841 snm <<
");" << endl;
3842 indent(out) <<
"data.__dsobj_" << snm <<
"->FillResult(data." <<
3843 snm <<
", data.__isset." << snm <<
", true);" << endl;
3846 indent(out) <<
"} else data.__isset." << snm <<
" = false;" << endl;
3849 indent(out) <<
"} else if (stype == ST_SYNC) data.__isset." <<
3850 snm <<
" = false;" << endl;
3853 indent(out) <<
"else data.__dsobj_" << snm <<
"->FillResult(data." <<
3854 snm <<
", data.__isset." << snm <<
", true);" <<endl;
3856 if (cat == PERIODIC) {
3857 indent(out) <<
"is_periodic_attr |= data.__isset." << snm <<
";" << endl;
3860 indent(out) <<
"}" << endl << endl;
3863 indent(out) <<
"if (stype == ST_PERIODIC) return ((is_periodic_attr) || (data.get_deleted()));" << endl;
3864 indent(out) <<
"else return true;" << endl;
3866 indent(out) <<
"}" << endl << endl;
3868 indent(out) <<
"std::map<std::string, std::string> " << tsandesh->
get_name() <<
3869 "::_DSConf(void) {" << endl;
3872 bool is_dsconf =
false;
3873 for (map<string,DSInfo>::const_iterator ds_iter = dsinfo.begin();
3874 ds_iter != dsinfo.end(); ++ds_iter) {
3876 indent(out) <<
"std::map<std::string, std::string> _dsconf = " <<
3877 "boost::assign::map_list_of" << endl;
3878 indent(out) <<
"(\"" << ds_iter->first <<
"\", \"" <<
3879 ds_iter->second.annotation_ <<
"\")" << endl;
3882 if (is_dsconf)
indent(out) <<
";" << endl;
3883 else indent(out) <<
"std::map<std::string, std::string> _dsconf;" << endl;
3885 indent(out) <<
"return _dsconf;" << endl;
3887 indent(out) <<
"}" << endl << endl;
3890 "::_InitDerivedStats(" << dtype <<
3891 " & _data, const map<string,string> & _dsconf) {" << endl;
3894 for (map<string,DSInfo>::const_iterator ds_iter = dsinfo.begin();
3895 ds_iter != dsinfo.end(); ++ds_iter) {
3897 indent(out) <<
"{" << endl;
3899 indent(out) <<
"map<string,string>::const_iterator _dci = _dsconf.find(\"" <<
3900 ds_iter->first <<
"\");" << endl;
3901 if (ds_iter->second.rmtype_ == RM_AGG) {
3902 indent(out) <<
"bool is_agg = true;" << endl;
3904 indent(out) <<
"bool is_agg = false;" << endl;
3906 indent(out) <<
"assert(_dci != _dsconf.end());" << endl;
3908 indent(out) <<
"_data.__dsobj_" << ds_iter->first <<
".reset();" << endl;
3910 if ((ds_iter->second.cat_ == PERIODIC) ||
3911 (ds_iter->second.cat_ == HIDDEN_PER)) {
3913 if (ds_iter->second.prealgo_.empty()) {
3914 indent(out) <<
"_data.__dsobj_" << ds_iter->first <<
" = boost::make_shared<" <<
3915 " ::contrail::sandesh::DerivedStatsPeriodicIf< ::contrail::sandesh::" <<
3916 ds_iter->second.algo_ <<
", " <<
3917 ds_iter->second.rawtype_ <<
", " <<
3918 ds_iter->second.resulttype_.substr(0, ds_iter->second.resulttype_.size() - 3) <<
", " <<
3919 ds_iter->second.resulttype_ <<
"> >(_dci->second, is_agg);" << endl;
3921 indent(out) <<
"_data.__dsobj_" << ds_iter->first <<
" = boost::make_shared<" <<
3922 " ::contrail::sandesh::DerivedStatsPeriodicAnomalyIf< ::contrail::sandesh::" <<
3923 ds_iter->second.algo_ <<
", " <<
3924 ds_iter->second.rawtype_ <<
", ::contrail::sandesh::" <<
3925 ds_iter->second.prealgo_ <<
", " <<
3926 ds_iter->second.resulttype_ <<
"> >(_dci->second, is_agg);" << endl;
3929 indent(out) <<
"_data.__dsobj_" << ds_iter->first <<
" = boost::make_shared<" <<
3930 " ::contrail::sandesh::DerivedStatsIf< ::contrail::sandesh::" <<
3931 ds_iter->second.algo_ <<
", " <<
3932 ds_iter->second.rawtype_ <<
", " << ds_iter->second.resulttype_ <<
3933 "> >(_dci->second, is_agg);" << endl;
3936 indent(out) <<
"}" << endl;
3939 indent(out) <<
"}" << endl << endl;
3942 "::UpdateUVE(" << dtype <<
3943 " & _data, " << dtype <<
3944 " & tdata, uint64_t mono_usec, SandeshLevel::type Xlevel) {" << endl;
3948 indent(out) <<
"bool send = false;" << endl;
3950 for (s_iter = sfields.begin(); s_iter != sfields.end(); ++s_iter) {
3951 string snm = (*s_iter)->get_name();
3954 if (dsinfo.find(snm) == dsinfo.end()) {
3955 CacheAttribute cat = (cache_attrs.find(snm))->second;
3958 if (cat != INLINE) {
3959 indent(out) <<
"if (_data.__isset." << snm <<
") { _data.__isset." <<
3960 snm <<
" = false;" << endl;
3962 indent(out) <<
"if (_data.__isset." << snm <<
") { send = true;" << endl;
3965 if ((snm.compare(
"name") == 0) || (snm.compare(
"proxy") == 0)) {
3966 indent(out) <<
"{" << endl;
3968 indent(out) <<
"{ send = true;" << endl;
3972 indent(out) <<
"tdata.set_" << snm <<
"(_data.get_" <<
3973 snm <<
"());" << endl;
3974 map<string,set<string> >::const_iterator r_iter = rawmap.find(snm);
3976 if (r_iter != rawmap.end()) {
3977 t_type* ratype = (*s_iter)->get_type();
3981 " _T_" << snm <<
";" << endl;
3982 indent(out) <<
"std::map<string,bool> _delmap_" << snm
3984 indent(out) <<
"BOOST_FOREACH(const _T_" << snm <<
3985 "::value_type& _tp, _data.get_" << snm <<
"())" << endl;
3986 indent(out) <<
" _delmap_" << snm <<
3987 ".insert(make_pair(_tp.first, SandeshStructDeleteTrait<" <<
3988 type_name(vtype) <<
">::get(_tp.second)));" << endl;
3990 set<string>::const_iterator d_iter;
3991 for (d_iter = r_iter->second.begin(); d_iter != r_iter->second.end(); ++d_iter) {
3992 map<string,DSInfo>::const_iterator c_iter = dsinfo.find(*d_iter);
3993 CacheAttribute dat = c_iter->second.cat_;
3995 if (c_iter->second.compattr_.empty()) {
3996 if (!c_iter->second.is_map_) {
3997 indent(out) <<
"tdata.__dsobj_" << *d_iter <<
3998 "->Update(_data.get_" << snm <<
"(), mono_usec);" << endl;
4000 indent(out) <<
"tdata.__dsobj_" << *d_iter <<
4001 "->Update(_data.get_" << snm <<
"(), _delmap_" <<
4002 snm <<
", mono_usec);" << endl;
4005 string getexpr = string(
"get_") + c_iter->second.compattr_ +
4007 if (!c_iter->second.subcompattr_.empty()) {
4008 getexpr += string(
".get_") + c_iter->second.subcompattr_ +
4011 if (!c_iter->second.is_map_) {
4012 indent(out) <<
"tdata.__dsobj_" << *d_iter <<
"->Update(_data.get_" <<
4013 snm <<
"()." << getexpr <<
", mono_usec);" << endl;
4015 indent(out) <<
"std::map<string," << c_iter->second.rawtype_ <<
"> temp_" <<
4016 *d_iter <<
";" << endl;
4017 indent(out) <<
"BOOST_FOREACH(const _T_" << snm <<
4018 "::value_type& _tp, _data.get_" << snm <<
"()) {" << endl;
4020 indent(out) <<
"temp_" << *d_iter <<
4021 ".insert(make_pair(_tp.first, _tp.second." <<
4022 getexpr <<
"));" << endl;
4024 indent(out) <<
"}" << endl;
4025 indent(out) <<
"tdata.__dsobj_" << *d_iter <<
"->Update(temp_" <<
4026 *d_iter <<
", _delmap_" << snm <<
", mono_usec);" << endl;
4027 indent(out) <<
"temp_" << *d_iter <<
".clear();" << endl;
4031 if (dat == INLINE) {
4032 indent(out) <<
"tdata.__dsobj_" << *d_iter <<
"->FillResult(_data." <<
4033 *d_iter <<
", _data.__isset." << *d_iter <<
");" << endl;
4034 indent(out) <<
"if (_data.__isset." << *d_iter <<
") send = true;" << endl;
4040 indent(out) <<
"}" << endl << endl;
4043 if (!periodic_ustruct) {
4044 indent(out) <<
"send = true;" << endl;
4046 indent(out) <<
"return send;" << endl;
4048 indent(out) <<
"}" << endl << endl;
4051 assert(f_iter == fields.end());
4060 void t_cpp_generator::generate_sandesh_reader(ofstream& out,
4063 "int32_t " << tsandesh->
get_name() <<
4064 "::Read(boost::shared_ptr<contrail::sandesh::protocol::TProtocol> iprot) {"
4067 generate_common_struct_reader_body(out, tsandesh,
false);
4070 "}" << endl << endl;
4079 void t_cpp_generator::generate_sandesh_writer(ofstream& out,
4082 "int32_t " << tsandesh->
get_name() <<
4083 "::Write(boost::shared_ptr<contrail::sandesh::protocol::TProtocol> oprot) const {" <<
4086 generate_common_struct_writer_body(out, tsandesh,
false);
4100 void t_cpp_generator::generate_sandesh_uve_creator(
4101 std::ofstream& out,
t_sandesh* tsandesh) {
4102 const vector<t_field*>& fields = tsandesh->
get_members();
4103 vector<t_field*>::const_iterator f_iter = fields.begin();
4104 assert((*f_iter)->get_name() ==
"data");
4106 bool is_proxy =
false;
4107 std::map<std::string, std::string>::iterator ait;
4108 ait = ((*f_iter)->get_type())->annotations_.find(
"period");
4110 std::string sname = tsandesh->
get_name();
4111 indent(out) <<
"SANDESH_UVE_DEF(" << sname <<
"," <<
4114 if (ait == ((*f_iter)->get_type())->annotations_.end()) {
4115 indent(out) <<
", 0, 0);" << endl;
4117 std::map<std::string, std::string>::iterator tmit;
4118 tmit = ((*f_iter)->get_type())->annotations_.find(
"timeout");
4119 if (tmit == ((*f_iter)->get_type())->annotations_.end()) {
4120 indent(out) <<
", " << atoi(ait->second.c_str()) <<
", 0);" << endl;
4122 indent(out) <<
", " << atoi(ait->second.c_str()) <<
", " <<
4123 atoi(tmit->second.c_str()) <<
");" << endl;
4128 indent(out) <<
"void " << sname <<
4129 "::Send(const " <<
type_name((*f_iter)->get_type()) <<
4130 "& cdata, SandeshLevel::type Xlevel, SandeshUVE::SendType stype," <<
4131 " uint32_t seqno, uint32_t cycle, std::string ctx) {" << endl;
4133 indent(out) << sname <<
" *snh = new " << sname <<
"(seqno, cdata);" << endl;
4134 indent(out) <<
"snh->set_level(Xlevel);" << endl;
4135 indent(out) <<
"if (snh->LoadUVE(stype, cycle)) {" << endl;
4137 indent(out) <<
"snh->set_context(ctx); snh->set_more(!ctx.empty());" << endl;
4138 indent(out) <<
"if (stype == SandeshUVE::ST_SYNC) snh->set_hints(snh->hints() | " <<
4139 "g_sandesh_constants.SANDESH_SYNC_HINT);" << endl;
4140 indent(out) <<
"snh->Dispatch();" << endl;
4142 indent(out) <<
"} else snh->Release();" << endl;
4144 indent(out) <<
"}" << endl << endl;
4146 indent(out) <<
"void " << sname <<
4147 "::Send(const " <<
type_name((*f_iter)->get_type()) <<
4148 "& cdata, SandeshUVE::SendType stype, uint32_t seqno," <<
4149 " uint32_t cycle, std::string ctx) {" << endl;
4151 indent(out) << sname <<
" *snh = new " << sname <<
"(seqno, cdata);" << endl;
4152 indent(out) <<
"snh->set_level(SandeshLevel::SYS_NOTICE);" << endl;
4153 indent(out) <<
"if (snh->LoadUVE(stype, cycle)) {" << endl;
4155 indent(out) <<
"snh->set_context(ctx); snh->set_more(!ctx.empty());" << endl;
4156 indent(out) <<
"if (stype == SandeshUVE::ST_SYNC) snh->set_hints(snh->hints() | " <<
4157 "g_sandesh_constants.SANDESH_SYNC_HINT);" << endl;
4158 indent(out) <<
"snh->Dispatch();" << endl;
4160 indent(out) <<
"} else snh->Release();" << endl;
4162 indent(out) <<
"}" << endl << endl;
4165 indent(out) <<
"void " << sname <<
4166 "::Send(const " <<
type_name((*f_iter)->get_type()) <<
4167 "& data, SandeshLevel::type Xlevel, std::string table, " <<
4168 "uint64_t mono_usec, int partition) {" << endl;
4171 indent(out) <<
"void " << sname <<
4172 "::Send(const " <<
type_name((*f_iter)->get_type()) <<
4173 "& data, SandeshLevel::type Xlevel, std::string table, " <<
4174 "uint64_t mono_usec) {" << endl;
4176 indent(out) <<
"int partition = -1;" << endl;
4180 " & cdata = const_cast<" <<
type_name((*f_iter)->get_type()) <<
4181 " &>(data);" << endl;
4182 indent(out) <<
"uint32_t msg_seqno = lseqnum_.fetch_and_increment() + 1;" << endl;
4183 indent(out) <<
"if (!table.empty()) cdata.table_ = table;" << endl;
4184 indent(out) <<
"if (uvemap" << sname <<
4185 ".UpdateUVE(cdata, msg_seqno, mono_usec, partition, Xlevel)) {" << endl;
4187 indent(out) << sname <<
" *snh = new " << sname <<
"(msg_seqno, cdata);" << endl;
4188 indent(out) <<
"snh->set_level(Xlevel);" << endl;
4189 indent(out) <<
"snh->Dispatch();" << endl;
4191 indent(out) <<
"}" << endl;
4194 indent(out) <<
"}" << endl << endl;
4197 indent(out) <<
"void " << sname <<
4198 "::Send(const " <<
type_name((*f_iter)->get_type()) <<
4199 "& data, std::string table, " <<
4200 "uint64_t mono_usec, int partition) {" << endl;
4203 indent(out) <<
"void " << sname <<
4204 "::Send(const " <<
type_name((*f_iter)->get_type()) <<
4205 "& data, std::string table, " <<
4206 "uint64_t mono_usec) {" << endl;
4208 indent(out) <<
"int partition = -1;" << endl;
4212 " & cdata = const_cast<" <<
type_name((*f_iter)->get_type()) <<
4213 " &>(data);" << endl;
4214 indent(out) <<
"uint32_t msg_seqno = lseqnum_.fetch_and_increment() + 1;" << endl;
4215 indent(out) <<
"if (!table.empty()) cdata.table_ = table;" << endl;
4216 indent(out) <<
"if (uvemap" << sname <<
4217 ".UpdateUVE(cdata, msg_seqno, mono_usec, partition, SandeshLevel::SYS_NOTICE)) {" << endl;
4219 indent(out) << sname <<
" *snh = new " << sname <<
"(msg_seqno, cdata);" << endl;
4220 indent(out) <<
"snh->set_level(SandeshLevel::SYS_NOTICE);" << endl;
4221 indent(out) <<
"snh->Dispatch();" << endl;
4223 indent(out) <<
"}" << endl;
4226 indent(out) <<
"}" << endl << endl;
4235 void t_cpp_generator::generate_sandesh_creator(ofstream& out,
4242 indent(out) <<
"extern int " << program_name_ <<
"_marker;" << endl;
4244 indent(out) <<
"SANDESH_REGISTER_DEF_TYPE(" << tsandesh->
get_name() <<
4245 ");" << endl << endl;
4247 }
else if (((
t_base_type *)t)->is_sandesh_trace() ||
4249 generate_sandesh_trace(out, tsandesh);
4251 }
else if (((
t_base_type *)t)->is_sandesh_buffer()) {
4253 indent(out) <<
"SANDESH_REGISTER_DEF_TYPE(" << tsandesh->
get_name() <<
4254 ");" << endl << endl;
4256 }
else if (((
t_base_type *)t)->is_sandesh_uve() ||
4258 generate_sandesh_uve_creator(out, tsandesh);
4267 void t_cpp_generator::generate_get_size_field(ofstream& out,
t_field *tfield) {
4272 out <<
indent() <<
"if (__isset." << name <<
") {" <<
4277 generate_get_size_struct(out, (
t_struct *)type, name);
4279 generate_get_size_container(out, type, name);
4280 }
else if (type->
is_string() || type->is_xml() ||
4281 type->is_static_const_string()) {
4282 out <<
indent() <<
"size += " << name <<
".length();" << endl;
4284 out <<
indent() <<
"size += sizeof(" + name +
");" << endl;
4289 out <<
indent() <<
"}" << endl;
4296 void t_cpp_generator::generate_logger_field(ofstream& out,
4299 bool log_value_only,
4309 out <<
indent() <<
"if (__isset." << name <<
") {" <<
4315 out <<
indent() <<
"Xbuf << " << prefix <<
"\"[ \";" << endl;
4317 out <<
indent() <<
"Xbuf << " << prefix <<
"\"" << name <<
"\"" <<
" << \"= [ \";" << endl;
4319 generate_logger_struct(out, (
t_struct *)type, prefix, name);
4320 out <<
indent() <<
"Xbuf << " <<
"\" ]\";" << endl;
4323 out <<
indent() <<
"Xbuf << " << prefix <<
"\"[ \";" << endl;
4325 out <<
indent() <<
"Xbuf << " << prefix <<
"\"" << name <<
"\"" <<
" << \"= [ \";" << endl;
4327 generate_logger_container(out, type, name, log_value_only);
4328 out <<
indent() <<
"Xbuf << " <<
"\" ]\";" << endl;
4331 if (log_value_only) {
4332 if (tbase->is_integer()) {
4333 out <<
indent() <<
"Xbuf << " << prefix <<
4334 "integerToString(" << name <<
4337 out <<
indent() <<
"Xbuf << " << prefix <<
4338 name <<
";" << endl;
4341 if (tbase->is_integer()) {
4342 out <<
indent() <<
"Xbuf << " << prefix <<
4343 "\"" << name <<
"\"" <<
4344 " << \" = \" << integerToString(" << name <<
4349 out <<
indent() <<
"struct in_addr ip_addr_"<< name <<
";" << endl;
4350 out <<
indent() <<
"ip_addr_" << name <<
".s_addr = htonl(" << name <<
");" << endl;
4351 out <<
indent() <<
"Xbuf << " << prefix <<
4352 "\"" << name <<
"\"" <<
4353 " << \" = \" << inet_ntoa(ip_addr_" << name <<
");" << endl;
4357 out <<
indent() <<
"Xbuf << " << prefix <<
4358 "\"" << name <<
"\"" <<
4359 " << \" = \" << " << name <<
4368 out <<
indent() <<
"}" << endl;
4375 void t_cpp_generator::generate_get_size_container(ofstream& out,
4379 string iter = tmp(
"_iter");
4382 out <<
indent() <<
"for (" << iter <<
" = " << name <<
".begin(); "
4383 << iter <<
" != " << name <<
".end(); ++" << iter <<
")" << endl;
4386 generate_get_size_map_element(out, (
t_map *)ttype, iter);
4387 }
else if(ttype->
is_set()) {
4388 generate_get_size_set_element(out, (
t_set *)ttype, iter);
4390 generate_get_size_list_element(out, (
t_list *)ttype, iter);
4399 void t_cpp_generator::generate_get_size_map_element(ofstream& out,
4403 generate_get_size_field(out, &kfield);
4405 generate_get_size_field(out, &vfield);
4411 void t_cpp_generator::generate_get_size_list_element(ofstream& out,
4415 generate_get_size_field(out, &efield);
4421 void t_cpp_generator::generate_get_size_set_element(ofstream& out,
4425 generate_get_size_field(out, &efield);
4431 void t_cpp_generator::generate_logger_container(ofstream& out,
4434 bool log_value_only) {
4436 string iter = tmp(
"_iter");
4437 string prefix =
"\" \" << ";
4438 out <<
indent() <<
"Xbuf << " << prefix <<
"\"[\";" << endl;
4440 indent() <<
type_name(ttype) <<
"::const_iterator " << iter <<
";" << endl <<
4441 indent() <<
"for (" << iter <<
" = " << name <<
".begin(); " << iter <<
" != " << name <<
".end(); ++" << iter <<
")" << endl;
4444 generate_logger_map_element(out, (
t_map*)ttype, iter, log_value_only);
4445 }
else if (ttype->
is_set()) {
4446 generate_logger_set_element(out, (
t_set*)ttype, iter, log_value_only);
4447 }
else if (ttype->
is_list()) {
4448 generate_logger_list_element(out, (
t_list*)ttype, iter, log_value_only);
4450 out <<
indent() <<
"Xbuf << " <<
"\", \";" << endl;
4452 out <<
indent() <<
"Xbuf << " << prefix <<
"\"]\";" << endl;
4459 void t_cpp_generator::generate_logger_map_element(ofstream& out,
4462 bool log_value_only) {
4463 string prefix =
"\" \" << ";
4465 generate_logger_field(out, &kfield, prefix, log_value_only,
true);
4467 generate_logger_field(out, &vfield, prefix, log_value_only,
true);
4473 void t_cpp_generator::generate_logger_set_element(ofstream& out,
4476 bool log_value_only) {
4477 string prefix =
"\" \" << ";
4479 generate_logger_field(out, &efield, prefix, log_value_only,
true);
4485 void t_cpp_generator::generate_logger_list_element(ofstream& out,
4488 bool log_value_only) {
4489 string prefix =
"\" \" << ";
4491 generate_logger_field(out, &efield, prefix, log_value_only,
true);
4497 void t_cpp_generator::generate_get_size_struct(ofstream& out,
4501 out <<
indent() <<
"size += " << name <<
".GetSize();" << endl;
4507 void t_cpp_generator::generate_logger_struct(ofstream& out,
4512 out <<
indent() <<
"Xbuf << " << prefix << name <<
".log();" << endl;
4521 void t_cpp_generator::generate_sandesh_static_drop_logger(ofstream &out,
4522 t_sandesh *tsandesh,
bool generate_sandesh_object) {
4524 if (generate_sandesh_object) {
4525 out <<
indent() <<
"static void DropLog(const std::string& " <<
4526 "drop_reason, std::string category, SandeshLevel::type level, " <<
4527 tsandesh->
get_name() <<
" *snh) {" << endl;
4529 out <<
indent() <<
"static void DropLog" <<
4530 generate_sandesh_async_creator(tsandesh,
true,
false,
false,
"",
"",
4531 false,
false,
true) <<
" {" << endl;
4534 out <<
indent() <<
"log4cplus::LogLevel Xlog4level(" <<
4535 "SandeshLevelTolog4Level(SandeshLevel::SYS_ERR));" << endl;
4537 "log4cplus::Logger Xlogger = Sandesh::logger();" << endl;
4539 "if (!Xlogger.isEnabledFor(Xlog4level)) {" << endl;
4541 out <<
indent() <<
"return;" << endl;
4543 out <<
indent() <<
"log4cplus::tostringstream Xbuf;" << endl;
4547 if (generate_sandesh_object) {
4548 out <<
indent() <<
"Xbuf << drop_reason << snh->ToString();"
4551 out <<
indent() <<
"Xbuf << drop_reason << category << " <<
4552 "\" [\" << LevelToString(level) << \"]: " <<
4553 tsandesh->
get_name() <<
": \";" << endl;
4556 assert(!generate_sandesh_object);
4557 out <<
indent() <<
"Xbuf << drop_reason << \"" <<
4558 tsandesh->
get_name() <<
": \";" << endl;
4565 bool log_value_only = is_system || is_trace;
4568 const vector<t_field*>& fields = tsandesh->
get_members();
4569 vector<t_field*>::const_iterator f_iter;
4570 for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
4572 prefix =
"\" \" << ";
4576 if (!generate_sandesh_object) {
4577 generate_logger_field(out, *f_iter, prefix, log_value_only,
false,
4581 out <<
indent() <<
"Xlogger.forcedLog(Xlog4level, Xbuf.str());" <<
4584 indent(out) <<
"}" << endl << endl;
4587 void t_cpp_generator::generate_sandesh_static_logger(ofstream &out,
4588 t_sandesh *tsandesh,
bool generate_sandesh_object) {
4590 if (generate_sandesh_object) {
4591 out <<
indent() <<
"static void Log(std::string category, " <<
4592 "SandeshLevel::type level, " << tsandesh->
get_name() <<
4595 out <<
indent() <<
"static void Log" <<
4596 generate_sandesh_async_creator(tsandesh,
true,
false,
false,
"",
"",
4597 false,
false,
false) <<
" {" << endl;
4601 "if (!IsLevelCategoryLoggingAllowed(" <<
4602 generate_sandesh_base_name(tsandesh,
true) <<
4603 ", level, category)) {" << endl;
4605 out <<
indent() <<
"return;" << endl;
4607 out <<
indent() <<
"log4cplus::LogLevel Xlog4level(" <<
4608 "SandeshLevelTolog4Level(level));" << endl;
4610 "log4cplus::Logger Xlogger = Sandesh::logger();" << endl;
4612 "if (!Xlogger.isEnabledFor(Xlog4level)) {" << endl;
4614 out <<
indent() <<
"return;" << endl;
4616 out <<
indent() <<
"log4cplus::tostringstream Xbuf;" << endl;
4620 if (generate_sandesh_object) {
4621 out <<
indent() <<
"Xbuf << snh->ToString();" << endl;
4623 out <<
indent() <<
"Xbuf << category << " <<
4624 "\" [\" << LevelToString(level) << \"]: " <<
4625 tsandesh->
get_name() <<
": \";" << endl;
4628 assert(!generate_sandesh_object);
4629 out <<
indent() <<
"Xbuf << \"" <<
4630 tsandesh->
get_name() <<
": \";" << endl;
4637 bool log_value_only = is_system || is_trace;
4640 const vector<t_field*>& fields = tsandesh->
get_members();
4641 vector<t_field*>::const_iterator f_iter;
4642 for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
4644 prefix =
"\" \" << ";
4648 if (!generate_sandesh_object) {
4649 generate_logger_field(out, *f_iter, prefix, log_value_only,
false,
4653 out <<
indent() <<
"Xlogger.forcedLog(Xlog4level, Xbuf.str());" <<
4656 indent(out) <<
"}" << endl << endl;
4666 void t_cpp_generator::generate_sandesh_logger(ofstream &out,
4669 if (ltype == sandesh_logger::BUFFER) {
4671 "::ToString() const {" << endl;
4675 "::Log() const {" << endl;
4677 }
else if (ltype == sandesh_logger::FORCED_LOG) {
4679 "::ForcedLog() const {" << endl;
4684 const vector<t_field*>& fields = tsandesh->
get_members();
4685 vector<t_field*>::const_iterator f_iter;
4687 bool log_value_only =
4690 for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
4691 string prefix =
"\" \" << ";
4695 string category_str =
"Sandesh::category()";
4696 string level_str =
"Sandesh::level()";
4698 out <<
indent() <<
"if (!IsLevelCategoryLoggingAllowed(" <<
4699 generate_sandesh_base_name(tsandesh,
true) <<
", " <<
4700 level_str <<
", " << category_str <<
")) {" << endl;
4702 out <<
indent() <<
"return;" << endl;
4704 out <<
indent() <<
"log4cplus::LogLevel Xlog4level(" <<
4705 "SandeshLevelTolog4Level(" << level_str <<
"));" << endl;
4707 "log4cplus::Logger Xlogger = Sandesh::logger();" << endl;
4709 "if (!Xlogger.isEnabledFor(Xlog4level)) {" << endl;
4711 out <<
indent() <<
"return;" << endl;
4713 out <<
indent() <<
"log4cplus::tostringstream Xbuf;" << endl;
4714 }
else if (ltype == sandesh_logger::FORCED_LOG) {
4715 out <<
indent() <<
"log4cplus::LogLevel Xlog4level(" <<
4716 "SandeshLevelTolog4Level(" << level_str <<
"));" << endl;
4718 "log4cplus::Logger Xlogger = Sandesh::logger();" << endl;
4719 out <<
indent() <<
"log4cplus::tostringstream Xbuf;" << endl;
4720 }
else if (ltype == sandesh_logger::BUFFER) {
4721 out <<
indent() <<
"std::stringstream Xbuf;" << endl;
4724 "Xbuf << integerToString(timestamp()) << \" \";" <<
4730 out <<
indent() <<
"Xbuf << " << category_str <<
4731 " << \" [\" << LevelToString(" << level_str <<
") << \"]: "
4732 << tsandesh->
get_name() <<
": \";" << endl;
4738 generate_logger_field(out, *f_iter, prefix, log_value_only,
false);
4741 if (ltype == sandesh_logger::BUFFER) {
4742 out <<
indent() <<
"return Xbuf.str();" << endl;
4744 out <<
indent() <<
"Xlogger.forcedLog(Xlog4level, Xbuf.str());" <<
4748 if (ltype == sandesh_logger::BUFFER) {
4749 out <<
indent() <<
"return std::string();" << endl;
4753 indent(out) <<
"}" << endl << endl;
4762 void t_cpp_generator::generate_sandesh_get_size(ofstream& out,
4766 "::GetSize() const {" << endl;
4768 indent(out) <<
"size_t size = 0;" << endl;
4769 const vector<t_field*>& fields = tsandesh->
get_members();
4770 vector<t_field*>::const_iterator f_iter;
4771 for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
4772 generate_get_size_field(out, *f_iter);
4774 indent(out) <<
"return size;" << endl;
4776 indent(out) <<
"}" << endl << endl;
4785 void t_cpp_generator::generate_sandesh_loggers(ofstream& out,
4790 generate_sandesh_logger(out, tsandesh, sandesh_logger::FORCED_LOG);
4792 generate_sandesh_logger(out, tsandesh, sandesh_logger::BUFFER);
4801 void t_cpp_generator::generate_sandesh_trace(ofstream& out,
4803 std::string creator_name =
"trace_sandesh";
4804 indent(out) <<
"void " << tsandesh->
get_name() <<
"::TraceMsg" <<
4805 generate_sandesh_no_static_const_string_function(tsandesh,
true,
false,
true) <<
4808 out <<
indent() <<
"TraceSandeshType *trace = " <<
4809 "TraceSandeshType::GetInstance();" << endl;
4810 out <<
indent() <<
"if (trace != NULL && trace->IsTraceOn() && trace_buf->IsTraceOn()) {" << endl;
4812 out <<
indent() << tsandesh->
get_name() <<
" *" << creator_name <<
" = " <<
4814 generate_sandesh_no_static_const_string_function(tsandesh,
false,
false,
false,
false,
true) <<
4816 out <<
indent() << creator_name <<
"->set_category(trace_buf->Name());" << endl;
4817 out <<
indent() <<
"uint32_t seqnum(trace_buf->GetNextSeqNum());" << endl;
4818 out <<
indent() << creator_name <<
"->set_seqnum(seqnum);" << endl;
4819 out <<
indent() <<
"trace_buf->TraceWrite(" << creator_name <<
");" << endl;
4820 out <<
indent() <<
"if ((IsLocalLoggingEnabled() && IsTracePrintEnabled()) || IsUnitTest()) " << creator_name <<
"->Log();" << endl;
4822 out <<
indent() <<
"}" <<endl;
4825 "}" << endl << endl;
4832 void t_cpp_generator::generate_isRatelimitPass(ofstream& out,
4834 out <<
indent() <<
"uint32_t send_rate_limit = Sandesh::get_send_rate_limit();" << endl;
4835 out <<
indent() <<
"if (send_rate_limit == 0) {" << endl;
4837 out <<
indent() <<
"return false;" << endl;
4839 out <<
indent() <<
"}" << endl;
4840 out <<
indent() <<
"tbb::mutex::scoped_lock lock(rate_limit_mutex_);" << endl;
4841 out <<
indent() <<
"if (rate_limit_buffer_.capacity() !="
4842 " send_rate_limit) {" << endl;
4844 out <<
indent() <<
"//Resize the buffer to the "
4845 "buffer_threshold_" << endl;
4846 out <<
indent() <<
"rate_limit_buffer_.rresize(send_rate_limit);"
4848 out <<
indent() <<
"rate_limit_buffer_.set_capacity("
4849 "send_rate_limit);" << endl;
4851 out <<
indent() <<
"}" << endl;
4852 out <<
indent() <<
"time_t current_time = time(0);" << endl;
4853 out <<
indent() <<
"if (rate_limit_buffer_.capacity() == rate_limit_buffer_"
4854 ".size()) {" << endl;
4856 out <<
indent() <<
"if (*rate_limit_buffer_.begin() == current_time) {" << endl;
4858 out <<
indent() <<
"//update tx and call droplog" << endl;
4859 out <<
indent() <<
"//Dont have to log more than once" << endl;
4860 out <<
indent() <<
"return false;" << endl;
4862 out <<
indent() <<
"}" << endl;
4864 out <<
indent() <<
"}" << endl;
4865 out <<
indent() <<
"//Should log failure after a sucessful write" << endl;
4866 out <<
indent() <<
"do_rate_limit_drop_log_ = true;" << endl;
4867 out <<
indent() <<
"rate_limit_buffer_.push_back(current_time);" << endl;
4868 out <<
indent() <<
"return true;" << endl;
4887 vector<t_field*>::const_iterator f_iter;
4889 if (gen_templates_) {
4891 indent() <<
"template <class Protocol_>" << endl <<
4893 "::write(Protocol_* oprot) const {" << endl;
4896 "uint32_t " << tstruct->
get_name() <<
4897 "::write(::contrail::sandesh::protocol::TProtocol* oprot) const {" << endl;
4903 indent() <<
"uint32_t xfer = 0;" << endl <<
4907 "xfer += oprot->writeStructBegin(\"" << name <<
"\");" << endl;
4910 for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
4921 out <<
"(this->__isset." << (*f_iter)->get_name() <<
") {" << endl;
4927 indent() <<
"xfer += oprot->writeFieldBegin(" <<
4928 "\"" << (*f_iter)->get_name() <<
"\", " <<
4929 type_to_enum((*f_iter)->get_type()) <<
", " <<
4930 (*f_iter)->get_key() <<
");" << endl;
4933 generate_serialize_field(out, *f_iter,
"(*(this->",
"))");
4935 generate_serialize_field(out, *f_iter,
"this->");
4938 indent(out) <<
"xfer += oprot->writeFieldEnd();" << endl;
4947 indent() <<
"xfer += oprot->writeFieldStop();" << endl <<
4948 indent() <<
"xfer += oprot->writeStructEnd();" << endl <<
4949 indent() <<
"return xfer;" << endl;
4966 string svcname = tservice->
get_name();
4969 string f_header_name = get_out_dir()+svcname+
".h";
4976 "#ifndef " << svcname <<
"_H" << endl <<
4977 "#define " << svcname <<
"_H" << endl <<
4979 if (gen_cob_style_) {
4981 "#include <transport/TBufferTransports.h>" << endl <<
4982 "#include <tr1/functional>" << endl <<
4983 "namespace apache { namespace thrift { namespace async {" << endl <<
4984 "class TAsyncChannel;" << endl <<
4988 "#include <TProcessor.h>" << endl;
4989 if (gen_cob_style_) {
4991 "#include <async/TAsyncProcessor.h>" << endl;
4994 "#include \"" << get_include_prefix(*get_program()) << program_name_ <<
4995 "_types.h\"" << endl;
4998 if (extends_service != NULL) {
5000 "#include \"" << get_include_prefix(*(extends_service->
get_program())) <<
5001 extends_service->
get_name() <<
".h\"" << endl;
5010 string f_service_name = get_out_dir()+svcname+
".cpp";
5011 f_service_.open(f_service_name.c_str());
5015 "#include \"" << get_include_prefix(*get_program()) << svcname <<
".h\"" << endl;
5016 if (gen_cob_style_) {
5018 "#include \"async/TAsyncChannel.h\"" << endl;
5020 if (gen_templates_) {
5022 "#include \"" << get_include_prefix(*get_program()) << svcname <<
5025 string f_service_tcc_name = get_out_dir()+svcname+
".tcc";
5026 f_service_tcc_.open(f_service_tcc_name.c_str());
5030 "#include \"" << get_include_prefix(*get_program()) << svcname <<
5034 "#ifndef " << svcname <<
"_TCC" << endl <<
5035 "#define " << svcname <<
"_TCC" << endl <<
5038 if (gen_cob_style_) {
5040 "#include \"async/TAsyncChannel.h\"" << endl;
5045 endl << ns_open_ << endl << endl;
5047 endl << ns_open_ << endl << endl;
5050 generate_service_interface(tservice,
"");
5051 generate_service_interface_factory(tservice,
"");
5052 generate_service_null(tservice,
"");
5053 generate_service_helpers(tservice);
5054 generate_service_client(tservice,
"");
5055 generate_service_processor(tservice,
"");
5056 generate_service_multiface(tservice);
5057 generate_service_skeleton(tservice);
5060 if (gen_cob_style_) {
5061 generate_service_interface(tservice,
"CobCl");
5062 generate_service_interface(tservice,
"CobSv");
5063 generate_service_interface_factory(tservice,
"CobSv");
5064 generate_service_null(tservice,
"CobSv");
5065 generate_service_client(tservice,
"Cob");
5066 generate_service_processor(tservice,
"Cob");
5067 generate_service_async_skeleton(tservice);
5072 ns_close_ << endl <<
5075 ns_close_ << endl <<
5078 ns_close_ << endl <<
5082 if (gen_templates_) {
5084 "#include \"" << get_include_prefix(*get_program()) << svcname <<
5086 "#include \"" << get_include_prefix(*get_program()) << program_name_ <<
5087 "_types.tcc\"" << endl <<
5097 f_service_tcc_.close();
5110 vector<t_function*>::iterator f_iter;
5111 std::ofstream& out = (gen_templates_ ? f_service_tcc_ : f_service_);
5113 for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
5114 t_struct* ts = (*f_iter)->get_arglist();
5118 ts->
set_name(tservice->
get_name() +
"_" + (*f_iter)->get_name() +
"_args");
5119 generate_struct_definition(
f_header_, ts,
false);
5120 generate_struct_reader(out, ts);
5121 generate_struct_writer(out, ts);
5122 ts->
set_name(tservice->
get_name() +
"_" + (*f_iter)->get_name() +
"_pargs");
5123 generate_struct_definition(
f_header_, ts,
false,
true,
false,
true);
5124 generate_struct_writer(out, ts,
true);
5127 generate_function_helpers(tservice, *f_iter);
5139 if (style ==
"CobCl") {
5142 if (gen_templates_) {
5144 service_if_name +=
"T";
5146 "template <class Protocol_>" << endl;
5152 string extends =
"";
5156 if (style ==
"CobCl" && gen_templates_) {
5159 extends +=
"T<Protocol_>";
5163 if (style ==
"CobCl" && gen_templates_) {
5164 f_header_ <<
"template <class Protocol_>" << endl;
5167 "class " << service_if_name << extends <<
" {" << endl <<
5171 indent() <<
"virtual ~" << service_if_name <<
"() {}" << endl;
5174 vector<t_function*>::iterator f_iter;
5175 for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
5177 indent() <<
"virtual " << function_signature(*f_iter, style) <<
" = 0;" << endl;
5181 "};" << endl << endl;
5183 if (style ==
"CobCl" && gen_templates_) {
5187 "typedef " << service_if_name <<
5188 "< ::contrail::sandesh::protocol::TProtocol> " <<
5225 string base_if_name =
type_name(base_service) + style +
"If";
5228 string factory_name = service_if_name +
"Factory";
5232 style +
"IfFactory";
5236 "class " << factory_name << extends <<
" {" << endl <<
5240 indent() <<
"typedef " << service_if_name <<
" Handler;" << endl <<
5242 indent() <<
"virtual ~" << factory_name <<
"() {}" << endl <<
5244 indent() <<
"virtual " << service_if_name <<
"* getHandler(" <<
5245 "const ::contrail::sandesh::TConnectionInfo& connInfo) = 0;" <<
5247 indent() <<
"virtual void releaseHandler(" << base_if_name <<
5248 "* /* handler */) = 0;" << endl;
5252 "};" << endl << endl;
5255 string singleton_factory_name = service_if_name +
"SingletonFactory";
5257 "class " << singleton_factory_name <<
5258 " : virtual public " << factory_name <<
" {" << endl <<
5262 indent() << singleton_factory_name <<
"(const boost::shared_ptr<" <<
5263 service_if_name <<
">& iface) : iface_(iface) {}" << endl <<
5264 indent() <<
"virtual ~" << singleton_factory_name <<
"() {}" << endl <<
5266 indent() <<
"virtual " << service_if_name <<
"* getHandler(" <<
5267 "const ::contrail::sandesh::TConnectionInfo&) {" << endl <<
5268 indent() <<
" return iface_.get();" << endl <<
5269 indent() <<
"}" << endl <<
5270 indent() <<
"virtual void releaseHandler(" << base_if_name <<
5271 "* /* handler */) {}" << endl;
5275 " protected:" << endl <<
5276 indent() <<
"boost::shared_ptr<" << service_if_name <<
"> iface_;" << endl;
5280 "};" << endl << endl;
5289 string extends =
"";
5294 "class " <<
service_name_ << style <<
"Null : virtual public " <<
service_name_ << style <<
"If" << extends <<
" {" << endl <<
5300 vector<t_function*>::iterator f_iter;
5301 for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
5303 indent() << function_signature(*f_iter, style,
"",
false) <<
" {" << endl;
5306 t_type* returntype = (*f_iter)->get_returntype();
5307 t_field returnfield(returntype,
"_return");
5310 if (returntype->
is_void() || is_complex_type(returntype)) {
5314 indent() << declare_field(&returnfield,
true) << endl <<
5315 indent() <<
"return _return;" << endl;
5317 }
else if (style ==
"CobSv") {
5321 t_field returnfield(returntype,
"_return");
5323 indent() << declare_field(&returnfield,
true) << endl <<
5324 indent() <<
"return cob(_return);" << endl;
5328 throw "UNKNOWN STYLE";
5337 "};" << endl << endl;
5345 if (is_complex_type(ret_type)) {
5347 out << iface <<
"->" << tfunction->
get_name() <<
"(" << target;
5349 out << target <<
" = " << iface <<
"->" << tfunction->
get_name() <<
"(";
5352 out << iface <<
"->" << tfunction->
get_name() <<
"(";
5355 vector<t_field*>::const_iterator f_iter;
5356 for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
5362 out << arg_prefix << (*f_iter)->get_name();
5364 out <<
");" << endl;
5368 string svcname = tservice->
get_name();
5371 string f_skeleton_name = get_out_dir()+svcname+
"_async_server.skeleton.cpp";
5375 ofstream f_skeleton;
5376 f_skeleton.open(f_skeleton_name.c_str());
5378 "// This autogenerated skeleton file illustrates one way to adapt a synchronous" << endl <<
5379 "// interface into an asynchronous interface. You should copy it to another" << endl <<
5380 "// filename to avoid overwriting it and rewrite as asynchronous any functions" << endl <<
5381 "// that would otherwise introduce unwanted latency." << endl <<
5383 "#include \"" << get_include_prefix(*get_program()) << svcname <<
".h\"" << endl <<
5384 "#include <protocol/TBinaryProtocol.h>" << endl <<
5385 "#include <async/TEventServer.h>" << endl <<
5387 "using namespace ::contrail::sandesh;" << endl <<
5388 "using namespace ::contrail::sandesh::protocol;" << endl <<
5389 "using namespace ::contrail::sandesh::transport;" << endl <<
5390 "using namespace ::contrail::sandesh::async;" << endl <<
5392 "using boost::shared_ptr;" << endl <<
5397 "using namespace " << string(ns, 0, ns.size()-2) <<
";" << endl <<
5402 "class " << svcname <<
"AsyncHandler : " <<
5403 "public " << svcname <<
"CobSvIf {" << endl <<
5407 indent() << svcname <<
"AsyncHandler() {" << endl <<
5408 indent() <<
" syncHandler_ = std::unique_ptr<" << svcname <<
5409 "Handler>(new " << svcname <<
"Handler);" << endl <<
5410 indent() <<
" // Your initialization goes here" << endl <<
5416 vector<t_function*>::iterator f_iter;
5417 for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
5420 indent() << function_signature(*f_iter,
"CobSv",
"",
true) <<
" {" << endl;
5423 t_type* returntype = (*f_iter)->get_returntype();
5424 t_field returnfield(returntype,
"_return");
5426 string target = returntype->
is_void() ?
"" :
"_return";
5429 indent() << declare_field(&returnfield,
true) << endl;
5431 generate_function_call(f_skeleton, *f_iter, target,
"syncHandler_",
"");
5432 f_skeleton <<
indent() <<
"return cob(" << target <<
");" << endl;
5434 scope_down(f_skeleton);
5436 f_skeleton << endl <<
5437 " protected:" << endl <<
5438 indent() <<
"std::unique_ptr<" << svcname <<
"Handler> syncHandler_;" << endl;
5441 "};" << endl << endl;
5454 vector<t_function*>::iterator f_iter;
5456 string extends =
"";
5457 string extends_multiface =
"";
5460 extends_multiface =
", public " + extends +
"Multiface";
5463 string list_type = string(
"std::vector<boost::shared_ptr<") +
service_name_ +
"If> >";
5469 extends_multiface <<
" {" << endl <<
5473 indent() <<
service_name_ <<
"Multiface(" << list_type <<
"& ifaces) : ifaces_(ifaces) {" << endl;
5474 if (!extends.empty()) {
5476 indent() <<
" std::vector<boost::shared_ptr<" +
service_name_ +
"If> >::iterator iter;" << endl <<
5477 indent() <<
" for (iter = ifaces.begin(); iter != ifaces.end(); ++iter) {" << endl <<
5478 indent() <<
" " << extends <<
"Multiface::add(*iter);" << endl <<
5479 indent() <<
" }" << endl;
5482 indent() <<
"}" << endl <<
5488 " protected:" << endl;
5491 indent() << list_type <<
" ifaces_;" << endl <<
5494 if (!extends.empty()) {
5496 indent() <<
" " << extends <<
"Multiface::add(iface);" << endl;
5499 indent() <<
" ifaces_.push_back(iface);" << endl <<
5504 indent() <<
" public:" << endl;
5507 for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
5508 t_struct* arglist = (*f_iter)->get_arglist();
5509 const vector<t_field*>& args = arglist->
get_members();
5510 vector<t_field*>::const_iterator a_iter;
5512 string call = string(
"ifaces_[i]->") + (*f_iter)->get_name() +
"(";
5514 if (is_complex_type((*f_iter)->get_returntype())) {
5518 for (a_iter = args.begin(); a_iter != args.end(); ++a_iter) {
5524 call += (*a_iter)->get_name();
5529 indent() << function_signature(*f_iter,
"") <<
" {" << endl;
5532 indent() <<
"size_t sz = ifaces_.size();" << endl <<
5533 indent() <<
"for (size_t i = 0; i < sz; ++i) {" << endl;
5534 if (!(*f_iter)->get_returntype()->is_void()) {
5536 indent() <<
" if (i == sz - 1) {" << endl;
5537 if (is_complex_type((*f_iter)->get_returntype())) {
5539 indent() <<
" " << call <<
";" << endl <<
5540 indent() <<
" return;" << endl;
5543 indent() <<
" return " << call <<
";" << endl;
5546 indent() <<
" } else {" << endl <<
5547 indent() <<
" " << call <<
";" << endl <<
5548 indent() <<
" }" << endl;
5551 indent() <<
" " << call <<
";" << endl;
5559 indent() <<
"}" << endl <<
5565 indent() <<
"};" << endl <<
5576 if (style ==
"Cob") {
5580 std::ofstream& out = (gen_templates_ ? f_service_tcc_ : f_service_);
5581 string template_header, template_suffix, short_suffix, protocol_type, _this;
5582 string const prot_factory_type =
5583 "::contrail::sandesh::protocol::TProtocolFactory";
5584 if (gen_templates_) {
5585 template_header =
"template <class Protocol_>\n";
5587 template_suffix =
"T<Protocol_>";
5588 protocol_type =
"Protocol_";
5591 protocol_type =
"::contrail::sandesh::protocol::TProtocol";
5593 string prot_ptr =
"boost::shared_ptr< " + protocol_type +
">";
5594 string client_suffix =
"Client" + template_suffix;
5595 string if_suffix =
"If";
5596 if (style ==
"Cob") {
5597 if_suffix += template_suffix;
5600 string extends =
"";
5601 string extends_client =
"";
5606 extends_client =
", public " + extends + style + client_suffix;
5612 "class " <<
service_name_ << style <<
"Client" << short_suffix <<
" : " <<
5613 "virtual public " <<
service_name_ << ifstyle << if_suffix <<
5614 extends_client <<
" {" << endl <<
5618 if (style !=
"Cob") {
5621 "(" << prot_ptr <<
" prot) :" <<
5623 if (extends.empty()) {
5625 indent() <<
" piprot_(prot)," << endl <<
5626 indent() <<
" poprot_(prot) {" << endl <<
5627 indent() <<
" iprot_ = prot.get();" << endl <<
5628 indent() <<
" oprot_ = prot.get();" << endl <<
5632 indent() <<
" " << extends << style << client_suffix <<
5633 "(prot, prot) {}" << endl;
5638 "(" << prot_ptr <<
" iprot, " << prot_ptr <<
" oprot) :" << endl;
5639 if (extends.empty()) {
5641 indent() <<
" piprot_(iprot)," << endl <<
5642 indent() <<
" poprot_(oprot) {" << endl <<
5643 indent() <<
" iprot_ = iprot.get();" << endl <<
5644 indent() <<
" oprot_ = oprot.get();" << endl <<
5648 indent() <<
" " << extends << style << client_suffix <<
5649 "(iprot, oprot) {}" << endl;
5656 indent() <<
"boost::shared_ptr< ::contrail::sandesh::protocol::TProtocol> getInputProtocol() {" << endl <<
5657 indent() <<
" return " << _this <<
"piprot_;" << endl <<
5661 indent() <<
"boost::shared_ptr< ::contrail::sandesh::protocol::TProtocol> getOutputProtocol() {" << endl <<
5662 indent() <<
" return " << _this <<
"poprot_;" << endl <<
5668 "boost::shared_ptr< ::contrail::sandesh::async::TAsyncChannel> channel, " <<
5669 "::contrail::sandesh::protocol::TProtocolFactory* protocolFactory) :" <<
5671 if (extends.empty()) {
5673 indent() <<
" channel_(channel)," << endl <<
5674 indent() <<
" itrans_(new ::contrail::sandesh::transport::TMemoryBuffer())," << endl <<
5675 indent() <<
" otrans_(new ::contrail::sandesh::transport::TMemoryBuffer())," << endl;
5676 if (gen_templates_) {
5680 indent() <<
" piprot_(boost::dynamic_pointer_cast<Protocol_>(" <<
5681 "protocolFactory->getProtocol(itrans_)))," << endl <<
5682 indent() <<
" poprot_(boost::dynamic_pointer_cast<Protocol_>(" <<
5683 "protocolFactory->getProtocol(otrans_))) {" << endl;
5686 indent() <<
" if (!piprot_ || !poprot_) {" << endl <<
5687 indent() <<
" throw ::contrail::sandesh::TException(\"" <<
5688 "TProtocolFactory returned unexpected protocol type in " <<
5690 " constructor\");" << endl <<
5691 indent() <<
" }" << endl;
5694 indent() <<
" piprot_(protocolFactory->getProtocol(itrans_))," <<
5696 indent() <<
" poprot_(protocolFactory->getProtocol(otrans_)) {" <<
5700 indent() <<
" iprot_ = piprot_.get();" << endl <<
5701 indent() <<
" oprot_ = poprot_.get();" << endl <<
5705 indent() <<
" " << extends << style << client_suffix <<
5706 "(channel, protocolFactory) {}" << endl;
5710 if (style ==
"Cob") {
5712 indent() <<
"boost::shared_ptr< ::contrail::sandesh::async::TAsyncChannel> getChannel() {" << endl <<
5713 indent() <<
" return " << _this <<
"channel_;" << endl <<
5715 if (!gen_no_client_completion_) {
5717 indent() <<
"virtual void completed__(bool /* success */) {}" << endl;
5722 vector<t_function*>::const_iterator f_iter;
5723 for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
5724 indent(
f_header_) << function_signature(*f_iter, ifstyle) <<
";" << endl;
5727 string(
"send_") + (*f_iter)->
get_name(),
5728 (*f_iter)->get_arglist());
5729 indent(
f_header_) << function_signature(&send_function,
"") <<
";" << endl;
5730 if (!(*f_iter)->is_oneway()) {
5732 t_function recv_function((*f_iter)->get_returntype(),
5733 string(
"recv_") + (*f_iter)->get_name(),
5735 indent(
f_header_) << function_signature(&recv_function,
"") <<
";" << endl;
5740 if (extends.empty()) {
5742 " protected:" << endl;
5745 if (style ==
"Cob") {
5747 indent() <<
"boost::shared_ptr< ::contrail::sandesh::async::TAsyncChannel> channel_;" << endl <<
5748 indent() <<
"boost::shared_ptr< ::contrail::sandesh::transport::TMemoryBuffer> itrans_;" << endl <<
5749 indent() <<
"boost::shared_ptr< ::contrail::sandesh::transport::TMemoryBuffer> otrans_;" << endl;
5752 indent() << prot_ptr <<
" piprot_;" << endl <<
5753 indent() << prot_ptr <<
" poprot_;" << endl <<
5754 indent() << protocol_type <<
"* iprot_;" << endl <<
5755 indent() << protocol_type <<
"* oprot_;" << endl;
5764 if (gen_templates_) {
5769 "ClientT< ::contrail::sandesh::protocol::TProtocol> " <<
5774 string scope =
service_name_ + style + client_suffix +
"::";
5777 for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
5778 string funname = (*f_iter)->get_name();
5781 if (gen_templates_) {
5782 indent(out) << template_header;
5785 function_signature(*f_iter, ifstyle, scope) << endl;
5788 "send_" << funname <<
"(";
5791 t_struct* arg_struct = (*f_iter)->get_arglist();
5794 const vector<t_field*>& fields = arg_struct->
get_members();
5795 vector<t_field*>::const_iterator fld_iter;
5797 for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
5803 out << (*fld_iter)->get_name();
5805 out <<
");" << endl;
5807 if (style !=
"Cob") {
5808 if (!(*f_iter)->is_oneway()) {
5810 if (!(*f_iter)->get_returntype()->is_void()) {
5811 if (is_complex_type((*f_iter)->get_returntype())) {
5812 out <<
"recv_" << funname <<
"(_return);" << endl;
5814 out <<
"return recv_" << funname <<
"();" << endl;
5818 "recv_" << funname <<
"();" << endl;
5822 if (!(*f_iter)->is_oneway()) {
5824 indent() << _this <<
"channel_->sendAndRecvMessage(" <<
5825 "std::tr1::bind(cob, this), " << _this <<
"otrans_.get(), " <<
5826 _this <<
"itrans_.get());" << endl;
5829 indent() << _this <<
"channel_->sendMessage(" <<
5830 "std::tr1::bind(cob, this), " << _this <<
"otrans_.get());" << endl;
5840 string(
"send_") + (*f_iter)->
get_name(),
5841 (*f_iter)->get_arglist());
5844 if (gen_templates_) {
5845 indent(out) << template_header;
5848 function_signature(&send_function,
"", scope) << endl;
5852 string argsname = tservice->
get_name() +
"_" + (*f_iter)->get_name() +
"_pargs";
5853 string resultname = tservice->
get_name() +
"_" + (*f_iter)->get_name() +
"_presult";
5857 indent() <<
"int32_t cseqid = 0;" << endl <<
5858 indent() << _this <<
"oprot_->writeMessageBegin(\"" <<
5859 (*f_iter)->get_name() <<
5860 "\", ::contrail::sandesh::protocol::T_CALL, cseqid);" << endl <<
5862 indent() << argsname <<
" args;" << endl;
5864 for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
5866 indent() <<
"args." << (*fld_iter)->get_name() <<
" = &" << (*fld_iter)->get_name() <<
";" << endl;
5870 indent() <<
"args.write(" << _this <<
"oprot_);" << endl <<
5872 indent() << _this <<
"oprot_->writeMessageEnd();" << endl <<
5873 indent() << _this <<
"oprot_->getTransport()->writeEnd();" << endl <<
5874 indent() << _this <<
"oprot_->getTransport()->flush();" << endl;
5880 if (!(*f_iter)->is_oneway()) {
5882 t_function recv_function((*f_iter)->get_returntype(),
5883 string(
"recv_") + (*f_iter)->get_name(),
5886 if (gen_templates_) {
5887 indent(out) << template_header;
5890 function_signature(&recv_function,
"", scope) << endl;
5895 indent() <<
"int32_t rseqid = 0;" << endl <<
5896 indent() <<
"std::string fname;" << endl <<
5897 indent() <<
"::contrail::sandesh::protocol::TMessageType mtype;" << endl;
5898 if (style ==
"Cob" && !gen_no_client_completion_) {
5900 indent() <<
"bool completed = false;" << endl << endl <<
5905 indent() << _this <<
"iprot_->readMessageBegin(fname, mtype, rseqid);" << endl <<
5906 indent() <<
"if (mtype == ::contrail::sandesh::protocol::T_EXCEPTION) {" << endl <<
5907 indent() <<
" ::contrail::sandesh::TApplicationException x;" << endl <<
5908 indent() <<
" x.read(" << _this <<
"iprot_);" << endl <<
5909 indent() <<
" " << _this <<
"iprot_->readMessageEnd();" << endl <<
5910 indent() <<
" " << _this <<
"iprot_->getTransport()->readEnd();" <<
5912 if (style ==
"Cob" && !gen_no_client_completion_) {
5914 indent() <<
" completed = true;" << endl <<
5915 indent() <<
" completed__(true);" << endl;
5918 indent() <<
" throw x;" << endl <<
5919 indent() <<
"}" << endl <<
5920 indent() <<
"if (mtype != ::contrail::sandesh::protocol::T_REPLY) {" << endl <<
5921 indent() <<
" " << _this <<
"iprot_->skip(" <<
5922 "::contrail::sandesh::protocol::T_STRUCT);" << endl <<
5923 indent() <<
" " << _this <<
"iprot_->readMessageEnd();" << endl <<
5924 indent() <<
" " << _this <<
"iprot_->getTransport()->readEnd();" <<
5926 if (style ==
"Cob" && !gen_no_client_completion_) {
5928 indent() <<
" completed = true;" << endl <<
5929 indent() <<
" completed__(false);" << endl;
5932 indent() <<
"}" << endl <<
5933 indent() <<
"if (fname.compare(\"" << (*f_iter)->get_name() <<
"\") != 0) {" << endl <<
5934 indent() <<
" " << _this <<
"iprot_->skip(" <<
5935 "::contrail::sandesh::protocol::T_STRUCT);" << endl <<
5936 indent() <<
" " << _this <<
"iprot_->readMessageEnd();" << endl <<
5937 indent() <<
" " << _this <<
"iprot_->getTransport()->readEnd();" <<
5939 if (style ==
"Cob" && !gen_no_client_completion_) {
5941 indent() <<
" completed = true;" << endl <<
5942 indent() <<
" completed__(false);" << endl;
5947 if (!(*f_iter)->get_returntype()->is_void() &&
5948 !is_complex_type((*f_iter)->get_returntype())) {
5949 t_field returnfield((*f_iter)->get_returntype(),
"_return");
5951 indent() << declare_field(&returnfield) << endl;
5955 indent() << resultname <<
" result;" << endl;
5957 if (!(*f_iter)->get_returntype()->is_void()) {
5959 indent() <<
"result.success = &_return;" << endl;
5963 indent() <<
"result.read(" << _this <<
"iprot_);" << endl <<
5964 indent() << _this <<
"iprot_->readMessageEnd();" << endl <<
5965 indent() << _this <<
"iprot_->getTransport()->readEnd();" << endl <<
5969 if (!(*f_iter)->get_returntype()->is_void()) {
5970 if (is_complex_type((*f_iter)->get_returntype())) {
5972 indent() <<
"if (result.__isset.success) {" << endl <<
5973 indent() <<
" // _return pointer has now been filled" << endl;
5974 if (style ==
"Cob" && !gen_no_client_completion_) {
5976 indent() <<
" completed = true;" << endl <<
5977 indent() <<
" completed__(true);" << endl;
5980 indent() <<
" return;" << endl <<
5984 indent() <<
"if (result.__isset.success) {" << endl;
5985 if (style ==
"Cob" && !gen_no_client_completion_) {
5987 indent() <<
" completed = true;" << endl <<
5988 indent() <<
" completed__(true);" << endl;
5991 indent() <<
" return _return;" << endl <<
5996 t_struct* xs = (*f_iter)->get_xceptions();
5997 const std::vector<t_field*>& xceptions = xs->
get_members();
5998 vector<t_field*>::const_iterator x_iter;
5999 for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) {
6001 indent() <<
"if (result.__isset." << (*x_iter)->get_name() <<
") {" << endl;
6002 if (style ==
"Cob" && !gen_no_client_completion_) {
6004 indent() <<
" completed = true;" << endl <<
6005 indent() <<
" completed__(true);" << endl;
6008 indent() <<
" throw result." << (*x_iter)->get_name() <<
";" << endl <<
6013 if ((*f_iter)->get_returntype()->is_void()) {
6014 if (style ==
"Cob" && !gen_no_client_completion_) {
6016 indent() <<
"completed = true;" << endl <<
6017 indent() <<
"completed__(true);" << endl;
6022 if (style ==
"Cob" && !gen_no_client_completion_) {
6024 indent() <<
"completed = true;" << endl <<
6025 indent() <<
"completed__(true);" << endl;
6028 indent() <<
"throw ::contrail::sandesh::TApplicationException(::contrail::sandesh::TApplicationException::MISSING_RESULT, \"" << (*f_iter)->get_name() <<
" failed: unknown result\");" << endl;
6030 if (style ==
"Cob" && !gen_no_client_completion_) {
6033 indent() <<
"} catch (...) {" << endl <<
6034 indent() <<
" if (!completed) {" << endl <<
6035 indent() <<
" completed__(false);" << endl <<
6036 indent() <<
" }" << endl <<
6037 indent() <<
" throw;" << endl <<
6051 const string& style);
6054 generate_class_definition();
6058 generate_process_fn();
6060 generate_process_functions();
6065 void generate_class_definition();
6066 void generate_process();
6067 void generate_process_fn();
6068 void generate_process_functions();
6069 void generate_factory();
6073 return generator_->type_name(ttype, in_typedef, arg);
6077 return generator_->indent();
6080 return generator_->indent(os);
6084 generator_->indent_up();
6087 generator_->indent_down();
6117 const string& style)
6118 : generator_(generator),
6120 f_header_(generator->f_header_),
6121 f_out_(generator->gen_templates_ ?
6122 generator->f_service_tcc_ : generator->f_service_),
6123 service_name_(generator->service_name_),
6130 finish_cob_ =
"std::tr1::function<void(bool ok)> cob, ";
6171 vector<t_function*>::iterator f_iter;
6181 " protected:" << endl;
6184 indent() <<
"boost::shared_ptr<" <<
if_name_ <<
"> iface_;" << endl;
6186 indent() <<
"virtual " <<
ret_type_ <<
"process_fn(" <<
finish_cob_ <<
"contrail::sandesh::protocol::TProtocol* iprot, contrail::sandesh::protocol::TProtocol* oprot, std::string& fname, int32_t seqid" <<
call_context_ <<
");" << endl;
6191 " private:" << endl;
6194 indent() <<
"std::map<std::string, void (" <<
6196 "int32_t, contrail::sandesh::protocol::TProtocol*, " <<
6198 ")> processMap_;" << endl;
6199 for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
6201 "void process_" << (*f_iter)->get_name() <<
"(" <<
finish_cob_ <<
"int32_t seqid, contrail::sandesh::protocol::TProtocol* iprot, contrail::sandesh::protocol::TProtocol* oprot" <<
call_context_ <<
");" << endl;
6204 "void process_" << (*f_iter)->get_name() <<
"(" <<
finish_cob_ <<
6205 "int32_t seqid, Protocol_* iprot, Protocol_* oprot" <<
6210 string ret_arg = ((*f_iter)->get_returntype()->is_void()
6212 :
", const " +
type_name((*f_iter)->get_returntype()) +
"& _return");
6214 indent() <<
"void return_" << (*f_iter)->get_name() <<
6215 "(std::tr1::function<void(bool ok)> cob, int32_t seqid, " <<
6216 "::contrail::sandesh::protocol::TProtocol* oprot, " <<
6217 "void* ctx" << ret_arg <<
");" << endl;
6220 indent() <<
"void return_" << (*f_iter)->get_name() <<
6221 "(std::tr1::function<void(bool ok)> cob, int32_t seqid, " <<
6222 "Protocol_* oprot, void* ctx" << ret_arg <<
");" << endl;
6226 indent() <<
"void throw_" << (*f_iter)->get_name() <<
6227 "(std::tr1::function<void(bool ok)> cob, int32_t seqid, " <<
6228 "contrail::sandesh::protocol::TProtocol* oprot, void* ctx, " <<
6229 "contrail::sandesh::TDelayedException* _throw);" << endl;
6232 indent() <<
"void throw_" << (*f_iter)->get_name() <<
6233 "(std::tr1::function<void(bool ok)> cob, int32_t seqid, " <<
6234 "Protocol_* oprot, void* ctx, " <<
6235 "::contrail::sandesh::TDelayedException* _throw);" << endl;
6242 string declare_map =
"";
6245 for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
6247 declare_map +=
"processMap_[\"";
6248 declare_map += (*f_iter)->get_name();
6249 declare_map +=
"\"] = &";
6251 declare_map +=
"::process_";
6252 declare_map += (*f_iter)->get_name();
6253 declare_map +=
";\n";
6258 " public:" << endl <<
6260 "(boost::shared_ptr<" <<
if_name_ <<
"> iface) :" << endl;
6263 indent() <<
" iface_(iface) {" << endl;
6267 indent() <<
" iface_(iface) {" << endl;
6271 indent() <<
"}" << endl <<
6273 indent() <<
"virtual " <<
ret_type_ <<
"process(" <<
finish_cob_ <<
"boost::shared_ptr<contrail::sandesh::protocol::TProtocol> piprot, boost::shared_ptr<contrail::sandesh::protocol::TProtocol> poprot" <<
call_context_ <<
");" << endl <<
6278 "};" << endl << endl;
6292 "<contrail::sandesh::protocol::TDummyProtocol> " <<
6302 "boost::shared_ptr<contrail::sandesh::protocol::TProtocol> piprot, " <<
6303 "boost::shared_ptr<contrail::sandesh::protocol::TProtocol> poprot" <<
6309 indent() <<
"::contrail::sandesh::protocol::TProtocol* iprot = piprot.get();" << endl <<
6310 indent() <<
"::contrail::sandesh::protocol::TProtocol* oprot = poprot.get();" << endl <<
6311 indent() <<
"std::string fname;" << endl <<
6312 indent() <<
"::contrail::sandesh::protocol::TMessageType mtype;" << endl <<
6313 indent() <<
"int32_t seqid;" << endl <<
6315 indent() <<
"iprot->readMessageBegin(fname, mtype, seqid);" << endl <<
6317 indent() <<
"if (mtype != ::contrail::sandesh::protocol::T_CALL && mtype != ::contrail::sandesh::protocol::T_ONEWAY) {" << endl <<
6318 indent() <<
" iprot->skip(::contrail::sandesh::protocol::T_STRUCT);" << endl <<
6319 indent() <<
" iprot->readMessageEnd();" << endl <<
6320 indent() <<
" iprot->getTransport()->readEnd();" << endl <<
6321 indent() <<
" ::contrail::sandesh::TApplicationException x(::contrail::sandesh::TApplicationException::INVALID_MESSAGE_TYPE);" << endl <<
6322 indent() <<
" oprot->writeMessageBegin(fname, ::contrail::sandesh::protocol::T_EXCEPTION, seqid);" << endl <<
6323 indent() <<
" x.write(oprot);" << endl <<
6324 indent() <<
" oprot->writeMessageEnd();" << endl <<
6325 indent() <<
" oprot->getTransport()->writeEnd();" << endl <<
6326 indent() <<
" oprot->getTransport()->flush();" << endl <<
6327 indent() << (
style_ ==
"Cob" ?
" return cob(true);" :
" return true;") << endl <<
6328 indent() <<
"}" << endl <<
6330 indent() <<
"return process_fn(" << (style_ ==
"Cob" ?
"cob, " :
"")
6336 indent() <<
"}" << endl <<
6345 "contrail::sandesh::protocol::TProtocol* iprot, " <<
6346 "contrail::sandesh::protocol::TProtocol* oprot, " <<
6347 "std::string& fname, int32_t seqid" <<
call_context_ <<
") {" << endl;
6354 "int32_t, contrail::sandesh::protocol::TProtocol*, " <<
6355 "contrail::sandesh::protocol::TProtocol*" <<
call_context_decl_ <<
")>::iterator pfn;" << endl <<
6356 indent() <<
"pfn = processMap_.find(fname);" << endl <<
6357 indent() <<
"if (pfn == processMap_.end()) {" << endl;
6360 indent() <<
" iprot->skip(contrail::sandesh::protocol::T_STRUCT);" << endl <<
6361 indent() <<
" iprot->readMessageEnd();" << endl <<
6362 indent() <<
" iprot->getTransport()->readEnd();" << endl <<
6363 indent() <<
" ::contrail::sandesh::TApplicationException x(::contrail::sandesh::TApplicationException::UNKNOWN_METHOD, \"Invalid method name: '\"+fname+\"'\");" << endl <<
6364 indent() <<
" oprot->writeMessageBegin(fname, ::contrail::sandesh::protocol::T_EXCEPTION, seqid);" << endl <<
6365 indent() <<
" x.write(oprot);" << endl <<
6366 indent() <<
" oprot->writeMessageEnd();" << endl <<
6367 indent() <<
" oprot->getTransport()->writeEnd();" << endl <<
6368 indent() <<
" oprot->getTransport()->flush();" << endl <<
6369 indent() << (
style_ ==
"Cob" ?
" return cob(true);" :
" return true;") << endl;
6374 << (
style_ ==
"Cob" ?
"cob, " :
"")
6378 indent() <<
"}" << endl <<
6384 indent() <<
"return;" << endl;
6387 indent() <<
"return true;" << endl;
6398 vector<t_function*>::iterator f_iter;
6399 for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
6410 string if_factory_name =
if_name_ +
"Factory";
6416 " : public ::contrail::sandesh::" <<
6417 (
style_ ==
"Cob" ?
"async::TAsyncProcessorFactory" :
"TProcessorFactory") <<
6424 if_factory_name <<
" >& handlerFactory) :" << endl <<
6425 indent() <<
" handlerFactory_(handlerFactory) {}" << endl <<
6427 indent() <<
"::boost::shared_ptr< ::contrail::sandesh::" <<
6428 (style_ ==
"Cob" ?
"async::TAsyncProcessor" :
"TProcessor") <<
" > " <<
6429 "getProcessor(const ::contrail::sandesh::TConnectionInfo& connInfo);" <<
6434 " protected:" << endl <<
6435 indent() <<
"::boost::shared_ptr< " << if_factory_name <<
6436 " > handlerFactory_;" << endl;
6440 "};" << endl << endl;
6447 "< ::contrail::sandesh::protocol::TDummyProtocol > " <<
6454 indent() <<
"::boost::shared_ptr< ::contrail::sandesh::" <<
6455 (style_ ==
"Cob" ?
"async::TAsyncProcessor" :
"TProcessor") <<
" > " <<
6457 "const ::contrail::sandesh::TConnectionInfo& connInfo) {" << endl;
6461 indent() <<
"::contrail::sandesh::ReleaseHandler< " << if_factory_name <<
6462 " > cleanup(handlerFactory_);" << endl <<
6463 indent() <<
"::boost::shared_ptr< " <<
if_name_ <<
" > handler(" <<
6464 "handlerFactory_->getHandler(connInfo), cleanup);" << endl <<
6465 indent() <<
"::boost::shared_ptr< ::contrail::sandesh::" <<
6466 (style_ ==
"Cob" ?
"async::TAsyncProcessor" :
"TProcessor") <<
" > " <<
6468 "(handler));" << endl <<
6469 indent() <<
"return processor;" << endl;
6503 result.append(&success);
6507 const vector<t_field*>& fields = xs->
get_members();
6508 vector<t_field*>::const_iterator f_iter;
6509 for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
6510 result.append(*f_iter);
6517 result.set_name(tservice->
get_name() +
"_" + tfunction->
get_name() +
"_presult");
6536 const std::vector<t_field*>& fields = arg_struct->
get_members();
6537 vector<t_field*>::const_iterator f_iter;
6540 const std::vector<t_field*>& xceptions = xs->
get_members();
6541 vector<t_field*>::const_iterator x_iter;
6542 string service_func_name = tservice->
get_name() +
"." +
6548 (specialized ?
"Protocol_" :
"::contrail::sandesh::protocol::TProtocol");
6549 string class_suffix;
6551 class_suffix =
"T<Protocol_>";
6555 if (style !=
"Cob") {
6559 indent() <<
"template <class Protocol_>" << endl;
6561 const bool unnamed_oprot_seqid = tfunction->
is_oneway() &&
6564 "void " << tservice->
get_name() <<
"Processor" << class_suffix <<
"::" <<
6565 "process_" << tfunction->
get_name() <<
"(" <<
6566 "int32_t" << (unnamed_oprot_seqid ?
", " :
" seqid, ") <<
6567 prot_type <<
"* iprot, " <<
6568 prot_type <<
"*" << (unnamed_oprot_seqid ?
", " :
" oprot, ") <<
6569 "void* callContext)" << endl;
6576 indent() <<
"Protocol_* _iprot = dynamic_cast<Protocol_*>(iprot);" <<
6578 indent() <<
"Protocol_* _oprot = dynamic_cast<Protocol_*>(oprot);" <<
6580 indent() <<
"if (_iprot && _oprot) {" << endl <<
6582 "(seqid, _iprot, _oprot, callContext);" << endl <<
6583 indent() <<
"}" << endl <<
6584 indent() <<
"T_GENERIC_PROTOCOL(this, iprot, _iprot);" << endl <<
6585 indent() <<
"T_GENERIC_PROTOCOL(this, oprot, _oprot);" << endl << endl;
6594 indent() <<
"void* ctx = NULL;" << endl <<
6595 indent() <<
"if (this->eventHandler_.get() != NULL) {" << endl <<
6596 indent() <<
" ctx = this->eventHandler_->getContext(\"" <<
6597 service_func_name <<
"\", callContext);" << endl <<
6598 indent() <<
"}" << endl <<
6599 indent() <<
"contrail::sandesh::TProcessorContextFreer freer(" <<
6600 "this->eventHandler_.get(), ctx, \"" << service_func_name <<
"\");" <<
6602 indent() <<
"if (this->eventHandler_.get() != NULL) {" << endl <<
6603 indent() <<
" this->eventHandler_->preRead(ctx, \"" <<
6604 service_func_name <<
"\");" << endl <<
6605 indent() <<
"}" << endl << endl <<
6606 indent() << argsname <<
" args;" << endl <<
6607 indent() <<
"args.read(iprot);" << endl <<
6608 indent() <<
"iprot->readMessageEnd();" << endl <<
6609 indent() <<
"uint32_t bytes = iprot->getTransport()->readEnd();" <<
6611 indent() <<
"if (this->eventHandler_.get() != NULL) {" << endl <<
6612 indent() <<
" this->eventHandler_->postRead(ctx, \"" <<
6613 service_func_name <<
"\", bytes);" << endl <<
6614 indent() <<
"}" << endl <<
6620 indent() << resultname <<
" result;" << endl;
6625 indent() <<
"try {" << endl;
6634 out <<
"iface_->" << tfunction->
get_name() <<
"(result.success";
6636 out <<
"result.success = iface_->" << tfunction->
get_name() <<
"(";
6640 "iface_->" << tfunction->
get_name() <<
"(";
6642 for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
6648 out <<
"args." << (*f_iter)->get_name();
6650 out <<
");" << endl;
6655 indent() <<
"result.__isset.success = true;" << endl;
6662 for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) {
6663 out <<
" catch (" <<
type_name((*x_iter)->get_type()) <<
" &" <<
6664 (*x_iter)->get_name() <<
") {" << endl;
6668 indent() <<
"result." << (*x_iter)->get_name() <<
" = " <<
6669 (*x_iter)->get_name() <<
";" << endl <<
6670 indent() <<
"result.__isset." << (*x_iter)->get_name() <<
6680 out <<
" catch (const std::exception& e) {" << endl;
6684 indent() <<
"if (this->eventHandler_.get() != NULL) {" << endl <<
6685 indent() <<
" this->eventHandler_->handlerError(ctx, \"" <<
6686 service_func_name <<
"\");" << endl <<
6692 indent() <<
"contrail::sandesh::TApplicationException x(e.what());" <<
6694 indent() <<
"oprot->writeMessageBegin(\"" << tfunction->
get_name() <<
6695 "\", contrail::sandesh::protocol::T_EXCEPTION, seqid);" << endl <<
6696 indent() <<
"x.write(oprot);" << endl <<
6697 indent() <<
"oprot->writeMessageEnd();" << endl <<
6698 indent() <<
"oprot->getTransport()->writeEnd();" << endl <<
6699 indent() <<
"oprot->getTransport()->flush();" << endl;
6701 out <<
indent() <<
"return;" << endl;
6703 out <<
indent() <<
"}" << endl << endl;
6708 indent() <<
"if (this->eventHandler_.get() != NULL) {" << endl <<
6709 indent() <<
" this->eventHandler_->asyncComplete(ctx, \"" <<
6710 service_func_name <<
"\");" << endl <<
6711 indent() <<
"}" << endl << endl <<
6712 indent() <<
"return;" << endl;
6714 out <<
"}" << endl <<
6721 indent() <<
"if (this->eventHandler_.get() != NULL) {" << endl <<
6722 indent() <<
" this->eventHandler_->preWrite(ctx, \"" <<
6723 service_func_name <<
"\");" << endl <<
6724 indent() <<
"}" << endl << endl <<
6725 indent() <<
"oprot->writeMessageBegin(\"" << tfunction->
get_name() <<
6726 "\", contrail::sandesh::protocol::T_REPLY, seqid);" << endl <<
6727 indent() <<
"result.write(oprot);" << endl <<
6728 indent() <<
"oprot->writeMessageEnd();" << endl <<
6729 indent() <<
"bytes = oprot->getTransport()->writeEnd();" << endl <<
6730 indent() <<
"oprot->getTransport()->flush();" << endl << endl <<
6731 indent() <<
"if (this->eventHandler_.get() != NULL) {" << endl <<
6732 indent() <<
" this->eventHandler_->postWrite(ctx, \"" <<
6733 service_func_name <<
"\", bytes);" << endl <<
6747 indent() <<
"template <class Protocol_>" << endl;
6750 "void " << tservice->
get_name() <<
"AsyncProcessor" << class_suffix <<
6751 "::process_" << tfunction->
get_name() <<
6752 "(std::tr1::function<void(bool ok)> cob, int32_t seqid, " <<
6753 prot_type <<
"* iprot, " << prot_type <<
"* oprot)" << endl;
6762 indent() <<
"Protocol_* _iprot = dynamic_cast<Protocol_*>(iprot);" <<
6764 indent() <<
"Protocol_* _oprot = dynamic_cast<Protocol_*>(oprot);" <<
6766 indent() <<
"if (_iprot && _oprot) {" << endl <<
6768 "(cob, seqid, _iprot, _oprot);" << endl <<
6769 indent() <<
"}" << endl <<
6770 indent() <<
"T_GENERIC_PROTOCOL(this, iprot, _iprot);" << endl <<
6771 indent() <<
"T_GENERIC_PROTOCOL(this, oprot, _oprot);" << endl << endl;
6776 indent() <<
"(void) seqid;" << endl <<
6777 indent() <<
"(void) oprot;" << endl;
6782 "_args args;" << endl <<
6783 indent() <<
"void* ctx = NULL;" << endl <<
6784 indent() <<
"if (this->eventHandler_.get() != NULL) {" << endl <<
6785 indent() <<
" ctx = this->eventHandler_->getContext(\"" <<
6786 service_func_name <<
"\", NULL);" << endl <<
6787 indent() <<
"}" << endl <<
6788 indent() <<
"contrail::sandesh::TProcessorContextFreer freer(" <<
6789 "this->eventHandler_.get(), ctx, \"" << service_func_name <<
"\");" <<
6791 indent() <<
"try {" << endl;
6794 indent() <<
"if (this->eventHandler_.get() != NULL) {" << endl <<
6795 indent() <<
" this->eventHandler_->preRead(ctx, \"" <<
6796 service_func_name <<
"\");" << endl <<
6797 indent() <<
"}" << endl <<
6798 indent() <<
"args.read(iprot);" << endl <<
6799 indent() <<
"iprot->readMessageEnd();" << endl <<
6800 indent() <<
"uint32_t bytes = iprot->getTransport()->readEnd();" <<
6802 indent() <<
"if (this->eventHandler_.get() != NULL) {" << endl <<
6803 indent() <<
" this->eventHandler_->postRead(ctx, \"" <<
6804 service_func_name <<
"\", bytes);" << endl <<
6810 indent() <<
"catch (const std::exception& exn) {" << endl <<
6811 indent() <<
" if (this->eventHandler_.get() != NULL) {" << endl <<
6812 indent() <<
" this->eventHandler_->handlerError(ctx, \"" <<
6813 service_func_name <<
"\");" << endl <<
6814 indent() <<
" }" << endl <<
6815 indent() <<
" return cob(false);" << endl <<
6820 indent() <<
"if (this->eventHandler_.get() != NULL) {" << endl <<
6821 indent() <<
" this->eventHandler_->asyncComplete(ctx, \"" <<
6822 service_func_name <<
"\");" << endl <<
6827 indent() <<
"freer.unregister();" << endl;
6833 "std::tr1::bind(cob, true)" << endl;
6836 string ret_arg, ret_placeholder;
6840 ret_placeholder =
", std::tr1::placeholders::_1";
6847 indent() <<
"void (" << tservice->
get_name() <<
"AsyncProcessor" <<
6848 class_suffix <<
"::*return_fn)(std::tr1::function<void(bool ok)> " <<
6849 "cob, int32_t seqid, " << prot_type <<
"* oprot, void* ctx" <<
6850 ret_arg <<
") =" << endl;
6853 class_suffix <<
"::return_" << tfunction->
get_name() <<
";" << endl;
6854 if (!xceptions.empty()) {
6856 indent() <<
"void (" << tservice->
get_name() <<
"AsyncProcessor" <<
6857 class_suffix <<
"::*throw_fn)(std::tr1::function<void(bool ok)> " <<
6858 "cob, int32_t seqid, " << prot_type <<
"* oprot, void* ctx, " <<
6859 "::contrail::sandesh::TDelayedException* _throw) =" << endl;
6862 class_suffix <<
"::throw_" << tfunction->
get_name() <<
";" << endl;
6869 indent() <<
"std::tr1::bind(return_fn, this, cob, seqid, oprot, ctx" <<
6870 ret_placeholder <<
")";
6871 if (!xceptions.empty()) {
6874 indent() <<
"std::tr1::bind(throw_fn, this, cob, seqid, oprot, " <<
6875 "ctx, std::tr1::placeholders::_1)";
6880 for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
6883 indent() <<
"args." << (*f_iter)->get_name();
6885 out <<
");" << endl;
6892 string ret_arg_decl, ret_arg_name;
6896 ret_arg_name =
", _return";
6900 indent() <<
"template <class Protocol_>" << endl;
6903 "void " << tservice->
get_name() <<
"AsyncProcessor" << class_suffix <<
6904 "::return_" << tfunction->
get_name() <<
6905 "(std::tr1::function<void(bool ok)> cob, int32_t seqid, " <<
6906 prot_type <<
"* oprot, void* ctx" << ret_arg_decl <<
')' << endl;
6913 indent() <<
"Protocol_* _oprot = dynamic_cast<Protocol_*>(oprot);" <<
6915 indent() <<
"if (_oprot) {" << endl <<
6917 "(cob, seqid, _oprot, ctx" << ret_arg_name <<
");" << endl <<
6918 indent() <<
"}" << endl <<
6919 indent() <<
"T_GENERIC_PROTOCOL(this, oprot, _oprot);" <<
6925 "_presult result;" << endl;
6930 indent() <<
"result.success = const_cast<" <<
6933 indent() <<
"result.__isset.success = true;" << endl;
6938 indent() <<
"if (this->eventHandler_.get() != NULL) {" << endl <<
6939 indent() <<
" ctx = this->eventHandler_->getContext(\"" <<
6940 service_func_name <<
"\", NULL);" << endl <<
6941 indent() <<
"}" << endl <<
6942 indent() <<
"contrail::sandesh::TProcessorContextFreer freer(" <<
6943 "this->eventHandler_.get(), ctx, \"" << service_func_name <<
6944 "\");" << endl << endl <<
6945 indent() <<
"if (this->eventHandler_.get() != NULL) {" << endl <<
6946 indent() <<
" this->eventHandler_->preWrite(ctx, \"" <<
6947 service_func_name <<
"\");" << endl <<
6948 indent() <<
"}" << endl << endl <<
6949 indent() <<
"oprot->writeMessageBegin(\"" << tfunction->
get_name() <<
6950 "\", contrail::sandesh::protocol::T_REPLY, seqid);" << endl <<
6951 indent() <<
"result.write(oprot);" << endl <<
6952 indent() <<
"oprot->writeMessageEnd();" << endl <<
6953 indent() <<
"uint32_t bytes = oprot->getTransport()->writeEnd();" <<
6955 indent() <<
"oprot->getTransport()->flush();" << endl <<
6956 indent() <<
"if (this->eventHandler_.get() != NULL) {" << endl <<
6957 indent() <<
" this->eventHandler_->postWrite(ctx, \"" <<
6958 service_func_name <<
"\", bytes);" << endl <<
6959 indent() <<
"}" << endl <<
6960 indent() <<
"return cob(true);" << endl;
6966 if (!tfunction->
is_oneway() && !xceptions.empty()) {
6969 indent() <<
"template <class Protocol_>" << endl;
6972 "void " << tservice->
get_name() <<
"AsyncProcessor" << class_suffix <<
6973 "::throw_" << tfunction->
get_name() <<
6974 "(std::tr1::function<void(bool ok)> cob, int32_t seqid, " <<
6975 prot_type <<
"* oprot, void* ctx, " <<
6976 "::contrail::sandesh::TDelayedException* _throw)" << endl;
6983 indent() <<
"Protocol_* _oprot = dynamic_cast<Protocol_*>(oprot);" <<
6985 indent() <<
"if (_oprot) {" << endl <<
6987 "(cob, seqid, _oprot, ctx, _throw);" << endl <<
6988 indent() <<
"}" << endl <<
6989 indent() <<
"T_GENERIC_PROTOCOL(this, oprot, _oprot);" <<
6996 indent() <<
"if (this->eventHandler_.get() != NULL) {" << endl <<
6997 indent() <<
" ctx = this->eventHandler_->getContext(\"" <<
6998 service_func_name <<
"\", NULL);" << endl <<
6999 indent() <<
"}" << endl <<
7000 indent() <<
"contrail::sandesh::TProcessorContextFreer freer(" <<
7001 "this->eventHandler_.get(), ctx, \"" << service_func_name <<
"\");" <<
7007 "_result result;" << endl << endl <<
7008 indent() <<
"try {" << endl;
7011 indent() <<
"_throw->throw_it();" << endl <<
7012 indent() <<
"return cob(false);" << endl;
7016 for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) {
7017 out <<
" catch (" <<
type_name((*x_iter)->get_type()) <<
" &" <<
7018 (*x_iter)->get_name() <<
") {" << endl;
7021 indent() <<
"result." << (*x_iter)->get_name() <<
" = " <<
7022 (*x_iter)->get_name() <<
";" << endl <<
7023 indent() <<
"result.__isset." << (*x_iter)->get_name() <<
7029 out <<
" catch (std::exception& e) {" << endl;
7032 indent() <<
"if (this->eventHandler_.get() != NULL) {" << endl <<
7033 indent() <<
" this->eventHandler_->handlerError(ctx, \"" <<
7034 service_func_name <<
"\");" << endl <<
7035 indent() <<
"}" << endl <<
7037 indent() <<
"contrail::sandesh::TApplicationException x(e.what());" <<
7039 indent() <<
"oprot->writeMessageBegin(\"" << tfunction->
get_name() <<
7040 "\", contrail::sandesh::protocol::T_EXCEPTION, seqid);" << endl <<
7041 indent() <<
"x.write(oprot);" << endl <<
7042 indent() <<
"oprot->writeMessageEnd();" << endl <<
7043 indent() <<
"oprot->getTransport()->writeEnd();" << endl <<
7044 indent() <<
"oprot->getTransport()->flush();" << endl <<
7048 indent() <<
"return cob(true);" << endl;
7053 indent() <<
"if (this->eventHandler_.get() != NULL) {" << endl <<
7054 indent() <<
" this->eventHandler_->preWrite(ctx, \"" <<
7055 service_func_name <<
"\");" << endl <<
7056 indent() <<
"}" << endl << endl <<
7057 indent() <<
"oprot->writeMessageBegin(\"" << tfunction->
get_name() <<
7058 "\", contrail::sandesh::protocol::T_REPLY, seqid);" << endl <<
7059 indent() <<
"result.write(oprot);" << endl <<
7060 indent() <<
"oprot->writeMessageEnd();" << endl <<
7061 indent() <<
"uint32_t bytes = oprot->getTransport()->writeEnd();" <<
7063 indent() <<
"oprot->getTransport()->flush();" << endl <<
7064 indent() <<
"if (this->eventHandler_.get() != NULL) {" << endl <<
7065 indent() <<
" this->eventHandler_->postWrite(ctx, \"" <<
7066 service_func_name <<
"\", bytes);" << endl <<
7067 indent() <<
"}" << endl <<
7068 indent() <<
"return cob(true);" << endl;
7081 string svcname = tservice->
get_name();
7084 string f_skeleton_name =
get_out_dir()+svcname+
"_server.skeleton.cpp";
7088 ofstream f_skeleton;
7089 f_skeleton.open(f_skeleton_name.c_str());
7091 "// This autogenerated skeleton file illustrates how to build a server." << endl <<
7092 "// You should copy it to another filename to avoid overwriting it." << endl <<
7095 "#include <protocol/TBinaryProtocol.h>" << endl <<
7096 "#include <server/TSimpleServer.h>" << endl <<
7097 "#include <transport/TServerSocket.h>" << endl <<
7098 "#include <transport/TBufferTransports.h>" << endl <<
7100 "using namespace ::contrail::sandesh;" << endl <<
7101 "using namespace ::contrail::sandesh::protocol;" << endl <<
7102 "using namespace ::contrail::sandesh::transport;" << endl <<
7103 "using namespace ::contrail::sandesh::server;" << endl <<
7105 "using boost::shared_ptr;" << endl <<
7110 "using namespace " << string(ns, 0, ns.size()-2) <<
";" << endl <<
7115 "class " << svcname <<
"Handler : virtual public " << svcname <<
"If {" << endl <<
7119 indent() << svcname <<
"Handler() {" << endl <<
7120 indent() <<
" // Your initialization goes here" << endl <<
7121 indent() <<
"}" << endl <<
7125 vector<t_function*>::iterator f_iter;
7126 for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
7129 indent() <<
" // Your implementation goes here" << endl <<
7130 indent() <<
" printf(\"" << (*f_iter)->get_name() <<
"\\n\");" << endl <<
7131 indent() <<
"}" << endl <<
7141 indent() <<
"int main(int argc, char **argv) {" << endl;
7144 indent() <<
"int port = 9090;" << endl <<
7145 indent() <<
"shared_ptr<" << svcname <<
"Handler> handler(new " << svcname <<
"Handler());" << endl <<
7146 indent() <<
"shared_ptr<TProcessor> processor(new " << svcname <<
"Processor(handler));" << endl <<
7147 indent() <<
"shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));" << endl <<
7148 indent() <<
"shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());" << endl <<
7149 indent() <<
"shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());" << endl <<
7151 indent() <<
"TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory);" << endl <<
7152 indent() <<
"server.serve();" << endl <<
7153 indent() <<
"return 0;" << endl;
7173 throw "CANNOT GENERATE DESERIALIZE CODE FOR void TYPE: " +
7177 string name = prefix + tfield->
get_name() + suffix;
7185 "if ((ret = iprot->";
7189 throw "compiler error: cannot serialize void field in a struct: " + name;
7193 case t_base_type::TYPE_STATIC_CONST_STRING:
7196 out <<
"readBinary(" << name <<
")) < 0) {" << endl;
7199 out <<
"readString(" << name <<
")) < 0) {" << endl;
7203 case t_base_type::TYPE_XML:
7204 out <<
"readXML(" << name <<
")) < 0) {" << endl;
7206 case t_base_type::TYPE_UUID:
7207 out <<
"readUUID(" << name <<
")) < 0) {" << endl;
7211 out <<
"readBool(" << name <<
")) < 0) {" << endl;
7214 out <<
"readByte(" << name <<
")) < 0) {" << endl;
7217 out <<
"readI16(" << name <<
")) < 0) {" << endl;
7220 out <<
"readI32(" << name <<
")) < 0) {" << endl;
7223 out <<
"readI64(" << name <<
")) < 0) {" << endl;
7226 case t_base_type::TYPE_U16:
7227 out <<
"readU16(" << name <<
")) < 0) {" << endl;
7229 case t_base_type::TYPE_U32:
7230 out <<
"readU32(" << name <<
")) < 0) {" << endl;
7232 case t_base_type::TYPE_U64:
7233 out <<
"readU64(" << name <<
")) < 0) {" << endl;
7235 case t_base_type::TYPE_IPV4:
7236 out <<
"readIPV4(" << name <<
")) < 0) {" << endl;
7238 case t_base_type::TYPE_IPADDR:
7239 out <<
"readIPADDR(" << name <<
")) < 0) {" << endl;
7243 out <<
"readDouble(" << name <<
")) < 0) {" << endl;
7249 out <<
indent() <<
"return ret;" << endl;
7251 out <<
indent() <<
"xfer += ret;" << endl;
7255 string t =
tmp(
"ecast");
7257 indent() <<
"int32_t " << t <<
";" << endl <<
7258 indent() <<
"if ((ret = iprot->readI32(" << t <<
")) < 0) {" << endl <<
7259 indent() <<
" return ret;" << endl <<
7260 indent() <<
"}" << endl <<
7261 indent() <<
"xfer += ret;" << endl <<
7262 indent() << name <<
" = (" <<
type_name(type) <<
")" << t <<
";" << endl;
7264 printf(
"DO NOT KNOW HOW TO DESERIALIZE FIELD '%s' TYPE '%s'\n",
7280 "if ((ret = " << prefix <<
".read(iprot)) < 0) {" << endl;
7282 indent(out) <<
"return ret;" << endl;
7284 indent(out) <<
"xfer += ret;" << endl;
7292 string size =
tmp(
"_size");
7293 string ktype =
tmp(
"_ktype");
7294 string vtype =
tmp(
"_vtype");
7295 string etype =
tmp(
"_etype");
7301 prefix <<
".clear();" << endl <<
7302 indent() <<
"uint32_t " << size <<
";" << endl;
7307 indent() <<
"::contrail::sandesh::protocol::TType " << ktype <<
";" << endl <<
7308 indent() <<
"::contrail::sandesh::protocol::TType " << vtype <<
";" << endl <<
7309 indent() <<
"if ((ret = iprot->readMapBegin(" <<
7310 ktype <<
", " << vtype <<
", " << size <<
")) < 0) {" << endl <<
7311 indent() <<
" return ret;" << endl <<
7312 indent() <<
"}" << endl <<
7313 indent() <<
"xfer += ret;" << endl;
7314 }
else if (ttype->
is_set()) {
7316 indent() <<
"::contrail::sandesh::protocol::TType " << etype <<
";" << endl <<
7317 indent() <<
"if ((ret = iprot->readSetBegin(" <<
7318 etype <<
", " << size <<
")) < 0) {" << endl <<
7319 indent() <<
" return ret;" << endl <<
7320 indent() <<
"}" << endl <<
7321 indent() <<
"xfer += ret;" << endl;
7322 }
else if (ttype->
is_list()) {
7324 indent() <<
"::contrail::sandesh::protocol::TType " << etype <<
";" << endl <<
7325 indent() <<
"if ((ret = iprot->readListBegin(" <<
7326 etype <<
", " << size <<
")) < 0) {" << endl <<
7327 indent() <<
" return ret;" << endl <<
7328 indent() <<
"}" << endl <<
7329 indent() <<
"xfer += ret;" << endl;
7331 indent(out) << prefix <<
".resize(" << size <<
");" << endl;
7337 string i =
tmp(
"_i");
7339 indent() <<
"uint32_t " << i <<
";" << endl <<
7340 indent() <<
"for (" << i <<
" = 0; " << i <<
" < " << size <<
"; ++" << i <<
")" << endl;
7346 }
else if (ttype->
is_set()) {
7350 indent(out) <<
"if ((ret = iprot->readContainerElementBegin()) < 0) {" << endl;
7352 indent(out) <<
"return ret;" << endl;
7354 indent(out) <<
"xfer += ret;" << endl;
7360 indent(out) <<
"if ((ret = iprot->readContainerElementEnd()) < 0) {" << endl;
7362 indent(out) <<
"return ret;" << endl;
7364 indent(out) <<
"xfer += ret;" << endl;
7367 }
else if (ttype->
is_list()) {
7371 indent(out) <<
"if ((ret = iprot->readContainerElementBegin()) < 0) {" << endl;
7373 indent(out) <<
"return ret;" << endl;
7375 indent(out) <<
"xfer += ret;" << endl;
7381 indent(out) <<
"if ((ret = iprot->readContainerElementEnd()) < 0) {" << endl;
7383 indent(out) <<
"return ret;" << endl;
7385 indent(out) <<
"xfer += ret;" << endl;
7395 indent(out) <<
"if ((ret = iprot->readMapEnd()) < 0) {" << endl;
7397 indent(out) <<
"return ret;" << endl;
7399 indent(out) <<
"xfer += ret;" << endl;
7401 indent(out) <<
"iprot->readMapEnd();" << endl;
7403 }
else if (ttype->
is_set()) {
7405 indent(out) <<
"if ((ret = iprot->readSetEnd()) < 0) {" << endl;
7407 indent(out) <<
"return ret;" << endl;
7409 indent(out) <<
"xfer += ret;" << endl;
7411 indent(out) <<
"iprot->readSetEnd();" << endl;
7413 }
else if (ttype->
is_list()) {
7415 indent(out) <<
"if ((ret = iprot->readListEnd()) < 0) {" << endl;
7417 indent(out) <<
"return ret;" << endl;
7419 indent(out) <<
"xfer += ret;" << endl;
7421 indent(out) <<
"iprot->readListEnd();" << endl;
7435 string key =
tmp(
"_key");
7436 string val =
tmp(
"_val");
7446 indent(out) <<
"if ((ret = iprot->readContainerElementBegin()) < 0) {" << endl;
7448 indent(out) <<
"return ret;" << endl;
7450 indent(out) <<
"xfer += ret;" << endl;
7456 indent(out) <<
"if ((ret = iprot->readContainerElementEnd()) < 0) {" << endl;
7458 indent(out) <<
"return ret;" << endl;
7460 indent(out) <<
"xfer += ret;" << endl;
7465 prefix <<
"[" << key <<
"];" << endl;
7470 indent(out) <<
"if ((ret = iprot->readContainerElementBegin()) < 0) {" << endl;
7472 indent(out) <<
"return ret;" << endl;
7474 indent(out) <<
"xfer += ret;" << endl;
7480 indent(out) <<
"if ((ret = iprot->readContainerElementEnd()) < 0) {" << endl;
7482 indent(out) <<
"return ret;" << endl;
7484 indent(out) <<
"xfer += ret;" << endl;
7492 string elem =
tmp(
"_elem");
7501 prefix <<
".insert(" << elem <<
");" << endl;
7510 string elem =
tmp(
"_elem");
7514 indent(out) << prefix <<
".push_back(" << elem <<
");" << endl;
7534 string name = prefix + tfield->
get_name() + suffix;
7538 throw "CANNOT GENERATE SERIALIZE CODE FOR void TYPE: " + name;
7552 "if ((ret = oprot->";
7559 "compiler error: cannot serialize void field in a struct: " + name;
7563 case t_base_type::TYPE_STATIC_CONST_STRING:
7566 out <<
"writeBinary(" << name <<
")) < 0) {" << endl;
7569 out <<
"writeString(" << name <<
")) < 0) {" << endl;
7573 case t_base_type::TYPE_XML:
7574 out <<
"writeXML(" << name <<
")) < 0) {" << endl;
7576 case t_base_type::TYPE_UUID:
7577 out <<
"writeUUID(" << name <<
")) < 0) {" << endl;
7581 out <<
"writeBool(" << name <<
")) < 0) {" << endl;
7584 out <<
"writeByte(" << name <<
")) < 0) {" << endl;
7587 out <<
"writeI16(" << name <<
")) < 0) {" << endl;
7590 out <<
"writeI32(" << name <<
")) < 0) {" << endl;
7593 out <<
"writeI64(" << name <<
")) < 0) {" << endl;
7596 case t_base_type::TYPE_U16:
7597 out <<
"writeU16(" << name <<
")) < 0) {" << endl;
7599 case t_base_type::TYPE_U32:
7600 out <<
"writeU32(" << name <<
")) < 0) {" << endl;
7602 case t_base_type::TYPE_U64:
7603 out <<
"writeU64(" << name <<
")) < 0) {" << endl;
7605 case t_base_type::TYPE_IPV4:
7606 out <<
"writeIPV4(" << name <<
")) < 0) {" << endl;
7608 case t_base_type::TYPE_IPADDR:
7609 out <<
"writeIPADDR(" << name <<
")) < 0) {" << endl;
7613 out <<
"writeDouble(" << name <<
")) < 0) {" << endl;
7619 out <<
"writeI32((int32_t)" << name <<
")) < 0) {" << endl;
7622 out <<
indent() <<
"return ret;" << endl;
7624 out <<
indent() <<
"xfer += ret;" << endl;
7627 }
else if (type->is_sandesh()) {
7628 generate_serialize_sandesh(out, (
t_sandesh*)type, name);
7631 printf(
"DO NOT KNOW HOW TO SERIALIZE FIELD '%s' TYPE '%s'\n",
7644 void t_cpp_generator::generate_serialize_sandesh(ofstream& out,
7649 "if ((ret = " << prefix <<
".write(oprot)) < 0) {" << endl;
7651 indent(out) <<
"return ret;" << endl;
7653 indent(out) <<
"xfer += ret;" << endl;
7668 "if ((ret = " << prefix <<
".write(oprot)) < 0) {" << endl;
7670 indent(out) <<
"return ret;" << endl;
7672 indent(out) <<
"xfer += ret;" << endl;
7682 "if ((ret = oprot->writeMapBegin(" <<
7685 "static_cast<uint32_t>(" << prefix <<
".size()))) < 0) {" << endl;
7687 indent(out) <<
"return ret;" << endl;
7689 indent(out) <<
"xfer += ret;" << endl;
7690 }
else if (ttype->
is_set()) {
7692 "if ((ret = oprot->writeSetBegin(" <<
7694 "static_cast<uint32_t>(" << prefix <<
".size()))) < 0) {" << endl;
7696 indent(out) <<
"return ret;" << endl;
7698 indent(out) <<
"xfer += ret;" << endl;
7699 }
else if (ttype->
is_list()) {
7701 "if ((ret = oprot->writeListBegin(" <<
7703 "static_cast<uint32_t>(" << prefix <<
".size()))) < 0) {" << endl;
7705 indent(out) <<
"return ret;" << endl;
7707 indent(out) <<
"xfer += ret;" << endl;
7710 string iter =
tmp(
"_iter");
7712 indent() <<
type_name(ttype) <<
"::const_iterator " << iter <<
";" << endl <<
7713 indent() <<
"for (" << iter <<
" = " << prefix <<
".begin(); " << iter <<
" != " << prefix <<
".end(); ++" << iter <<
")" << endl;
7717 }
else if (ttype->
is_set()) {
7721 indent(out) <<
"if ((ret = oprot->writeContainerElementBegin()) < 0) {" << endl;
7723 indent(out) <<
"return ret;" << endl;
7725 indent(out) <<
"xfer += ret;" << endl;
7731 indent(out) <<
"if ((ret = oprot->writeContainerElementEnd()) < 0) {" << endl;
7733 indent(out) <<
"return ret;" << endl;
7735 indent(out) <<
"xfer += ret;" << endl;
7738 }
else if (ttype->
is_list()) {
7742 indent(out) <<
"if ((ret = oprot->writeContainerElementBegin()) < 0) {" << endl;
7744 indent(out) <<
"return ret;" << endl;
7746 indent(out) <<
"xfer += ret;" << endl;
7752 indent(out) <<
"if ((ret = oprot->writeContainerElementEnd()) < 0) {" << endl;
7754 indent(out) <<
"return ret;" << endl;
7756 indent(out) <<
"xfer += ret;" << endl;
7764 "if ((ret = oprot->writeMapEnd()) < 0) {" << endl;
7766 indent(out) <<
"return ret;" << endl;
7768 indent(out) <<
"xfer += ret;" << endl;
7769 }
else if (ttype->
is_set()) {
7771 "if ((ret = oprot->writeSetEnd()) < 0) {" << endl;
7773 indent(out) <<
"return ret;" << endl;
7775 indent(out) <<
"xfer += ret;" << endl;
7776 }
else if (ttype->
is_list()) {
7778 "if ((ret = oprot->writeListEnd()) < 0) {" << endl;
7780 indent(out) <<
"return ret;" << endl;
7782 indent(out) <<
"xfer += ret;" << endl;
7798 indent(out) <<
"if ((ret = oprot->writeContainerElementBegin()) < 0) {" << endl;
7800 indent(out) <<
"return ret;" << endl;
7802 indent(out) <<
"xfer += ret;" << endl;
7809 indent(out) <<
"if ((ret = oprot->writeContainerElementEnd()) < 0) {" << endl;
7811 indent(out) <<
"return ret;" << endl;
7813 indent(out) <<
"xfer += ret;" << endl;
7819 indent(out) <<
"if ((ret = oprot->writeContainerElementBegin()) < 0) {" << endl;
7821 indent(out) <<
"return ret;" << endl;
7823 indent(out) <<
"xfer += ret;" << endl;
7830 indent(out) <<
"if ((ret = oprot->writeContainerElementEnd()) < 0) {" << endl;
7832 indent(out) <<
"return ret;" << endl;
7834 indent(out) <<
"xfer += ret;" << endl;
7872 string result =
" ::";
7874 if (ns.size() == 0) {
7877 string::size_type loc;
7878 while ((loc = ns.find(
".")) != string::npos) {
7879 result += ns.substr(0, loc);
7881 ns = ns.substr(loc+1);
7883 if (ns.size() > 0) {
7884 result += ns +
"::";
7896 if (ns.size() == 0) {
7900 string separator =
"";
7901 string::size_type loc;
7902 while ((loc = ns.find(
".")) != string::npos) {
7903 result += separator;
7904 result +=
"namespace ";
7905 result += ns.substr(0, loc);
7908 ns = ns.substr(loc+1);
7910 if (ns.size() > 0) {
7911 result += separator +
"namespace " + ns +
" {";
7923 if (ns.size() == 0) {
7926 string result =
"}";
7927 string::size_type loc;
7928 while ((loc = ns.find(
".")) != string::npos) {
7930 ns = ns.substr(loc+1);
7932 result +=
" // namespace";
7951 || ((
t_base_type*)ttype)->get_base() == t_base_type::TYPE_XML
7952 || ((
t_base_type*)ttype)->get_base() == t_base_type::TYPE_UUID
7953 || ((
t_base_type*)ttype)->get_base() == t_base_type::TYPE_IPADDR
7956 return "const " + bname +
"&";
7958 return "const " + bname;
7969 }
else if (ttype->
is_map()) {
7971 cname =
"std::map<" +
7974 }
else if (ttype->
is_set()) {
7977 }
else if (ttype->
is_list()) {
7983 return "const " + cname +
"&";
7989 string class_prefix;
7991 class_prefix =
"class ";
7997 if (program != NULL && program !=
program_) {
8003 pname = class_prefix + ttype->
get_name();
8012 return "const " + pname +
"&";
8014 return "const " + pname;
8032 case t_base_type::TYPE_STATIC_CONST_STRING:
8033 return "static std::string";
8037 case t_base_type::TYPE_XML:
8039 return "std::string";
8051 case t_base_type::TYPE_U16:
8053 case t_base_type::TYPE_U32:
8055 case t_base_type::TYPE_U64:
8057 case t_base_type::TYPE_IPV4:
8059 case t_base_type::TYPE_IPADDR:
8060 return "boost::asio::ip::address";
8061 case t_base_type::TYPE_UUID:
8062 return "boost::uuids::uuid";
8094 result +=
" " + tfield->
get_name();
8104 case t_base_type::TYPE_UUID:
8105 result +=
" = boost::uuids::nil_uuid()";
8107 case t_base_type::TYPE_STATIC_CONST_STRING:
8108 case t_base_type::TYPE_XML:
8111 result +=
" = \"\"";
8114 result +=
" = false";
8121 case t_base_type::TYPE_U16:
8122 case t_base_type::TYPE_U32:
8123 case t_base_type::TYPE_U64:
8124 case t_base_type::TYPE_IPV4:
8129 result +=
" = (double)0";
8132 case t_base_type::TYPE_IPADDR:
8133 result +=
" = boost::asio::ip::address()";
8140 result +=
" = (" +
type_name(type) +
")0";
8167 bool is_static = tfunction->is_static();
8168 bool is_virtual = tfunction->is_virtual();
8169 string func_begin_modifier =
"", func_end_modifier =
"";
8174 func_begin_modifier =
"static ";
8175 }
else if (is_virtual) {
8176 func_begin_modifier =
"virtual ";
8177 func_end_modifier =
" = 0";
8185 func_begin_modifier +
8187 "void " + prefix + tfunction->
get_name() +
8188 "(" +
type_name(ttype) + (name_params ?
"& _return" :
"& /* _return */") +
8197 func_begin_modifier +
8206 }
else if (style.substr(0,3) ==
"Cob") {
8209 if (style ==
"CobCl") {
8212 cob_type +=
"T<Protocol_>";
8214 cob_type +=
"* client)";
8215 }
else if (style ==
"CobSv") {
8218 : (
"(" +
type_name(ttype) +
" const& _return)"));
8219 if (has_xceptions) {
8220 exn_cob =
", std::tr1::function<void(::contrail::sandesh::TDelayedException* _throw)> /* exn_cob */";
8223 throw "UNKNOWN STYLE";
8227 "void " + prefix + tfunction->
get_name() +
8228 "(std::tr1::function<void" + cob_type +
"> cob" + exn_cob +
8231 throw "UNKNOWN STYLE";
8244 const vector<t_field*>& fields = tstruct->
get_members();
8245 vector<t_field*>::const_iterator f_iter;
8246 bool first = !start_comma;
8247 for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
8253 result +=
type_name((*f_iter)->get_type(),
false,
true) +
" " +
8254 (name_params ? (*f_iter)->get_name() :
"/* " + (*f_iter)->get_name() +
" */");
8272 throw "NO T_VOID CONSTRUCT";
8274 return "::contrail::sandesh::protocol::T_STRING";
8276 return "::contrail::sandesh::protocol::T_BOOL";
8278 return "::contrail::sandesh::protocol::T_BYTE";
8280 return "::contrail::sandesh::protocol::T_I16";
8282 return "::contrail::sandesh::protocol::T_I32";
8284 return "::contrail::sandesh::protocol::T_I64";
8286 return "::contrail::sandesh::protocol::T_DOUBLE";
8288 case t_base_type::TYPE_XML:
8289 return "::contrail::sandesh::protocol::T_XML";
8290 case t_base_type::TYPE_UUID:
8291 return "::contrail::sandesh::protocol::T_UUID";
8292 case t_base_type::TYPE_U16:
8293 return "::contrail::sandesh::protocol::T_U16";
8294 case t_base_type::TYPE_U32:
8295 return "::contrail::sandesh::protocol::T_U32";
8296 case t_base_type::TYPE_U64:
8297 return "::contrail::sandesh::protocol::T_U64";
8298 case t_base_type::TYPE_IPV4:
8299 return "::contrail::sandesh::protocol::T_IPV4";
8300 case t_base_type::TYPE_IPADDR:
8301 return "::contrail::sandesh::protocol::T_IPADDR";
8302 case t_base_type::TYPE_STATIC_CONST_STRING:
8303 case t_base_type::TYPE_SANDESH_SYSTEM:
8304 case t_base_type::TYPE_SANDESH_REQUEST:
8305 case t_base_type::TYPE_SANDESH_RESPONSE:
8306 case t_base_type::TYPE_SANDESH_TRACE:
8307 case t_base_type::TYPE_SANDESH_TRACE_OBJECT:
8308 case t_base_type::TYPE_SANDESH_BUFFER:
8309 case t_base_type::TYPE_SANDESH_UVE:
8310 case t_base_type::TYPE_SANDESH_ALARM:
8311 case t_base_type::TYPE_SANDESH_OBJECT:
8312 case t_base_type::TYPE_SANDESH_FLOW:
8313 case t_base_type::TYPE_SANDESH_SESSION:
8314 return "::contrail::sandesh::protocol::T_STRING";
8318 return "::contrail::sandesh::protocol::T_I32";
8320 return "::contrail::sandesh::protocol::T_STRUCT";
8322 return "::contrail::sandesh::protocol::T_STRUCT";
8324 }
else if (type->is_sandesh()) {
8325 return "::contrail::sandesh::protocol::T_SANDESH";
8327 }
else if (type->
is_map()) {
8328 return "::contrail::sandesh::protocol::T_MAP";
8329 }
else if (type->
is_set()) {
8330 return "::contrail::sandesh::protocol::T_SET";
8332 return "::contrail::sandesh::protocol::T_LIST";
8335 throw "INVALID TYPE IN type_to_enum: " + type->
get_name();
8358 }
else if (ttype->
is_enum()) {
8378 return nspace +
"trlo_" + prefix +
"_" + prog +
"_" + name;
8384 (include_prefix.size() > 0 && include_prefix[0] ==
'/')) {
8389 string::size_type last_slash = string::npos;
8390 if ((last_slash = include_prefix.rfind(
"/")) != string::npos) {
8391 return include_prefix.substr(0, last_slash) +
"/" +
out_dir_base_ +
"/";
8405 const vector<t_field*>& fields = tstruct->
get_members();
8406 vector<t_field*>::const_iterator f_iter;
8411 indent() <<
"int32_t xfer = 0, ret;" << endl <<
8412 indent() <<
"std::string fname;" << endl <<
8413 indent() <<
"::contrail::sandesh::protocol::TType ftype;" << endl <<
8414 indent() <<
"int16_t fid;" << endl <<
8417 "if ((ret = iprot->read" << struct_type_name <<
"Begin(fname)) < 0) {" <<
8419 indent() <<
" return ret;" << endl <<
8420 indent() <<
"}" << endl <<
8421 indent() <<
"xfer += ret;" << endl <<
8425 for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
8427 indent(out) <<
"bool isset_" << (*f_iter)->get_name() <<
" = false;" << endl;
8433 "while (true)" << endl;
8438 "if ((ret = iprot->readFieldBegin(fname, ftype, fid)) < 0) {" << endl;
8440 indent(out) <<
"return ret;" << endl;
8442 indent(out) <<
"xfer += ret;" << endl;
8446 indent() <<
"if (ftype == ::contrail::sandesh::protocol::T_STOP) {" << endl <<
8447 indent() <<
" break;" << endl <<
8453 if (fields.empty()) {
8455 indent() <<
"if ((ret = iprot->skip(ftype)) < 0) {" << endl <<
8456 indent() <<
" return ret;" << endl <<
8457 indent() <<
"}" << endl <<
8458 indent() <<
"xfer += ret;" << endl;
8462 "switch (fid)" << endl;
8467 for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
8469 "case " << (*f_iter)->get_key() <<
":" << endl;
8472 "if (ftype == " <<
type_to_enum((*f_iter)->get_type()) <<
") {" << endl;
8475 const char *isset_prefix =
8484 indent() <<
"if (" << isset_prefix << (*f_iter)->get_name() <<
")" << endl <<
8485 indent() <<
" throw TProtocolException(TProtocolException::INVALID_DATA);" << endl;
8488 if (pointers && !(*f_iter)->get_type()->is_xception()) {
8494 indent() << isset_prefix << (*f_iter)->get_name() <<
" = true;" << endl;
8497 indent() <<
"} else {" << endl <<
8498 indent() <<
" if ((ret = iprot->skip(ftype)) < 0) {" << endl <<
8499 indent() <<
" return ret;" << endl <<
8500 indent() <<
" }" << endl <<
8501 indent() <<
" xfer += ret;" << endl <<
8505 indent() <<
"}" << endl <<
8506 indent() <<
"break;" << endl;
8512 indent() <<
"default:" << endl <<
8513 indent() <<
" if ((ret = iprot->skip(ftype)) < 0) {" << endl <<
8514 indent() <<
" return ret;" << endl <<
8515 indent() <<
" }" << endl <<
8516 indent() <<
" xfer += ret;" << endl <<
8517 indent() <<
" break;" << endl;
8524 "if ((ret = iprot->readFieldEnd()) < 0) {" << endl;
8526 indent(out) <<
"return ret;" << endl;
8528 indent(out) <<
"xfer += ret;" << endl;
8535 "if ((ret = iprot->read" << struct_type_name <<
"End()) < 0) {" << endl;
8538 indent(out) <<
"return ret;" << endl;
8540 indent(out) <<
"xfer += ret;" << endl;
8546 for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
8549 indent() <<
"if (!isset_" << (*f_iter)->get_name() <<
") {" << endl <<
8550 indent() <<
" LOG(ERROR, __func__ << \": Required field " << (*f_iter)->get_name()
8551 <<
" not set\");" << endl <<
8552 indent() <<
" return -1;" << endl <<
8556 indent(out) <<
"return xfer;" << endl;
8570 const vector<t_field*>& fields = tstruct->
get_members();
8571 vector<t_field*>::const_iterator f_iter;
8574 indent() <<
"int32_t xfer = 0, ret;" << endl;
8577 "if ((ret = oprot->write" << struct_type_name <<
"Begin(\"" << name <<
"\")) < 0) {" <<
8581 indent(out) <<
"return ret;" << endl;
8583 indent(out) <<
"xfer += ret;" << endl;
8584 for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
8586 indent(out) <<
"if (this->__isset." << (*f_iter)->get_name() <<
") {" << endl;
8590 if (!((*f_iter)->annotations_.empty())) {
8591 out <<
indent() <<
"{" << endl;
8593 out <<
indent() <<
"std::map<std::string, std::string> annotations_;" << endl;
8594 std::map<std::string, std::string>::iterator it;
8595 for (it = (*f_iter)->annotations_.begin(); it != (*f_iter)->annotations_.end(); it++) {
8596 if (!tstruct->is_sandesh() &&
8597 ((*f_iter)->get_name() ==
"name") && (it->first ==
"key")) {
8598 out <<
indent() <<
"assert(!table_.empty());" << endl;
8599 out <<
indent() <<
"annotations_.insert("
8600 "std::make_pair(\"key\", table_));" << endl;
8602 out <<
indent() <<
"annotations_.insert(std::make_pair(\"" << (*it).first
8603 <<
"\"" <<
", \"" << (*it).second <<
"\"));" << endl;
8607 indent() <<
"if ((ret = oprot->writeFieldBegin(" <<
8608 "\"" << (*f_iter)->get_name() <<
"\", " <<
8610 (*f_iter)->get_key() <<
", &annotations_)) < 0) {" << endl;
8612 indent(out) <<
"return ret;" << endl;
8614 indent(out) <<
"xfer += ret;" << endl;
8616 out <<
indent() <<
"}" << endl;
8619 indent() <<
"if ((ret = oprot->writeFieldBegin(" <<
8620 "\"" << (*f_iter)->get_name() <<
"\", " <<
8622 (*f_iter)->get_key() <<
")) < 0) {" << endl;
8624 indent(out) <<
"return ret;" << endl;
8626 indent(out) <<
"xfer += ret;" << endl;
8630 if (pointers && !(*f_iter)->get_type()->is_xception()) {
8637 "if ((ret = oprot->writeFieldEnd()) < 0) {" << endl;
8639 indent(out) <<
"return ret;" << endl;
8641 indent(out) <<
"xfer += ret;" << endl;
8644 indent(out) <<
'}' << endl;
8650 indent() <<
"if ((ret = oprot->writeFieldStop()) < 0) {" << endl <<
8651 indent() <<
" return ret;" << endl <<
8652 indent() <<
"}" << endl <<
8653 indent() <<
"xfer += ret;" << endl <<
8655 "if ((ret = oprot->write" << struct_type_name <<
"End()) < 0) {" <<
8657 indent() <<
" return ret;" << endl <<
8658 indent() <<
"}" << endl <<
8659 indent() <<
"xfer += ret;" << endl <<
8660 indent() <<
"return xfer;" << endl;
8667 " cob_style: Generate \"Continuation OBject\"-style classes.\n"
8668 " no_client_completion:\n"
8669 " Omit calls to completion__() in CobClient class.\n"
8670 " templates: Generate templatized reader/writer methods.\n"
8671 " pure_enums: Generate pure enums instead of wrapper classes.\n"
8672 " dense: Generate type specifications for the dense protocol.\n"
8673 " include_prefix: Use full include paths in generated files.\n"
std::ofstream f_types_impl_
void generate_enum(t_enum *tenum)
void generate_service_async_skeleton(t_service *tservice)
virtual bool is_xception() const
const std::string & get_name() const
void generate_serialize_set_element(std::ofstream &out, t_set *tmap, std::string iter)
void generate_serialize_field(std::ofstream &out, t_field *tfield, std::string prefix="", std::string suffix="")
const std::string & get_include_prefix() const
std::ofstream & f_header_
t_type * get_type() const
void generate_xception(t_struct *txception)
std::string tmp(std::string name)
std::string local_reflection_name(const char *, t_type *ttype, bool external=false)
void generate_service_helpers(t_service *tservice)
void generate_service_skeleton(t_service *tservice)
void generate_struct_writer(std::ofstream &out, t_struct *tstruct, bool pointers=false)
std::string get_include_prefix(const t_program &program) const
void set_use_include_prefix(bool use_include_prefix)
static std::string t_base_name(t_base tbase)
void generate_class_definition()
const std::string & get_name() const
bool is_level_category_supported() const
const uint32_t get_4byte_fingerprint() const
void generate_struct(t_struct *tstruct)
virtual bool is_map() const
bool has_fingerprint() const
const std::string & get_name() const
virtual std::string get_fingerprint_material() const =0
std::string declare_field(t_field *tfield, bool init=false, bool pointer=false, bool constant=false, bool reference=false)
std::string get_cpp_name()
string factory_class_name_
std::string namespace_prefix(std::string ns)
virtual std::string get_out_dir() const
void generate_enum_constant_list(std::ofstream &f, const vector< t_enum_value * > &constants, const char *prefix, const char *suffix, bool include_values)
const members_type & get_sorted_members()
static const int fingerprint_len
void generate_process_functions()
virtual bool is_enum() const
t_type * get_type() const
virtual bool is_base_type() const
string call_context_decl_
void scope_up(std::ostream &out)
const t_program * get_program() const
t_cpp_generator(t_program *program, const std::map< std::string, std::string > &parsed_options, const std::string &option_string)
void generate_deserialize_container(std::ofstream &out, t_type *ttype, std::string prefix="")
void generate_process_function(t_service *tservice, t_function *tfunction, string style, bool specialized=false)
void generate_service_multiface(t_service *tservice)
t_type * get_returntype() const
std::string type_to_enum(t_type *ttype)
const std::map< t_const_value *, t_const_value * > & get_map() const
void print_const_value(std::ofstream &out, std::string name, t_type *type, t_const_value *value)
const members_type & get_members()
std::string argument_list(t_struct *tstruct, bool name_params=true, bool start_comma=false)
void generate_service(t_service *tservice)
std::ofstream f_types_tcc_
int64_t get_integer() const
t_type * get_key_type() const
void generate_process_fn()
void generate_service_interface(t_service *tservice, string style)
virtual std::string get_struct_type_name()=0
std::string service_name_
t_const_value_type get_type() const
virtual bool is_container() const
void generate_deserialize_set_element(std::ofstream &out, t_set *tset, std::string prefix="")
std::string render_const_value(std::ofstream &out, std::string name, t_type *type, t_const_value *value)
void generate_service_client(t_service *tservice, string style)
t_struct * get_xceptions() const
bool gen_no_client_completion_
t_type * get_elem_type() const
std::string out_dir_base_
ProcessorGenerator(t_cpp_generator *generator, t_service *service, const string &style)
void generate_function_helpers(t_service *tservice, t_function *tfunction)
void generate_struct_reader(std::ofstream &out, t_struct *tstruct, bool pointers=false)
std::string namespace_close(std::string ns)
virtual bool is_set() const
void generate_struct_result_writer(std::ofstream &out, t_struct *tstruct, bool pointers=false)
virtual void set_name(const std::string &name)
std::string get_uuid() const
void generate_serialize_container(std::ofstream &out, t_type *ttype, std::string prefix="")
std::string type_name(t_type *ttype, bool in_typedef=false, bool arg=false)
void generate_common_struct_reader_body(std::ofstream &out, t_struct_common *tstruct, bool pointers=false)
virtual bool is_void() const
std::string type_name(t_type *ttype, bool in_typedef=false, bool arg=false)
std::ofstream f_service_tcc_
void generate_serialize_list_element(std::ofstream &out, t_list *tlist, std::string iter)
t_type * get_elem_type() const
void generate_serialize_struct(std::ofstream &out, t_struct *tstruct, std::string prefix="")
t_type * get_val_type() const
void scope_down(std::ostream &out)
void generate_local_reflection(std::ofstream &out, t_type *ttype, bool is_definition)
const std::string & get_symbolic() const
const std::vector< t_function * > & get_functions() const
bool is_complex_type(t_type *ttype)
std::string namespace_open(std::string ns)
virtual const std::string & get_name() const
void generate_cpp_struct(t_struct *tstruct, bool is_exception)
virtual bool is_list() const
virtual bool has_key_annotation() const
void generate_typedef(t_typedef *ttypedef)
string extends_processor_
std::string function_signature(t_function *tfunction, std::string style, std::string prefix="", bool name_params=true)
const std::vector< t_enum_value * > & get_constants()
void generate_service_processor(t_service *tservice, string style)
static std::string byte_to_hex(uint8_t byte)
void generate_struct_fingerprint(std::ofstream &out, t_struct *tstruct, bool is_definition)
void generate_serialize_map_element(std::ofstream &out, t_map *tmap, std::string iter)
void generate_deserialize_struct(std::ofstream &out, t_struct *tstruct, std::string prefix="")
std::string get_string() const
static t_type * get_true_type(t_type *type)
double get_double() const
const std::string & get_namespace() const
std::string get_ascii_fingerprint() const
t_program * get_program()
virtual bool is_struct() const
t_service * get_extends()
const t_type * get_type()
#define LOG(_Level, _Msg)
void generate_consts(std::vector< t_const * > consts)
std::map< std::string, std::string > annotations_
void generate_common_struct_writer_body(std::ofstream &out, t_struct_common *tstruct, bool pointers=false)
const uint8_t * get_binary_fingerprint() const
std::ostream & indent(std::ostream &os)
std::set< std::string > reflected_fingerprints_
void generate_deserialize_map_element(std::ofstream &out, t_map *tmap, std::string prefix="")
std::string base_type_name(t_base_type::t_base tbase)
void generate_function_call(ostream &out, t_function *tfunction, string target, string iface, string arg_prefix)
void generate_local_reflection_pointer(std::ofstream &out, t_type *ttype)
t_cpp_generator * generator_
void generate_struct_definition(std::ofstream &out, t_struct *tstruct, bool is_exception=false, bool pointers=false, bool read=true, bool write=true)
virtual bool is_string() const
void generate_service_interface_factory(t_service *tservice, string style)
void generate_service_null(t_service *tservice, string style)
void generate_deserialize_list_element(std::ofstream &out, t_list *tlist, std::string prefix, bool push_back, std::string index)
static const char namespace_prefix[]
int32_t skip(Protocol_ &prot, TType type)
#define THRIFT_REGISTER_GENERATOR(language, long_name, doc)
void generate_deserialize_field(std::ofstream &out, t_field *tfield, std::string prefix="", std::string suffix="")
const std::vector< t_const_value * > & get_list() const
t_struct * get_arglist() const