ulxr_connection.h

Go to the documentation of this file.
00001 /***************************************************************************
00002            ulxr_connection.h  -  provide a connection for rpc-data
00003                              -------------------
00004     begin                : Sun Mar 24 2002
00005     copyright            : (C) 2002-2007 by Ewald Arnold
00006     email                : ulxmlrpcpp@ewald-arnold.de
00007 
00008     $Id: ulxr_connection.h 1062 2007-08-19 09:07:58Z ewald-arnold $
00009 
00010  ***************************************************************************/
00011 
00012 /**************************************************************************
00013  *
00014  * This program is free software; you can redistribute it and/or modify
00015  * it under the terms of the GNU Lesser General Public License as
00016  * published by the Free Software Foundation; either version 2 of the License,
00017  * or (at your option) any later version.
00018  *
00019  * This program is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  * GNU General Public License for more details.
00023  *
00024  * You should have received a copy of the GNU Lesser General Public License
00025  * along with this program; if not, write to the Free Software
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00027  *
00028  ***************************************************************************/
00029 
00030 #ifndef ULXR_CONNECTION_H
00031 #define ULXR_CONNECTION_H
00032 
00033 #include <ulxmlrpcpp/ulxmlrpcpp.h>  // always first header
00034 
00035 #if defined(__BORLANDC__)  || defined (_MSC_VER)
00036 typedef long ssize_t; // TODO detect
00037 #endif
00038 
00039 namespace ulxr {
00040 
00048 class ULXR_API_DECL0 ConnectorWrapperBase
00049 {
00050   public:
00051 
00052     virtual ~ConnectorWrapperBase();
00053 
00054     virtual void call() = 0;
00055 };
00056 
00057 
00061 template <class T>
00062 class ULXR_API_DECL0 ConnectorWrapper : public ConnectorWrapperBase
00063 {
00064   public:
00065 
00066    typedef void (T::*PMF)();
00067 
00068    virtual void call ()
00069    {
00070       (obj->*adr) ();
00071    }
00072 
00073    ConnectorWrapper(T *o, PMF a)
00074      : obj(o), adr(a)
00075    {}
00076 
00077   private:
00078 
00079    T    *obj;
00080    PMF   adr ;
00081 
00082  private:
00083     // forbid them all due to internal pointers
00084     const ConnectorWrapper& operator= (const ConnectorWrapper&);
00085     ConnectorWrapper (const ConnectorWrapper&);
00086 };
00087 
00088 
00092 class ULXR_API_DECL0 Connection
00093 {
00094  public:
00095 
00099    Connection();
00100 
00104    virtual ~Connection();
00105 
00108    virtual void close();
00109 
00116    virtual void shutdown(int mode) = 0;
00117 
00122    virtual Connection *detach() = 0;
00123 
00128    virtual void write(char const *buff, long len);
00129 
00135    virtual ssize_t read(char *buff, long len);
00136 
00139    virtual void open() = 0;
00140 
00146    virtual bool accept(int timeout = 0) = 0;
00147 
00151    virtual bool isOpen() const;
00152 
00156    void setTimeout(unsigned to_sec);
00157 
00170    void setConnectionTimeout(unsigned def_to_sec = 0, unsigned alive_to_sec = 0);
00171 
00175    unsigned getTimeout() const;
00176 
00180    unsigned getDefaultTimeout() const;
00181 
00185    unsigned getPersistentTimeout() const;
00186 
00190    virtual int getLastError();
00191 
00196    virtual CppString getErrorString(int err_number);
00197 
00201    virtual CppString getInterfaceName() = 0;
00202 
00206    virtual void cut();
00207 
00211    int getHandle() const;
00212 
00216     virtual int getServerHandle() = 0;
00217 
00220    void doConnect();
00221 
00225    void setConnector(ConnectorWrapperBase *connector);
00226 
00227  protected:
00228 
00232    void setHandle(int handle);
00233 
00237    bool isConnecting() const;
00238 
00243    void setIsConnecting(bool connecting);
00244 
00250    virtual ssize_t low_level_write(char const *buff, long len);
00251 
00257    virtual ssize_t low_level_read(char *buff, long len);
00258 
00262    virtual bool hasPendingInput() const;
00263 
00264  private:
00265 
00268    void init();
00269 
00270  private:
00271 
00272    bool                   isconnecting;
00273    ConnectorWrapperBase  *connector;
00274    int                    fd_handle;
00275 
00276    unsigned               current_to;
00277    unsigned               default_to;
00278    unsigned               persist_to;
00279 
00280  private:
00281 
00282     // forbid them all due to internal pointers
00283 //    const ConnectorWrapper& operator= (const ConnectorWrapper&);
00284 //    ConnectorWrapper (const ConnectorWrapper&);
00285 };
00286 
00287 
00288 }  // namespace ulxr
00289 
00290 
00291 #endif // ULXR_CONNECTION_H

Generated on Sun Aug 19 20:08:57 2007 for ulxmlrpcpp by  doxygen 1.5.1