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 #include <drizzled/common_fwd.h>
00030 
00031 namespace drizzled {
00032 namespace plugin {
00033 
00034 class DRIZZLED_API Plugin : boost::noncopyable
00035 {
00036 private:
00037   const std::string _name;
00038   bool _is_active;
00039   module::Module *_module;
00040   const std::string _type_name;
00041 
00042 public:
00043   typedef std::pair<const std::string, const std::string> map_key;
00044   typedef std::map<const map_key, plugin::Plugin *> map;
00045   typedef std::vector<Plugin *> vector;
00046 
00047   explicit Plugin(const std::string &name, const std::string &type_name);
00048   virtual ~Plugin() {}
00049 
00050   /*
00051    * This method is called for all plug-ins on shutdown,
00052    * _before_ the plug-ins are deleted. It can be used
00053    * when shutdown code references other plug-ins.
00054    */
00055   virtual void shutdownPlugin()
00056   {
00057   }
00058 
00059   // This is run after all plugins have been initialized.
00060   virtual void prime()
00061   {
00062   }
00063 
00064   virtual void startup(drizzled::Session &)
00065   {
00066   }
00067  
00068   void activate()
00069   {
00070     _is_active= true;
00071   }
00072  
00073   void deactivate()
00074   {
00075     _is_active= false;
00076   }
00077  
00078   bool isActive() const
00079   {
00080     return _is_active;
00081   }
00082 
00083   const std::string &getName() const
00084   {
00085     return _name;
00086   } 
00087 
00088   void setModule(module::Module *module)
00089   {
00090     _module= module;
00091   }
00092 
00093   const std::string& getTypeName() const
00094   {
00095     return _type_name;
00096   }
00097 
00098   virtual bool removeLast() const
00099   {
00100     return false;
00101   }
00102 
00103   const std::string& getModuleName() const;
00104 };
00105 } /* end namespace plugin */
00106 } /* end namespace drizzled */
00107