diff --git a/compiler/generate/t_doc_generator.cc b/compiler/generate/t_doc_generator.cc index db16306a..73d426e9 100644 --- a/compiler/generate/t_doc_generator.cc +++ b/compiler/generate/t_doc_generator.cc @@ -57,12 +57,56 @@ class t_doc_generator : public t_generator { escape_['\''] = "'"; } - void generate_program(); - void generate_program_toc(); - void generate_program_toc_row(t_program* tprog); - void generate_program_toc_rows(t_program* tprog, - vector& finished); + struct doc_ftype { + enum type { + LOGS, + LOGS_LEVEL_INVALID, + LOGS_LEVEL_DEBUG, + LOGS_LEVEL_INFO, + LOGS_LEVEL_NOTICE, + LOGS_LEVEL_WARN, + LOGS_LEVEL_ERR, + LOGS_LEVEL_CRIT, + LOGS_LEVEL_ALERT, + LOGS_LEVEL_EMERG, + UVES, + TRACES, + INTROSPECT, + }; + }; + + // Sync with SandeshLevel from tools/sandesh/library/common/sandesh.sandesh + struct sandesh_level { + enum type { + INVALID, + DBG, + INFO, + NOTICE, + WARN, + ERR, + CRIT, + ALERT, + EMERG, + }; + }; + + sandesh_level::type string_to_sandesh_level(const string &level); + sandesh_level::type get_sandesh_level(t_sandesh *tsandesh); + bool is_sandesh_type(t_sandesh *tsandesh, doc_ftype::type dtype); + string get_doc_file_suffix(doc_ftype::type dtype); + string get_doc_file_description(doc_ftype::type dtype); void generate_index(); + void generate_stats_schema_program(); + bool generate_sandesh_program(ofstream &f_out, doc_ftype::type dtype); + void generate_const_enum_typedef_object_program(); + void generate_doc_type(ofstream &f_out); + void generate_program(); + void generate_program_toc(ofstream &f_out, string fsuffix, + doc_ftype::type dtype); + void generate_program_toc_row(t_program* tprog, ofstream &f_out, + string fsuffix, doc_ftype::type dtype); + void generate_program_list(t_program* tprog, ofstream &f_out, string fsuffix, + doc_ftype::type dtype); /** * Program-level generation functions @@ -105,128 +149,340 @@ class t_doc_generator : public t_generator { template void find_recursive_tags_map(T*, t_field*, string, t_type*, t_type*, string); string find_obj_table_name(const vector); - void generate_typedef (t_typedef* ttypedef); - void generate_enum (t_enum* tenum); - void generate_const (t_const* tconst); - void generate_struct (t_struct* tstruct); + void generate_typedef (t_typedef* ttypedef) {} + void generate_enum (t_enum* tenum) {} + void generate_const (t_const* tconst) {} + void generate_struct (t_struct* tstruct) {} void generate_service (t_service* tservice) {} - void generate_sandesh (t_sandesh* tsandesh); + void generate_sandesh (t_sandesh* tsandesh) {} - void print_doc (t_doc* tdoc); - int print_type (t_type* ttype); - void print_const_value(t_const_value* tvalue); - void print_sandesh (t_sandesh* tdoc); - void print_sandesh_message(t_sandesh* tdoc); - void print_sandesh_message_table(t_sandesh* tdoc); - void print_doc_string (string doc); + void print_doc (t_doc* tdoc, ofstream &f_out); + int print_type (t_type* ttype, ofstream &f_out); + void print_const_value(t_const_value* tvalue, ofstream &f_out); + void print_sandesh (t_sandesh* tdoc, ofstream &f_out); + void print_sandesh_message(t_sandesh* tdoc, ofstream &f_out); + void print_sandesh_message_table(t_sandesh* tdoc, ofstream &f_out); + void print_doc_string (string doc, ofstream &f_out); + ofstream f_index_out_; + ofstream f_messages_out_; + bool f_log_initialized_; + bool f_log_invalid_initialized_; + bool f_log_debug_initialized_; + bool f_log_info_initialized_; + bool f_log_notice_initialized_; + bool f_log_warn_initialized_; + bool f_log_error_initialized_; + bool f_log_crit_initialized_; + bool f_log_alert_initialized_; + bool f_log_emerg_initialized_; + bool f_uve_initialized_; + bool f_trace_initialized_; + bool f_introspect_initialized_; ofstream f_out_; ofstream f_stats_tables_; + private: - bool stat_table_created; - bool first_member; + void generate_typedef (t_typedef* ttypedef, ofstream &f_out); + void generate_enum (t_enum* tenum, ofstream &f_out); + void generate_const (t_const* tconst, ofstream &f_out); + void generate_consts (vector consts, ofstream &f_out); + void generate_struct (t_struct* tstruct, ofstream &f_out); + void generate_sandesh (t_sandesh* tsandesh, ofstream &f_out); + + bool stat_table_created_; + bool first_member_; }; -/** - * Emits the Table of Contents links at the top of the module's page - */ -void t_doc_generator::generate_program_toc() { - f_out_ << "" << endl; - generate_program_toc_row(program_); - f_out_ << "
ModuleMessages
" << endl; +bool t_doc_generator::is_sandesh_type(t_sandesh *tsandesh, + doc_ftype::type dtype) { + t_base_type *tbtype((t_base_type *)tsandesh->get_type()); + switch (dtype) { + case doc_ftype::LOGS: + if (tbtype->is_sandesh_system() || tbtype->is_sandesh_object()) { + return true; + } + return false; + case doc_ftype::LOGS_LEVEL_INVALID: + if ((tbtype->is_sandesh_system() || tbtype->is_sandesh_object()) && + get_sandesh_level(tsandesh) == sandesh_level::INVALID) { + return true; + } + return false; + case doc_ftype::LOGS_LEVEL_DEBUG: + if ((tbtype->is_sandesh_system() || tbtype->is_sandesh_object()) && + get_sandesh_level(tsandesh) == sandesh_level::DBG) { + return true; + } + return false; + case doc_ftype::LOGS_LEVEL_INFO: + if ((tbtype->is_sandesh_system() || tbtype->is_sandesh_object()) && + get_sandesh_level(tsandesh) == sandesh_level::INFO) { + return true; + } + return false; + case doc_ftype::LOGS_LEVEL_NOTICE: + if ((tbtype->is_sandesh_system() || tbtype->is_sandesh_object()) && + get_sandesh_level(tsandesh) == sandesh_level::NOTICE) { + return true; + } + return false; + case doc_ftype::LOGS_LEVEL_WARN: + if ((tbtype->is_sandesh_system() || tbtype->is_sandesh_object()) && + get_sandesh_level(tsandesh) == sandesh_level::WARN) { + return true; + } + return false; + case doc_ftype::LOGS_LEVEL_ERR: + if ((tbtype->is_sandesh_system() || tbtype->is_sandesh_object()) && + get_sandesh_level(tsandesh) == sandesh_level::ERR) { + return true; + } + return false; + case doc_ftype::LOGS_LEVEL_CRIT: + if ((tbtype->is_sandesh_system() || tbtype->is_sandesh_object()) && + get_sandesh_level(tsandesh) == sandesh_level::CRIT) { + return true; + } + return false; + case doc_ftype::LOGS_LEVEL_ALERT: + if ((tbtype->is_sandesh_system() || tbtype->is_sandesh_object()) && + get_sandesh_level(tsandesh) == sandesh_level::ALERT) { + return true; + } + return false; + case doc_ftype::LOGS_LEVEL_EMERG: + if ((tbtype->is_sandesh_system() || tbtype->is_sandesh_object()) && + get_sandesh_level(tsandesh) == sandesh_level::EMERG) { + return true; + } + return false; + case doc_ftype::UVES: + if (tbtype->is_sandesh_uve()) { + return true; + } + return false; + case doc_ftype::TRACES: + if (tbtype->is_sandesh_trace() || tbtype->is_sandesh_trace_object()) { + return true; + } + return false; + case doc_ftype::INTROSPECT: + if (tbtype->is_sandesh_request() || tbtype->is_sandesh_response()) { + return true; + } + return false; + default: + return false; + } + return false; } +string t_doc_generator::get_doc_file_suffix(doc_ftype::type dtype) { + switch (dtype) { + case doc_ftype::LOGS: + return "_logs"; + case doc_ftype::LOGS_LEVEL_INVALID: + return "_logs.invalid"; + case doc_ftype::LOGS_LEVEL_DEBUG: + return "_logs.debug"; + case doc_ftype::LOGS_LEVEL_INFO: + return "_logs.info"; + case doc_ftype::LOGS_LEVEL_NOTICE: + return "_logs.notice"; + case doc_ftype::LOGS_LEVEL_WARN: + return "_logs.warn"; + case doc_ftype::LOGS_LEVEL_ERR: + return "_logs.error"; + case doc_ftype::LOGS_LEVEL_CRIT: + return "_logs.crit"; + case doc_ftype::LOGS_LEVEL_ALERT: + return "_logs.alert"; + case doc_ftype::LOGS_LEVEL_EMERG: + return "_logs.emerg"; + case doc_ftype::UVES: + return "_uves"; + case doc_ftype::TRACES: + return "_traces"; + case doc_ftype::INTROSPECT: + return "_introspect"; + default: + return ""; + } +} -/** - * Recurses through from the provided program and generates a ToC row - * for each discovered program exactly once by maintaining the list of - * completed rows in 'finished' - */ -void t_doc_generator::generate_program_toc_rows(t_program* tprog, - vector& finished) { - for (vector::iterator iter = finished.begin(); - iter != finished.end(); iter++) { - if (tprog->get_path() == (*iter)->get_path()) { - return; - } +string t_doc_generator::get_doc_file_description(doc_ftype::type dtype) { + switch (dtype) { + case doc_ftype::LOGS: + return "all systemlog and objectlog"; + case doc_ftype::LOGS_LEVEL_INVALID: + return "systemlog and objectlog with unknown severity"; + case doc_ftype::LOGS_LEVEL_DEBUG: + return "debug systemlog and objectlog"; + case doc_ftype::LOGS_LEVEL_INFO: + return "informational systemlog and objectlog"; + case doc_ftype::LOGS_LEVEL_NOTICE: + return "notice systemlog and objectlog"; + case doc_ftype::LOGS_LEVEL_WARN: + return "warning systemlog and objectlog"; + case doc_ftype::LOGS_LEVEL_ERR: + return "error systemlog and objectlog"; + case doc_ftype::LOGS_LEVEL_CRIT: + return "critical systemlog and objectlog"; + case doc_ftype::LOGS_LEVEL_ALERT: + return "alert systemlog and objectlog"; + case doc_ftype::LOGS_LEVEL_EMERG: + return "emergency systemlog and objectlog"; + case doc_ftype::UVES: + return "UVE"; + case doc_ftype::TRACES: + return "traces"; + case doc_ftype::INTROSPECT: + return "introspect"; + default: + return ""; } - finished.push_back(tprog); - generate_program_toc_row(tprog); - vector includes = tprog->get_includes(); - for (vector::iterator iter = includes.begin(); - iter != includes.end(); iter++) { - generate_program_toc_rows(*iter, finished); +} + +void t_doc_generator::generate_program_list(t_program* tprog, ofstream &f_out, + string fsuffix, doc_ftype::type dtype) { + string fname = tprog->get_name() + fsuffix + ".html"; + if (!tprog->get_sandeshs().empty()) { + vector sandeshs = tprog->get_sandeshs(); + vector::iterator snh_iter; + for (snh_iter = sandeshs.begin(); snh_iter != sandeshs.end(); ++snh_iter) { + string name = get_sandesh_name(*snh_iter); + if (is_sandesh_type(*snh_iter, dtype)) { + f_out << "" << name + << "" << endl; + } + } } } /** * Emits the Table of Contents links at the top of the module's page */ -void t_doc_generator::generate_program_toc_row(t_program* tprog) { - string fname = tprog->get_name() + ".html"; - f_out_ << "" << endl << "" << tprog->get_name() << ""; +void t_doc_generator::generate_program_toc(ofstream &f_out, string fsuffix, + doc_ftype::type dtype) { + f_out << "" << endl; + generate_program_toc_row(program_, f_out, fsuffix, dtype); + f_out << "
ModuleMessages
" << endl; +} + +/** + * Emits the Table of Contents links at the top of the module's page + */ +void t_doc_generator::generate_program_toc_row(t_program* tprog, ofstream &f_out, + string fsuffix, doc_ftype::type dtype) { + string fname = tprog->get_name() + fsuffix + ".html"; + f_out << "" << endl << "" << tprog->get_name() << ""; if (!tprog->get_sandeshs().empty()) { vector sandeshs = tprog->get_sandeshs(); vector::iterator snh_iter; for (snh_iter = sandeshs.begin(); snh_iter != sandeshs.end(); ++snh_iter) { string name = get_sandesh_name(*snh_iter); - f_out_ << "" << name - << "
" << endl; + if (is_sandesh_type(*snh_iter, dtype)) { + f_out << "" << name + << "
" << endl; + } } } - f_out_ << "" << endl; - f_out_ << ""; + f_out << "" << endl; + f_out << ""; } -/** - * Prepares for file generation by opening up the necessary file output - * stream. - */ -void t_doc_generator::generate_program() { - // Make output directory - MKDIR(get_out_dir().c_str()); - string fname = get_out_dir() + program_->get_name() + ".html"; - f_out_.open(fname.c_str()); - f_out_ << "" << endl; - f_out_ << "" << endl; - f_out_ << "" << endl; - f_out_ << "" << endl; - f_out_ << "" +void t_doc_generator::generate_doc_type(ofstream &f_out) { + f_out << "" << endl; + f_out << "" << endl; + f_out << "" << endl; + f_out << "" << endl; + f_out << "" << endl; - f_out_ << "Documentation for module: " << program_->get_name() - << "" << endl << "

Documentation for module: " - << program_->get_name() << "

" << endl; +} - fname = get_out_dir() + program_->get_name() + "_stats_tables.json"; +void t_doc_generator::generate_stats_schema_program() { + string fname = get_out_dir() + program_->get_name() + "_stats_tables.json"; f_stats_tables_.open(fname.c_str()); - stat_table_created = false; - first_member = true; - print_doc(program_); - - generate_program_toc(); - + stat_table_created_ = false; + first_member_ = true; f_stats_tables_ << "{\"_STAT_TABLES\":[" << endl; if (!program_->get_sandeshs().empty()) { - f_out_ << "

Messages

" << endl; // Generate sandeshs vector sandeshs = program_->get_sandeshs(); vector::iterator snh_iter; for (snh_iter = sandeshs.begin(); snh_iter != sandeshs.end(); ++snh_iter) { - sandesh_name_ = get_sandesh_name(*snh_iter); - f_out_ << "
"; - generate_sandesh(*snh_iter); - f_out_ << "
"; generate_stat_tables_schema(*snh_iter); } } + f_stats_tables_ << "]" << endl << "}" << endl; +} + +bool t_doc_generator::generate_sandesh_program(ofstream &f_out, + doc_ftype::type dtype) { + string fsuffix = get_doc_file_suffix(dtype); + string fname = get_out_dir() + program_->get_name() + fsuffix + ".html"; + f_out.open(fname.c_str()); + + generate_doc_type(f_out); + + string mdesc(get_doc_file_description(dtype)); + f_out << "Documentation for " << mdesc << " messages in " << + "module: " << program_->get_name() << "" << endl << + "

Documentation for " << mdesc << " messages in module: " + << program_->get_name() << "

" << endl; + + print_doc(program_, f_out); + + generate_program_toc(f_out, fsuffix, dtype); + + bool init = false; + if (!program_->get_sandeshs().empty()) { + f_out << "

Messages

" << endl; + vector sandeshs = program_->get_sandeshs(); + vector::iterator snh_iter; + for (snh_iter = sandeshs.begin(); snh_iter != sandeshs.end(); ++snh_iter) { + if (!is_sandesh_type(*snh_iter, dtype)) { + continue; + } + init = true; + sandesh_name_ = get_sandesh_name(*snh_iter); + f_out << "
"; + generate_sandesh(*snh_iter, f_out); + f_out << "
"; + } + } + f_out << "" << endl; + f_out.close(); + + string fname_list = get_out_dir() + program_->get_name() + fsuffix + ".list.html"; + ofstream f_out_list; + f_out_list.open(fname_list.c_str()); + generate_program_list(program_, f_out_list, fsuffix, dtype); + f_out_list.close(); + return init; +} + +void t_doc_generator::generate_const_enum_typedef_object_program() { + string fsuffix = ""; + string fname = get_out_dir() + program_->get_name() + fsuffix + ".html"; + f_out_.open(fname.c_str()); + + generate_doc_type(f_out_); + f_out_ << "Documentation for constants, enums, types, and data structures in " << + "module: " << program_->get_name() << "" << endl << + "

Documentation for constants, enums, types, and data structures in module: " + << program_->get_name() << "

" << endl; + + print_doc(program_, f_out_); if (!program_->get_consts().empty()) { f_out_ << "

Constants

" << endl; vector consts = program_->get_consts(); f_out_ << ""; f_out_ << "" << endl; - generate_consts(consts); + generate_consts(consts, f_out_); f_out_ << "
ConstantTypeValue
"; } @@ -236,7 +492,7 @@ void t_doc_generator::generate_program() { vector enums = program_->get_enums(); vector::iterator en_iter; for (en_iter = enums.begin(); en_iter != enums.end(); ++en_iter) { - generate_enum(*en_iter); + generate_enum(*en_iter, f_out_); } } @@ -246,7 +502,7 @@ void t_doc_generator::generate_program() { vector typedefs = program_->get_typedefs(); vector::iterator td_iter; for (td_iter = typedefs.begin(); td_iter != typedefs.end(); ++td_iter) { - generate_typedef(*td_iter); + generate_typedef(*td_iter, f_out_); } } @@ -256,11 +512,10 @@ void t_doc_generator::generate_program() { vector objects = program_->get_objects(); vector::iterator o_iter; for (o_iter = objects.begin(); o_iter != objects.end(); ++o_iter) { - generate_struct(*o_iter); + generate_struct(*o_iter, f_out_); } } - f_stats_tables_ << "]" << endl << "}" << endl; f_out_ << "" << endl; f_out_.close(); } @@ -269,26 +524,99 @@ void t_doc_generator::generate_program() { * Emits the index.html file for the recursive set of Thrift programs */ void t_doc_generator::generate_index() { - string index_fname = get_out_dir() + "index.html"; - f_out_.open(index_fname.c_str()); - f_out_ << "" << endl; - f_out_ << "" + string index_fname = get_out_dir() + program_->get_name() + "_index.html"; + f_index_out_.open(index_fname.c_str()); + f_index_out_ << "" << endl; + f_index_out_ << "Documentation for " << program_->get_name() << "" << endl; + f_index_out_ << "" << endl; - f_out_ << "" << endl; - vector programs; - generate_program_toc_rows(program_, programs); - f_out_ << "
ModuleMessages
" << endl; - f_out_ << "" << endl; - f_out_.close(); + f_index_out_ << "" << endl; + if (f_log_initialized_) { + f_index_out_ << "" << endl; + } + if (f_log_emerg_initialized_) { + f_index_out_ << "" << endl; + } + if (f_log_alert_initialized_) { + f_index_out_ << "" << endl; + } + if (f_log_crit_initialized_) { + f_index_out_ << "" << endl; + } + if (f_log_error_initialized_) { + f_index_out_ << "" << endl; + } + if (f_log_warn_initialized_) { + f_index_out_ << "" << endl; + } + if (f_log_notice_initialized_) { + f_index_out_ << "" << endl; + } + if (f_log_info_initialized_) { + f_index_out_ << "" << endl; + } + if (f_log_debug_initialized_) { + f_index_out_ << "" << endl; + } + if (f_log_invalid_initialized_) { + f_index_out_ << "" << endl; + } + if (f_uve_initialized_) { + f_index_out_ << "" << endl; + } + if (f_trace_initialized_) { + f_index_out_ << "" << endl; + } + if (f_introspect_initialized_) { + f_index_out_ << "" << endl; + } + f_index_out_ << "
Message Types
All Logs
Emergency Logs
Alert Logs
Critical Logs
Error Logs
Warning Logs
Notice Logs
Informational Logs
Debugging Logs
Unknown severity logs
UVEs
Traces
Request-Response
" << endl; + f_index_out_ << "" << endl; + f_index_out_.close(); +} + +/** + * Prepares for file generation by opening up the necessary file output + * stream. + */ +void t_doc_generator::generate_program() { + // Make output directory + MKDIR(get_out_dir().c_str()); + generate_stats_schema_program(); + f_log_initialized_ = generate_sandesh_program(f_messages_out_, doc_ftype::LOGS); + f_log_invalid_initialized_ = generate_sandesh_program(f_messages_out_, doc_ftype::LOGS_LEVEL_INVALID); + f_log_debug_initialized_ = generate_sandesh_program(f_messages_out_, doc_ftype::LOGS_LEVEL_DEBUG); + f_log_info_initialized_ = generate_sandesh_program(f_messages_out_, doc_ftype::LOGS_LEVEL_INFO); + f_log_notice_initialized_ = generate_sandesh_program(f_messages_out_, doc_ftype::LOGS_LEVEL_NOTICE); + f_log_warn_initialized_ = generate_sandesh_program(f_messages_out_, doc_ftype::LOGS_LEVEL_WARN); + f_log_error_initialized_ = generate_sandesh_program(f_messages_out_, doc_ftype::LOGS_LEVEL_ERR); + f_log_crit_initialized_ = generate_sandesh_program(f_messages_out_, doc_ftype::LOGS_LEVEL_CRIT); + f_log_alert_initialized_ = generate_sandesh_program(f_messages_out_, doc_ftype::LOGS_LEVEL_ALERT); + f_log_emerg_initialized_ = generate_sandesh_program(f_messages_out_, doc_ftype::LOGS_LEVEL_EMERG); + f_uve_initialized_ = generate_sandesh_program(f_messages_out_, doc_ftype::UVES); + f_trace_initialized_ = generate_sandesh_program(f_messages_out_, doc_ftype::TRACES); + f_introspect_initialized_ = generate_sandesh_program(f_messages_out_, doc_ftype::INTROSPECT); + generate_index(); + generate_const_enum_typedef_object_program(); } -void t_doc_generator::print_doc_string(string doc) { +void t_doc_generator::print_doc_string(string doc, ofstream &f_out) { size_t index; while ((index = doc.find_first_of("\r\n")) != string::npos) { if (index == 0) { - f_out_ << "

" << endl; + f_out << "

" << endl; } else { - f_out_ << doc.substr(0, index) << endl; + f_out << doc.substr(0, index) << endl; } if (index + 1 < doc.size() && doc.at(index) != doc.at(index + 1) && (doc.at(index + 1) == '\r' || doc.at(index + 1) == '\n')) { @@ -296,21 +624,21 @@ void t_doc_generator::print_doc_string(string doc) { } doc = doc.substr(index + 1); } - f_out_ << doc << "
"; + f_out << doc << "
"; } /** * If the provided documentable object has documentation attached, this * will emit it to the output stream in HTML format. */ -void t_doc_generator::print_doc(t_doc* tdoc) { +void t_doc_generator::print_doc(t_doc* tdoc, ofstream &f_out) { if (tdoc->has_doc()) { string doc = tdoc->get_doc(); - print_doc_string(doc); + print_doc_string(doc, f_out); } } -void t_doc_generator::print_sandesh_message(t_sandesh* tsandesh) { +void t_doc_generator::print_sandesh_message(t_sandesh* tsandesh, ofstream &f_out) { bool first = true; // Print the message vector members = tsandesh->get_members(); @@ -319,33 +647,103 @@ void t_doc_generator::print_sandesh_message(t_sandesh* tsandesh) { continue; } if (first) { - f_out_ << "Message"; + f_out << "Message"; } t_type *type = tfield->get_type(); if (type->is_static_const_string()) { t_const_value* default_val = tfield->get_value(); if (!first) { - f_out_ << " "; + f_out << " "; } - f_out_ << get_escaped_string(default_val); + f_out << get_escaped_string(default_val); } else { - f_out_ << ""; + f_out << ""; if (!first) { - f_out_ << " "; + f_out << " "; } - f_out_ << tfield->get_name() << ""; + f_out << tfield->get_name() << ""; } first = false; } if (!first) { - f_out_ << "" << endl; + f_out << "" << endl; + } +} + +void t_doc_generator::print_sandesh_message_table(t_sandesh* tsandesh, ofstream &f_out) { + f_out << ""; + print_sandesh_message(tsandesh, f_out); + f_out << "

" << endl; +} + +t_doc_generator::sandesh_level::type t_doc_generator::string_to_sandesh_level( + const string &ilevel) { + string level(ilevel); + // Trim and convert to lower case + boost::algorithm::trim(level); + if (level.empty()) { + return t_doc_generator::sandesh_level::INVALID; + } + boost::algorithm::to_lower(level); + if (level == "debug") { + return t_doc_generator::sandesh_level::DBG; + } + if (level == "info") { + return t_doc_generator::sandesh_level::INFO; } + if (level == "notice") { + return t_doc_generator::sandesh_level::NOTICE; + } + if (level == "warn") { + return t_doc_generator::sandesh_level::WARN; + } + if (level == "error") { + return t_doc_generator::sandesh_level::ERR; + } + if (level == "critical") { + return t_doc_generator::sandesh_level::CRIT; + } + if (level == "alert") { + return t_doc_generator::sandesh_level::ALERT; + } + if (level == "emerg") { + return t_doc_generator::sandesh_level::EMERG; + } + return t_doc_generator::sandesh_level::INVALID; } -void t_doc_generator::print_sandesh_message_table(t_sandesh* tsandesh) { - f_out_ << ""; - print_sandesh_message(tsandesh); - f_out_ << "

" << endl; +typedef boost::tokenizer > tokenizer; +t_doc_generator::sandesh_level::type t_doc_generator::get_sandesh_level( + t_sandesh* tsandesh) { + if (tsandesh->has_doc()) { + string doc = tsandesh->get_doc(); + size_t index; + if ((index = doc.find_first_of("@")) != string::npos) { + // Skip leading documentation + string fdoc(doc.substr(index + 1)); + // Extract tokens beginning with @ + boost::char_separator fsep("@"); + tokenizer ftokens(fdoc, fsep); + BOOST_FOREACH(const string &f, ftokens) { + // Has 2 parts, the first ending with ':' or ' ' or '\t' is + // the type and the next is the content + size_t lindex; + if ((lindex = f.find_first_of(": \t")) != string::npos) { + string type(f.substr(0, lindex)); + if (lindex + 1 < f.size() && f.at(lindex) != f.at(lindex + 1) && + (f.at(lindex + 1) == ':' || f.at(lindex + 1) == '\t' || + f.at(lindex + 1) == ' ')) { + lindex++; + } + string content(f.substr(lindex + 1)); + if (type == "severity") { + return string_to_sandesh_level(content); + } + } + } + } + } + return sandesh_level::INVALID; } /** @@ -353,19 +751,18 @@ void t_doc_generator::print_sandesh_message_table(t_sandesh* tsandesh) { * will emit it to the output stream in HTML format and print the @variables * in a table format. */ -typedef boost::tokenizer > tokenizer; -void t_doc_generator::print_sandesh(t_sandesh* tsandesh) { +void t_doc_generator::print_sandesh(t_sandesh* tsandesh, ofstream &f_out) { if (tsandesh->has_doc()) { bool table = false; string doc = tsandesh->get_doc(); size_t index; if ((index = doc.find_first_of("@")) != string::npos) { // Print leading documentation - f_out_ << doc.substr(0, index) << "

" << endl; + f_out << doc.substr(0, index) << "

" << endl; string fdoc(doc.substr(index + 1)); if (!table) { - f_out_ << "" << endl; - print_sandesh_message(tsandesh); + f_out << "
" << endl; + print_sandesh_message(tsandesh, f_out); table = true; } // Extract tokens beginning with @ @@ -378,129 +775,129 @@ void t_doc_generator::print_sandesh(t_sandesh* tsandesh) { if ((lindex = f.find_first_of(": \t")) != string::npos) { string type(f.substr(0, lindex)); type.at(0) = toupper(type.at(0)); - f_out_ << ""; + f_out << ""; if (lindex + 1 < f.size() && f.at(lindex) != f.at(lindex + 1) && (f.at(lindex + 1) == ':' || f.at(lindex + 1) == '\t' || f.at(lindex + 1) == ' ')) { lindex++; } string content(f.substr(lindex + 1)); - f_out_ << "" << endl; + f_out << "" << endl; } else { - f_out_ << "" << endl; + f_out << "" << endl; } } } else { - f_out_ << doc << "

" << endl; - print_sandesh_message_table(tsandesh); + f_out << doc << "

" << endl; + print_sandesh_message_table(tsandesh, f_out); } if (table) { - f_out_ << "

" << type << "
" << type << "" << content << "
" << content << "
" << f << "" << f << "

" << endl; + f_out << "
" << endl; } } else { - print_sandesh_message_table(tsandesh); + print_sandesh_message_table(tsandesh, f_out); } } /** * Prints out the provided type in HTML */ -int t_doc_generator::print_type(t_type* ttype) { +int t_doc_generator::print_type(t_type* ttype, ofstream &f_out) { int len = 0; - f_out_ << ""; + f_out << ""; if (ttype->is_container()) { if (ttype->is_list()) { - f_out_ << "list<"; - len = 6 + print_type(((t_list*)ttype)->get_elem_type()); - f_out_ << ">"; + f_out << "list<"; + len = 6 + print_type(((t_list*)ttype)->get_elem_type(), f_out); + f_out << ">"; } else if (ttype->is_set()) { - f_out_ << "set<"; - len = 5 + print_type(((t_set*)ttype)->get_elem_type()); - f_out_ << ">"; + f_out << "set<"; + len = 5 + print_type(((t_set*)ttype)->get_elem_type(), f_out); + f_out << ">"; } else if (ttype->is_map()) { - f_out_ << "map<"; - len = 5 + print_type(((t_map*)ttype)->get_key_type()); - f_out_ << ", "; - len += print_type(((t_map*)ttype)->get_val_type()); - f_out_ << ">"; + f_out << "map<"; + len = 5 + print_type(((t_map*)ttype)->get_key_type(), f_out); + f_out << ", "; + len += print_type(((t_map*)ttype)->get_val_type(), f_out); + f_out << ">"; } } else if (ttype->is_base_type()) { - f_out_ << (((t_base_type*)ttype)->is_binary() ? "binary" : ttype->get_name()); + f_out << (((t_base_type*)ttype)->is_binary() ? "binary" : ttype->get_name()); len = ttype->get_name().size(); } else { string prog_name = ttype->get_program()->get_name(); string type_name = ttype->get_name(); - f_out_ << "is_typedef()) { - f_out_ << "Typedef_"; + f_out << "Typedef_"; } else if (ttype->is_struct() || ttype->is_xception()) { - f_out_ << "Struct_"; + f_out << "Struct_"; } else if (ttype->is_enum()) { - f_out_ << "Enum_"; + f_out << "Enum_"; } else if (ttype->is_service()) { - f_out_ << "Svc_"; + f_out << "Svc_"; } - f_out_ << type_name << "\">"; + f_out << type_name << "\">"; len = type_name.size(); if (ttype->get_program() != program_) { - f_out_ << prog_name << "."; + f_out << prog_name << "."; len += prog_name.size() + 1; } - f_out_ << type_name << ""; + f_out << type_name << ""; } - f_out_ << ""; + f_out << ""; return len; } /** * Prints out an HTML representation of the provided constant value */ -void t_doc_generator::print_const_value(t_const_value* tvalue) { +void t_doc_generator::print_const_value(t_const_value* tvalue, ofstream &f_out) { bool first = true; switch (tvalue->get_type()) { case t_const_value::CV_INTEGER: - f_out_ << tvalue->get_integer(); + f_out << tvalue->get_integer(); break; case t_const_value::CV_DOUBLE: - f_out_ << tvalue->get_double(); + f_out << tvalue->get_double(); break; case t_const_value::CV_STRING: - f_out_ << '"' << get_escaped_string(tvalue) << '"'; + f_out << '"' << get_escaped_string(tvalue) << '"'; break; case t_const_value::CV_MAP: { - f_out_ << "{ "; + f_out << "{ "; map map_elems = tvalue->get_map(); map::iterator map_iter; for (map_iter = map_elems.begin(); map_iter != map_elems.end(); map_iter++) { if (!first) { - f_out_ << ", "; + f_out << ", "; } first = false; - print_const_value(map_iter->first); - f_out_ << " = "; - print_const_value(map_iter->second); + print_const_value(map_iter->first, f_out); + f_out << " = "; + print_const_value(map_iter->second, f_out); } - f_out_ << " }"; + f_out << " }"; } break; case t_const_value::CV_LIST: { - f_out_ << "{ "; + f_out << "{ "; vector list_elems = tvalue->get_list();; vector::iterator list_iter; for (list_iter = list_elems.begin(); list_iter != list_elems.end(); list_iter++) { if (!first) { - f_out_ << ", "; + f_out << ", "; } first = false; - print_const_value(*list_iter); + print_const_value(*list_iter, f_out); } - f_out_ << " }"; + f_out << " }"; } break; default: - f_out_ << "UNKNOWN"; + f_out << "UNKNOWN"; break; } } @@ -510,16 +907,16 @@ void t_doc_generator::print_const_value(t_const_value* tvalue) { * * @param ttypedef The type definition */ -void t_doc_generator::generate_typedef(t_typedef* ttypedef) { +void t_doc_generator::generate_typedef(t_typedef* ttypedef, ofstream &f_out) { string name = ttypedef->get_name(); - f_out_ << "

"; - f_out_ << "

Typedef: " << name + f_out << "
"; + f_out << "

Typedef: " << name << "

" << endl; - f_out_ << "

Base type: "; - print_type(ttypedef->get_type()); - f_out_ << "

" << endl; - print_doc(ttypedef); - f_out_ << "
" << endl; + f_out << "

Base type: "; + print_type(ttypedef->get_type(), f_out); + f_out << "

" << endl; + print_doc(ttypedef, f_out); + f_out << "

" << endl; } /** @@ -527,46 +924,53 @@ void t_doc_generator::generate_typedef(t_typedef* ttypedef) { * * @param tenum The enumeration */ -void t_doc_generator::generate_enum(t_enum* tenum) { +void t_doc_generator::generate_enum(t_enum* tenum, ofstream &f_out) { string name = tenum->get_name(); - f_out_ << "
"; - f_out_ << "

Enumeration: " << name + f_out << "
"; + f_out << "

Enumeration: " << name << "

" << endl; - print_doc(tenum); + print_doc(tenum, f_out); vector values = tenum->get_constants(); vector::iterator val_iter; - f_out_ << "
" << endl; + f_out << "
" << endl; for (val_iter = values.begin(); val_iter != values.end(); ++val_iter) { - f_out_ << "" << endl; + f_out << "" << endl; } - f_out_ << "
"; - f_out_ << (*val_iter)->get_name(); - f_out_ << ""; - f_out_ << (*val_iter)->get_value(); - f_out_ << "
"; + f_out << (*val_iter)->get_name(); + f_out << ""; + f_out << (*val_iter)->get_value(); + f_out << "
" << endl; + f_out << "

" << endl; } /** * Generates a constant value */ -void t_doc_generator::generate_const(t_const* tconst) { +void t_doc_generator::generate_const(t_const* tconst, ofstream &f_out) { string name = tconst->get_name(); - f_out_ << "" << name + f_out << "" << name << ""; - print_type(tconst->get_type()); - f_out_ << ""; - print_const_value(tconst->get_value()); - f_out_ << ""; + print_type(tconst->get_type(), f_out); + f_out << ""; + print_const_value(tconst->get_value(), f_out); + f_out << ""; if (tconst->has_doc()) { - f_out_ << "
"; - print_doc(tconst); - f_out_ << "
"; + f_out << "
"; + print_doc(tconst, f_out); + f_out << "
"; + } +} + +void t_doc_generator::generate_consts(vector consts, ofstream &f_out) { + vector::iterator c_iter; + for (c_iter = consts.begin(); c_iter != consts.end(); ++c_iter) { + generate_const(*c_iter, f_out); } } void t_doc_generator::generate_stat_table_schema_header(string type, string attr, string table_name, string display_name) { - if (stat_table_created == false) { - stat_table_created = true; + if (stat_table_created_ == false) { + stat_table_created_ = true; f_stats_tables_ << "{\n\"stat_type\":\"" << type << "\"," << endl; } else { f_stats_tables_ << ",\n{\n\"stat_type\":\"" << type << "\"," << endl; @@ -575,7 +979,7 @@ void t_doc_generator::generate_stat_table_schema_header(string type, string attr f_stats_tables_ << "\"display_name\":\"" << display_name << "\"," << endl; f_stats_tables_ << "\"obj_table\": \"" << table_name << "\",\n"; f_stats_tables_ << "\"attributes\":[" << endl; - first_member = true; + first_member_ = true; } template @@ -785,10 +1189,10 @@ void t_doc_generator::generate_stat_schema_struct_base_member(string prefix, t_f fname = prefix+ "." + fname; } string datatype = get_datatype_from_tfield(tfield->get_type()); - if(!first_member) { + if (!first_member_) { f_stats_tables_ << ",\n\t{\"name\":\"" << fname << "\",\"datatype\":\"" << datatype << "\",\"index\":" << index << "}"; } else { - first_member = false; + first_member_ = false; f_stats_tables_ << "\t{\"name\":\"" << fname << "\",\"datatype\":\"" << datatype << "\",\"index\":" << index << "}"; } } @@ -879,8 +1283,8 @@ void t_doc_generator::generate_stat_schema_list(string name, t_type* ttype, t_fi bool is_suffixed_field = false; is_indexed_or_suffixed_field(tname, member_tags, suffixes, index, is_suffixed_field); if (!is_suffixed_field) { - if (first_member) { - first_member = false; + if (first_member_) { + first_member_ = false; f_stats_tables_ << "\t{\"name\":\"" << tname << "\",\"datatype\":\"" << datatype << "\",\"index\":" << index << "}"; } else { f_stats_tables_ << ",\n\t{\"name\":\"" << tname << "\",\"datatype\":\"" << datatype << "\",\"index\":" << index << "}"; @@ -1043,42 +1447,42 @@ void t_doc_generator::generate_stat_tables_schema(t_sandesh* tsandesh) { * * @param tstruct The struct definition */ -void t_doc_generator::generate_struct(t_struct* tstruct) { +void t_doc_generator::generate_struct(t_struct* tstruct, ofstream &f_out) { string name = tstruct->get_name(); - f_out_ << "
"; - f_out_ << "

"; - f_out_ << "Struct: "; - f_out_ << name << "

" << endl; + f_out << "
"; + f_out << "

"; + f_out << "Struct: "; + f_out << name << "

" << endl; vector members = tstruct->get_members(); vector::iterator mem_iter = members.begin(); - f_out_ << ""; - f_out_ << "" + f_out << "
KeyFieldTypeDescriptionRequirednessDefault value
"; + f_out << "" << endl; for ( ; mem_iter != members.end(); mem_iter++) { - f_out_ << "" << endl; + f_out << "" << endl; } - f_out_ << "
KeyFieldTypeDescriptionRequirednessDefault value
" << (*mem_iter)->get_key() << ""; - f_out_ << (*mem_iter)->get_name(); - f_out_ << ""; - print_type((*mem_iter)->get_type()); - f_out_ << ""; - f_out_ << (*mem_iter)->get_doc(); - f_out_ << ""; + f_out << "
" << (*mem_iter)->get_key() << ""; + f_out << (*mem_iter)->get_name(); + f_out << ""; + print_type((*mem_iter)->get_type(), f_out); + f_out << ""; + f_out << (*mem_iter)->get_doc(); + f_out << ""; if ((*mem_iter)->get_req() == t_field::T_OPTIONAL) { - f_out_ << "optional"; + f_out << "optional"; } else if ((*mem_iter)->get_req() == t_field::T_REQUIRED) { - f_out_ << "required"; + f_out << "required"; } else { - f_out_ << "default"; + f_out << "default"; } - f_out_ << ""; + f_out << ""; t_const_value* default_val = (*mem_iter)->get_value(); if (default_val != NULL) { - print_const_value(default_val); + print_const_value(default_val, f_out); } - f_out_ << "

"; - print_doc(tstruct); - f_out_ << "
"; + f_out << "
"; + print_doc(tstruct, f_out); + f_out << "
"; } /** @@ -1086,13 +1490,13 @@ void t_doc_generator::generate_struct(t_struct* tstruct) { * * @param tsandesh The sandesh definition */ -void t_doc_generator::generate_sandesh(t_sandesh* tsandesh) { - f_out_ << "

" +void t_doc_generator::generate_sandesh(t_sandesh* tsandesh, ofstream &f_out) { + f_out << "

" << sandesh_name_ << "

" << endl; - print_sandesh(tsandesh); + print_sandesh(tsandesh, f_out); vector members = tsandesh->get_members(); - f_out_ << ""; - f_out_ << "" + f_out << "
FieldTypeDescription
"; + f_out << "" << endl; BOOST_FOREACH(t_field *tfield, members) { if (tfield->get_auto_generated()) { @@ -1102,13 +1506,13 @@ void t_doc_generator::generate_sandesh(t_sandesh* tsandesh) { if (type->is_static_const_string()) { continue; } - f_out_ << "" << endl; + f_out << "" << endl; } - f_out_ << "
FieldTypeDescription
" << tfield->get_name() << ""; - print_type(tfield->get_type()); - f_out_ << ""; - f_out_ << tfield->get_doc(); - f_out_ << "
" << tfield->get_name() << ""; + print_type(tfield->get_type(), f_out); + f_out << ""; + f_out << tfield->get_doc(); + f_out << "

"; + f_out << "
"; } THRIFT_REGISTER_GENERATOR(doc, "Documentation", "")