31 #include <boost/algorithm/string.hpp>
38 #include <boost/foreach.hpp>
39 #include <boost/tokenizer.hpp>
51 const map<string, string>& parsed_options,
52 const string& option_string)
55 (void) parsed_options;
57 out_dir_base_ =
"gen-doc";
59 escape_[
'&'] =
"&";
60 escape_[
'<'] =
"<";
61 escape_[
'>'] =
">";
62 escape_[
'"'] =
""";
63 escape_[
'\''] =
"'";
102 string get_object_type(
t_sandesh* tsandesh);
103 string get_doc_member(
t_sandesh* tsandesh,
string member);
107 void generate_index();
108 void generate_stats_schema_program();
110 void generate_const_enum_typedef_object_program();
111 void generate_doc_type(ofstream &f_out);
112 void generate_program();
113 void generate_program_toc(ofstream &f_out,
string fsuffix,
115 void generate_program_toc_row(
t_program* tprog, ofstream &f_out,
117 bool generate_sandesh_program_doc(
t_program* tprog, ofstream &f_out,
119 void generate_sandesh_program_doc_schema(
t_program* tprog, ofstream &f_out,
121 void generate_sandesh_program_doc_schema_uve(
t_program* tprog, ofstream &f_out,
128 template <
typename T>
129 void generate_stat_table_schema(
string,
t_field*, T*,
string, vector<string>&);
130 template <
typename T>
131 void generate_stat_schema_map(
string,
t_type*,
t_type*,
t_field*, T*,
bool,
bool, vector<string>&);
132 template <
typename T>
133 void generate_stat_schema_list(
string,
t_type*,
t_field*, T*,
bool,
bool, vector<string>&);
134 t_struct* find_struct_with_name(
string sname);
135 template <
typename T>
136 void generate_stat_schema_struct(
string,
t_field*,
t_struct*, T*,
bool, vector<string>&);
137 template <
typename T>
138 void extract_tags(T*, map<
string, vector<string> >&, vector<string>&, vector<string>&);
139 string generate_stat_schema_struct_base_member(
string,
t_field*,
string,
t_field*);
140 void generate_stat_table_schema_header(
string,
string,
string,
string);
141 string get_datatype_from_tfield(
t_type* tfield);
142 string generate_table_entry(
string name,
string datatype,
string index,
string);
143 template <
typename T>
145 string get_uve_type(
string,
t_field*);
146 template <
typename T>
148 void generate_stat_schema_struct_members(
string name,
t_field*,
t_struct*, vector<string>, map<
string, vector<string> >, vector<string>&);
149 void is_indexed_or_suffixed_field(
string, vector<string>, map<
string, vector<string> >,
string&,
bool&,
bool&);
150 template <
typename T>
151 void generate_stat_schema_suffixes(
string,
t_field*,
t_struct*, T*, map<
string, vector<string> >&, vector<string>&);
152 template <
typename T>
153 void generate_stat_schema_toplevel_tags(T*, vector<string>&, vector<string>&,
t_field*);
154 void generate_stat_tables_schema(
t_sandesh*);
155 template <
typename T>
156 void generate_stat_tables_schema(T*,
const vector<t_field*>,
string,
string, vector<string>&);
157 string get_display_name_from_comments(
t_field*);
158 template <
typename T>
159 void find_recursive_tags(T*,
t_field*,
string,
string, vector<string>&);
160 template <
typename T>
161 void find_recursive_tags_struct(T*,
t_field*,
string,
string,
string, vector<string>&);
162 template <
typename T>
163 void find_recursive_tags_list(T*,
t_field*,
string,
t_type*,
string, vector<string>&);
164 template <
typename T>
165 void find_recursive_tags_map(T*,
t_field*,
string,
t_type*,
t_type*,
string, vector<string>&);
166 string find_obj_table_name(
const vector<t_field*>);
173 bool generate_introspect_cli (
t_sandesh* , ofstream &f_out,
bool &first_file);
175 void print_doc (
t_doc* tdoc, ofstream &f_out);
176 int print_type (
t_type* ttype, ofstream &f_out);
177 void print_const_value(
t_const_value* tvalue, ofstream &f_out);
178 void print_sandesh (
t_sandesh* tdoc, ofstream &f_out);
179 void print_sandesh_message(
t_sandesh* tdoc, ofstream &f_out);
180 void print_sandesh_message_table(
t_sandesh* tdoc, ofstream &f_out);
181 void print_doc_string (
string doc, ofstream &f_out);
201 void generate_typedef (
t_typedef* ttypedef, ofstream &f_out);
202 void generate_enum (
t_enum* tenum, ofstream &f_out);
203 void generate_const (
t_const* tconst, ofstream &f_out);
204 void generate_consts (vector<t_const*> consts, ofstream &f_out);
205 void generate_struct (
t_struct* tstruct, ofstream &f_out);
206 void generate_struct_table (
t_struct* tstruct, ofstream &f_out);
207 void generate_sandesh (
t_sandesh* tsandesh, ofstream &f_out);
208 void generate_sandesh_uve (
t_sandesh* tsandesh, ofstream &f_out);
218 case doc_ftype::LOGS:
219 if (tbtype->is_sandesh_system() || tbtype->is_sandesh_object()) {
223 case doc_ftype::LOGS_LEVEL_INVALID:
224 if ((tbtype->is_sandesh_system() || tbtype->is_sandesh_object()) &&
229 case doc_ftype::LOGS_LEVEL_DEBUG:
230 if ((tbtype->is_sandesh_system() || tbtype->is_sandesh_object()) &&
231 get_sandesh_level(tsandesh) == sandesh_level::DBG) {
235 case doc_ftype::LOGS_LEVEL_INFO:
236 if ((tbtype->is_sandesh_system() || tbtype->is_sandesh_object()) &&
237 get_sandesh_level(tsandesh) == sandesh_level::INFO) {
241 case doc_ftype::LOGS_LEVEL_NOTICE:
242 if ((tbtype->is_sandesh_system() || tbtype->is_sandesh_object()) &&
243 get_sandesh_level(tsandesh) == sandesh_level::NOTICE) {
247 case doc_ftype::LOGS_LEVEL_WARN:
248 if ((tbtype->is_sandesh_system() || tbtype->is_sandesh_object()) &&
249 get_sandesh_level(tsandesh) == sandesh_level::WARN) {
253 case doc_ftype::LOGS_LEVEL_ERR:
254 if ((tbtype->is_sandesh_system() || tbtype->is_sandesh_object()) &&
255 get_sandesh_level(tsandesh) == sandesh_level::ERR) {
259 case doc_ftype::LOGS_LEVEL_CRIT:
260 if ((tbtype->is_sandesh_system() || tbtype->is_sandesh_object()) &&
261 get_sandesh_level(tsandesh) == sandesh_level::CRIT) {
265 case doc_ftype::LOGS_LEVEL_ALERT:
266 if ((tbtype->is_sandesh_system() || tbtype->is_sandesh_object()) &&
267 get_sandesh_level(tsandesh) == sandesh_level::ALERT) {
271 case doc_ftype::LOGS_LEVEL_EMERG:
272 if ((tbtype->is_sandesh_system() || tbtype->is_sandesh_object()) &&
273 get_sandesh_level(tsandesh) == sandesh_level::EMERG) {
277 case doc_ftype::UVES:
278 if (tbtype->is_sandesh_uve()) {
282 case doc_ftype::TRACES:
283 if (tbtype->is_sandesh_trace() || tbtype->is_sandesh_trace_object()) {
287 case doc_ftype::INTROSPECT:
288 if (tbtype->is_sandesh_request() || tbtype->is_sandesh_response()) {
300 case doc_ftype::LOGS:
302 case doc_ftype::LOGS_LEVEL_INVALID:
303 return "_logs.invalid";
304 case doc_ftype::LOGS_LEVEL_DEBUG:
305 return "_logs.debug";
306 case doc_ftype::LOGS_LEVEL_INFO:
308 case doc_ftype::LOGS_LEVEL_NOTICE:
309 return "_logs.notice";
310 case doc_ftype::LOGS_LEVEL_WARN:
312 case doc_ftype::LOGS_LEVEL_ERR:
313 return "_logs.error";
314 case doc_ftype::LOGS_LEVEL_CRIT:
316 case doc_ftype::LOGS_LEVEL_ALERT:
317 return "_logs.alert";
318 case doc_ftype::LOGS_LEVEL_EMERG:
319 return "_logs.emerg";
320 case doc_ftype::UVES:
322 case doc_ftype::TRACES:
324 case doc_ftype::INTROSPECT:
325 return "_introspect";
333 case doc_ftype::LOGS:
334 return "all systemlog and objectlog";
335 case doc_ftype::LOGS_LEVEL_INVALID:
336 return "systemlog and objectlog with unknown severity";
337 case doc_ftype::LOGS_LEVEL_DEBUG:
338 return "debug systemlog and objectlog";
339 case doc_ftype::LOGS_LEVEL_INFO:
340 return "informational systemlog and objectlog";
341 case doc_ftype::LOGS_LEVEL_NOTICE:
342 return "notice systemlog and objectlog";
343 case doc_ftype::LOGS_LEVEL_WARN:
344 return "warning systemlog and objectlog";
345 case doc_ftype::LOGS_LEVEL_ERR:
346 return "error systemlog and objectlog";
347 case doc_ftype::LOGS_LEVEL_CRIT:
348 return "critical systemlog and objectlog";
349 case doc_ftype::LOGS_LEVEL_ALERT:
350 return "alert systemlog and objectlog";
351 case doc_ftype::LOGS_LEVEL_EMERG:
352 return "emergency systemlog and objectlog";
353 case doc_ftype::UVES:
355 case doc_ftype::TRACES:
357 case doc_ftype::INTROSPECT:
369 f_out <<
"<table><tr><th>Module</th><th>Messages</th></tr>" << endl;
370 generate_program_toc_row(program_, f_out, fsuffix, dtype);
371 f_out <<
"</table>" << endl;
379 string fname = tprog->
get_name() + fsuffix +
".html";
380 f_out <<
"<tr>" << endl <<
"<td>" << tprog->
get_name() <<
"</td><td>";
381 if (!tprog->get_sandeshs().empty()) {
382 vector<t_sandesh*> sandeshs = tprog->get_sandeshs();
383 vector<t_sandesh*>::iterator snh_iter;
384 for (snh_iter = sandeshs.begin(); snh_iter != sandeshs.end(); ++snh_iter) {
385 string name = get_sandesh_name(*snh_iter);
386 if (is_sandesh_type(*snh_iter, dtype)) {
387 if (dtype == doc_ftype::UVES) {
388 vector<t_field*> members = (*snh_iter)->get_members();
389 BOOST_FOREACH(
t_field *tfield, members) {
391 f_out <<
"<a href=\"" << fname <<
"#Snh_" << name <<
"\">" << name
392 <<
"</a><br/>" << endl;
395 f_out <<
"<a href=\"" << fname <<
"#Snh_" << name <<
"\">" << name
396 <<
"</a><br/>" << endl;
401 f_out <<
"</td>" << endl;
406 f_out <<
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"" << endl;
407 f_out <<
" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" << endl;
408 f_out <<
"<html xmlns=\"http://www.w3.org/1999/xhtml\">" << endl;
409 f_out <<
"<head>" << endl;
410 f_out <<
"<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />" << endl;
411 f_out <<
"<link href=\"/doc-style.css\" rel=\"stylesheet\" type=\"text/css\"/>"
416 string fname = get_out_dir() + program_->get_name() +
"_stats_tables.json";
417 f_stats_tables_.open(fname.c_str());
418 stat_table_created_ =
false;
419 first_member_ =
true;
420 f_stats_tables_ <<
"{\"_STAT_TABLES\":[" << endl;
421 if (!program_->get_sandeshs().empty()) {
423 vector<t_sandesh*> sandeshs = program_->get_sandeshs();
424 vector<t_sandesh*>::iterator snh_iter;
425 for (snh_iter = sandeshs.begin(); snh_iter != sandeshs.end(); ++snh_iter) {
426 generate_stat_tables_schema(*snh_iter);
429 f_stats_tables_ <<
"]" << endl <<
"}" << endl;
434 if (dtype == doc_ftype::UVES)
435 return generate_sandesh_program_doc_schema_uve(tprog, f_out, fsuffix);
437 f_out <<
"{\"messages\":{" << endl;
438 if (!tprog->get_sandeshs().empty()) {
439 vector<t_sandesh*> sandeshs = tprog->get_sandeshs();
440 vector<t_sandesh*>::iterator snh_iter;
441 for (snh_iter = sandeshs.begin(); snh_iter != sandeshs.end(); ++snh_iter) {
442 if (!is_sandesh_type(*snh_iter, dtype)) {
448 f_out <<
"," << endl;
450 string sandesh_name(get_sandesh_name(*snh_iter));
451 string fname(tprog->
get_name() + fsuffix +
".html");
452 f_out <<
"\"" << sandesh_name <<
"\":{\"fingerprint\":\"" <<
453 (*snh_iter)->get_ascii_fingerprint() <<
"\", \"href\":\"" <<
454 fname <<
"#Snh_" << sandesh_name <<
"\"";
455 if (dtype == doc_ftype::LOGS) {
456 f_out <<
", \"severity\":\"" <<
457 sandesh_level_to_string(get_sandesh_level(*snh_iter)) <<
"\"";
458 }
else if (dtype == doc_ftype::UVES) {
459 f_out <<
", \"object\":\"" << get_object_type(*snh_iter) <<
"\"";
463 f_out <<
"}," << endl <<
"\"sandesh_cli\":{" << endl;
464 bool first_file =
true;
465 for (snh_iter = sandeshs.begin(); snh_iter != sandeshs.end(); ++snh_iter) {
466 sandesh_name_ = get_sandesh_name(*snh_iter);
467 if (!is_sandesh_type(*snh_iter, doc_ftype::INTROSPECT)) {
470 generate_introspect_cli(*snh_iter, f_out, first_file);
472 f_out << endl <<
"}" << endl <<
"}" << endl;
474 f_out <<
"}" << endl <<
"}" << endl;
479 ofstream &f_out,
string fsuffix) {
481 f_out <<
"{\"messages\":{" << endl;
482 if (!tprog->get_sandeshs().empty()) {
483 vector<t_sandesh*> sandeshs = tprog->get_sandeshs();
484 vector<t_sandesh*>::iterator snh_iter;
485 for (snh_iter = sandeshs.begin(); snh_iter != sandeshs.end(); ++snh_iter) {
486 if (!is_sandesh_type(*snh_iter, doc_ftype::UVES)) {
492 f_out <<
"," << endl;
494 string sandesh_name(get_sandesh_name(*snh_iter));
495 vector<t_field*> smembers = (*snh_iter)->get_members();
496 if (smembers.size() == 1 && smembers[0]->get_type()->is_struct()) {
497 sandesh_name = smembers[0]->get_type()->get_name();
499 string fname(tprog->
get_name() + fsuffix +
".html");
500 f_out <<
"\"" << sandesh_name <<
"\":{\"fingerprint\":\"" <<
501 (*snh_iter)->get_ascii_fingerprint() <<
"\", \"href\":\"" <<
502 fname <<
"#Snh_" << sandesh_name <<
"\"";
503 if (get_object_type(*snh_iter) !=
"") {
504 f_out <<
", \"object\":\"" << get_object_type(*snh_iter) <<
"\"";
508 f_out <<
"}," << endl <<
"\"sandesh_cli\":{" << endl;
509 bool first_file =
true;
510 for (snh_iter = sandeshs.begin(); snh_iter != sandeshs.end(); ++snh_iter) {
511 sandesh_name_ = get_sandesh_name(*snh_iter);
512 if (!is_sandesh_type(*snh_iter, doc_ftype::UVES)) {
515 generate_introspect_cli(*snh_iter, f_out, first_file);
517 f_out << endl <<
"}" << endl <<
"}" << endl;
519 f_out <<
"}" << endl <<
"}" << endl;
526 generate_doc_type(f_out);
528 string mdesc(get_doc_file_description(dtype));
529 f_out <<
"<title>Documentation for " << mdesc <<
" messages in " <<
530 "module: " << tprog->
get_name() <<
"</title></head><body>" << endl <<
531 "<h1>Documentation for " << mdesc <<
" messages in module: "
532 << tprog->
get_name() <<
"</h1>" << endl;
534 print_doc(tprog, f_out);
536 generate_program_toc(f_out, fsuffix, dtype);
539 if (!tprog->get_sandeshs().empty()) {
540 f_out <<
"<hr/><h2 id=\"Messages\">Messages</h2>" << endl;
541 vector<t_sandesh*> sandeshs = tprog->get_sandeshs();
542 vector<t_sandesh*>::iterator snh_iter;
543 for (snh_iter = sandeshs.begin(); snh_iter != sandeshs.end(); ++snh_iter) {
544 if (!is_sandesh_type(*snh_iter, dtype)) {
548 sandesh_name_ = get_sandesh_name(*snh_iter);
549 f_out <<
"<div class=\"definition\">";
550 if (dtype == doc_ftype::UVES) {
551 generate_sandesh_uve(*snh_iter, f_out);
553 generate_sandesh(*snh_iter, f_out);
558 f_out <<
"</body></html>" << endl;
563 string fsuffix = get_doc_file_suffix(dtype);
565 string fname = get_out_dir() + program_->get_name() + fsuffix +
".html";
567 f_out.open(fname.c_str());
568 bool init(generate_sandesh_program_doc(program_, f_out, fsuffix, dtype));
571 string fname_schema = get_out_dir() + program_->get_name() + fsuffix +
".doc.schema.json";
572 ofstream f_out_schema;
573 f_out_schema.open(fname_schema.c_str());
574 generate_sandesh_program_doc_schema(program_, f_out_schema, fsuffix, dtype);
575 f_out_schema.close();
581 string fname = get_out_dir() + program_->get_name() + fsuffix +
".html";
582 f_out_.open(fname.c_str());
584 generate_doc_type(f_out_);
585 f_out_ <<
"<title>Documentation for constants, enums, types, and data structures in " <<
586 "module: " << program_->get_name() <<
"</title></head><body>" << endl <<
587 "<h1>Documentation for constants, enums, types, and data structures in module: "
588 << program_->get_name() <<
"</h1>" << endl;
590 print_doc(program_, f_out_);
592 if (!program_->get_consts().empty()) {
593 f_out_ <<
"<hr/><h2 id=\"Constants\">Constants</h2>" << endl;
594 vector<t_const*> consts = program_->get_consts();
596 f_out_ <<
"<tr><th>Constant</th><th>Type</th><th>Value</th></tr>" << endl;
597 generate_consts(consts, f_out_);
598 f_out_ <<
"</table>";
601 if (!program_->get_enums().empty()) {
602 f_out_ <<
"<hr/><h2 id=\"Enumerations\">Enumerations</h2>" << endl;
604 vector<t_enum*> enums = program_->get_enums();
605 vector<t_enum*>::iterator en_iter;
606 for (en_iter = enums.begin(); en_iter != enums.end(); ++en_iter) {
607 generate_enum(*en_iter, f_out_);
611 if (!program_->get_typedefs().empty()) {
612 f_out_ <<
"<hr/><h2 id=\"Typedefs\">Type declarations</h2>" << endl;
614 vector<t_typedef*> typedefs = program_->get_typedefs();
615 vector<t_typedef*>::iterator td_iter;
616 for (td_iter = typedefs.begin(); td_iter != typedefs.end(); ++td_iter) {
617 generate_typedef(*td_iter, f_out_);
621 if (!program_->get_objects().empty()) {
622 f_out_ <<
"<hr/><h2 id=\"Structs\">Data structures</h2>" << endl;
624 vector<t_struct*> objects = program_->get_objects();
625 vector<t_struct*>::iterator o_iter;
626 for (o_iter = objects.begin(); o_iter != objects.end(); ++o_iter) {
627 generate_struct(*o_iter, f_out_);
631 f_out_ <<
"</body></html>" << endl;
639 string index_fname = get_out_dir() + program_->get_name() +
"_index.html";
640 f_index_out_.open(index_fname.c_str());
641 f_index_out_ <<
"<html>" << endl;
642 f_index_out_ <<
"<head>Documentation for " << program_->get_name() <<
"</head>" << endl;
643 f_index_out_ <<
"<link href=\"/doc-style.css\" rel=\"stylesheet\" type=\"text/css\"/>"
645 f_index_out_ <<
"<table><tr><th>Message Types</th></tr>" << endl;
646 if (f_log_initialized_) {
647 f_index_out_ <<
"<tr><td><a href=" << program_->get_name() <<
648 get_doc_file_suffix(doc_ftype::LOGS) <<
".html>All Logs</a></td></tr>" << endl;
650 if (f_log_emerg_initialized_) {
651 f_index_out_ <<
"<tr><td><a href=" << program_->get_name() <<
652 get_doc_file_suffix(doc_ftype::LOGS_LEVEL_EMERG) <<
".html>Emergency Logs</a></td></tr>" << endl;
654 if (f_log_alert_initialized_) {
655 f_index_out_ <<
"<tr><td><a href=" << program_->get_name() <<
656 get_doc_file_suffix(doc_ftype::LOGS_LEVEL_ALERT) <<
".html>Alert Logs</a></td></tr>" << endl;
658 if (f_log_crit_initialized_) {
659 f_index_out_ <<
"<tr><td><a href=" << program_->get_name() <<
660 get_doc_file_suffix(doc_ftype::LOGS_LEVEL_CRIT) <<
".html>Critical Logs</a></td></tr>" << endl;
662 if (f_log_error_initialized_) {
663 f_index_out_ <<
"<tr><td><a href=" << program_->get_name() <<
664 get_doc_file_suffix(doc_ftype::LOGS_LEVEL_ERR) <<
".html>Error Logs</a></td></tr>" << endl;
666 if (f_log_warn_initialized_) {
667 f_index_out_ <<
"<tr><td><a href=" << program_->get_name() <<
668 get_doc_file_suffix(doc_ftype::LOGS_LEVEL_WARN) <<
".html>Warning Logs</a></td></tr>" << endl;
670 if (f_log_notice_initialized_) {
671 f_index_out_ <<
"<tr><td><a href=" << program_->get_name() <<
672 get_doc_file_suffix(doc_ftype::LOGS_LEVEL_NOTICE) <<
".html>Notice Logs</a></td></tr>" << endl;
674 if (f_log_info_initialized_) {
675 f_index_out_ <<
"<tr><td><a href=" << program_->get_name() <<
676 get_doc_file_suffix(doc_ftype::LOGS_LEVEL_INFO) <<
".html>Informational Logs</a></td></tr>" << endl;
678 if (f_log_debug_initialized_) {
679 f_index_out_ <<
"<tr><td><a href=" << program_->get_name() <<
680 get_doc_file_suffix(doc_ftype::LOGS_LEVEL_DEBUG) <<
".html>Debugging Logs</a></td></tr>" << endl;
682 if (f_log_invalid_initialized_) {
683 f_index_out_ <<
"<tr><td><a href=" << program_->get_name() <<
684 get_doc_file_suffix(doc_ftype::LOGS_LEVEL_INVALID) <<
".html>Unknown severity logs</a></td></tr>" << endl;
686 if (f_uve_initialized_) {
687 f_index_out_ <<
"<tr><td><a href=" << program_->get_name() <<
"_uves.html>UVEs</a></td></tr>" << endl;
689 if (f_trace_initialized_) {
690 f_index_out_ <<
"<tr><td><a href=" << program_->get_name() <<
"_traces.html>Traces</a></td></tr>" << endl;
692 if (f_introspect_initialized_) {
693 f_index_out_ <<
"<tr><td><a href=" << program_->get_name() <<
"_introspect.html>Request-Response</a></td></tr>" << endl;
695 f_index_out_ <<
"</table>" << endl;
696 f_index_out_ <<
"</html>" << endl;
697 f_index_out_.close();
706 MKDIR(get_out_dir().c_str());
707 generate_stats_schema_program();
708 f_log_initialized_ = generate_sandesh_program(doc_ftype::LOGS);
709 f_log_invalid_initialized_ = generate_sandesh_program(doc_ftype::LOGS_LEVEL_INVALID);
710 f_log_debug_initialized_ = generate_sandesh_program(doc_ftype::LOGS_LEVEL_DEBUG);
711 f_log_info_initialized_ = generate_sandesh_program(doc_ftype::LOGS_LEVEL_INFO);
712 f_log_notice_initialized_ = generate_sandesh_program(doc_ftype::LOGS_LEVEL_NOTICE);
713 f_log_warn_initialized_ = generate_sandesh_program(doc_ftype::LOGS_LEVEL_WARN);
714 f_log_error_initialized_ = generate_sandesh_program(doc_ftype::LOGS_LEVEL_ERR);
715 f_log_crit_initialized_ = generate_sandesh_program(doc_ftype::LOGS_LEVEL_CRIT);
716 f_log_alert_initialized_ = generate_sandesh_program(doc_ftype::LOGS_LEVEL_ALERT);
717 f_log_emerg_initialized_ = generate_sandesh_program(doc_ftype::LOGS_LEVEL_EMERG);
718 f_uve_initialized_ = generate_sandesh_program(doc_ftype::UVES);
719 f_trace_initialized_ = generate_sandesh_program(doc_ftype::TRACES);
720 f_introspect_initialized_ = generate_sandesh_program(doc_ftype::INTROSPECT);
722 generate_const_enum_typedef_object_program();
727 while ((index = doc.find_first_of(
"\r\n")) != string::npos) {
729 f_out <<
"<p/>" << endl;
731 f_out << doc.substr(0, index) << endl;
733 if (index + 1 < doc.size() && doc.at(index) != doc.at(index + 1) &&
734 (doc.at(index + 1) ==
'\r' || doc.at(index + 1) ==
'\n')) {
737 doc = doc.substr(index + 1);
739 f_out << doc <<
"<br/>";
749 print_doc_string(doc, f_out);
756 vector<t_field*> members = tsandesh->
get_members();
757 BOOST_FOREACH(
t_field *tfield, members) {
758 if (tfield->get_auto_generated()) {
762 f_out <<
"<tr><th>Message</th><td>";
765 if (
type->is_static_const_string()) {
770 f_out << get_escaped_string(default_val);
776 f_out << tfield->
get_name() <<
"</code>";
781 f_out <<
"</td></tr>" << endl;
787 print_sandesh_message(tsandesh, f_out);
788 f_out <<
"</table><br/>" << endl;
792 const string &ilevel) {
793 string level(ilevel);
795 boost::algorithm::trim(level);
799 boost::algorithm::to_lower(level);
800 if (level ==
"debug") {
803 if (level ==
"informational" || level ==
"info") {
806 if (level ==
"notice") {
809 if (level ==
"warning" || level ==
"warn") {
812 if (level ==
"error" || level ==
"err") {
815 if (level ==
"critical" || level ==
"crit") {
818 if (level ==
"alert") {
821 if (level ==
"emergency" || level ==
"emerg") {
843 return "informational";
852 typedef boost::tokenizer<boost::char_separator<char> >
tokenizer;
855 string doc = tsandesh->
get_doc();
857 if ((index = doc.find_first_of(
"@")) != string::npos) {
859 string fdoc(doc.substr(index + 1));
861 boost::char_separator<char> fsep(
"@");
863 BOOST_FOREACH(
const string &f, ftokens) {
867 if ((lindex = f.find_first_of(
": \t")) != string::npos) {
868 string type(f.substr(0, lindex));
869 if (lindex + 1 < f.size() && f.at(lindex) != f.at(lindex + 1) &&
870 (f.at(lindex + 1) ==
':' || f.at(lindex + 1) ==
'\t' ||
871 f.at(lindex + 1) ==
' ')) {
874 string content(f.substr(lindex + 1));
875 if (
type == member) {
886 string content = get_doc_member(tsandesh,
"object");
888 boost::algorithm::trim(content);
896 string content = get_doc_member(tsandesh,
"severity");
898 return string_to_sandesh_level(content);
910 string doc = tsandesh->
get_doc();
912 if ((index = doc.find_first_of(
"@")) != string::npos) {
914 f_out << doc.substr(0, index) <<
"<p/>" << endl;
915 string fdoc(doc.substr(index + 1));
917 f_out <<
"<table>" << endl;
918 print_sandesh_message(tsandesh, f_out);
922 boost::char_separator<char> fsep(
"@");
924 BOOST_FOREACH(
const string &f, ftokens) {
928 if ((lindex = f.find_first_of(
": \t")) != string::npos) {
929 string type(f.substr(0, lindex));
931 f_out <<
"<tr><th>" <<
type <<
"</th>";
932 if (lindex + 1 < f.size() && f.at(lindex) != f.at(lindex + 1) &&
933 (f.at(lindex + 1) ==
':' || f.at(lindex + 1) ==
'\t' ||
934 f.at(lindex + 1) ==
' ')) {
937 string content(f.substr(lindex + 1));
938 f_out <<
"<td>" << content <<
"</td></tr>" << endl;
940 f_out <<
"<td>" << f <<
"</td>" << endl;
944 f_out << doc <<
"<p/>" << endl;
945 print_sandesh_message_table(tsandesh, f_out);
948 f_out <<
"</table><br/>" << endl;
951 print_sandesh_message_table(tsandesh, f_out);
964 len = 6 + print_type(((
t_list*)ttype)->get_elem_type(), f_out);
966 }
else if (ttype->
is_set()) {
968 len = 5 + print_type(((
t_set*)ttype)->get_elem_type(), f_out);
970 }
else if (ttype->
is_map()) {
972 len = 5 + print_type(((
t_map*)ttype)->get_key_type(), f_out);
974 len += print_type(((
t_map*)ttype)->get_val_type(), f_out);
978 f_out << (((
t_base_type*)ttype)->is_binary() ?
"binary" : ttype->get_name());
979 len = ttype->get_name().size();
982 string type_name = ttype->
get_name();
983 f_out <<
"<a href=\"" << prog_name <<
".html#";
993 f_out << type_name <<
"\">";
994 len = type_name.size();
996 f_out << prog_name <<
".";
997 len += prog_name.size() + 1;
999 f_out << type_name <<
"</a>";
1018 f_out <<
'"' << get_escaped_string(tvalue) <<
'"';
1023 map<t_const_value*, t_const_value*> map_elems = tvalue->
get_map();
1024 map<t_const_value*, t_const_value*>::iterator map_iter;
1025 for (map_iter = map_elems.begin(); map_iter != map_elems.end(); map_iter++) {
1030 print_const_value(map_iter->first, f_out);
1032 print_const_value(map_iter->second, f_out);
1040 vector<t_const_value*> list_elems = tvalue->
get_list();;
1041 vector<t_const_value*>::iterator list_iter;
1042 for (list_iter = list_elems.begin(); list_iter != list_elems.end(); list_iter++) {
1047 print_const_value(*list_iter, f_out);
1064 string name = ttypedef->
get_name();
1065 f_out <<
"<div class=\"definition\">";
1066 f_out <<
"<h3 id=\"Typedef_" << name <<
"\">Typedef: " << name
1068 f_out <<
"<p><strong>Base type:</strong> ";
1069 print_type(ttypedef->
get_type(), f_out);
1070 f_out <<
"</p>" << endl;
1071 print_doc(ttypedef, f_out);
1072 f_out <<
"</div>" << endl;
1082 f_out <<
"<div class=\"definition\">";
1083 f_out <<
"<h3 id=\"Enum_" << name <<
"\">Enumeration: " << name
1085 print_doc(tenum, f_out);
1087 vector<t_enum_value*>::iterator val_iter;
1088 f_out <<
"<br/><table>" << endl;
1089 for (val_iter = values.begin(); val_iter != values.end(); ++val_iter) {
1090 f_out <<
"<tr><td><code>";
1091 f_out << (*val_iter)->get_name();
1092 f_out <<
"</code></td><td><code>";
1093 f_out << (*val_iter)->get_value();
1094 f_out <<
"</code></td></tr>" << endl;
1096 f_out <<
"</table></div>" << endl;
1104 f_out <<
"<tr id=\"Const_" << name <<
"\"><td><code>" << name
1105 <<
"</code></td><td><code>";
1106 print_type(tconst->
get_type(), f_out);
1107 f_out <<
"</code></td><td><code>";
1108 print_const_value(tconst->
get_value(), f_out);
1109 f_out <<
"</code></td></tr>";
1111 f_out <<
"<tr><td colspan=\"3\"><blockquote>";
1112 print_doc(tconst, f_out);
1113 f_out <<
"</blockquote></td></tr>";
1118 vector<t_const*>::iterator c_iter;
1119 for (c_iter = consts.begin(); c_iter != consts.end(); ++c_iter) {
1120 generate_const(*c_iter, f_out);
1125 if (stat_table_created_ ==
false) {
1126 stat_table_created_ =
true;
1127 f_stats_tables_ <<
"{\n\"stat_type\":\"" <<
type <<
"\"," << endl;
1129 f_stats_tables_ <<
",\n{\n\"stat_type\":\"" <<
type <<
"\"," << endl;
1131 f_stats_tables_ <<
"\"stat_attr\":\"" << attr <<
"\"," << endl;
1132 f_stats_tables_ <<
"\"display_name\":\"" << display_name <<
"\"," << endl;
1133 f_stats_tables_ <<
"\"obj_table\": \"" << table_name <<
"\",\n";
1134 f_stats_tables_ <<
"\"attributes\":[" << endl;
1135 first_member_ =
true;
1139 map<string, string>::iterator jt;
1140 string uve_type =
"";
1143 string annotations = jt->second;
1144 boost::char_separator<char> fsep(
",");
1146 BOOST_FOREACH(
const string &tag, tags) {
1147 size_t index = tag.find(
':');
1148 if(index != string::npos) {
1149 string fname = tag.substr(0, index);
1151 uve_type = tag.substr(index+1);
1152 boost::trim(uve_type);
1161 template <
typename T>
1164 vector<t_field*>::const_iterator m_iter;
1165 if (!boost::starts_with(name,
".")) {
1167 const vector<t_field*>& tmembers = tstruct->get_members();
1168 for (m_iter = tmembers.begin(); m_iter != tmembers.end(); ++m_iter) {
1169 map<string, string>::iterator jt;
1170 if (name == (*m_iter)->get_name()) {
1171 return get_datatype_from_tfield((*m_iter)->get_type());
1174 }
else if (name.compare(
".__key") == 0) {
1177 return get_datatype_from_tfield(keytype);
1180 const vector<t_field*>& tmembers = cstruct->
get_members();
1181 for (m_iter = tmembers.begin(); m_iter != tmembers.end(); ++m_iter) {
1182 map<string, string>::iterator jt;
1183 if (name.substr(1) == (*m_iter)->get_name()) {
1184 return get_datatype_from_tfield((*m_iter)->get_type());
1191 template <
typename T>
1193 string>& top_level_tags, vector<string>& schema,
t_field* tfield) {
1194 BOOST_FOREACH(
const string &tag, top_level_tags) {
1196 const vector<t_field*>& tmembers = tstruct->get_members();
1197 vector<t_field*>::const_iterator m_iter;
1198 for (m_iter = tmembers.begin(); m_iter != tmembers.end(); ++m_iter) {
1199 map<string, string>::iterator jt;
1200 if (tag == (*m_iter)->get_name()) {
1202 schema.push_back(generate_stat_schema_struct_base_member(
1203 fname, *m_iter,
"true", tfield));
1210 template <
typename T>
1213 vector<string> >& suffixes, vector<string>& schemas) {
1214 map<string, vector<string> >::iterator it;
1215 for (it=suffixes.begin(); it!=suffixes.end(); ++it) {
1216 string fname = it->first;
1217 string datatype = get_type_of_member(fname, tfield, cstruct, tstruct);
1218 if (boost::starts_with(fname,
".")) {
1219 fname = tfield->
get_name() + fname;
1221 if (!prefix.empty()) {
1222 fname = prefix +
"." + fname;
1224 string index =
"true";
1226 vector<string>::iterator name_it;
1227 for (name_it = it->second.begin(); name_it!=it->second.end(); ++name_it) {
1228 string suffix_name = tfield->
get_name() + *name_it;
1229 if (boost::starts_with(suffix_name,
".")) {
1230 suffix_name = tfield->
get_name() + suffix_name;
1232 if (!prefix.empty()) {
1233 suffix_name = prefix +
"." + suffix_name;
1235 if(name_it == it->second.begin()) {
1236 suffix = suffix +
"\"" + suffix_name +
"\"";
1238 suffix = suffix +
", \"" + suffix_name +
"\"";
1242 f_stats_tables_ <<
"," << endl;
1243 string uve_type = get_uve_type(it->first, tfield);
1244 std::ostringstream oss;
1245 if (uve_type !=
"") {
1246 oss <<
"{\"name\":\"" << fname <<
1247 "\",\"datatype\":\"" << datatype <<
"\",\"index\":" << index <<
1248 ",\"uve_type\":\"" << uve_type <<
1249 "\",\"suffixes\":[" << suffix <<
"]}";
1251 oss <<
"{\"name\":\"" << fname <<
1252 "\",\"datatype\":\"" << datatype <<
"\",\"index\":" << index <<
1253 ",\"suffixes\":[" << suffix <<
"]}";
1255 schemas.push_back(oss.str());
1256 indent(f_stats_tables_) << oss.str();
1262 vector<string> tags, map<
string, vector<string> > suffixes,
1263 string& index,
bool& is_suffixed_field,
bool& is_tag) {
1264 BOOST_FOREACH(
const string &tag, tags) {
1265 string field_name = string(
".") + fname;
1266 string trimmed_tag = tag;
1267 boost::trim(trimmed_tag);
1268 if (trimmed_tag == field_name) {
1273 for(map<
string, vector<string> >::iterator it = suffixes.begin(); it != suffixes.end(); ++it) {
1274 string field_name = string(
".") + fname;
1275 string trimmed_tag = it->first;
1276 boost::trim(trimmed_tag);
1277 if (trimmed_tag == field_name) {
1278 is_suffixed_field =
true;
1282 for(map<
string, vector<string> >::iterator it = suffixes.begin(); it != suffixes.end(); ++it) {
1283 string field_name = string(
".") + fname;
1284 vector<string> values = it->second;
1285 BOOST_FOREACH(
string value, values) {
1286 if (value == field_name) {
1296 map<
string, vector<string> > suffixes, vector<string>& schemas) {
1297 const vector<t_field*> members = tstruct->
get_members();
1298 vector<t_field*>::const_iterator m_iter;
1300 if(!prefix.empty()) {
1301 prefix = prefix +
"." + name;
1305 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
1306 string index =
"false";
1307 bool is_suffixed_field =
false, is_tag =
false, is_index =
false;
1308 is_indexed_or_suffixed_field((*m_iter)->get_name(), tags, suffixes, index, is_suffixed_field, is_tag);
1309 if (index ==
"true") {
1314 if (is_suffixed_field) {
1317 t_type* mtype = (*m_iter)->get_type();
1319 string schema = generate_stat_schema_struct_base_member(prefix, *m_iter, index, tfield);
1320 if (index ==
"true" || is_tag)
1321 schemas.push_back(schema);
1323 string mtype_name = mtype->
get_name();
1324 t_struct *cstruct = find_struct_with_name(mtype_name);
1326 generate_stat_schema_struct(prefix, (*m_iter), cstruct, tstruct,
false, schemas);
1330 generate_stat_schema_list(prefix, etype, (*m_iter), tstruct,
false, is_index, schemas);
1331 }
else if (mtype->
is_map()) {
1332 t_type* valtype= ((
t_map*)((*m_iter)->get_type()))->get_val_type();
1333 t_type* keytype= ((
t_map*)((*m_iter)->get_type()))->get_key_type();
1334 generate_stat_schema_map(prefix, keytype, valtype, (*m_iter), tstruct,
false, is_index, schemas);
1340 string datatype = ttype->
get_name();
1341 if ((datatype ==
"u32") || (datatype ==
"u16") || (datatype ==
"u64"))
1348 if (!first_member_) {
1349 f_stats_tables_ <<
"," << endl;
1351 std::ostringstream oss;
1352 if (uve_type !=
"") {
1353 oss <<
"{\"name\":\"" << name <<
"\",\"datatype\":\""
1354 << datatype <<
"\",\"index\":" << index <<
",\"uve_type\":\""
1355 << uve_type <<
"\"}";
1357 oss <<
"{\"name\":\"" << name <<
"\",\"datatype\":\""
1358 << datatype <<
"\",\"index\":" << index <<
"}";
1360 string schema = oss.str();
1361 indent(f_stats_tables_) << schema;
1362 first_member_ =
false;
1367 template <
typename T>
1369 map<string, vector<string> > suffixes;
1370 vector<string> top_level_tags;
1371 vector<string> member_tags;
1372 bool is_empty_tag =
false;
1373 map<string, string>::iterator jt;
1377 is_empty_tag =
true;
1378 if (!is_top_level && !is_empty_tag && !is_index) {
1381 if(!prefix.empty()) {
1382 tname = prefix +
"." + tname;
1384 if (is_empty_tag ==
false) {
1385 extract_tags(tfield, suffixes, top_level_tags, member_tags);
1388 string name = tname + string(
".__key");
1389 string datatype = get_datatype_from_tfield(keytype);
1390 string index =
"false";
1391 bool is_suffixed_field =
false, is_tag =
false;
1392 is_indexed_or_suffixed_field(
string(
"__key"), member_tags, suffixes, index, is_suffixed_field, is_tag);
1393 string uve_type = get_uve_type(
"__key", tfield);
1394 if (!is_suffixed_field) {
1395 string schema = generate_table_entry(name, datatype, index, uve_type);
1396 if (index ==
"true" || is_tag)
1397 schemas.push_back(schema);
1400 name = tname + string(
".__value");
1401 datatype = get_datatype_from_tfield(valtype);
1403 BOOST_FOREACH(
const string &f, member_tags) {
1404 if (f ==
string(
".__value")) {
1408 uve_type = get_uve_type(
"__value", tfield);
1409 generate_table_entry(name, datatype, index, uve_type);
1413 string name = tname +
".*";
1414 string datatype = get_datatype_from_tfield(valtype);
1415 string index =
"false";
1419 string uve_type = get_uve_type(tname, tfield);
1420 string schema = generate_table_entry(name, datatype, index, uve_type);
1421 if (index ==
"true") {
1422 schemas.push_back(schema);
1428 uve_type = get_uve_type(tname, tfield);
1429 schema = generate_table_entry(name, datatype, index, uve_type);
1432 string empty_prefix;
1434 string sname = valtype->
get_name();
1435 t_struct *cstruct = find_struct_with_name(sname);
1438 generate_stat_schema_struct_members(empty_prefix, tfield, cstruct, member_tags, suffixes, schemas);
1440 generate_stat_schema_toplevel_tags(tstruct, top_level_tags, schemas, tfield);
1441 generate_stat_schema_suffixes(empty_prefix, tfield, cstruct, tstruct, suffixes, schemas);
1444 generate_stat_schema_toplevel_tags(tstruct, top_level_tags, schemas, tfield);
1445 generate_stat_schema_suffixes(empty_prefix, tfield, NULL, tstruct, suffixes, schemas);
1453 if (!prefix.empty()) {
1454 uve_type = get_uve_type(
"." + fname, top_field);
1455 fname = prefix+
"." + fname;
1457 uve_type = get_uve_type(fname, top_field);
1459 string datatype = get_datatype_from_tfield(tfield->
get_type());
1460 return generate_table_entry(fname, datatype, index, uve_type);
1463 template <
typename T>
1465 &suffixes, vector<string> &top_level_tags, vector<string> &member_tags) {
1466 boost::char_separator<char> fsep(
",");
1467 tokenizer tags(tfield->annotations_[
"tags"], fsep);
1468 BOOST_FOREACH(
const string &tag, tags) {
1469 size_t index = tag.find(
':');
1470 if(index != string::npos) {
1471 string fname = tag.substr(0, index);
1473 string suffix_name = tag.substr(index+1);
1474 boost::trim(suffix_name);
1475 if(suffixes.find(fname) == suffixes.end()) {
1476 vector<string> new_suffix;
1477 new_suffix.push_back(suffix_name);
1478 suffixes.insert(make_pair(fname, new_suffix));
1480 vector<string> old_suffixes = suffixes[fname];
1481 old_suffixes.push_back(suffix_name);
1482 suffixes[fname] = old_suffixes;
1485 string trimmed_tag = tag;
1486 boost::trim(trimmed_tag);
1487 if (!boost::starts_with(trimmed_tag,
".")) {
1488 top_level_tags.push_back(trimmed_tag);
1490 member_tags.push_back(trimmed_tag);
1496 template <
typename T>
1498 map<string, vector<string> > suffixes;
1499 vector<string> top_level_tags;
1500 vector<string> member_tags;
1501 bool is_empty_tag =
false;
1503 extract_tags(tfield, suffixes, top_level_tags, member_tags);
1505 map<string, string>::iterator jt = tfield->
annotations_.find(
"tags");
1507 is_empty_tag =
true;
1512 if(is_empty_tag || is_top_level)
1513 generate_stat_schema_struct_members(prefix, tfield, cstruct, member_tags, suffixes, schemas);
1514 generate_stat_schema_toplevel_tags(tstruct, top_level_tags, schemas, tfield);
1515 generate_stat_schema_suffixes(prefix, tfield, cstruct, tstruct, suffixes, schemas);
1518 template <
typename T>
1522 t_struct *cstruct = find_struct_with_name(sname);
1524 generate_stat_schema_struct(name, tfield, cstruct, tstruct, is_top_level, schemas);
1527 map<string, vector<string> > suffixes;
1528 vector<string> top_level_tags;
1529 vector<string> member_tags;
1530 bool is_empty_tag =
false;
1531 map<string, string>::iterator jt;
1535 is_empty_tag =
true;
1536 if (!is_top_level && !is_empty_tag && !is_index) {
1540 tname = name +
"." + tname;
1542 if (is_empty_tag ==
false) {
1543 extract_tags(tfield, suffixes, top_level_tags, member_tags);
1551 string index =
"false";
1552 bool is_suffixed_field =
false, is_tag =
false;
1553 is_indexed_or_suffixed_field(tname, member_tags, suffixes, index, is_suffixed_field, is_tag);
1560 string uve_type =
"";
1562 uve_type = jt->second;
1563 if (!is_suffixed_field) {
1564 string schema = generate_table_entry(tname, datatype, index, uve_type);
1565 if (is_tag || index ==
"true")
1566 schemas.push_back(schema);
1572 t_struct *cstruct = program_->get_struct(sname.c_str());
1577 const vector<t_program*>& includes = program_->get_includes();
1578 vector<t_program*>::const_iterator iter;
1579 for (iter = includes.begin(); iter != includes.end(); ++iter) {
1580 cstruct = (*iter)->get_struct(sname.c_str());
1588 template <
typename T>
1591 t_type* ltype= ((
t_list*)((tfield)->get_type()))->get_elem_type();
1592 generate_stat_schema_list(prefix, ltype, tfield, tsandesh,
true,
false, tags);
1596 generate_stat_schema_map(prefix, keytype, valtype, tfield, tsandesh,
true,
false, tags);
1598 string sname = (tfield->
get_type())->get_name();
1599 t_struct *cstruct = find_struct_with_name(sname);
1601 generate_stat_schema_struct(prefix, tfield, cstruct, tsandesh,
true, tags);
1607 string obj_table_name;
1608 vector<t_field*>::const_iterator m_iter;
1609 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
1610 map<string, string>::iterator jt;
1611 if((*m_iter)->get_name() ==
"name") {
1612 jt = (*m_iter)->annotations_.find(
"key");
1613 if (jt != (*m_iter)->annotations_.end()) {
1614 return (*m_iter)->annotations_[
"key"];
1618 return obj_table_name;
1621 template <
typename T>
1624 string sname = valtype->
get_name();
1625 find_recursive_tags_struct(tsandesh, tfield, table, sname, prefix, schemas);
1629 template <
typename T>
1633 find_recursive_tags_struct(tsandesh, tfield, table, sname, prefix, schemas);
1637 template <
typename T>
1639 t_struct *cstruct = find_struct_with_name(sname);
1641 const vector<t_field*> members = cstruct->
get_members();
1642 generate_stat_tables_schema(tsandesh, members, table, prefix, schemas);
1646 template <
typename T>
1650 t_type* ltype= ((
t_list*)((tfield)->get_type()))->get_elem_type();
1651 find_recursive_tags_list(tsandesh, tfield, table, ltype, fname, index_schemas);
1655 find_recursive_tags_map(tsandesh, tfield, table, keytype, valtype, fname, index_schemas);
1657 string sname = (tfield->
get_type())->get_name();
1658 find_recursive_tags_struct(tsandesh, tfield, table, sname, fname, index_schemas);
1664 string doc = tfield->
get_doc();
1666 string display_name;
1667 if ((index = doc.find_first_of(
"@")) != string::npos) {
1668 boost::char_separator<char> fsep(
"@");
1670 BOOST_FOREACH(
const string &f, ftokens) {
1672 if ((lindex = f.find_first_of(
": \t")) != string::npos) {
1673 string attr_name = f.substr(0, lindex);
1674 boost::trim(attr_name);
1675 if(attr_name ==
"display_name") {
1676 string dn = f.substr(lindex+1);
1677 display_name = dn.substr(0, dn.find_first_of(
'\n'));
1678 boost::trim(display_name);
1679 return display_name;
1684 return display_name;
1687 template <
typename T>
1689 vector<t_field*>::const_iterator m_iter;
1690 string oname = tsandesh->get_name();
1691 for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
1692 map<string, string>::iterator jt;
1693 jt = (*m_iter)->annotations_.find(
"tags");
1694 if (jt != (*m_iter)->annotations_.end()) {
1695 string fname = (*m_iter)->get_name();
1696 if (!prefix.empty())
1697 fname = prefix +
"." + fname;
1698 string display_name = get_display_name_from_comments(*m_iter);
1699 generate_stat_table_schema_header(oname, fname, table, display_name);
1700 vector<string> new_tags;
1701 generate_stat_table_schema(oname, *m_iter, tsandesh, prefix, new_tags);
1702 for (
int i = 0; i < tags.size(); i++) {
1703 if (tags[i][0] !=
',')
1704 f_stats_tables_ <<
"," << endl;
1706 indent(f_stats_tables_) << tags[i];
1709 f_stats_tables_ <<
"\n]\n}";
1710 find_recursive_tags(tsandesh, *m_iter, table, fname, new_tags);
1717 const vector<t_field*> members = tsandesh->
get_members();
1718 string empty_prefix;
1719 vector<string> empty_tag;
1721 t_struct* data = program_->get_struct(members.front()->get_type()->get_name().c_str());
1722 const vector<t_field*> tmembers = data->
get_members();
1723 string obj_table_name = find_obj_table_name(tmembers);
1724 generate_stat_tables_schema(data, tmembers, obj_table_name, empty_prefix, empty_tag);
1726 string obj_table_name =
"NONE";
1727 generate_stat_tables_schema(tsandesh, members, obj_table_name, empty_prefix, empty_tag);
1737 vector<t_field*> members = tstruct->
get_members();
1738 vector<t_field*>::iterator mem_iter = members.begin();
1740 f_out <<
"<tr><th>Key</th><th>Field</th><th>Type</th><th>Description</th><th>Requiredness</th><th>Default value</th></tr>"
1742 for ( ; mem_iter != members.end(); mem_iter++) {
1743 f_out <<
"<tr><td>" << (*mem_iter)->get_key() <<
"</td><td>";
1744 f_out << (*mem_iter)->get_name();
1745 f_out <<
"</td><td>";
1746 print_type((*mem_iter)->get_type(), f_out);
1747 f_out <<
"</td><td>";
1748 f_out << (*mem_iter)->get_doc();
1749 f_out <<
"</td><td>";
1751 f_out <<
"optional";
1753 f_out <<
"required";
1757 f_out <<
"</td><td>";
1759 if (default_val != NULL) {
1760 print_const_value(default_val, f_out);
1762 f_out <<
"</td></tr>" << endl;
1764 f_out <<
"</table><br/>";
1774 f_out <<
"<div class=\"definition\">";
1775 f_out <<
"<h3 id=\"Struct_" << name <<
"\">";
1776 f_out <<
"Struct: ";
1777 f_out << name <<
"</h3>" << endl;
1778 generate_struct_table(tstruct, f_out);
1779 print_doc(tstruct, f_out);
1785 string doc = tsandesh->
get_doc();
1787 string cli_name =
"", cli_help =
"";
1788 if ((index = doc.find_first_of(
"@")) != string::npos) {
1789 string fdoc(doc.substr(index + 1));
1791 boost::char_separator<char> fsep(
"@");
1793 BOOST_FOREACH(
const string &f, ftokens) {
1797 if ((lindex = f.find_first_of(
": \t")) != string::npos) {
1798 string type(f.substr(0, lindex));
1799 if (lindex + 1 < f.size() && f.at(lindex) != f.at(lindex + 1) &&
1800 (f.at(lindex + 1) ==
':' || f.at(lindex + 1) ==
'\t' ||
1801 f.at(lindex + 1) ==
' ')) {
1804 string content(f.substr(lindex + 1));
1805 content.erase(content.length()-1);
1806 if (boost::starts_with(
type,
"cli_name")) {
1808 }
else if (boost::starts_with(
type,
"description")) {
1817 f_out <<
"," << endl;
1823 indent(f_out) <<
"\"" << tsandesh->
get_name() <<
"\" : {" << endl;
1824 indent(f_out) <<
"\"" << cli_name <<
"\" : " <<
"{ \"" << cli_help <<
"\" :" << endl;
1825 vector<t_field*> members = tsandesh->
get_members();
1826 int size = members.size();
1828 indent(f_out) <<
"[ " << endl;
1830 BOOST_FOREACH(
t_field *tfield, members) {
1831 indent(f_out) <<
"[\"" << tfield->
get_name();
1832 string field_doc =
"\"\"";
1833 if (!tfield->
get_doc().empty()) {
1834 field_doc = tfield->
get_doc();
1835 field_doc.erase(field_doc.length()-1);
1836 field_doc =
"\""+field_doc+
"\"";
1838 f_out <<
"\", " << field_doc <<
"]";
1845 indent(f_out) <<
"]}}";
1858 f_out <<
"<h3 id=\"Snh_" << sandesh_name_ <<
"\"> "
1859 << sandesh_name_ <<
"</h3>" << endl;
1860 print_sandesh(tsandesh, f_out);
1861 vector<t_field*> members = tsandesh->
get_members();
1863 f_out <<
"<tr><th>Field</th><th>Type</th><th>Description</th></tr>"
1865 BOOST_FOREACH(
t_field *tfield, members) {
1866 if (tfield->get_auto_generated()) {
1870 if (
type->is_static_const_string()) {
1873 f_out <<
"<tr><td>" << tfield->
get_name() <<
"</td><td>";
1874 print_type(tfield->
get_type(), f_out);
1875 f_out <<
"</td><td>";
1877 f_out <<
"</td></tr>" << endl;
1879 f_out <<
"</table><br/>";
1888 vector<t_field*> smembers = tsandesh->
get_members();
1889 if (smembers.size() == 1 && smembers[0]->get_type()->is_struct()) {
1890 sandesh_name_ = smembers[0]->get_type()->get_name();
1891 boost::trim(sandesh_name_);
1892 f_out <<
"<h3 id=\"Snh_" << sandesh_name_ <<
"\"> "
1893 << sandesh_name_ <<
"</h3>" << endl;
1894 print_sandesh(tsandesh, f_out);
1895 t_struct *cstruct = find_struct_with_name(sandesh_name_);
1897 f_out <<
"</table><br/>";
1900 generate_struct_table(cstruct, f_out);
const std::vector< t_const_value * > & get_list() const
double get_double() const
t_const_value_type get_type() const
const std::map< t_const_value *, t_const_value * > & get_map() const
int64_t get_integer() const
t_type * get_type() const
std::string get_name() const
t_const_value * get_value() const
void generate_stat_table_schema_header(string, string, string, string)
string get_doc_file_description(doc_ftype::type dtype)
void print_doc(t_doc *tdoc, ofstream &f_out)
void find_recursive_tags(T *, t_field *, string, string, vector< string > &)
void generate_stat_schema_struct(string, t_field *, t_struct *, T *, bool, vector< string > &)
void generate_sandesh_uve(t_sandesh *tsandesh, ofstream &f_out)
void generate_service(t_service *tservice)
string get_doc_member(t_sandesh *tsandesh, string member)
string generate_stat_schema_struct_base_member(string, t_field *, string, t_field *)
void generate_stat_table_schema(string, t_field *, T *, string, vector< string > &)
bool f_log_debug_initialized_
void generate_enum(t_enum *tenum)
void generate_sandesh_program_doc_schema(t_program *tprog, ofstream &f_out, string fsuffix, doc_ftype::type dtype)
string sandesh_level_to_string(const sandesh_level::type &slevel)
bool f_log_warn_initialized_
void generate_sandesh(t_sandesh *tsandesh)
void generate_doc_type(ofstream &f_out)
t_struct * find_struct_with_name(string sname)
void print_sandesh_message_table(t_sandesh *tdoc, ofstream &f_out)
void generate_struct_table(t_struct *tstruct, ofstream &f_out)
void find_recursive_tags_map(T *, t_field *, string, t_type *, t_type *, string, vector< string > &)
sandesh_level::type get_sandesh_level(t_sandesh *tsandesh)
void generate_stat_schema_toplevel_tags(T *, vector< string > &, vector< string > &, t_field *)
bool f_log_crit_initialized_
bool generate_sandesh_program(doc_ftype::type dtype)
void generate_stat_schema_struct_members(string name, t_field *, t_struct *, vector< string >, map< string, vector< string > >, vector< string > &)
void generate_stat_schema_suffixes(string, t_field *, t_struct *, T *, map< string, vector< string > > &, vector< string > &)
t_doc_generator(t_program *program, const map< string, string > &parsed_options, const string &option_string)
bool f_log_info_initialized_
void generate_stats_schema_program()
void generate_const(t_const *tconst)
void generate_sandesh_program_doc_schema_uve(t_program *tprog, ofstream &f_out, string fsuffix)
void generate_stat_schema_map(string, t_type *, t_type *, t_field *, T *, bool, bool, vector< string > &)
void generate_typedef(t_typedef *ttypedef)
string get_object_type(t_sandesh *tsandesh)
void print_sandesh_message(t_sandesh *tdoc, ofstream &f_out)
void print_const_value(t_const_value *tvalue, ofstream &f_out)
string get_type_of_member(string, t_field *, t_struct *, T *)
bool f_log_alert_initialized_
void generate_struct(t_struct *tstruct)
string get_doc_file_suffix(doc_ftype::type dtype)
string get_datatype_from_tfield(t_type *tfield)
bool f_log_notice_initialized_
bool f_log_emerg_initialized_
void is_indexed_or_suffixed_field(string, vector< string >, map< string, vector< string > >, string &, bool &, bool &)
void generate_const_enum_typedef_object_program()
void print_doc_string(string doc, ofstream &f_out)
bool f_trace_initialized_
void generate_stat_schema_list(string, t_type *, t_field *, T *, bool, bool, vector< string > &)
bool f_introspect_initialized_
void find_recursive_tags_list(T *, t_field *, string, t_type *, string, vector< string > &)
bool generate_introspect_cli(t_sandesh *, ofstream &f_out, bool &first_file)
string get_uve_type(string, t_field *)
void find_recursive_tags_struct(T *, t_field *, string, string, string, vector< string > &)
void generate_program_toc_row(t_program *tprog, ofstream &f_out, string fsuffix, doc_ftype::type dtype)
sandesh_level::type string_to_sandesh_level(const string &level)
void generate_consts(vector< t_const * > consts, ofstream &f_out)
int print_type(t_type *ttype, ofstream &f_out)
bool f_log_error_initialized_
bool f_log_invalid_initialized_
string find_obj_table_name(const vector< t_field * >)
void generate_stat_tables_schema(t_sandesh *)
bool generate_sandesh_program_doc(t_program *tprog, ofstream &f_out, string fsuffix, doc_ftype::type dtype)
void populate_stat_schema_map_key_value(t_field *tfield, t_type *, t_type *, T *)
void print_sandesh(t_sandesh *tdoc, ofstream &f_out)
string get_display_name_from_comments(t_field *)
bool is_sandesh_type(t_sandesh *tsandesh, doc_ftype::type dtype)
void extract_tags(T *, map< string, vector< string > > &, vector< string > &, vector< string > &)
void generate_program_toc(ofstream &f_out, string fsuffix, doc_ftype::type dtype)
string generate_table_entry(string name, string datatype, string index, string)
const std::string & get_doc() const
const std::vector< t_enum_value * > & get_constants()
t_const_value * get_value()
const std::string & get_name() const
t_type * get_type() const
std::map< std::string, std::string > annotations_
const std::string & get_name() const
const t_type * get_type()
const members_type & get_members()
virtual bool is_service() const
virtual bool is_set() const
virtual bool is_xception() const
virtual bool is_struct() const
virtual bool is_enum() const
virtual const std::string & get_name() const
t_program * get_program()
virtual bool is_base_type() const
virtual bool is_list() const
virtual bool is_container() const
virtual bool is_typedef() const
virtual bool is_map() const
t_type * get_type() const
boost::tokenizer< boost::char_separator< char > > tokenizer
#define THRIFT_REGISTER_GENERATOR(language, long_name, doc)