WvStreams
|
00001 /* -*- Mode: C++ -*- 00002 * Worldvisions Weaver Software: 00003 * Copyright (C) 1997-2002 Net Integration Technologies, Inc. 00004 * 00005 * The basic streaming I/O interface. 00006 */ 00007 #ifndef __IWVSTREAM_H 00008 #define __IWVSTREAM_H 00009 00010 #include "wvbuf.h" 00011 #include "wverror.h" 00012 #include "wvtr1.h" 00013 #include "wvxplc.h" 00014 00015 00016 class WvAddr; 00017 class WvStream; 00018 00019 00020 /* The stream gets passed back as a parameter. */ 00021 typedef wv::function<void()> IWvStreamCallback; 00022 typedef unsigned int WSID; 00023 00024 class IWvStream : public WvErrorBase, public IObject 00025 { 00026 public: 00027 static IWvStream *create(WvStringParm moniker, IObject *obj = NULL); 00028 00034 struct SelectRequest { 00035 bool readable, writable, isexception; 00036 00037 SelectRequest() { } 00038 SelectRequest(bool r, bool w, bool x = false) 00039 { readable = r; writable = w; isexception = x; } 00040 00041 SelectRequest &operator |= (const SelectRequest &r) 00042 { readable |= r.readable; writable |= r.writable; 00043 isexception |= r.isexception; return *this; } 00044 }; 00045 00050 struct SelectInfo { 00051 fd_set read, write, except; // set by pre_select, read by post_select 00052 SelectRequest wants; // what is the user looking for? 00053 int max_fd; // largest fd in read, write, or except 00054 time_t msec_timeout; // max time to wait, or -1 for forever 00055 bool inherit_request; // 'wants' values passed to child streams 00056 bool global_sure; // should we run the globalstream callback 00057 }; 00058 00059 IWvStream(); 00060 virtual ~IWvStream(); 00061 virtual void close() = 0; 00062 virtual bool isok() const = 0; 00063 virtual void callback() = 0; 00064 00065 // FIXME: these really have no place in the interface... 00066 virtual int getrfd() const = 0; 00067 virtual int getwfd() const = 0; 00068 00069 // FIXME: evil, should go away (or be changed to localaddr/remoteaddr) 00070 virtual const WvAddr *src() const = 0; 00071 00072 // needed for select(). 00073 // Some say that pre_select() should go away. 00074 virtual void pre_select(SelectInfo &si) = 0; 00075 virtual bool post_select(SelectInfo &si) = 0; 00076 00077 // these are now the official way to get/put data to your stream. 00078 // The old uread() and uwrite() are just implementation details! 00079 virtual size_t read(void *buf, size_t count) = 0; 00080 virtual size_t write(const void *buf, size_t count) = 0; 00081 00082 // FIXME: these are the new fancy versions, but WvBuf needs to have 00083 // a safely abstracted interface class (IWvBuf) before IWvStream will 00084 // really be safe, if we include these. 00085 virtual size_t read(WvBuf &outbuf, size_t count) = 0; 00086 virtual size_t write(WvBuf &inbuf, size_t count = INT_MAX) = 0; 00087 00100 virtual void noread() = 0; 00101 00110 virtual void nowrite() = 0; 00111 00116 virtual void maybe_autoclose() = 0; 00117 00119 virtual bool isreadable() = 0; 00120 00122 virtual bool iswritable() = 0; 00123 00133 virtual bool flush(time_t msec_timeout) = 0; 00134 00141 virtual bool should_flush() = 0; 00142 00143 /* 00144 * WARNING: these don't work as expected! 00145 */ 00147 virtual IWvStreamCallback setreadcallback(IWvStreamCallback _callfunc) = 0; 00148 00150 virtual IWvStreamCallback setwritecallback(IWvStreamCallback _callfunc) = 0; 00151 00154 virtual IWvStreamCallback setexceptcallback(IWvStreamCallback _callfunc) = 0; 00155 /* 00156 * END WARNING 00157 */ 00158 00160 virtual IWvStreamCallback setclosecallback(IWvStreamCallback _callfunc) = 0; 00161 00162 /* Stream identification/debugging */ 00163 virtual const char *wsname() const = 0; 00164 virtual void set_wsname(WvStringParm name) = 0; 00165 virtual const char *wstype() const = 0; // This is not static due to, eg, WvStreamClone 00166 virtual WSID wsid() const = 0; 00167 00173 virtual void outbuf_limit(size_t size) = 0; 00174 virtual WvString getattr(WvStringParm name) const = 0; 00175 }; 00176 00177 DEFINE_IID(IWvStream, {0x7ca76e98, 0xb653, 0x43d7, 00178 {0xb0, 0x56, 0x8b, 0x9d, 0xde, 0x9a, 0xbe, 0x9d}}); 00179 00180 00181 #endif /* __IWVSTREAM_H */