Drizzled Public API Documentation

shutdown.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 #include <drizzled/session.h>
00041 #include <drizzled/sql_base.h>
00042 #include <drizzled/function/str/strfunc.h>
00043 #include <drizzled/plugin/function.h>
00044 
00045 using namespace drizzled;
00046 
00047 #define SHUTDOWN_MESSAGE "Beginning shutdown"
00048 
00049 class Shutdown : public Item_str_func
00050 {
00051 public:
00052   Shutdown()
00053   { }
00054 
00055   void fix_length_and_dec()
00056   {
00057     max_length= sizeof(SHUTDOWN_MESSAGE) * system_charset_info->mbmaxlen;
00058     maybe_null= true;
00059   }
00060   const char *func_name() const { return "shutdown"; }
00061   const char *fully_qualified_func_name() const { return "shutdown()"; }
00062 
00063   String *val_str(String *str)
00064   {
00065     kill_drizzle();
00066 
00067     str->copy(SHUTDOWN_MESSAGE, sizeof(SHUTDOWN_MESSAGE) -1, system_charset_info);
00068 
00069     return str;
00070   }
00071 };
00072 
00073 static int initialize(drizzled::module::Context &context)
00074 {
00075   context.add(new plugin::Create_function<Shutdown>("shutdown"));
00076   return 0;
00077 }
00078 
00079 DRIZZLE_DECLARE_PLUGIN
00080 {
00081   DRIZZLE_VERSION_ID,
00082   "shutdown",
00083   "1.0",
00084   "Brian Aker",
00085   "Cause the database to shutdown.",
00086   PLUGIN_LICENSE_BSD,
00087   initialize, /* Plugin Init */
00088   NULL,   /* depends */
00089   NULL    /* config options */
00090 }
00091 DRIZZLE_DECLARE_PLUGIN_END;