AsyncCall.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9#ifndef SQUID_ASYNCCALL_H
10#define SQUID_ASYNCCALL_H
11
12#include "base/CodeContext.h"
13#include "base/forward.h"
14#include "base/InstanceId.h"
15#include "event.h"
16#include "RefCount.h"
17
38class CallDialer;
39
41{
42public:
44
45 AsyncCall(int aDebugSection, int aDebugLevel, const char *aName);
46 ~AsyncCall() override;
47
48 void make(); // fire if we can; handles general call debugging
49
50 // can be called from canFire() for debugging; always returns false
51 bool cancel(const char *reason);
52
53 bool canceled() const { return isCanceled != nullptr; }
54
55 virtual CallDialer *getDialer() = 0;
56
57 void print(std::ostream &os);
58
61
63 theNext = aNext;
64 }
65
67 return theNext;
68 }
69
70public:
71 const char *const name;
72
75
76 const int debugSection;
77 const int debugLevel;
79
80protected:
81 virtual bool canFire();
82
83 virtual void fire() = 0;
84
86
87private:
88 const char *isCanceled; // set to the cancellation reason by cancel()
89
90 // not implemented to prevent nil calls from being passed around and unknowingly scheduled, for now.
93};
94
95inline
96std::ostream &operator <<(std::ostream &os, AsyncCall &call)
97{
98 call.print(os);
99 return os;
100}
101
107{
108public:
110 virtual ~CallDialer() {}
111
112 // TODO: Add these for clarity when CommCbFunPtrCallT is gone
113 //virtual bool canDial(AsyncCall &call) = 0;
114 //virtual void dial(AsyncCall &call) = 0;
115
116 virtual void print(std::ostream &os) const = 0;
117};
118
123template <class DialerClass>
125{
126public:
127 using Dialer = DialerClass;
128
129 AsyncCallT(int aDebugSection, int aDebugLevel, const char *aName,
130 const Dialer &aDialer): AsyncCall(aDebugSection, aDebugLevel, aName),
131 dialer(aDialer) {}
132
135 dialer(o.dialer) {}
136
137 ~AsyncCallT() override {}
138
139 CallDialer *getDialer() override { return &dialer; }
140
142
143protected:
144 bool canFire() override {
145 return AsyncCall::canFire() &&
146 dialer.canDial(*this);
147 }
148 void fire() override { dialer.dial(*this); }
149
150private:
151 AsyncCallT & operator=(const AsyncCallT &); // not defined. call assignments not permitted.
152};
153
154template <class Dialer>
156asyncCall(int aDebugSection, int aDebugLevel, const char *aName,
157 const Dialer &aDialer)
158{
159 return new AsyncCallT<Dialer>(aDebugSection, aDebugLevel, aName, aDialer);
160}
161
163bool ScheduleCall(const char *fileName, int fileLine, const AsyncCall::Pointer &);
164
166#define ScheduleCallHere(call) ScheduleCall(__FILE__, __LINE__, (call))
167
168#endif /* SQUID_ASYNCCALL_H */
169
std::ostream & operator<<(std::ostream &os, AsyncCall &call)
Definition: AsyncCall.h:96
RefCount< AsyncCallT< Dialer > > asyncCall(int aDebugSection, int aDebugLevel, const char *aName, const Dialer &aDialer)
Definition: AsyncCall.h:156
bool ScheduleCall(const char *fileName, int fileLine, const AsyncCall::Pointer &)
Definition: AsyncCall.cc:94
#define RefCountable
The locking interface for use on Reference-Counted classes.
Definition: Lock.h:66
squidaio_request_t * head
Definition: aiops.cc:127
RefCount< AsyncCall > AsyncCallPointer
Definition: forward.h:30
CallDialer * getDialer() override
Definition: AsyncCall.h:139
DialerClass Dialer
Definition: AsyncCall.h:127
~AsyncCallT() override
Definition: AsyncCall.h:137
AsyncCallT(int aDebugSection, int aDebugLevel, const char *aName, const Dialer &aDialer)
Definition: AsyncCall.h:129
void fire() override
Definition: AsyncCall.h:148
AsyncCallT & operator=(const AsyncCallT &)
Dialer dialer
Definition: AsyncCall.h:141
bool canFire() override
Definition: AsyncCall.h:144
AsyncCallT(const AsyncCallT< Dialer > &o)
Definition: AsyncCall.h:133
const int debugLevel
Definition: AsyncCall.h:77
virtual bool canFire()
Definition: AsyncCall.cc:67
virtual void fire()=0
void dequeue(AsyncCall::Pointer &head, AsyncCall::Pointer &prev)
remove us from the queue; we are head unless we are queued after prev
Definition: AsyncCall.cc:84
const InstanceId< AsyncCall > id
Definition: AsyncCall.h:78
~AsyncCall() override
Definition: AsyncCall.cc:33
AsyncCall(const AsyncCall &)
bool cancel(const char *reason)
Definition: AsyncCall.cc:56
bool canceled() const
Definition: AsyncCall.h:53
AsyncCall::Pointer & Next()
Definition: AsyncCall.h:66
const int debugSection
Definition: AsyncCall.h:76
void print(std::ostream &os)
Definition: AsyncCall.cc:74
virtual CallDialer * getDialer()=0
const char * isCanceled
Definition: AsyncCall.h:88
AsyncCall::Pointer theNext
for AsyncCallList and similar lists
Definition: AsyncCall.h:85
void make()
Definition: AsyncCall.cc:39
const char *const name
Definition: AsyncCall.h:71
CodeContext::Pointer codeContext
what the callee is expected to work on
Definition: AsyncCall.h:74
void setNext(AsyncCall::Pointer aNext)
Definition: AsyncCall.h:62
virtual ~CallDialer()
Definition: AsyncCall.h:110
virtual void print(std::ostream &os) const =0

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors