00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef ULXR_CONNECTION_H
00031 #define ULXR_CONNECTION_H
00032
00033 #include <ulxmlrpcpp/ulxmlrpcpp.h>
00034
00035 #if defined(__BORLANDC__) || defined (_MSC_VER)
00036 typedef long ssize_t;
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
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
00283
00284
00285 };
00286
00287
00288 }
00289
00290
00291 #endif // ULXR_CONNECTION_H