iwvstream.h

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 "wverror.h"
00011 #include "wvcallback.h"
00012 #include "wvbuf.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 WvCallback<void, WvStream&> IWvStreamCallback;
00022 typedef unsigned int WSID;
00023 
00024 class IWvStream : public WvErrorBase, public IObject
00025 {
00026 public:
00032     struct SelectRequest {
00033         bool readable, writable, isexception;
00034         
00035         SelectRequest() { }
00036         SelectRequest(bool r, bool w, bool x = false)
00037                 { readable = r; writable = w; isexception = x; }
00038         
00039         SelectRequest &operator |= (const SelectRequest &r)
00040                 { readable |= r.readable; writable |= r.writable;
00041                     isexception |= r.isexception; return *this; }
00042     };
00043     
00048     struct SelectInfo {
00049         fd_set read, write, except; // set by pre_select, read by post_select
00050         SelectRequest wants;        // what is the user looking for?
00051         int max_fd;                 // largest fd in read, write, or except
00052         time_t msec_timeout;        // max time to wait, or -1 for forever
00053         bool inherit_request;       // 'wants' values passed to child streams
00054         bool global_sure;           // should we run the globalstream callback
00055     };
00056     
00057     IWvStream();
00058     virtual ~IWvStream();
00059     virtual void close() = 0;
00060     virtual bool isok() const = 0;
00061     virtual void callback() = 0;
00062     
00063     // FIXME: these really have no place in the interface...
00064     virtual int getrfd() const = 0;
00065     virtual int getwfd() const = 0;
00066 
00067     // FIXME: evil, should go away (or be changed to localaddr/remoteaddr)
00068     virtual const WvAddr *src() const = 0;
00069     
00070     // needed for select().
00071     // Some say that pre_select() should go away.
00072     virtual void pre_select(SelectInfo &si) = 0;
00073     virtual bool post_select(SelectInfo &si) = 0;
00074     
00075     // these are now the official way to get/put data to your stream.
00076     // The old uread() and uwrite() are just implementation details!
00077     virtual size_t read(void *buf, size_t count) = 0;
00078     virtual size_t write(const void *buf, size_t count) = 0;
00079 
00080     // FIXME: these are the new fancy versions, but WvBuf needs to have
00081     // a safely abstracted interface class (IWvBuf) before IWvStream will
00082     // really be safe, if we include these.
00083     virtual size_t read(WvBuf &outbuf, size_t count) = 0;
00084     virtual size_t write(WvBuf &inbuf, size_t count = INT_MAX) = 0;
00085 
00098     virtual void noread() = 0;
00099 
00108     virtual void nowrite() = 0;
00109     
00114     virtual void maybe_autoclose() = 0;
00115     
00117     virtual bool isreadable() = 0;
00118     
00120     virtual bool iswritable() = 0;
00121     
00131     virtual bool flush(time_t msec_timeout) = 0;
00132 
00139     virtual bool should_flush() = 0;
00140 
00141     /*
00142      * WARNING: these don't work as expected!
00143      */
00145     virtual IWvStreamCallback setreadcallback(IWvStreamCallback _callfunc) = 0;
00146 
00148     virtual IWvStreamCallback setwritecallback(IWvStreamCallback _callfunc) = 0;
00149 
00152     virtual IWvStreamCallback setexceptcallback(IWvStreamCallback _callfunc) = 0;
00153     /* 
00154      * END WARNING
00155      */
00156 
00158     virtual IWvStreamCallback setclosecallback(IWvStreamCallback _callfunc) = 0;
00159 
00160     /* Stream identification/debugging */
00161     virtual const char *wsname() const = 0;
00162     virtual void set_wsname(WvStringParm name) = 0;
00163     virtual const char *wstype() const = 0; // This is not static due to, eg, WvStreamClone
00164     virtual WSID wsid() const = 0;
00165 
00171      virtual void outbuf_limit(size_t size) = 0;
00172 };
00173 
00174 DEFINE_IID(IWvStream, {0x7ca76e98, 0xb653, 0x43d7,
00175     {0xb0, 0x56, 0x8b, 0x9d, 0xde, 0x9a, 0xbe, 0x9d}});
00176 
00177 
00178 #endif /* __IWVSTREAM_H */

Generated on Thu Jan 24 16:50:54 2008 for WvStreams by  doxygen 1.5.4