Drizzled Public API Documentation

hello_events.h

00001 /*
00002   *  Copyright (C) 2010 PrimeBase Technologies GmbH, Germany
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; version 2 of the License.
00007  *
00008  *  This program is distributed in the hope that it will be useful,
00009  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  *  GNU General Public License for more details.
00012  *
00013  *  You should have received a copy of the GNU General Public License
00014  *  along with this program; if not, write to the Free Software
00015  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00016  *
00017  * Barry Leslie
00018  *
00019  * 2010-05-12
00020  */
00021 
00022 #pragma once
00023 
00024 #include <drizzled/plugin/event_observer.h>
00025 
00026 namespace drizzled
00027 {
00028 
00029 namespace plugin
00030 {
00031 class HelloEvents: public EventObserver
00032 {
00033 public:
00034 
00035   HelloEvents(std::string name_arg): EventObserver(name_arg), is_enabled(false), db_list(""), table_list(""){}
00036   ~HelloEvents();
00037 
00038   void registerTableEventsDo(TableShare &table_share, EventObserverList &observers);
00039   void registerSchemaEventsDo(const std::string &db, EventObserverList &observers);
00040   void registerSessionEventsDo(Session &session, EventObserverList &observers);
00041 
00042   bool observeEventDo(EventData &);
00043 
00044   // Some custom things for my plugin:
00045   void enable() { is_enabled= true;}
00046   void disable() { is_enabled= false;}
00047   bool isEnabled() const
00048   {
00049     return is_enabled;
00050   }
00051 
00052 private:
00053   
00054   bool is_enabled;
00055   //----------------------
00056   std::string db_list;
00057   
00058 public:
00059   void setDatabasesOfInterest(const char *list) 
00060   {
00061     db_list.assign(list);
00062   }
00063   
00064   const char *getDatabasesOfInterest() 
00065   {
00066     return db_list.c_str();
00067   }
00068   
00069 private:
00070   bool isDatabaseInteresting(const std::string &db_name)
00071   {
00072     std::string list(db_list);
00073     list.append(",");
00074     
00075     std::string target(db_name);
00076     target.append(",");
00077     
00078     return (list.find(target) != std::string::npos);
00079   }
00080   
00081   //----------------------
00082   std::string table_list;
00083   
00084 public:
00085   void setTablesOfInterest(const char *list) 
00086   {
00087     table_list.assign(list);
00088   }
00089   
00090   const char *getTablesOfInterest() 
00091   {
00092     return table_list.c_str();
00093   }
00094   
00095 private:
00096   bool isTableInteresting(const std::string &table_name)
00097   {
00098     std::string list(table_list);
00099     list.append(",");
00100     
00101     std::string target(table_name);
00102     target.append(",");
00103     
00104     return (list.find(target) != std::string::npos);
00105   }
00106 
00107 
00108   //----------------------
00109   bool isSessionInteresting(Session &)
00110   {
00111     /* You could filter sessions of interest based on login
00112      * information.
00113      */
00114     return true;
00115   }
00116 
00117   
00118 };
00119 } /* namespace plugin */
00120 } /* namespace drizzled */