Drizzled Public API Documentation

dictionary.cc
00001 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2011 Andrew Hutchings
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 #include <config.h>
00022 #include <plugin/protocol_dictionary/dictionary.h>
00023 #include <drizzled/plugin/listen.h>
00024 
00025 using namespace drizzled;
00026 
00027 ProtocolTool::ProtocolTool() :
00028   plugin::TableFunction("DATA_DICTIONARY", "PROTOCOL_COUNTERS")
00029 {
00030   add_field("PROTOCOL");
00031   add_field("COUNTER");
00032   add_field("VALUE", plugin::TableFunction::NUMBER, 0, false);
00033 }
00034 
00035 ProtocolTool::Generator::Generator(Field **arg) :
00036   plugin::TableFunction::Generator(arg)
00037 {
00038   protocol_it= plugin::Listen::getListenProtocols().begin();
00039   protocol= *protocol_it;
00040   counter_it= protocol->getListenCounters().begin();
00041 }
00042 
00043 bool ProtocolTool::Generator::populate()
00044 {
00045   if (protocol_it == plugin::Listen::getListenProtocols().end())
00046     return false;
00047 
00048   protocol= *protocol_it;
00049 
00050   while (counter_it == protocol->getListenCounters().end())
00051   {
00052     protocol_it++;
00053     if (protocol_it == plugin::Listen::getListenProtocols().end())
00054       return false;
00055     protocol= *protocol_it;
00056     counter_it= protocol->getListenCounters().begin();
00057   }
00058 
00059   fill();
00060   counter_it++;
00061   return true;
00062 }
00063 
00064 void ProtocolTool::Generator::fill()
00065 {
00066   protocol= *protocol_it;
00067   counter= *counter_it;
00068 
00069   push(protocol->getName());
00070   push(*counter->first);
00071   push((uint64_t) *counter->second);
00072 }
00073 
00074 static ProtocolTool *protocols;
00075 
00076 static int init(drizzled::module::Context &context)
00077 {
00078   protocols= new(std::nothrow)ProtocolTool;
00079 
00080   context.add(protocols);
00081 
00082   return 0;
00083 }
00084 
00085 DRIZZLE_DECLARE_PLUGIN
00086 {
00087   DRIZZLE_VERSION_ID,
00088   "protocol_dictionary",
00089   "1.0",
00090   "Andrew Hutchings",
00091   "Provides dictionary for protocol counters.",
00092   PLUGIN_LICENSE_GPL,
00093   init,     /* Plugin Init */
00094   NULL,               /* depends */
00095   NULL                /* config options   */
00096 }
00097 DRIZZLE_DECLARE_PLUGIN_END;
00098