Drizzled Public API Documentation

module.cc

00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  * Copyright (C) 2010 Brian Aker
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions are
00009  * met:
00010  *
00011  *     * Redistributions of source code must retain the above copyright
00012  * notice, this list of conditions and the following disclaimer.
00013  *
00014  *     * Redistributions in binary form must reproduce the above
00015  * copyright notice, this list of conditions and the following disclaimer
00016  * in the documentation and/or other materials provided with the
00017  * distribution.
00018  *
00019  *     * The names of its contributors may not be used to endorse or
00020  * promote products derived from this software without specific prior
00021  * written permission.
00022  *
00023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00026  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00027  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00028  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00029  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00030  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00031  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00032  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034  *
00035  */
00036 
00037 #include <config.h>
00038 
00039 #include <signal.h>
00040 
00041 #include <drizzled/function/func.h>
00042 #include <drizzled/item/cmpfunc.h>
00043 #include <drizzled/item/function/boolean.h>
00044 #include <drizzled/plugin/function.h>
00045 #include <drizzled/util/backtrace.h>
00046 
00047 using namespace drizzled;
00048 
00049 namespace debug {
00050 
00051 class Assert :public item::function::Boolean
00052 {
00053 public:
00054   Assert() :
00055     item::function::Boolean()
00056   {
00057     unsigned_flag= true;
00058   }
00059 
00060   const char *func_name() const { return "assert_and_crash"; }
00061   const char *fully_qualified_func_name() const { return "assert_and_crash()"; }
00062 
00063   bool val_bool()
00064   {
00065     String _res;
00066     String *res= args[0]->val_str(&_res);
00067 
00068     null_value= false;
00069 
00070     if (not res or not res->length())
00071     {
00072       assert(0);
00073       return true;
00074     }
00075 
00076     return false;
00077   }
00078 
00079   int64_t val_int()
00080   {
00081     return val_bool();
00082   }
00083 
00084   bool check_argument_count(int n)
00085   {
00086     return (n == 1);
00087   }
00088 };
00089 
00090 class Backtrace :public item::function::Boolean
00091 {
00092 public:
00093   Backtrace() :
00094     item::function::Boolean()
00095   {
00096     unsigned_flag= true;
00097   }
00098 
00099   const char *func_name() const { return "backtrace"; }
00100   const char *fully_qualified_func_name() const { return "backtrace()"; }
00101 
00102   bool val_bool()
00103   {
00104     util::custom_backtrace();
00105     return true;
00106   }
00107 
00108   int64_t val_int()
00109   {
00110     return val_bool();
00111   }
00112 };
00113 
00114 class Crash :public item::function::Boolean
00115 {
00116 public:
00117   Crash() :
00118     item::function::Boolean()
00119   { }
00120 
00121   const char *func_name() const { return "crash"; }
00122   const char *fully_qualified_func_name() const { return "crash()"; }
00123 
00124   bool val_bool()
00125   {
00126     raise(SIGSEGV);
00127 
00128     return true;
00129   }
00130 
00131   int64_t val_int()
00132   {
00133     return val_bool();
00134   }
00135 };
00136 
00137 } // namespace debug
00138 
00139 static int initialize(drizzled::module::Context &context)
00140 {
00141   context.add(new drizzled::plugin::Create_function<debug::Assert>("assert_and_crash"));
00142   context.add(new drizzled::plugin::Create_function<debug::Backtrace>("backtrace"));
00143   context.add(new drizzled::plugin::Create_function<debug::Crash>("crash"));
00144 
00145   return 0;
00146 }
00147 
00148 DRIZZLE_DECLARE_PLUGIN
00149 {
00150   DRIZZLE_VERSION_ID,
00151   "debug",
00152   "1.1",
00153   "Brian Aker",
00154   "Useful functions for programmers to debug the server.",
00155   PLUGIN_LICENSE_BSD,
00156   initialize, /* Plugin Init */
00157   NULL,   /* depends */
00158   NULL    /* config options */
00159 }
00160 DRIZZLE_DECLARE_PLUGIN_END;