WvStreams
wvistreamlist.h
1 /* -*- Mode: C++ -*-
2  * Worldvisions Weaver Software:
3  * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4  *
5  * FIXME: Suspiciously similar to wvstreamlist, and with tons of duplicated
6  * code. Blech.
7  */
8 #ifndef __WVISTREAMLIST_H
9 #define __WVISTREAMLIST_H
10 
11 #include "wvstream.h"
12 
14 DeclareWvList2(WvIStreamListBase, IWvStream);
15 
20 class WvIStreamList : public WvStream, public WvIStreamListBase
21 {
22 public:
23  WvIStreamList();
24  virtual ~WvIStreamList();
25  virtual bool isok() const;
26  virtual void pre_select(SelectInfo &si);
27  virtual bool post_select(SelectInfo &si);
28  virtual void execute();
29 
30  void unlink(IWvStream *data)
31  { sure_thing.unlink(data); WvIStreamListBase::unlink(data); }
32 
33  void add_after(WvLink *after, IWvStream *data, bool autofree,
34  const char *id)
35  {
36  WvIStreamListBase::add_after(after, data, autofree, id);
37  }
38  void add(IWvStream *data, bool autofree, const char *id)
39  {
40  WvIStreamListBase::add(data, autofree, id);
41  }
42  void prepend(IWvStream *data, bool autofree, const char *id)
43  {
44  WvIStreamListBase::prepend(data, autofree, id);
45  }
46 
47 public:
48  bool auto_prune; // remove !isok() streams from the list automatically?
49  static WvIStreamList globallist;
50 
51 protected:
52  WvIStreamListBase sure_thing;
53 
54 private:
55  // Create some undefined overrides to prevent accidentally using a
56  // WvString as an id; these functions will keep a long-term reference to
57  // the string, so you should probably use a string constant.
58  void add_after(WvLink *after, IWvStream *data, bool autofree, WvString id);
59  void add(IWvStream *data, bool autofree, WvString id);
60  void prepend(IWvStream *data, bool autofree, WvString id);
61 
62 private:
63  bool in_select;
64  bool dead_stream;
65 
66 #ifndef _WIN32
67  static void onfork(pid_t p);
68 #endif
69 
70 public:
71  void append(IWvStream *s, bool auto_free, const char *id)
72  {
73  if (s->wsname() == NULL)
74  s->set_wsname(id);
75  WvIStreamListBase::append(s, auto_free, id);
76  }
77  void append(IWvStream *s, bool auto_free, WVSTRING_FORMAT_DECL)
78  {
79  if (s->wsname() == NULL)
80  s->set_wsname(WvString(WVSTRING_FORMAT_CALL));
81  WvIStreamListBase::append(s, auto_free, s->wsname());
82  }
83 
84 public:
85  const char *wstype() const { return "WvIStreamList"; }
86 
87 private:
88  static void add_debugger_commands();
89 private:
90  static WvString debugger_globallist_run_cb(WvStringParm cmd,
91  WvStringList &args,
92  WvStreamsDebugger::ResultCallback result_cb, void *);
93 };
94 
95 #endif // __WVISTREAMLIST_H
WvIStreamList::post_select
virtual bool post_select(SelectInfo &si)
post_select() is called after ::select(), and returns true if this object is now ready.
Definition: wvistreamlist.cc:141
WvIStreamList::execute
virtual void execute()
The callback() function calls execute(), and then calls the user- specified callback if one is define...
Definition: wvistreamlist.cc:205
WvIStreamList::pre_select
virtual void pre_select(SelectInfo &si)
pre_select() sets up for eventually calling ::select().
Definition: wvistreamlist.cc:89
IWvStream
Definition: iwvstream.h:24
WvString
WvString is an implementation of a simple and efficient printable-string class.
Definition: wvstring.h:329
IWvStream::SelectInfo
the data structure used by pre_select()/post_select() and internally by select().
Definition: iwvstream.h:50
WvStream
Unified support for streams, that is, sequences of bytes that may or may not be ready for read/write ...
Definition: wvstream.h:24
WvIStreamList::isok
virtual bool isok() const
return true if the stream is actually usable right now
Definition: wvistreamlist.cc:65
WvIStreamList
WvStreamList holds a list of WvStream objects – and its select() and callback() functions know how to...
Definition: wvistreamlist.h:20
WvStringList
This is a WvList of WvStrings, and is a really handy way to parse strings.
Definition: wvstringlist.h:27