OpenSDN source code
t_doc_generator.cc
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  * Copyright 2006-2017 The Apache Software Foundation.
20  * https://github.com/apache/thrift
21  *
22  * Modifications Copyright (c) Juniper Networks, Inc.
23  * Copyright Contributors to the OpenSDN project
24  */
25 
26 #include <string>
27 #include <fstream>
28 #include <iostream>
29 #include <vector>
30 #include <algorithm>
31 #include <boost/algorithm/string.hpp>
32 #include <map>
33 #include <utility>
34 
35 #include <stdlib.h>
36 #include <sys/stat.h>
37 #include <sstream>
38 #include <boost/foreach.hpp>
39 #include <boost/tokenizer.hpp>
40 #include "t_generator.h"
41 #include "platform.h"
42 using namespace std;
43 
47 class t_doc_generator : public t_generator {
48  public:
50  t_program* program,
51  const map<string, string>& parsed_options,
52  const string& option_string)
53  : t_generator(program)
54  {
55  (void) parsed_options;
56  (void) option_string;
57  out_dir_base_ = "gen-doc";
58  escape_.clear();
59  escape_['&'] = "&amp;";
60  escape_['<'] = "&lt;";
61  escape_['>'] = "&gt;";
62  escape_['"'] = "&quot;";
63  escape_['\''] = "&apos;";
64  }
65 
66  struct doc_ftype {
67  enum type {
81  };
82  };
83 
84  // Sync with SandeshLevel from tools/sandesh/library/common/sandesh.sandesh
85  struct sandesh_level {
86  enum type {
88  DBG,
92  ERR,
96  };
97  };
98 
99  sandesh_level::type string_to_sandesh_level(const string &level);
100  string sandesh_level_to_string(const sandesh_level::type &slevel);
101  sandesh_level::type get_sandesh_level(t_sandesh *tsandesh);
102  string get_object_type( t_sandesh* tsandesh);
103  string get_doc_member(t_sandesh* tsandesh, string member);
104  bool is_sandesh_type(t_sandesh *tsandesh, doc_ftype::type dtype);
105  string get_doc_file_suffix(doc_ftype::type dtype);
106  string get_doc_file_description(doc_ftype::type dtype);
107  void generate_index();
108  void generate_stats_schema_program();
109  bool generate_sandesh_program(doc_ftype::type dtype);
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,
114  doc_ftype::type dtype);
115  void generate_program_toc_row(t_program* tprog, ofstream &f_out,
116  string fsuffix, doc_ftype::type dtype);
117  bool generate_sandesh_program_doc(t_program* tprog, ofstream &f_out,
118  string fsuffix, doc_ftype::type dtype);
119  void generate_sandesh_program_doc_schema(t_program* tprog, ofstream &f_out,
120  string fsuffix, doc_ftype::type dtype);
121  void generate_sandesh_program_doc_schema_uve(t_program* tprog, ofstream &f_out,
122  string fsuffix);
123 
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>
144  string get_type_of_member(string, t_field*, t_struct*, 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*>);
167  void generate_typedef (t_typedef* ttypedef) {}
168  void generate_enum (t_enum* tenum) {}
169  void generate_const (t_const* tconst) {}
170  void generate_struct (t_struct* tstruct) {}
171  void generate_service (t_service* tservice) {}
172  void generate_sandesh (t_sandesh* tsandesh) {}
173  bool generate_introspect_cli (t_sandesh* , ofstream &f_out, bool &first_file);
174 
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);
182 
183  ofstream f_index_out_;
197  ofstream f_out_;
198  ofstream f_stats_tables_;
199 
200  private:
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);
209 
212 };
213 
215  doc_ftype::type dtype) {
216  t_base_type *tbtype((t_base_type *)tsandesh->get_type());
217  switch (dtype) {
218  case doc_ftype::LOGS:
219  if (tbtype->is_sandesh_system() || tbtype->is_sandesh_object()) {
220  return true;
221  }
222  return false;
223  case doc_ftype::LOGS_LEVEL_INVALID:
224  if ((tbtype->is_sandesh_system() || tbtype->is_sandesh_object()) &&
225  get_sandesh_level(tsandesh) == sandesh_level::INVALID) {
226  return true;
227  }
228  return false;
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) {
232  return true;
233  }
234  return false;
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) {
238  return true;
239  }
240  return false;
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) {
244  return true;
245  }
246  return false;
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) {
250  return true;
251  }
252  return false;
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) {
256  return true;
257  }
258  return false;
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) {
262  return true;
263  }
264  return false;
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) {
268  return true;
269  }
270  return false;
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) {
274  return true;
275  }
276  return false;
277  case doc_ftype::UVES:
278  if (tbtype->is_sandesh_uve()) {
279  return true;
280  }
281  return false;
282  case doc_ftype::TRACES:
283  if (tbtype->is_sandesh_trace() || tbtype->is_sandesh_trace_object()) {
284  return true;
285  }
286  return false;
287  case doc_ftype::INTROSPECT:
288  if (tbtype->is_sandesh_request() || tbtype->is_sandesh_response()) {
289  return true;
290  }
291  return false;
292  default:
293  return false;
294  }
295  return false;
296 }
297 
299  switch (dtype) {
300  case doc_ftype::LOGS:
301  return "_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:
307  return "_logs.info";
308  case doc_ftype::LOGS_LEVEL_NOTICE:
309  return "_logs.notice";
310  case doc_ftype::LOGS_LEVEL_WARN:
311  return "_logs.warn";
312  case doc_ftype::LOGS_LEVEL_ERR:
313  return "_logs.error";
314  case doc_ftype::LOGS_LEVEL_CRIT:
315  return "_logs.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:
321  return "_uves";
322  case doc_ftype::TRACES:
323  return "_traces";
324  case doc_ftype::INTROSPECT:
325  return "_introspect";
326  default:
327  return "";
328  }
329 }
330 
332  switch (dtype) {
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:
354  return "UVE";
355  case doc_ftype::TRACES:
356  return "traces";
357  case doc_ftype::INTROSPECT:
358  return "introspect";
359  default:
360  return "";
361  }
362 }
363 
367 void t_doc_generator::generate_program_toc(ofstream &f_out, string fsuffix,
368  doc_ftype::type dtype) {
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;
372 }
373 
378  string fsuffix, doc_ftype::type dtype) {
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) {
390  name = tfield->get_type()->get_name();
391  f_out << "<a href=\"" << fname << "#Snh_" << name << "\">" << name
392  << "</a><br/>" << endl;
393  }
394  } else {
395  f_out << "<a href=\"" << fname << "#Snh_" << name << "\">" << name
396  << "</a><br/>" << endl;
397  }
398  }
399  }
400  }
401  f_out << "</td>" << endl;
402  f_out << "</tr>";
403 }
404 
405 void t_doc_generator::generate_doc_type(ofstream &f_out) {
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\"/>"
412  << endl;
413 }
414 
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()) {
422  // Generate sandeshs
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);
427  }
428  }
429  f_stats_tables_ << "]" << endl << "}" << endl;
430 }
431 
433  ofstream &f_out, string fsuffix, doc_ftype::type dtype) {
434  if (dtype == doc_ftype::UVES)
435  return generate_sandesh_program_doc_schema_uve(tprog, f_out, fsuffix);
436  bool init = false;
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)) {
443  continue;
444  }
445  if (!init) {
446  init = true;
447  } else {
448  f_out << "," << endl;
449  }
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) << "\"";
460  }
461  f_out << "}";
462  }
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)) {
468  continue;
469  }
470  generate_introspect_cli(*snh_iter, f_out, first_file);
471  }
472  f_out << endl << "}" << endl << "}" << endl;
473  } else {
474  f_out << "}" << endl << "}" << endl;
475  }
476 }
477 
479  ofstream &f_out, string fsuffix) {
480  bool init = false;
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)) {
487  continue;
488  }
489  if (!init) {
490  init = true;
491  } else {
492  f_out << "," << endl;
493  }
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();
498  }
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) << "\"";
505  }
506  f_out << "}";
507  }
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)) {
513  continue;
514  }
515  generate_introspect_cli(*snh_iter, f_out, first_file);
516  }
517  f_out << endl << "}" << endl << "}" << endl;
518  } else {
519  f_out << "}" << endl << "}" << endl;
520  }
521 }
522 
524  ofstream &f_out, string fsuffix, doc_ftype::type dtype) {
525 
526  generate_doc_type(f_out);
527 
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;
533 
534  print_doc(tprog, f_out);
535 
536  generate_program_toc(f_out, fsuffix, dtype);
537 
538  bool init = false;
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)) {
545  continue;
546  }
547  init = true;
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);
552  } else {
553  generate_sandesh(*snh_iter, f_out);
554  }
555  f_out << "</div>";
556  }
557  }
558  f_out << "</body></html>" << endl;
559  return init;
560 }
561 
563  string fsuffix = get_doc_file_suffix(dtype);
564 
565  string fname = get_out_dir() + program_->get_name() + fsuffix + ".html";
566  ofstream f_out;
567  f_out.open(fname.c_str());
568  bool init(generate_sandesh_program_doc(program_, f_out, fsuffix, dtype));
569  f_out.close();
570 
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();
576  return init;
577 }
578 
580  string fsuffix = "";
581  string fname = get_out_dir() + program_->get_name() + fsuffix + ".html";
582  f_out_.open(fname.c_str());
583 
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;
589 
590  print_doc(program_, f_out_);
591 
592  if (!program_->get_consts().empty()) {
593  f_out_ << "<hr/><h2 id=\"Constants\">Constants</h2>" << endl;
594  vector<t_const*> consts = program_->get_consts();
595  f_out_ << "<table>";
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>";
599  }
600 
601  if (!program_->get_enums().empty()) {
602  f_out_ << "<hr/><h2 id=\"Enumerations\">Enumerations</h2>" << endl;
603  // Generate enums
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_);
608  }
609  }
610 
611  if (!program_->get_typedefs().empty()) {
612  f_out_ << "<hr/><h2 id=\"Typedefs\">Type declarations</h2>" << endl;
613  // Generate typedefs
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_);
618  }
619  }
620 
621  if (!program_->get_objects().empty()) {
622  f_out_ << "<hr/><h2 id=\"Structs\">Data structures</h2>" << endl;
623  // Generate structs and exceptions in declared order
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_);
628  }
629  }
630 
631  f_out_ << "</body></html>" << endl;
632  f_out_.close();
633 }
634 
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\"/>"
644  << endl;
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;
649  }
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;
653  }
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;
657  }
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;
661  }
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;
665  }
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;
669  }
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;
673  }
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;
677  }
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;
681  }
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;
685  }
686  if (f_uve_initialized_) {
687  f_index_out_ << "<tr><td><a href=" << program_->get_name() << "_uves.html>UVEs</a></td></tr>" << endl;
688  }
689  if (f_trace_initialized_) {
690  f_index_out_ << "<tr><td><a href=" << program_->get_name() << "_traces.html>Traces</a></td></tr>" << endl;
691  }
692  if (f_introspect_initialized_) {
693  f_index_out_ << "<tr><td><a href=" << program_->get_name() << "_introspect.html>Request-Response</a></td></tr>" << endl;
694  }
695  f_index_out_ << "</table>" << endl;
696  f_index_out_ << "</html>" << endl;
697  f_index_out_.close();
698 }
699 
705  // Make output directory
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);
721  generate_index();
722  generate_const_enum_typedef_object_program();
723 }
724 
725 void t_doc_generator::print_doc_string(string doc, ofstream &f_out) {
726  size_t index;
727  while ((index = doc.find_first_of("\r\n")) != string::npos) {
728  if (index == 0) {
729  f_out << "<p/>" << endl;
730  } else {
731  f_out << doc.substr(0, index) << endl;
732  }
733  if (index + 1 < doc.size() && doc.at(index) != doc.at(index + 1) &&
734  (doc.at(index + 1) == '\r' || doc.at(index + 1) == '\n')) {
735  index++;
736  }
737  doc = doc.substr(index + 1);
738  }
739  f_out << doc << "<br/>";
740 }
741 
746 void t_doc_generator::print_doc(t_doc* tdoc, ofstream &f_out) {
747  if (tdoc->has_doc()) {
748  string doc = tdoc->get_doc();
749  print_doc_string(doc, f_out);
750  }
751 }
752 
753 void t_doc_generator::print_sandesh_message(t_sandesh* tsandesh, ofstream &f_out) {
754  bool first = true;
755  // Print the message
756  vector<t_field*> members = tsandesh->get_members();
757  BOOST_FOREACH(t_field *tfield, members) {
758  if (tfield->get_auto_generated()) {
759  continue;
760  }
761  if (first) {
762  f_out << "<tr><th>Message</th><td>";
763  }
764  t_type *type = tfield->get_type();
765  if (type->is_static_const_string()) {
766  t_const_value* default_val = tfield->get_value();
767  if (!first) {
768  f_out << " ";
769  }
770  f_out << get_escaped_string(default_val);
771  } else {
772  f_out << "<code>";
773  if (!first) {
774  f_out << " ";
775  }
776  f_out << tfield->get_name() << "</code>";
777  }
778  first = false;
779  }
780  if (!first) {
781  f_out << "</td></tr>" << endl;
782  }
783 }
784 
785 void t_doc_generator::print_sandesh_message_table(t_sandesh* tsandesh, ofstream &f_out) {
786  f_out << "<table>";
787  print_sandesh_message(tsandesh, f_out);
788  f_out << "</table><br/>" << endl;
789 }
790 
792  const string &ilevel) {
793  string level(ilevel);
794  // Trim and convert to lower case
795  boost::algorithm::trim(level);
796  if (level.empty()) {
798  }
799  boost::algorithm::to_lower(level);
800  if (level == "debug") {
802  }
803  if (level == "informational" || level == "info") {
805  }
806  if (level == "notice") {
808  }
809  if (level == "warning" || level == "warn") {
811  }
812  if (level == "error" || level == "err") {
814  }
815  if (level == "critical" || level == "crit") {
817  }
818  if (level == "alert") {
820  }
821  if (level == "emergency" || level == "emerg") {
823  }
825 }
826 
828  const t_doc_generator::sandesh_level::type &slevel) {
829  switch (slevel) {
831  return "emergency";
833  return "criticial";
835  return "alert";
837  return "error";
839  return "warning";
841  return "notice";
843  return "informational";
845  return "debug";
847  default:
848  return "unknown";
849  }
850 }
851 
852 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
853 string t_doc_generator::get_doc_member(t_sandesh* tsandesh, string member) {
854  if (tsandesh->has_doc()) {
855  string doc = tsandesh->get_doc();
856  size_t index;
857  if ((index = doc.find_first_of("@")) != string::npos) {
858  // Skip leading documentation
859  string fdoc(doc.substr(index + 1));
860  // Extract tokens beginning with @
861  boost::char_separator<char> fsep("@");
862  tokenizer ftokens(fdoc, fsep);
863  BOOST_FOREACH(const string &f, ftokens) {
864  // Has 2 parts, the first ending with ':' or ' ' or '\t' is
865  // the type and the next is the content
866  size_t lindex;
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) == ' ')) {
872  lindex++;
873  }
874  string content(f.substr(lindex + 1));
875  if (type == member) {
876  return content;
877  }
878  }
879  }
880  }
881  }
882  return "";
883 }
884 
886  string content = get_doc_member(tsandesh, "object");
887  if (content != "") {
888  boost::algorithm::trim(content);
889  return content;
890  }
891  return " ";
892 }
893 
895  t_sandesh* tsandesh) {
896  string content = get_doc_member(tsandesh, "severity");
897  if (content != "")
898  return string_to_sandesh_level(content);
899  return sandesh_level::INVALID;
900 }
901 
907 void t_doc_generator::print_sandesh(t_sandesh* tsandesh, ofstream &f_out) {
908  if (tsandesh->has_doc()) {
909  bool table = false;
910  string doc = tsandesh->get_doc();
911  size_t index;
912  if ((index = doc.find_first_of("@")) != string::npos) {
913  // Print leading documentation
914  f_out << doc.substr(0, index) << "<p/>" << endl;
915  string fdoc(doc.substr(index + 1));
916  if (!table) {
917  f_out << "<table>" << endl;
918  print_sandesh_message(tsandesh, f_out);
919  table = true;
920  }
921  // Extract tokens beginning with @
922  boost::char_separator<char> fsep("@");
923  tokenizer ftokens(fdoc, fsep);
924  BOOST_FOREACH(const string &f, ftokens) {
925  // Has 2 parts, the first ending with ':' or ' ' or '\t' is
926  // the type and the next is the content
927  size_t lindex;
928  if ((lindex = f.find_first_of(": \t")) != string::npos) {
929  string type(f.substr(0, lindex));
930  type.at(0) = toupper(type.at(0));
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) == ' ')) {
935  lindex++;
936  }
937  string content(f.substr(lindex + 1));
938  f_out << "<td>" << content << "</td></tr>" << endl;
939  } else {
940  f_out << "<td>" << f << "</td>" << endl;
941  }
942  }
943  } else {
944  f_out << doc << "<p/>" << endl;
945  print_sandesh_message_table(tsandesh, f_out);
946  }
947  if (table) {
948  f_out << "</table><br/>" << endl;
949  }
950  } else {
951  print_sandesh_message_table(tsandesh, f_out);
952  }
953 }
954 
958 int t_doc_generator::print_type(t_type* ttype, ofstream &f_out) {
959  int len = 0;
960  f_out << "<code>";
961  if (ttype->is_container()) {
962  if (ttype->is_list()) {
963  f_out << "list&lt;";
964  len = 6 + print_type(((t_list*)ttype)->get_elem_type(), f_out);
965  f_out << "&gt;";
966  } else if (ttype->is_set()) {
967  f_out << "set&lt;";
968  len = 5 + print_type(((t_set*)ttype)->get_elem_type(), f_out);
969  f_out << "&gt;";
970  } else if (ttype->is_map()) {
971  f_out << "map&lt;";
972  len = 5 + print_type(((t_map*)ttype)->get_key_type(), f_out);
973  f_out << ", ";
974  len += print_type(((t_map*)ttype)->get_val_type(), f_out);
975  f_out << "&gt;";
976  }
977  } else if (ttype->is_base_type()) {
978  f_out << (((t_base_type*)ttype)->is_binary() ? "binary" : ttype->get_name());
979  len = ttype->get_name().size();
980  } else {
981  string prog_name = ttype->get_program()->get_name();
982  string type_name = ttype->get_name();
983  f_out << "<a href=\"" << prog_name << ".html#";
984  if (ttype->is_typedef()) {
985  f_out << "Typedef_";
986  } else if (ttype->is_struct() || ttype->is_xception()) {
987  f_out << "Struct_";
988  } else if (ttype->is_enum()) {
989  f_out << "Enum_";
990  } else if (ttype->is_service()) {
991  f_out << "Svc_";
992  }
993  f_out << type_name << "\">";
994  len = type_name.size();
995  if (ttype->get_program() != program_) {
996  f_out << prog_name << ".";
997  len += prog_name.size() + 1;
998  }
999  f_out << type_name << "</a>";
1000  }
1001  f_out << "</code>";
1002  return len;
1003 }
1004 
1008 void t_doc_generator::print_const_value(t_const_value* tvalue, ofstream &f_out) {
1009  bool first = true;
1010  switch (tvalue->get_type()) {
1012  f_out << tvalue->get_integer();
1013  break;
1015  f_out << tvalue->get_double();
1016  break;
1018  f_out << '"' << get_escaped_string(tvalue) << '"';
1019  break;
1020  case t_const_value::CV_MAP:
1021  {
1022  f_out << "{ ";
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++) {
1026  if (!first) {
1027  f_out << ", ";
1028  }
1029  first = false;
1030  print_const_value(map_iter->first, f_out);
1031  f_out << " = ";
1032  print_const_value(map_iter->second, f_out);
1033  }
1034  f_out << " }";
1035  }
1036  break;
1038  {
1039  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++) {
1043  if (!first) {
1044  f_out << ", ";
1045  }
1046  first = false;
1047  print_const_value(*list_iter, f_out);
1048  }
1049  f_out << " }";
1050  }
1051  break;
1052  default:
1053  f_out << "UNKNOWN";
1054  break;
1055  }
1056 }
1057 
1063 void t_doc_generator::generate_typedef(t_typedef* ttypedef, ofstream &f_out) {
1064  string name = ttypedef->get_name();
1065  f_out << "<div class=\"definition\">";
1066  f_out << "<h3 id=\"Typedef_" << name << "\">Typedef: " << name
1067  << "</h3>" << endl;
1068  f_out << "<p><strong>Base type:</strong>&nbsp;";
1069  print_type(ttypedef->get_type(), f_out);
1070  f_out << "</p>" << endl;
1071  print_doc(ttypedef, f_out);
1072  f_out << "</div>" << endl;
1073 }
1074 
1080 void t_doc_generator::generate_enum(t_enum* tenum, ofstream &f_out) {
1081  string name = tenum->get_name();
1082  f_out << "<div class=\"definition\">";
1083  f_out << "<h3 id=\"Enum_" << name << "\">Enumeration: " << name
1084  << "</h3>" << endl;
1085  print_doc(tenum, f_out);
1086  vector<t_enum_value*> values = tenum->get_constants();
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;
1095  }
1096  f_out << "</table></div>" << endl;
1097 }
1098 
1102 void t_doc_generator::generate_const(t_const* tconst, ofstream &f_out) {
1103  string name = tconst->get_name();
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>";
1110  if (tconst->has_doc()) {
1111  f_out << "<tr><td colspan=\"3\"><blockquote>";
1112  print_doc(tconst, f_out);
1113  f_out << "</blockquote></td></tr>";
1114  }
1115 }
1116 
1117 void t_doc_generator::generate_consts(vector<t_const*> consts, ofstream &f_out) {
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);
1121  }
1122 }
1123 
1124 void t_doc_generator::generate_stat_table_schema_header(string type, string attr, string table_name, string display_name) {
1125  if (stat_table_created_ == false) {
1126  stat_table_created_ = true;
1127  f_stats_tables_ << "{\n\"stat_type\":\"" << type << "\"," << endl;
1128  } else {
1129  f_stats_tables_ << ",\n{\n\"stat_type\":\"" << type << "\"," << endl;
1130  }
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;
1136 }
1137 
1138 string t_doc_generator::get_uve_type(string name, t_field* tfield) {
1139  map<string, string>::iterator jt;
1140  string uve_type = "";
1141  jt = tfield->annotations_.find("uve_type");
1142  if (jt != tfield->annotations_.end()) {
1143  string annotations = jt->second;
1144  boost::char_separator<char> fsep(",");
1145  tokenizer tags(tfield->annotations_["uve_type"], 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);
1150  boost::trim(fname);
1151  uve_type = tag.substr(index+1);
1152  boost::trim(uve_type);
1153  if (name == fname)
1154  return uve_type;
1155  }
1156  }
1157  }
1158  return "";
1159 }
1160 
1161 template <typename T>
1162 string t_doc_generator::get_type_of_member(string name, t_field* tfield, t_struct* cstruct, T* tstruct) {
1163  string datatype;
1164  vector<t_field*>::const_iterator m_iter;
1165  if (!boost::starts_with(name, ".")) {
1166  //find the member in top level structure
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());
1172  }
1173  }
1174  } else if (name.compare(".__key") == 0) {
1175  if (tfield->get_type()->is_map()) {
1176  t_type* keytype= ((t_map*)(tfield->get_type()))->get_key_type();
1177  return get_datatype_from_tfield(keytype);
1178  }
1179  } else {
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());
1185  }
1186  }
1187  }
1188  return datatype;
1189 }
1190 
1191 template <typename T>
1193  string>& top_level_tags, vector<string>& schema, t_field* tfield) {
1194  BOOST_FOREACH(const string &tag, top_level_tags) {
1195  //find the member in top level structure
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()) {
1201  string fname;
1202  schema.push_back(generate_stat_schema_struct_base_member(
1203  fname, *m_iter, "true", tfield));
1204  break;
1205  }
1206  }
1207  }
1208 }
1209 
1210 template <typename T>
1212  t_field* tfield, t_struct* cstruct, T* tstruct, map<string,
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;
1220  }
1221  if (!prefix.empty()) {
1222  fname = prefix + "." + fname;
1223  }
1224  string index = "true";
1225  string suffix;
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;
1231  }
1232  if (!prefix.empty()) {
1233  suffix_name = prefix + "." + suffix_name;
1234  }
1235  if(name_it == it->second.begin()) {
1236  suffix = suffix + "\"" + suffix_name + "\"";
1237  } else {
1238  suffix = suffix + ", \"" + suffix_name + "\"";
1239  }
1240  }
1241  indent_up();
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 << "]}";
1250  } else {
1251  oss << "{\"name\":\"" << fname <<
1252  "\",\"datatype\":\"" << datatype << "\",\"index\":" << index <<
1253  ",\"suffixes\":[" << suffix << "]}";
1254  }
1255  schemas.push_back(oss.str());
1256  indent(f_stats_tables_) << oss.str();
1257  indent_down();
1258  }
1259 }
1260 
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) {
1269  index = "true";
1270  return;
1271  }
1272  }
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;
1279  return;
1280  }
1281  }
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) {
1287  is_tag = true;
1288  return;
1289  }
1290  }
1291  }
1292 }
1293 
1295  t_field* tfield, t_struct* tstruct, vector<string> tags,
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;
1299  string name = tfield->get_name();
1300  if(!prefix.empty()) {
1301  prefix = prefix + "." + name;
1302  } else {
1303  prefix = name;
1304  }
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") {
1310  is_index = true;
1311  } else {
1312  is_index = false;
1313  }
1314  if (is_suffixed_field) {
1315  continue;
1316  }
1317  t_type* mtype = (*m_iter)->get_type();
1318  if(mtype->is_base_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);
1322  } else if (mtype->is_struct()) {
1323  string mtype_name = mtype->get_name();
1324  t_struct *cstruct = find_struct_with_name(mtype_name);
1325  if (cstruct) {
1326  generate_stat_schema_struct(prefix, (*m_iter), cstruct, tstruct, false, schemas);
1327  }
1328  } else if (mtype->is_list() || mtype->is_set()) {
1329  t_type* etype= ((t_list*)mtype)->get_elem_type();
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);
1335  }
1336  }
1337 }
1338 
1340  string datatype = ttype->get_name();
1341  if ((datatype == "u32") || (datatype == "u16") || (datatype == "u64"))
1342  datatype = "int";
1343  return datatype;
1344 }
1345 
1346 string t_doc_generator::generate_table_entry(string name, string datatype, string index, string uve_type) {
1347  indent_up();
1348  if (!first_member_) {
1349  f_stats_tables_ << "," << endl;
1350  }
1351  std::ostringstream oss;
1352  if (uve_type != "") {
1353  oss << "{\"name\":\"" << name << "\",\"datatype\":\""
1354  << datatype << "\",\"index\":" << index << ",\"uve_type\":\""
1355  << uve_type << "\"}";
1356  } else {
1357  oss << "{\"name\":\"" << name << "\",\"datatype\":\""
1358  << datatype << "\",\"index\":" << index << "}";
1359  }
1360  string schema = oss.str();
1361  indent(f_stats_tables_) << schema;
1362  first_member_ = false;
1363  indent_down();
1364  return schema;
1365 }
1366 
1367 template <typename T>
1368 void t_doc_generator::generate_stat_schema_map(string prefix, t_type* keytype, t_type* valtype, t_field* tfield, T* tstruct, bool is_top_level, bool is_index, vector<string>& schemas) {
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;
1374  string tname = tfield->get_name();
1375  jt = tfield->annotations_.find("tags");
1376  if (jt == tfield->annotations_.end())
1377  is_empty_tag = true;
1378  if (!is_top_level && !is_empty_tag && !is_index) {
1379  return;
1380  }
1381  if(!prefix.empty()) {
1382  tname = prefix + "." + tname;
1383  }
1384  if (is_empty_tag == false) {
1385  extract_tags(tfield, suffixes, top_level_tags, member_tags);
1386  }
1387  if (!valtype->is_base_type()) {
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);
1398  }
1399  if(valtype->is_base_type()) {
1400  name = tname + string(".__value");
1401  datatype = get_datatype_from_tfield(valtype);
1402  index = "false";
1403  BOOST_FOREACH(const string &f, member_tags) {
1404  if (f == string(".__value")) {
1405  index = "true";
1406  }
1407  }
1408  uve_type = get_uve_type("__value", tfield);
1409  generate_table_entry(name, datatype, index, uve_type);
1410  }
1411  } else {
1412  // name:"field.*" datatype:"string" for querying/selecting individual elem
1413  string name = tname + ".*";
1414  string datatype = get_datatype_from_tfield(valtype);
1415  string index = "false";
1416  if (is_index) {
1417  index = "true";
1418  }
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);
1423  }
1424  // name:"field" datatype:"map" for selecting entire map
1425  name = tname;
1426  datatype = "map";
1427  index = "false";
1428  uve_type = get_uve_type(tname, tfield);
1429  schema = generate_table_entry(name, datatype, index, uve_type);
1430  }
1431 
1432  string empty_prefix;
1433  if (valtype->is_struct()) {
1434  string sname = valtype->get_name();
1435  t_struct *cstruct = find_struct_with_name(sname);
1436  if (cstruct) {
1437  if(!is_empty_tag) {
1438  generate_stat_schema_struct_members(empty_prefix, tfield, cstruct, member_tags, suffixes, schemas);
1439  }
1440  generate_stat_schema_toplevel_tags(tstruct, top_level_tags, schemas, tfield);
1441  generate_stat_schema_suffixes(empty_prefix, tfield, cstruct, tstruct, suffixes, schemas);
1442  }
1443  } else {
1444  generate_stat_schema_toplevel_tags(tstruct, top_level_tags, schemas, tfield);
1445  generate_stat_schema_suffixes(empty_prefix, tfield, NULL, tstruct, suffixes, schemas);
1446  }
1447 }
1448 
1450  t_field* tfield, string index, t_field* top_field) {
1451  string fname = tfield->get_name();
1452  string uve_type;
1453  if (!prefix.empty()) {
1454  uve_type = get_uve_type("." + fname, top_field);
1455  fname = prefix+ "." + fname;
1456  } else {
1457  uve_type = get_uve_type(fname, top_field);
1458  }
1459  string datatype = get_datatype_from_tfield(tfield->get_type());
1460  return generate_table_entry(fname, datatype, index, uve_type);
1461 }
1462 
1463 template <typename T>
1464 void t_doc_generator::extract_tags(T* tfield, map<string, vector<string> >
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);
1472  boost::trim(fname);
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));
1479  } else {
1480  vector<string> old_suffixes = suffixes[fname];
1481  old_suffixes.push_back(suffix_name);
1482  suffixes[fname] = old_suffixes;
1483  }
1484  } else {
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);
1489  } else {
1490  member_tags.push_back(trimmed_tag);
1491  }
1492  }
1493  }
1494 }
1495 
1496 template <typename T>
1497 void t_doc_generator::generate_stat_schema_struct(string prefix, t_field* tfield, t_struct* cstruct, T* tstruct, bool is_top_level, vector<string>& schemas) {
1498  map<string, vector<string> > suffixes;
1499  vector<string> top_level_tags;
1500  vector<string> member_tags;
1501  bool is_empty_tag = false;
1502  if (is_top_level) {
1503  extract_tags(tfield, suffixes, top_level_tags, member_tags);
1504  } else {
1505  map<string, string>::iterator jt = tfield->annotations_.find("tags");
1506  if (jt == tfield->annotations_.end()) {
1507  is_empty_tag = true;
1508  } else {
1509  return;
1510  }
1511  }
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);
1516 }
1517 
1518 template <typename T>
1519 void t_doc_generator::generate_stat_schema_list(string name, t_type* ttype, t_field* tfield, T* tstruct, bool is_top_level, bool is_index, vector<string>& schemas) {
1520  if (ttype->is_struct()) {
1521  string sname = ttype->get_name();
1522  t_struct *cstruct = find_struct_with_name(sname);
1523  if (cstruct) {
1524  generate_stat_schema_struct(name, tfield, cstruct, tstruct, is_top_level, schemas);
1525  }
1526  } else if (ttype->is_base_type()) {
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;
1532  string tname = tfield->get_name();
1533  jt = tfield->annotations_.find("tags");
1534  if (jt == tfield->annotations_.end())
1535  is_empty_tag = true;
1536  if (!is_top_level && !is_empty_tag && !is_index) {
1537  return;
1538  }
1539  if(!name.empty()) {
1540  tname = name + "." + tname;
1541  }
1542  if (is_empty_tag == false) {
1543  extract_tags(tfield, suffixes, top_level_tags, member_tags);
1544  }
1545  string datatype;
1546  if (tfield->get_type()->is_list()) {
1547  datatype = "list";
1548  } else if (tfield->get_type()->is_set()) {
1549  datatype = "set";
1550  }
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);
1554  if (is_index) {
1555  index = "true";
1556  } else {
1557  index = "false";
1558  }
1559  jt = tfield->annotations_.find("uve_type");
1560  string uve_type = "";
1561  if (jt != tfield->annotations_.end())
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);
1567  }
1568  }
1569 }
1570 
1572  t_struct *cstruct = program_->get_struct(sname.c_str());
1573  if (cstruct) {
1574  return cstruct;
1575  }
1576  // Check in includes
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());
1581  if (cstruct) {
1582  return cstruct;
1583  }
1584  }
1585  return NULL;
1586 }
1587 
1588 template <typename T>
1589 void t_doc_generator::generate_stat_table_schema(string oname, t_field* tfield, T* tsandesh, string prefix, vector<string>& tags) {
1590  if (tfield->get_type()->is_list()) {
1591  t_type* ltype= ((t_list*)((tfield)->get_type()))->get_elem_type();
1592  generate_stat_schema_list(prefix, ltype, tfield, tsandesh, true, false, tags);
1593  } else if (tfield->get_type()->is_map()) {
1594  t_type* valtype= ((t_map*)(tfield->get_type()))->get_val_type();
1595  t_type* keytype= ((t_map*)(tfield->get_type()))->get_key_type();
1596  generate_stat_schema_map(prefix, keytype, valtype, tfield, tsandesh, true, false, tags);
1597  } else if (tfield->get_type()->is_struct()) {
1598  string sname = (tfield->get_type())->get_name();
1599  t_struct *cstruct = find_struct_with_name(sname);
1600  if (cstruct) {
1601  generate_stat_schema_struct(prefix, tfield, cstruct, tsandesh, true, tags);
1602  }
1603  }
1604 }
1605 
1606 string t_doc_generator::find_obj_table_name(const vector<t_field*> members) {
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"];
1615  }
1616  }
1617  }
1618  return obj_table_name;
1619 }
1620 
1621 template <typename T>
1622 void t_doc_generator::find_recursive_tags_map(T* tsandesh, t_field* tfield, string table, t_type* keytype, t_type* valtype, string prefix, vector<string>& schemas) {
1623  if (valtype->is_struct()) {
1624  string sname = valtype->get_name();
1625  find_recursive_tags_struct(tsandesh, tfield, table, sname, prefix, schemas);
1626  }
1627 }
1628 
1629 template <typename T>
1630 void t_doc_generator::find_recursive_tags_list(T* tsandesh, t_field* tfield, string table, t_type* ttype, string prefix, vector<string>& schemas) {
1631  if (ttype->is_struct()) {
1632  string sname = ttype->get_name();
1633  find_recursive_tags_struct(tsandesh, tfield, table, sname, prefix, schemas);
1634  }
1635 }
1636 
1637 template <typename T>
1638 void t_doc_generator::find_recursive_tags_struct(T* tsandesh, t_field* tfield, string table, string sname, string prefix, vector<string>& schemas) {
1639  t_struct *cstruct = find_struct_with_name(sname);
1640  if(cstruct) {
1641  const vector<t_field*> members = cstruct->get_members();
1642  generate_stat_tables_schema(tsandesh, members, table, prefix, schemas);
1643  }
1644 }
1645 
1646 template <typename T>
1647 void t_doc_generator::find_recursive_tags(T* tsandesh, t_field* tfield, string table, string fname, vector<string>& index_schemas) {
1648  string tags;
1649  if (tfield->get_type()->is_list()) {
1650  t_type* ltype= ((t_list*)((tfield)->get_type()))->get_elem_type();
1651  find_recursive_tags_list(tsandesh, tfield, table, ltype, fname, index_schemas);
1652  } else if (tfield->get_type()->is_map()) {
1653  t_type* keytype= ((t_map*)(tfield->get_type()))->get_key_type();
1654  t_type* valtype= ((t_map*)(tfield->get_type()))->get_val_type();
1655  find_recursive_tags_map(tsandesh, tfield, table, keytype, valtype, fname, index_schemas);
1656  } else if (tfield->get_type()->is_struct()) {
1657  string sname = (tfield->get_type())->get_name();
1658  find_recursive_tags_struct(tsandesh, tfield, table, sname, fname, index_schemas);
1659  }
1660 
1661 }
1662 
1664  string doc = tfield->get_doc();
1665  size_t index;
1666  string display_name;
1667  if ((index = doc.find_first_of("@")) != string::npos) {
1668  boost::char_separator<char> fsep("@");
1669  tokenizer ftokens(doc, fsep);
1670  BOOST_FOREACH(const string &f, ftokens) {
1671  size_t lindex;
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;
1680  }
1681  }
1682  }
1683  }
1684  return display_name;
1685 }
1686 
1687 template <typename T>
1688 void t_doc_generator::generate_stat_tables_schema(T* tsandesh, const vector<t_field*> members, string table, string prefix, vector<string>& tags) {
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;
1705  indent_up();
1706  indent(f_stats_tables_) << tags[i];
1707  indent_down();
1708  }
1709  f_stats_tables_ << "\n]\n}";
1710  find_recursive_tags(tsandesh, *m_iter, table, fname, new_tags);
1711  }
1712  }
1713 }
1714 
1716  bool is_uve = ((t_base_type *)tsandesh->get_type())->is_sandesh_uve();
1717  const vector<t_field*> members = tsandesh->get_members();
1718  string empty_prefix;
1719  vector<string> empty_tag;
1720  if (is_uve) {
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);
1725  } else {
1726  string obj_table_name = "NONE";
1727  generate_stat_tables_schema(tsandesh, members, obj_table_name, empty_prefix, empty_tag);
1728  }
1729 }
1730 
1736 void t_doc_generator::generate_struct_table(t_struct* tstruct, ofstream &f_out) {
1737  vector<t_field*> members = tstruct->get_members();
1738  vector<t_field*>::iterator mem_iter = members.begin();
1739  f_out << "<table>";
1740  f_out << "<tr><th>Key</th><th>Field</th><th>Type</th><th>Description</th><th>Requiredness</th><th>Default value</th></tr>"
1741  << endl;
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>";
1750  if ((*mem_iter)->get_req() == t_field::T_OPTIONAL) {
1751  f_out << "optional";
1752  } else if ((*mem_iter)->get_req() == t_field::T_REQUIRED) {
1753  f_out << "required";
1754  } else {
1755  f_out << "default";
1756  }
1757  f_out << "</td><td>";
1758  t_const_value* default_val = (*mem_iter)->get_value();
1759  if (default_val != NULL) {
1760  print_const_value(default_val, f_out);
1761  }
1762  f_out << "</td></tr>" << endl;
1763  }
1764  f_out << "</table><br/>";
1765 }
1766 
1772 void t_doc_generator::generate_struct(t_struct* tstruct, ofstream &f_out) {
1773  string name = tstruct->get_name();
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);
1780  f_out << "</div>";
1781 }
1782 
1783 bool t_doc_generator::generate_introspect_cli(t_sandesh* tsandesh, ofstream &f_out, bool &first_file) {
1784  if (tsandesh->has_doc()) {
1785  string doc = tsandesh->get_doc();
1786  size_t index;
1787  string cli_name = "", cli_help = "";
1788  if ((index = doc.find_first_of("@")) != string::npos) {
1789  string fdoc(doc.substr(index + 1));
1790  // Extract tokens beginning with @
1791  boost::char_separator<char> fsep("@");
1792  tokenizer ftokens(fdoc, fsep);
1793  BOOST_FOREACH(const string &f, ftokens) {
1794  // Has 2 parts, the first ending with ':' or ' ' or '\t' is
1795  // the type and the next is the content
1796  size_t lindex;
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) == ' ')) {
1802  lindex++;
1803  }
1804  string content(f.substr(lindex + 1));
1805  content.erase(content.length()-1);
1806  if (boost::starts_with(type, "cli_name")) {
1807  cli_name = content;
1808  } else if (boost::starts_with(type, "description")) {
1809  cli_help = content;
1810  }
1811  }
1812  }
1813  }
1814  if (cli_name == "")
1815  return false;
1816  if (!first_file) {
1817  f_out << "," << endl;
1818  } else {
1819  first_file = false;
1820  }
1821 
1822  indent_up();
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();
1827  int count = 0;
1828  indent(f_out) << "[ " << endl;
1829  indent_up();
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+"\"";
1837  }
1838  f_out << "\", " << field_doc << "]";
1839  count++;
1840  if (count < size)
1841  f_out << ",";
1842  f_out << endl;
1843  }
1844  indent_down();
1845  indent(f_out) << "]}}";
1846  indent_down();
1847  return true;
1848  }
1849  return false;
1850 }
1851 
1857 void t_doc_generator::generate_sandesh(t_sandesh* tsandesh, ofstream &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();
1862  f_out << "<table>";
1863  f_out << "<tr><th>Field</th><th>Type</th><th>Description</th></tr>"
1864  << endl;
1865  BOOST_FOREACH(t_field *tfield, members) {
1866  if (tfield->get_auto_generated()) {
1867  continue;
1868  }
1869  t_type *type = tfield->get_type();
1870  if (type->is_static_const_string()) {
1871  continue;
1872  }
1873  f_out << "<tr><td>" << tfield->get_name() << "</td><td>";
1874  print_type(tfield->get_type(), f_out);
1875  f_out << "</td><td>";
1876  f_out << tfield->get_doc();
1877  f_out << "</td></tr>" << endl;
1878  }
1879  f_out << "</table><br/>";
1880 }
1881 
1887 void t_doc_generator::generate_sandesh_uve(t_sandesh* tsandesh, ofstream &f_out) {
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_);
1896  if (!cstruct) {
1897  f_out << "</table><br/>";
1898  return;
1899  }
1900  generate_struct_table(cstruct, f_out);
1901  }
1902 }
1903 
1904 THRIFT_REGISTER_GENERATOR(doc, "Documentation", "")
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
Definition: t_const_value.h:75
t_type * get_type() const
Definition: t_const.h:43
std::string get_name() const
Definition: t_const.h:47
t_const_value * get_value() const
Definition: t_const.h:51
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 > &)
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)
void generate_sandesh(t_sandesh *tsandesh)
ofstream f_stats_tables_
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 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)
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 *)
void generate_struct(t_struct *tstruct)
string get_doc_file_suffix(doc_ftype::type dtype)
string get_datatype_from_tfield(t_type *tfield)
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)
void generate_stat_schema_list(string, t_type *, t_field *, T *, bool, bool, vector< string > &)
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)
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)
Definition: t_doc.h:30
bool has_doc()
Definition: t_doc.h:44
const std::string & get_doc() const
Definition: t_doc.h:40
Definition: t_enum.h:33
const std::vector< t_enum_value * > & get_constants()
Definition: t_enum.h:46
t_const_value * get_value()
Definition: t_field.h:124
const std::string & get_name() const
Definition: t_field.h:98
t_type * get_type() const
Definition: t_field.h:94
@ T_OPTIONAL
Definition: t_field.h:108
@ T_REQUIRED
Definition: t_field.h:107
std::map< std::string, std::string > annotations_
Definition: t_field.h:202
Definition: t_list.h:32
Definition: t_map.h:33
const std::string & get_name() const
Definition: t_program.h:95
const t_type * get_type()
Definition: t_sandesh.h:74
Definition: t_set.h:32
const members_type & get_members()
Definition: t_type.h:51
virtual bool is_service() const
Definition: t_type.h:82
virtual bool is_set() const
Definition: t_type.h:80
virtual bool is_xception() const
Definition: t_type.h:77
virtual bool is_struct() const
Definition: t_type.h:76
virtual bool is_enum() const
Definition: t_type.h:75
virtual const std::string & get_name() const
Definition: t_type.h:59
t_program * get_program()
Definition: t_type.h:84
virtual bool is_base_type() const
Definition: t_type.h:64
virtual bool is_list() const
Definition: t_type.h:79
virtual bool is_container() const
Definition: t_type.h:78
virtual bool is_typedef() const
Definition: t_type.h:74
virtual bool is_map() const
Definition: t_type.h:81
t_type * get_type() const
Definition: t_typedef.h:45
@ INVALID
Definition: globals.h:150
uint8_t type
Definition: load_balance.h:2
void init()
Definition: bgp_log.cc:38
#define MKDIR(x)
Definition: platform.h:31
boost::tokenizer< boost::char_separator< char > > tokenizer
#define THRIFT_REGISTER_GENERATOR(language, long_name, doc)