Drizzled Public API Documentation

engine_state_history.cc
1 /*
2  Copyright (C) 2011 Stewart Smith
3 
4  This program is free software; you can redistribute it and/or
5  modify it under the terms of the GNU General Public License
6  as published by the Free Software Foundation; either version 2
7  of the License, or (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18 
19 #include <config.h>
20 #include <drizzled/plugin/table_function.h>
21 #include <drizzled/plugin/function.h>
22 #include <drizzled/item/func.h>
23 
24 #include "engine_state_history.h"
25 
26 #include <string>
27 #include <vector>
28 
29 using namespace std;
30 using namespace drizzled;
31 
32 std::vector<std::string> engine_state_history;
33 
35 {
36 public:
37 
39 
40  EngineStateHistory(const char *table_arg) :
41  drizzled::plugin::TableFunction("data_dictionary", table_arg)
42  { }
43 
44  ~EngineStateHistory() {}
45 
47  {
48  private:
49  std::vector<std::string>::iterator it;
50  public:
52  ~Generator();
53 
54  bool populate();
55  };
56 
58  {
59  return new Generator(arg);
60  }
61 };
62 
63 EngineStateHistory::EngineStateHistory() :
64  plugin::TableFunction("DATA_DICTIONARY", "SEAPITESTER_ENGINE_STATE_HISTORY")
65 {
66  add_field("STATE");
67 }
68 
69 EngineStateHistory::Generator::Generator(Field **arg) :
70  plugin::TableFunction::Generator(arg)
71 {
72  it= engine_state_history.begin();
73 }
74 
75 EngineStateHistory::Generator::~Generator()
76 {
77 }
78 
79 bool EngineStateHistory::Generator::populate()
80 {
81  if (engine_state_history.empty())
82  return false;
83 
84  if (it == engine_state_history.end())
85  return false; // No more rows
86 
87  push(*it);
88  it++;
89 
90 
91  return true;
92 }
93 
95 {
96 public:
97  int64_t val_int();
98 
100  {
101  unsigned_flag= true;
102  }
103 
104  const char *func_name() const
105  {
106  return "seapitester_clear_engine_state_history";
107  }
108 
109  void fix_length_and_dec()
110  {
111  max_length= 10;
112  }
113 
115  {
116  return (n == 0);
117  }
118 };
119 
120 extern uint64_t next_cursor_id;
121 
123 {
124  engine_state_history.clear();
125  null_value= false;
126  next_cursor_id= 0;
127  return 0;
128 }
129 
130 
131 int engine_state_history_table_initialize(drizzled::module::Context &context)
132 {
133  context.add(new EngineStateHistory);
134  context.add(new plugin::Create_function<ClearEngineStateHistoryFunction>("SEAPITESTER_CLEAR_ENGINE_STATE_HISTORY"));
135 
136  return 0;
137 }
TODO: Rename this file - func.h is stupid.
Definition: engine.cc:41