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/InstanceId.h"
14#include "event.h"
15#include "RefCount.h"
16
37class CallDialer;
38
40{
41public:
43
44 AsyncCall(int aDebugSection, int aDebugLevel, const char *aName);
45 ~AsyncCall() override;
46
47 void make(); // fire if we can; handles general call debugging
48
49 // can be called from canFire() for debugging; always returns false
50 bool cancel(const char *reason);
51
52 bool canceled() const { return isCanceled != nullptr; }
53
54 virtual CallDialer *getDialer() = 0;
55
56 void print(std::ostream &os);
57
60
62 theNext = aNext;
63 }
64
66 return theNext;
67 }
68
69public:
70 const char *const name;
71
74
75 const int debugSection;
76 const int debugLevel;
78
79protected:
80 virtual bool canFire();
81
82 virtual void fire() = 0;
83
85
86private:
87 const char *isCanceled; // set to the cancellation reason by cancel()
88
89 // not implemented to prevent nil calls from being passed around and unknowingly scheduled, for now.
92};
93
94inline
95std::ostream &operator <<(std::ostream &os, AsyncCall &call)
96{
97 call.print(os);
98 return os;
99}
100
106{
107public:
109 virtual ~CallDialer() {}
110
111 // TODO: Add these for clarity when CommCbFunPtrCallT is gone
112 //virtual bool canDial(AsyncCall &call) = 0;
113 //virtual void dial(AsyncCall &call) = 0;
114
115 virtual void print(std::ostream &os) const = 0;
116};
117
122template <class DialerClass>
124{
125public:
126 using Dialer = DialerClass;
127
128 AsyncCallT(int aDebugSection, int aDebugLevel, const char *aName,
129 const Dialer &aDialer): AsyncCall(aDebugSection, aDebugLevel, aName),
130 dialer(aDialer) {}
131
134 dialer(o.dialer) {}
135
136 ~AsyncCallT() override {}
137
138 CallDialer *getDialer() override { return &dialer; }
139
141
142protected:
143 bool canFire() override {
144 return AsyncCall::canFire() &&
145 dialer.canDial(*this);
146 }
147 void fire() override { dialer.dial(*this); }
148
149private:
150 AsyncCallT & operator=(const AsyncCallT &); // not defined. call assignments not permitted.
151};
152
153template <class Dialer>
155asyncCall(int aDebugSection, int aDebugLevel, const char *aName,
156 const Dialer &aDialer)
157{
158 return new AsyncCallT<Dialer>(aDebugSection, aDebugLevel, aName, aDialer);
159}
160
162bool ScheduleCall(const char *fileName, int fileLine, const AsyncCall::Pointer &);
163
165#define ScheduleCallHere(call) ScheduleCall(__FILE__, __LINE__, (call))
166
167#endif /* SQUID_ASYNCCALL_H */
168
std::ostream & operator<<(std::ostream &os, AsyncCall &call)
Definition: AsyncCall.h:95
RefCount< AsyncCallT< Dialer > > asyncCall(int aDebugSection, int aDebugLevel, const char *aName, const Dialer &aDialer)
Definition: AsyncCall.h:155
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
CallDialer * getDialer() override
Definition: AsyncCall.h:138
DialerClass Dialer
Definition: AsyncCall.h:126
~AsyncCallT() override
Definition: AsyncCall.h:136
AsyncCallT(int aDebugSection, int aDebugLevel, const char *aName, const Dialer &aDialer)
Definition: AsyncCall.h:128
void fire() override
Definition: AsyncCall.h:147
AsyncCallT & operator=(const AsyncCallT &)
Dialer dialer
Definition: AsyncCall.h:140
bool canFire() override
Definition: AsyncCall.h:143
AsyncCallT(const AsyncCallT< Dialer > &o)
Definition: AsyncCall.h:132
const int debugLevel
Definition: AsyncCall.h:76
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
RefCount< AsyncCall > Pointer
Definition: AsyncCall.h:42
const InstanceId< AsyncCall > id
Definition: AsyncCall.h:77
~AsyncCall() override
Definition: AsyncCall.cc:33
AsyncCall(const AsyncCall &)
bool cancel(const char *reason)
Definition: AsyncCall.cc:56
bool canceled() const
Definition: AsyncCall.h:52
AsyncCall::Pointer & Next()
Definition: AsyncCall.h:65
const int debugSection
Definition: AsyncCall.h:75
void print(std::ostream &os)
Definition: AsyncCall.cc:74
virtual CallDialer * getDialer()=0
const char * isCanceled
Definition: AsyncCall.h:87
AsyncCall::Pointer theNext
for AsyncCallList and similar lists
Definition: AsyncCall.h:84
void make()
Definition: AsyncCall.cc:39
const char *const name
Definition: AsyncCall.h:70
CodeContext::Pointer codeContext
what the callee is expected to work on
Definition: AsyncCall.h:73
void setNext(AsyncCall::Pointer aNext)
Definition: AsyncCall.h:61
virtual ~CallDialer()
Definition: AsyncCall.h:109
virtual void print(std::ostream &os) const =0

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors