Drizzled Public API Documentation

client.h

00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 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 #pragma once
00021 
00022 #include <drizzled/catalog/instance.h>
00023 #include <drizzled/catalog/local.h>
00024 #include <drizzled/error_t.h>
00025 #include <drizzled/item.h>
00026 #include <drizzled/sql_list.h>
00027 
00028 #include <drizzled/visibility.h>
00029 
00030 namespace drizzled
00031 {
00032 class Session;
00033 class String;
00034 
00035 namespace plugin
00036 {
00037 
00045 class DRIZZLED_API Client
00046 {
00047 protected:
00048   Session *session;
00049 
00050 public:
00051   virtual ~Client() {}
00052 
00057   virtual Session *getSession(void)
00058   {
00059     return session;
00060   }
00061 
00066   virtual void setSession(Session *session_arg)
00067   {
00068     session= session_arg;
00069   }
00070 
00075   virtual int getFileDescriptor(void)= 0;
00076 
00081   virtual bool isConnected(void)= 0;
00082 
00087   virtual bool isReading(void)= 0;
00088 
00093   virtual bool isWriting(void)= 0;
00094 
00099   virtual bool flush(void)= 0;
00100 
00104   virtual void close(void)= 0;
00105 
00109   virtual bool authenticate(void)= 0;
00110 
00111   virtual bool isConsole() const
00112   {
00113     return false;
00114   }
00115 
00116   virtual bool isInteractive() const
00117   {
00118     return false;
00119   }
00120 
00121   virtual bool isAdmin() const
00122   {
00123     return false;
00124   }
00125 
00126   virtual catalog::Instance::shared_ptr catalog()
00127   {
00128     return catalog::local();
00129   }
00130 
00134   virtual bool readCommand(char **packet, uint32_t *packet_length)= 0;
00135 
00136   /* Send responses. */
00137   virtual void sendOK(void)= 0;
00138   virtual void sendEOF(void)= 0;
00139   virtual void sendError(const drizzled::error_t sql_errno, const char *err)= 0;
00140 
00144   virtual bool sendFields(List<Item> *list)= 0;
00145 
00146   /* Send result fields in various forms. */
00147   virtual bool store(Field *from)= 0;
00148   virtual bool store(void)= 0;
00149   virtual bool store(int32_t from)= 0;
00150   virtual bool store(uint32_t from)= 0;
00151   virtual bool store(int64_t from)= 0;
00152   virtual bool store(uint64_t from)= 0;
00153   virtual bool store(double from, uint32_t decimals, String *buffer)= 0;
00154   virtual bool store(const type::Time *from);
00155   virtual bool store(const char *from);
00156   virtual bool store(const char *from, size_t length)= 0;
00157   virtual bool store(const std::string &from)
00158   {
00159     return store(from.c_str(), from.size());
00160   }
00161 
00162   /* Try to remove these. */
00163   virtual bool haveMoreData(void)= 0;
00164   virtual bool haveError(void)= 0;
00165   virtual bool wasAborted(void)= 0;
00166 
00167 };
00168 
00169 } /* namespace plugin */
00170 } /* namespace drizzled */
00171