Drizzled Public API Documentation

engine_state_history.cc

00001 /*
00002   Copyright (C) 2011 Stewart Smith
00003 
00004   This program is free software; you can redistribute it and/or
00005   modify it under the terms of the GNU General Public License
00006   as published by the Free Software Foundation; either version 2
00007   of the License, or (at your option) any later version.
00008 
00009   This program is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012   GNU General Public License for more details.
00013 
00014   You should have received a copy of the GNU General Public License
00015   along with this program; if not, write to the Free Software
00016   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
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 #include <drizzled/algorithm/crc32.h>
00024 
00025 #include "engine_state_history.h"
00026 
00027 #include <string>
00028 #include <vector>
00029 
00030 using namespace std;
00031 using namespace drizzled;
00032 
00033 std::vector<std::string> engine_state_history;
00034 
00035 class EngineStateHistory : public drizzled::plugin::TableFunction
00036 {
00037 public:
00038 
00039   EngineStateHistory();
00040 
00041   EngineStateHistory(const char *table_arg) :
00042     drizzled::plugin::TableFunction("data_dictionary", table_arg)
00043   { }
00044 
00045   ~EngineStateHistory() {}
00046 
00047   class Generator : public drizzled::plugin::TableFunction::Generator
00048   {
00049   private:
00050     std::vector<std::string>::iterator it;
00051   public:
00052     Generator(drizzled::Field **arg);
00053     ~Generator();
00054 
00055     bool populate();
00056   };
00057 
00058   EngineStateHistory::Generator *generator(drizzled::Field **arg)
00059   {
00060     return new Generator(arg);
00061   }
00062 };
00063 
00064 EngineStateHistory::EngineStateHistory() :
00065   plugin::TableFunction("DATA_DICTIONARY", "SEAPITESTER_ENGINE_STATE_HISTORY")
00066 {
00067   add_field("STATE");
00068 }
00069 
00070 EngineStateHistory::Generator::Generator(Field **arg) :
00071   plugin::TableFunction::Generator(arg)
00072 {
00073   it= engine_state_history.begin();
00074 }
00075 
00076 EngineStateHistory::Generator::~Generator()
00077 {
00078 }
00079 
00080 bool EngineStateHistory::Generator::populate()
00081 {
00082   if (engine_state_history.empty())
00083     return false;
00084 
00085   if (it == engine_state_history.end())
00086     return false; // No more rows
00087 
00088   push(*it);
00089   it++;
00090 
00091 
00092   return true;
00093 }
00094 
00095 class ClearEngineStateHistoryFunction :public Item_int_func
00096 {
00097 public:
00098   int64_t val_int();
00099 
00100   ClearEngineStateHistoryFunction() :Item_int_func()
00101   {
00102     unsigned_flag= true;
00103   }
00104 
00105   const char *func_name() const
00106   {
00107     return "seapitester_clear_engine_state_history";
00108   }
00109 
00110   void fix_length_and_dec()
00111   {
00112     max_length= 10;
00113   }
00114 
00115   bool check_argument_count(int n)
00116   {
00117     return (n == 0);
00118   }
00119 };
00120 
00121 int64_t ClearEngineStateHistoryFunction::val_int()
00122 {
00123   engine_state_history.clear();
00124   null_value= false;
00125   return 0;
00126 }
00127 
00128 
00129 int engine_state_history_table_initialize(drizzled::module::Context &context)
00130 {
00131   context.add(new(std::nothrow)EngineStateHistory());
00132   context.add(new plugin::Create_function<ClearEngineStateHistoryFunction>("SEAPITESTER_CLEAR_ENGINE_STATE_HISTORY"));
00133 
00134   return 0;
00135 }