Connection.h

00001 /* 
00002    EyeDB Object Database Management System
00003    Copyright (C) 1994-2008 SYSRA
00004    
00005    EyeDB is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009    
00010    EyeDB 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 GNU
00013    Lesser General Public License for more details.
00014    
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with this library; if not, write to the Free Software
00017    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA 
00018 */
00019 
00020 /*
00021    Author: Eric Viara <viara@sysra.com>
00022 */
00023 
00024 
00025 #ifndef _EYEDB_CONNECTION_H
00026 #define _EYEDB_CONNECTION_H
00027 
00028 class ConnHandle;
00029 
00030 namespace eyedb {
00031 
00037   class ConnectionPeer;
00038   class ServerMessageDisplayer;
00039 
00043   class Connection {
00044 
00045     // ----------------------------------------------------------------------
00046     // Connection Interface
00047     // ----------------------------------------------------------------------
00048   public:
00052     Connection();
00053 
00061     Connection(bool opening, const char *host = DefaultHost,
00062                const char *port = DefaultIDBPort);
00063 
00070     Status open(const char *host = DefaultHost,
00071                 const char *port = DefaultIDBPort);
00072 
00077     Status close();
00078 
00083     const char *getHost() const;
00084 
00089     const char *getIDBPort() const;
00090 
00095     int getServerUid() const;
00096 
00101     int getServerPid() const;
00102 
00107     Status sendInterrupt();
00108 
00113     ConnHandle *getConnHandle() {return connh;}
00114 
00118     ~Connection();
00119 
00124     static void setDefaultHost(const char *host);
00125 
00130     static const char *getDefaultHost();
00131 
00136     static void setDefaultIDBPort(const char *port);
00137 
00142     static const char *getDefaultIDBPort();
00143 
00148     static void setAuthRequired(Bool set_auth_required);
00149 
00154     static void setDefaultUser(const char *user);
00155 
00160     static const char *getDefaultUser();
00161 
00166     static void setDefaultPasswd(const char *passwd);
00167 
00172     static const char *getDefaultPasswd();
00173 
00178     static std::string makeUser(const char *_ser);
00179 
00180     static const char
00181       LocalHost[],
00182       DefaultHost[],
00183       DefaultIDBPort[],
00184       DefaultIDBPortValue[];
00185 
00191     void *setUserData(void *ud);
00192 
00197     void *getUserData(void);
00198 
00203     const void *getUserData(void) const;
00204 
00210     Status echoServerMessages(const ServerMessageDisplayer &dsp) const;
00211 
00212     // could be called from server side only
00217     static Bool isBackendInterrupted();
00218 
00223     static void setServerMessage(const char *msg);
00224 
00231     static void setOutOfBandData(unsigned int type, unsigned char *data,
00232                                  unsigned int len);
00233 
00234     // ----------------------------------------------------------------------
00235     // Connection Private Part
00236     // ----------------------------------------------------------------------
00237   private:
00238     friend class ConnectionPeer;
00239 
00240     char *host;
00241     char *port;
00242     int sv_pid, sv_uid;
00243     void *user_data;
00244     void *oql_info;
00245 
00246     static char *default_host, *default_port, *default_user, *default_passwd;
00247 
00248     static Bool set_auth_required;
00249 
00250     ConnHandle *connh;
00251 
00252     Status echoServerMessages(unsigned int mask, FILE *fd, std::ostream *os) const;
00253 
00254     // ----------------------------------------------------------------------
00255     // Connection Restricted Access (conceptually private)
00256     // ----------------------------------------------------------------------
00257   public:
00258     static void init();
00259     static void _release();
00260     void *setOQLInfo(void *);
00261     void *getOQLInfo();
00262     struct ServerMessageContext;
00263   };
00264 
00265   class ServerMessageDisplayer {
00266   public:
00267     virtual void display(const char *msg) const = 0;
00268     virtual ~ServerMessageDisplayer() {}
00269   };
00270 
00271   class StdServerMessageDisplayer : public ServerMessageDisplayer {
00272 
00273   public:
00274     StdServerMessageDisplayer(FILE *fd = stdout);
00275     StdServerMessageDisplayer(std::ostream &);
00276 
00277     virtual void display(const char *msg) const;
00278 
00279     virtual ~StdServerMessageDisplayer() {}
00280 
00281   private:
00282     FILE *fd;
00283     std::ostream *os;
00284   };
00285 
00290 }
00291 
00292 #endif

Generated on Mon Dec 22 18:15:53 2008 for eyedb by  doxygen 1.5.3