1 /**
2  * Copyright (c) 2007-2012, Timothy Stack
3  *
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  * * Neither the name of Timothy Stack nor the names of its contributors
15  * may be used to endorse or promote products derived from this software
16  * without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  * @file log_data_table.hh
30  */
31 
32 #ifndef lnav_log_data_table_hh
33 #define lnav_log_data_table_hh
34 
35 #include <string>
36 #include <vector>
37 
38 #include "logfile.hh"
39 #include "logfile_sub_source.hh"
40 #include "data_parser.hh"
41 #include "column_namer.hh"
42 #include "log_vtab_impl.hh"
43 
44 class log_data_table : public log_vtab_impl {
45 public:
46 
47     log_data_table(logfile_sub_source &lss,
48                    log_vtab_manager &lvm,
49                    content_line_t template_line,
50                    intern_string_t table_name);
51 
52     void get_columns_int();
53 
get_columns(std::vector<vtab_column> & cols) const54     void get_columns(std::vector<vtab_column> &cols) const override {
55         cols = this->ldt_cols;
56     };
57 
get_foreign_keys(std::vector<std::string> & keys_inout) const58     void get_foreign_keys(std::vector<std::string> &keys_inout) const override
59     {
60         log_vtab_impl::get_foreign_keys(keys_inout);
61         keys_inout.emplace_back("log_msg_instance");
62     };
63 
64     bool next(log_cursor &lc, logfile_sub_source &lss) override;
65 
66     void extract(std::shared_ptr<logfile> lf,
67                  uint64_t line_number,
68                  shared_buffer_ref &line,
69                  std::vector<logline_value> &values) override;
70 
71 private:
72     logfile_sub_source &ldt_log_source;
73     const content_line_t     ldt_template_line;
74     data_parser::schema_id_t ldt_schema_id;
75     shared_buffer_ref ldt_current_line;
76     data_parser::element_list_t ldt_pairs;
77     std::shared_ptr<log_vtab_impl> ldt_format_impl;
78     int64_t ldt_instance;
79     std::vector<vtab_column> ldt_cols;
80     std::vector<logline_value_meta> ldt_value_metas;
81 };
82 
83 #endif
84