/usr/include/wvstreams/wvdelayedcallback.h is in libwvstreams-dev 4.6.1-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | /* -*- Mode: C++ -*-
* Worldvisions Weaver Software:
* Copyright (C) 2003 Net Integration Technologies, Inc.
*
*/
#ifndef __WVDELAYEDCALLBACK_H
#define __WVDELAYEDCALLBACK_H
#include "wvistreamlist.h"
#include "wvtr1.h"
/**
* A WvCallback wrapper that delays until the next tick of the WvIStreamList
* main loop.
*
* There are restrictions on the type of the wrapped callback though:
* 1. The return type must be void
* 2. All parameter types must be copy-constructible value types
*
* Example: setcallback(wv::delayed(mycallback));
*
* FIXME: Because operator() makes a copy of the inner callback and thaw()
* destroys the copy, nesting WvDelayedCallback doesn't work as you might
* expect. That is, don't do: wv::delayed(wv::delayed(mycallback)).
* It creates a copy of the inner WvDelayedCallback, but that copy
* gets frozen, then destroyed before it has a chance to thaw! Anyway,
* it's a stupid thing to do anyway, so don't.
*/
template<class Functor>
class WvDelayedCallback
{
private:
Functor func;
WvStream *stream;
wv::function<void()> frozen;
public:
WvDelayedCallback(const Functor& _func):
func(_func), stream(new WvStream), frozen(0)
{
WvIStreamList::globallist.append(stream, true, "WvDelayedCallback");
}
WvDelayedCallback(const WvDelayedCallback &other):
func(other.func), stream(new WvStream), frozen(0)
{
WvIStreamList::globallist.append(stream, true, "WvDelayedCallback");
}
~WvDelayedCallback()
{
stream->close();
}
void operator()()
{
stream->setcallback(func);
stream->alarm(0);
}
template<typename P1>
void operator()(P1 &p1)
{
stream->setcallback(wv::bind(func, p1));
stream->alarm(0);
}
template<typename P1,
typename P2>
void operator()(P1 &p1, P2 &p2)
{
stream->setcallback(wv::bind(func, p1, p2));
stream->alarm(0);
}
template<typename P1,
typename P2,
typename P3>
void operator()(P1 &p1, P2 &p2, P3 &p3)
{
stream->setcallback(wv::bind(func, p1, p2, p3));
stream->alarm(0);
}
template<typename P1,
typename P2,
typename P3,
typename P4>
void operator()(P1 &p1, P2 &p2, P3 &p3, P4 &p4)
{
stream->setcallback(wv::bind(func, p1, p2, p3, p4));
stream->alarm(0);
}
template<typename P1,
typename P2,
typename P3,
typename P4,
typename P5>
void operator()(P1 &p1, P2 &p2, P3 &p3, P4 &p4, P5 &p5)
{
stream->setcallback(wv::bind(func, p1, p2, p3, p4, p5));
stream->alarm(0);
}
template<typename P1,
typename P2,
typename P3,
typename P4,
typename P5,
typename P6>
void operator()(P1 &p1, P2 &p2, P3 &p3, P4 &p4, P5 &p5, P6 &p6)
{
stream->setcallback(wv::bind(func, p1, p2, p3, p4, p5, p6));
stream->alarm(0);
}
template<typename P1,
typename P2,
typename P3,
typename P4,
typename P5,
typename P6,
typename P7>
void operator()(P1 &p1, P2 &p2, P3 &p3, P4 &p4, P5 &p5, P6 &p6, P7 &p7)
{
stream->setcallback(wv::bind(func, p1, p2, p3, p4, p5, p6, p7));
stream->alarm(0);
}
template<typename P1,
typename P2,
typename P3,
typename P4,
typename P5,
typename P6,
typename P7,
typename P8>
void operator()(P1 &p1, P2 &p2, P3 &p3, P4 &p4, P5 &p5, P6 &p6, P7 &p7,
P8 &p8)
{
stream->setcallback(wv::bind(func, p1, p2, p3, p4, p5, p6, p7, p8));
stream->alarm(0);
}
};
/*
* We put the following in the wv:: namespace so that they match wv::bind
* and wv::function from wvtr1.h.
*/
namespace wv
{
/**
* A convenience function for constructing WvDelayedCallback objects
* from wv::functions without explicitly specifying the type.
* Example:
* typedef wv::function<void(int, int)> Func;
* Func f = wv::delayed(wv::bind(mycallback, 5, _1));
* f(10);
*/
template <typename T>
inline T delayed(T cb)
{
return WvDelayedCallback<T>(cb);
}
/**
* A convenience function for constructing WvDelayedCallback objects
* from function pointers without explicitly specifying the type.
* Example:
* typedef wv::function<void(int)> Func;
* Func f = wv::delayed(mycallback);
* f(10);
*/
template <typename T>
inline wv::function<T> delayed(T *cb)
{
return WvDelayedCallback< wv::function<T> >(cb);
}
}
#endif
|