Drizzled Public API Documentation

modules.cc
00001 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2009 Sun Microsystems, Inc.
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 
00023 #include <plugin/registry_dictionary/dictionary.h>
00024 #include <drizzled/module/library.h>
00025 
00026 using namespace std;
00027 using namespace drizzled;
00028 
00029 /* 
00030  * Suffix _STRING was added because sys/param.h on OSX defines a BSD symbol
00031  * to the version of BSD being run. FAIL
00032  */
00033 static const string GPL_STRING("GPL");
00034 static const string LGPL_STRING("LGPL");
00035 static const string BSD_STRING("BSD");
00036 static const string PROPRIETARY_STRING("PROPRIETARY");
00037 
00038 ModulesTool::ModulesTool() :
00039   plugin::TableFunction("DATA_DICTIONARY", "MODULES")
00040 {
00041   add_field("MODULE_NAME");
00042   add_field("MODULE_VERSION", 20);
00043   add_field("MODULE_AUTHOR");
00044   add_field("IS_BUILTIN", plugin::TableFunction::BOOLEAN, 0, false);
00045   add_field("MODULE_LIBRARY", 254);
00046   add_field("MODULE_DESCRIPTION", 254);
00047   add_field("MODULE_LICENSE", 80);
00048 }
00049 
00050 ModulesTool::Generator::Generator(Field **arg) :
00051   plugin::TableFunction::Generator(arg)
00052 {
00053   module::Registry &registry= module::Registry::singleton();
00054   modules= registry.getList();
00055   it= modules.begin();
00056 }
00057 
00058 bool ModulesTool::Generator::populate()
00059 {
00060   if (it == modules.end())
00061     return false;
00062 
00063   {
00064     module::Module *module= *it;
00065     const module::Manifest &manifest= module->getManifest();
00066 
00067     /* MODULE_NAME */
00068     push(module->getName());
00069 
00070     /* MODULE_VERSION */
00071     push(manifest.version ? manifest.version : 0);
00072 
00073     /* MODULE_AUTHOR */
00074     manifest.author ? push(manifest.author) : push();
00075 
00076     /* IS_BUILTIN */
00077     push((module->plugin_dl == NULL));
00078 
00079     /* MODULE_LIBRARY */
00080     push((module->plugin_dl == NULL) ? "builtin" : module->plugin_dl->getName());
00081 
00082     /* MODULE_DESCRIPTION */
00083     manifest.descr ? push(manifest.descr) : push();
00084 
00085     /* MODULE_LICENSE */
00086     switch (manifest.license) {
00087     case PLUGIN_LICENSE_GPL:
00088       push(GPL_STRING);
00089       break;
00090     case PLUGIN_LICENSE_BSD:
00091       push(BSD_STRING);
00092       break;
00093     case PLUGIN_LICENSE_LGPL:
00094       push(LGPL_STRING);
00095       break;
00096     default:
00097       push(PROPRIETARY_STRING);
00098       break;
00099     }
00100   }
00101 
00102   it++;
00103 
00104   return true;
00105 }