]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/base/Subscription.h
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 #ifndef _SQUID_BASE_SUBSCRIPTION_H
10 #define _SQUID_BASE_SUBSCRIPTION_H
12 #include "base/AsyncCall.h"
14 /** API for creating a series of AsyncCalls.
15 * This is necessary because the same AsyncCall callback must not be
16 * fired multiple times.
18 * The call producer needs to accept and store a Subscription::Pointer.
19 * It also should provide some mechanism for adding/removing/changing
20 * the stored Subscription::Pointer.
22 * The callback() method of Subscription::Pointer will spawn AsyncCall
23 * to be filled out and scheduled as needed.
25 class Subscription
: public RefCountable
28 typedef RefCount
<Subscription
> Pointer
;
30 /** returns a call object to be used for the next call back.
31 * Child implementations must ensure the Call pointer produced
34 virtual AsyncCall::Pointer
callback() const = 0;
37 /** Implements Subscription API using Call's copy constructor.
39 * The subscriber creates one of these using a specific callback
40 * type and instance. The subscription object is then passed to a
41 * producer/factory which will use this API to generate calls.
42 * A subscription may be passed to multiple producers.
44 * Call_ must have a copy constructor.
45 * A pointer to Call_ must be convertable to AsyncCall::Pointer
48 class CallSubscription
: public Subscription
51 /// Must be passed an object. nil pointers are not permitted.
52 explicit CallSubscription(const RefCount
<Call_
> &aCall
) : call(aCall
) { assert(aCall
!= NULL
); }
53 virtual AsyncCall::Pointer
callback() const { return new Call_(*call
); }
56 const RefCount
<Call_
> call
; ///< gets copied to create callback calls
59 #endif /* _SQUID_BASE_SUBSCRIPTION_H */