Drizzled Public API Documentation

plugin.h

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; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 
00021 
00022 #pragma once
00023 
00024 #include <string>
00025 #include <vector>
00026 #include <map>
00027 
00028 #include <drizzled/visibility.h>
00029 
00030 namespace drizzled
00031 {
00032 
00033 class Session;
00034 
00035 namespace module
00036 {
00037 class Module;
00038 }
00039 
00040 namespace plugin
00041 {
00042 
00043 class DRIZZLED_API Plugin
00044 {
00045 private:
00046   const std::string _name;
00047   bool _is_active;
00048   module::Module *_module;
00049   const std::string _type_name;
00050 
00051   Plugin();
00052   Plugin(const Plugin&);
00053   Plugin& operator=(const Plugin &);
00054 public:
00055   typedef std::pair<const std::string, const std::string> map_key;
00056   typedef std::map<const map_key, plugin::Plugin *> map;
00057   typedef std::vector<Plugin *> vector;
00058 
00059   explicit Plugin(const std::string &name, const std::string &type_name);
00060   virtual ~Plugin() {}
00061 
00062   /*
00063    * This method is called for all plug-ins on shutdown,
00064    * _before_ the plug-ins are deleted. It can be used
00065    * when shutdown code references other plug-ins.
00066    */
00067   virtual void shutdownPlugin()
00068   {
00069   }
00070 
00071   // This is run after all plugins have been initialized.
00072   virtual void prime()
00073   {
00074   }
00075 
00076   virtual void startup(drizzled::Session &)
00077   {
00078   }
00079  
00080   void activate()
00081   {
00082     _is_active= true;
00083   }
00084  
00085   void deactivate()
00086   {
00087     _is_active= false;
00088   }
00089  
00090   bool isActive() const
00091   {
00092     return _is_active;
00093   }
00094 
00095   const std::string &getName() const
00096   {
00097     return _name;
00098   } 
00099 
00100   void setModule(module::Module *module)
00101   {
00102     _module= module;
00103   }
00104 
00105   const std::string& getTypeName() const
00106   {
00107     return _type_name;
00108   }
00109 
00110   virtual bool removeLast() const
00111   {
00112     return false;
00113   }
00114 
00115   const std::string& getModuleName() const;
00116 };
00117 } /* end namespace plugin */
00118 } /* end namespace drizzled */
00119