WvStreams
wvbellpull.h
1 /* -*- Mode: C++ -*-
2  * Worldvisions Weaver Software:
3  * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4  */
5 #ifndef __WVBATCHSIGNAL_H
6 #define __WVBATCHSIGNAL_H
7 
8 #include <uniconf.h>
9 #include <wvistreamlist.h>
10 #include <wvtr1.h>
11 
12 
14 {
15 public:
16  WvInvertedStream(char *_id):
17  WvStream()
18  {
19  WvIStreamList::globallist.append(this, false, _id);
20  }
22  {
23  WvIStreamList::globallist.unlink(this);
24  }
25 };
26 
27 
28 /*
29  * This class is a functor compatible with UniConfCallback,
30  * IWvStreamCallback and WvStreamCallback, as well as supporting being
31  * called with no parameters.
32  *
33  * It will turn any number of calls to any of these callbacks into a
34  * single call to the callback you give to it, which will be sent on
35  * the next run through the main loop.
36  *
37  * Think of it as an elevator button: pressing it a bunch of times has
38  * no more effect than pressing it once, and while it doesn't do what
39  * you tell it right away, it will do it soon enough.
40  */
42 {
43 public:
44  WvBellPull(WvCallback<> _cb):
45  cb(_cb),
46  bellpull(new WvInvertedStream("bellpull"))
47  {
48  bellpull->setcallback(
49  WvStreamCallback(this, &WvBellPull::bellpull_cb), NULL);
50  }
51 
52  WvBellPull(const WvBellPull& _other):
53  cb(_other.cb),
54  bellpull(_other.bellpull)
55  {
56  bellpull->addRef();
57  }
58 
59  ~WvBellPull()
60  {
61  bellpull->release();
62  }
63  void delay(time_t msec_timeout)
64  {
65  bellpull->alarm(msec_timeout);
66  }
67  void cancel()
68  {
69  bellpull->alarm(-1);
70  }
71  void operator()()
72  {
73  bellpull->alarm(0);
74  }
75  void operator()(IWvStream&)
76  {
77  bellpull->alarm(0);
78  }
79  void operator()(WvStream&, void*)
80  {
81  bellpull->alarm(0);
82  }
83  void operator()(const UniConf &, const UniConfKey &)
84  {
85  bellpull->alarm(0);
86  }
87 
88 private:
89  WvCallback<> cb;
90  WvInvertedStream *bellpull;
91 
92  void bellpull_cb(WvStream&, void*)
93  {
94  cb();
95  }
96 };
97 
98 #endif /* __WVBATCHSIGNAL_H */
UniConf
UniConf instances function as handles to subtrees of a UniConf tree and expose a high-level interface...
Definition: uniconf.h:50
IWvStream
Definition: iwvstream.h:24
WvStream::WvStream
WvStream()
Basic constructor for just a do-nothing WvStream.
Definition: wvstream.cc:249
WvBellPull
Definition: wvbellpull.h:41
UniConfKey
Represents a UniConf key which is a path in a hierarchy structured much like the traditional Unix fil...
Definition: uniconfkey.h:38
IObject::release
virtual unsigned int release()=0
Indicate that you are finished using this object.
WvStream::alarm
void alarm(time_t msec_timeout)
set an alarm, ie.
Definition: wvstream.cc:1048
WvInvertedStream
Definition: wvbellpull.h:13
WvStream
Unified support for streams, that is, sequences of bytes that may or may not be ready for read/write ...
Definition: wvstream.h:24
WvStream::setcallback
void setcallback(IWvStreamCallback _callfunc)
define the callback function for this stream, called whenever the callback() member is run,...
Definition: wvstream.cc:1130
IObject::addRef
virtual unsigned int addRef()=0
Indicate you are using this object.