WvStreams
debian/libwvstreams-dev/usr/include/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{
15public:
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{
43public:
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
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
88private:
89 WvCallback<> cb;
90 WvInvertedStream *bellpull;
91
92 void bellpull_cb(WvStream&, void*)
93 {
94 cb();
95 }
96};
97
98#endif /* __WVBATCHSIGNAL_H */
virtual unsigned int addRef()=0
Indicate you are using this object.
virtual unsigned int release()=0
Indicate that you are finished using this object.
Represents a UniConf key which is a path in a hierarchy structured much like the traditional Unix fil...
UniConf instances function as handles to subtrees of a UniConf tree and expose a high-level interface...
Unified support for streams, that is, sequences of bytes that may or may not be ready for read/write ...
void alarm(time_t msec_timeout)
set an alarm, ie.
Definition wvstream.cc:1049
void setcallback(IWvStreamCallback _callfunc)
define the callback function for this stream, called whenever the callback() member is run,...
Definition wvstream.cc:1129
WvStream()
Basic constructor for just a do-nothing WvStream.
Definition wvstream.cc:249