00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <config.h>
00020 #include <drizzled/plugin/table_function.h>
00021 #include <drizzled/plugin/function.h>
00022 #include <drizzled/item/func.h>
00023
00024 #include "engine_state_history.h"
00025
00026 #include <string>
00027 #include <vector>
00028
00029 using namespace std;
00030 using namespace drizzled;
00031
00032 std::vector<std::string> engine_state_history;
00033
00034 class EngineStateHistory : public drizzled::plugin::TableFunction
00035 {
00036 public:
00037
00038 EngineStateHistory();
00039
00040 EngineStateHistory(const char *table_arg) :
00041 drizzled::plugin::TableFunction("data_dictionary", table_arg)
00042 { }
00043
00044 ~EngineStateHistory() {}
00045
00046 class Generator : public drizzled::plugin::TableFunction::Generator
00047 {
00048 private:
00049 std::vector<std::string>::iterator it;
00050 public:
00051 Generator(drizzled::Field **arg);
00052 ~Generator();
00053
00054 bool populate();
00055 };
00056
00057 EngineStateHistory::Generator *generator(drizzled::Field **arg)
00058 {
00059 return new Generator(arg);
00060 }
00061 };
00062
00063 EngineStateHistory::EngineStateHistory() :
00064 plugin::TableFunction("DATA_DICTIONARY", "SEAPITESTER_ENGINE_STATE_HISTORY")
00065 {
00066 add_field("STATE");
00067 }
00068
00069 EngineStateHistory::Generator::Generator(Field **arg) :
00070 plugin::TableFunction::Generator(arg)
00071 {
00072 it= engine_state_history.begin();
00073 }
00074
00075 EngineStateHistory::Generator::~Generator()
00076 {
00077 }
00078
00079 bool EngineStateHistory::Generator::populate()
00080 {
00081 if (engine_state_history.empty())
00082 return false;
00083
00084 if (it == engine_state_history.end())
00085 return false;
00086
00087 push(*it);
00088 it++;
00089
00090
00091 return true;
00092 }
00093
00094 class ClearEngineStateHistoryFunction :public Item_int_func
00095 {
00096 public:
00097 int64_t val_int();
00098
00099 ClearEngineStateHistoryFunction() :Item_int_func()
00100 {
00101 unsigned_flag= true;
00102 }
00103
00104 const char *func_name() const
00105 {
00106 return "seapitester_clear_engine_state_history";
00107 }
00108
00109 void fix_length_and_dec()
00110 {
00111 max_length= 10;
00112 }
00113
00114 bool check_argument_count(int n)
00115 {
00116 return (n == 0);
00117 }
00118 };
00119
00120 extern uint64_t next_cursor_id;
00121
00122 int64_t ClearEngineStateHistoryFunction::val_int()
00123 {
00124 engine_state_history.clear();
00125 null_value= false;
00126 next_cursor_id= 0;
00127 return 0;
00128 }
00129
00130
00131 int engine_state_history_table_initialize(drizzled::module::Context &context)
00132 {
00133 context.add(new EngineStateHistory);
00134 context.add(new plugin::Create_function<ClearEngineStateHistoryFunction>("SEAPITESTER_CLEAR_ENGINE_STATE_HISTORY"));
00135
00136 return 0;
00137 }